As an extension of this question: How do I create a C# event handler that can be handled in IronPython?
My IronPython script looks like this:
def BarHandler(*args):
Foo.Bar -= BarHandler
Foo.Bar += BarHandler
There are no errors, but BarHandler will ALWAYS be called and will never unregister itself. Now, if the code looks like this:
def BarHandler(*args):
Foo.Bar -= BarHandler
Foo.Bar += BarHandler
Foo.Bar -= BarHandler
BarHandler will never be called. This leads me to believe that the BarHandler referred to within BarHandler is a separate instance which isn't getting removed from a list it doesn't belong to. However, something like Foo.Bar -= self
results in UnboundNameException: global name 'self' is not defined
. I assume it's because the C# event is not passing self
as an argument but I haven't been able to get anything like that to compile. Closest I've come is:
if (changed_selection != null) { //sending message to all delegates
changed_selection(changed_selection, this, e);
}
Which I know is incorrect but I haven't been able to figure out.
It's probably useful to know I'm using IronPython with Unity so I'm on Mono 2.6 which is essentially a bastard version of C# 2.0.