C# calling external method (delegate) from within
I'm generating and executing C# from within a C# program using as
described here.
As you can see, one can call "Execute" method of the compiled code via
classType.GetMethod("Execute").Invoke(instance, args).
The variable args is an object array of parameters to be passed to the
Execute method. I've been able to pass things relatively easy and without
issue using this system.
Now here's the big issue... I need to pass a callback function (eg a
Delegate) so that the Execute method will be able to signal stuff to the
main program. I've been trying to pass a typed Delegate that matches the
signature, but it failed (wouldn't even run). Next I tried passing a
Delegate without specifying the type which also failed (this time it
failed at when the call was attempted). I also tried passing it as a
normal object and cast it back inside the generated code, but it didn't do
anything different.
Since I'm not this much into C#, I think I'm missing something very basic.
Also, I don't have a valid test case code...but it shouldn't be too
difficult to work with the link I provided above..
See also: http://support.microsoft.com/kb/304655
No comments:
Post a Comment