[IronPython] .NET Events in IronPython
Martin.Maly at microsoft.com
Tue Nov 15 02:23:23 CET 2005
After playing with this for a bit, I think that at the moment IronPython is not capable of what you can do below in C#. The insurmountable (for now, I hope) obsctacle that I hit is that the events must be sealed classes, inherited from an abstract MulticastDelegate. IronPython doesn't know of this rule and for now doesn't generate sealed class and the IronPython code that attempts to mimic the output of C# compiler throws exception "delegate must be a sealed class".
I think that as we improve the 'static compiler' story, we may need to support creating sealed classes. For now, the scenario below is broken...
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Shilman
Sent: Friday, November 11, 2005 12:59 PM
To: Discussion of IronPython
Subject: [IronPython] .NET Events in IronPython
Is there any way to declare .NET events in IronPython?
Here is a simple example in C# that "abstracts" a button pressed event into a "hello" event:
public delegate void HelloInvoked();
public class HelloControl : Panel
public event HelloInvoked Hello;
Button b = new Button();
b.Text = "Hello";
b.Click += new EventHandler(b_Click);
b.Dock = DockStyle.Fill;
void b_Click(object sender, EventArgs e)
if (Hello != null) Hello();
I can do something equivalent with Python functions:
Hello = 
b = Button(Text="Hello",Dock=DockStyle.Fill)
b.Click += self.on_Click
for h in self.Hello: h()
def Foo(): print "hello"
hc.Hello += [Foo]
But for consistency with my other C# code I'd like to use events if possible.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users