[IronPython] Ironpython interop with C# - delegates

Pawel Gielmuda pawel.gielmuda at hotmail.com
Tue Sep 15 10:30:32 CEST 2009


Hello to all

Can you help me with this. I'm trying to extend my application with IronPython. I have class that I want to assign delegate from IronPython script. Here is an example:
public class T
{
        public int I { get; set; }
        public delegate void FunDelegate();
        public FunDelegate Fun;
}

And then I'm trying to assign Python function to my delegate(ScriptRunner is just a wrapper for calling IP code)
            T test = new T();
            Console.WriteLine(test.I);
            ScriptRunner.RunCode(@"def Fun():
    I = 10

Obj.Fun= Fun", ref test);

And this code fails with exception 
Object of type 'IronPython.Runtime.PythonFunction' cannot be converted to type 'testesting.T+FunDelegate'.

Is there any way to avoid this? Or there is a better way

Thanks for help
Pawel


_________________________________________________________________
Funkcja Co Nowego wyświetla informacje w czasie rzeczywistym. Pokaż mi jak.
http://home.live.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090915/2351b0fe/attachment.html>


More information about the Ironpython-users mailing list