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

Doug Blank doug.blank at gmail.com
Fri Mar 16 16:45:55 CET 2012


On Fri, Mar 16, 2012 at 11:36 AM, Jeff Hardy <jdhardy at gmail.com> wrote:
> On Fri, Mar 16, 2012 at 4:24 AM, Doug Blank <doug.blank at gmail.com> wrote:
>> This is looking more and more like a bug. I see from
>> http://stackoverflow.com/questions/799987/how-to-pass-a-lambda-expression-to-a-c-sharp-constructor-from-an-ironpython-scri
>>
>> that it works for constructors (and have verified that it does), but I
>> can't figure out any way to make it work with a static method. Why the
>> difference?
>
> Well, it could just be a bug :), and I haven't investigated it at all,
> so this is speculation. However, in the first method (the params []
> one) the callables are being passed directly, while in the second
> they're being converted as part of a list -> List<> conversion.
> IronPython's conversion code is, um, interesting -- Dino might
> understand it all, but I don't know if anyone else does -- so it's
> possible two different sets of conversions are being chosen. Now, this
> *shouldn't* be the case, but it's my hypothesis.
>
>>
>> If it is a bug, is there a workaround? How can I pass any Python
>> callable to a C# static method?
>
> Try the conversion on the Python side, manually:
>
>    f = System.Func[System.Object](test1)
>    Myro.getFunc1(f)
>    Myro.getFunc2([f])

That might work, but I don't want to use it that way. Developing
introductory educational materials, and I don't want to blow any young
minds... just yet :)

> Oh, and please open an issue on Codeplex with a minimal reproduction,
> if you can.

Will do!

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.

-Doug

> - Jeff


More information about the Ironpython-users mailing list