[Python.NET] Custom delegates and wrapping class instance in .netobject
Brian Lloyd
brian at zope.com
Thu Jan 19 20:30:41 CET 2006
> What I need is a custom delegate. If it was a C# program, it
> would be really easy to create:
> public delegate void DataArrived(object data);
>
> With Python.Net I don't see how I can do that. What I ended up doing is
> writing a simple assembly in C# that just contains the following lines:
>
> public delegate void NoArgDelegate();
> public delegate void ObjectArgDelegate(object arg);
> public delegate void ArrayArgDelegate(object[] arg);
>
> My hope is to keep this utility assembly around for those times when I
> need a custom delegate. The delegates are somewhat general and with the
> last one, it is possible to pass as many arguments as needed. I would
> like to know, however, if anyone else encountered this problem and how
> they solved it. Is there a way to solve it with pure Python .Net
> (without C#)? If not, maybe a custom delegate(s) should be included into
> Python .Net?
I don't think I understand what you're trying to do well enough
to advise here - if you can post an example that would be
helpful.
>
> My second problem is that I can't pass Python class instances as
> arguments to my delegates. For example:
>
> def callback(arg):
> pass
> d = ObjectArgDelegate(callback)
>
> class PythonClass(object):
> pass
>
> d(PythonClass())
>
> Results in:
>
> TypeError: no method matches given arguments
>
>
> Is there a way to convert a python class instance to a .Net object and
> then convert it back to python class instance?
In this case, you should just be able to have PythonClass
inherit from System.Object - that will get it a default
conversion that should work for what you want to do.
Brian Lloyd brian at zope.com
V.P. Engineering 540.361.1716
Zope Corporation http://www.zope.com
More information about the PythonDotNet
mailing list