(string statements, IListstring> parameters) method.
Here we have to do a little reflection, simply because we cant directly use a local variable of type "Type" as a generic type
parameter, so we grab the generic method, set the parameter and then invoke it.
However in the end, as you can see we get a real Delegate, which we can use DynamicInvoke upon.
This is actually pretty handy, and it's certainly a lot more script-friendly, compared to the alternative of forcing users to
look up values from context by index ie.
context['user'] + ' is ' + str(context['age']) +
' years old'
vs.
user + ' is ' + str(age) + ' years old'
I know what I prefer ;o)
" />
(string statements, IListstring> parameters) method.
Here we have to do a little reflection, simply because we cant directly use a local variable of type "Type" as a generic type
parameter, so we grab the generic method, set the parameter and then invoke it.
However in the end, as you can see we get a real Delegate, which we can use DynamicInvoke upon.
This is actually pretty handy, and it's certainly a lot more script-friendly, compared to the alternative of forcing users to
look up values from context by index ie.
context['user'] + ' is ' + str(context['age']) +
' years old'
vs.
user + ' is ' + str(age) + ' years old'
I know what I prefer ;o)
" />

The final solution (for generic IronPython delegates)...

Back once more...

I decided to spend ten minutes implementing a version of the last post which didn't require us to generate a function definition for a python method with a generic number of parameters... it's actually not too hard.

First off, the key to solving this problem is to generate a Type for our custom delegate - for performance reasons you would want to cache the results, but we won't do that here... Also I think it would be more apropriate for the first 0->9 parameters that we just return a generic Func delegate (generic Func & Proc delegates are going to be part of .Net 3.0, as mentioned here - At the moment I use something similar from the RhinoCommons library, have a look here)

So, first off we build a helper method for generating our delegate - just heavy use of emit here, based off an example on MSDN:

Our test creates our custom delegate type for the number of parameters we have, and then we use that when invoking thePythonEngine.CreateMethodTDelegate>(string statements, IListstring> parameters) method.

Here we have to do a little reflection, simply because we cant directly use a local variable of type "Type" as a generic type
parameter, so we grab the generic method, set the parameter and then invoke it.

However in the end, as you can see we get a real Delegate, which we can use DynamicInvoke upon.

This is actually pretty handy, and it's certainly a lot more script-friendly, compared to the alternative of forcing users to
look up values from context by index ie.