[Ironpython-users] Passing an IronPython function to C#

Jeff Hardy jdhardy at gmail.com
Fri Mar 16 17:26:15 CET 2012


On Fri, Mar 16, 2012 at 8:45 AM, Doug Blank <doug.blank at gmail.com> wrote:
> Can you think of *any* workaround on the C# side? Nothing I have tried
> will allow me to get a Python-based function (lambda, PythonFunction,
> builtin) out of an IList as a Func.

If you're in C# 4 this should work:

    void test3(IList<dynamic> functions) {
        return (Func<object>)functions[0];
    }

If not (or C# 3.5), you'll need to use DynamicOperations (totally untested!):
    void test4(CodeContext context, IList<object> functions) {
        return new
DynamicOperations(context.LanguageContext).ConvertTo<Func<object>>(functions[0]);
    }

- Jeff


More information about the Ironpython-users mailing list