[IronPython] Add/remove python function to C# event in C#
Dino Viehland
dinov at exchange.microsoft.com
Mon Jul 14 03:19:34 CEST 2008
It should just work in the next release :). There are problems with it right now but I checked in a fix to make this work last week.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Sunday, July 13, 2008 6:12 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Add/remove python function to C# event in C#
On Sun, Jul 13, 2008 at 7:20 PM, Dino Viehland
<dinov at exchange.microsoft.com> wrote:
> Ahh I see what you mean now. If you're doing this from the hosting APIs you can use the ObjectOperations class to do the conversion:
>
> someObj.someEvent += objOps.ConvertTo<DelegateType>(obj);
That is disturbingly easy. I knew you'd know the answer.
But I wonder if that would work for removing a handler from an event?
someObj.someEvent += objOps.ConvertTo<DelegateType>(obj);
someObj.someEvent -= objOps.ConvertTo<DelegateType>(obj);
One workaround might be to cache the delegate on the way in and use
the cached delegate to remove it.
_cache[obj] = objOps.ConvertTo<DelegateType>(obj);
someObj.someEvent += _cache[obj]
someObj.someEvent -= _cache[obj]
But maybe there's a better way, or maybe I'm daft and it'll just work.
-Dan
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list