Does someone knows if it’s possible to dynamically create a call chain and invoke it?
Lets say I have two classes A & B:
public class A public function Func() as B return new B() end function end class public class B public function Name() as string return 'a string'; end function end class
I want to be able to get MethodInfo for both Func() & Name() and invoke them dynamically so that I can get a call similar to A.Func().Name().
I know I can use Delegate.CreateDelegate to create a delegate I can invoke from the two MethodInfo objects but this way I can only call the two functions separately and not as part of a call chain.
I would like two solutions one for .NET 3.5 using expression tree and if possible a solution that is .NET 2.0 compatible as well
Are you using .NET 3.5? If so, it should be relatively straightforward to build an expression tree to represent this. I don’t have enough expression-tree-fu to easily write the relevant tree without VS open, but if you confirm that it’s an option, I’ll get to work in notepad (from my Eee… hence the lack of VS).
EDIT: Okay, as an expression tree, you want something like (C# code, but I’m sure you can translate):
This is untested, but I think it should work…