[IronPython] Overriding .NET methods within IronPython

Shri Borde Shri.Borde at microsoft.com
Fri Oct 23 21:10:30 CEST 2009


See the section on "Overriding methods" in http://ironpython.codeplex.com/SourceControl/changeset/view/60398#1011839 (IronPython_Main\Doc\dotnet-integration.rst) for more details on overriding, like dealing with ref params. We are working on making the info easily accessible, but for now, you can browse the content from the rst file.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Brian Curtin
Sent: Friday, October 23, 2009 11:53 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Overriding .NET methods within IronPython

I'm not sure what I was doing wrong when this clearly simpler way wasn't working, but this pretty much answers my question: do this - Form.OnLoad(self, evt_args)

Sorry for the noise.
On Fri, Oct 23, 2009 at 13:45, Brian Curtin <brian.curtin at gmail.com<mailto:brian.curtin at gmail.com>> wrote:
Hey list,

I think I got this right, and it seems to work, but I just feel like there is probably a better way to override a method in IP. Some time spent googling doesn't bring anything up except for IP/C# code examples containing the override keyword. For example, I want to override the Form class' OnLoad method, so I wrote a decorator to do so.

class frm(Form):
    def __init__(self):
            Form.__init__(self)

    def override(method):
        def inner(*args):
            base = super(Form, args[0]) #args[0] is frm instance
            base_method = getattr(base.__thisclass__, method.__name__)
            method(*args) #call our method first
            return base_method(*args)
        return inner

    @override
    def OnLoad(self, evt_args):
            print evt_args

It doesn't do anything snazzy - just prints out the EventArgs, then calls the base class Form.OnLoad.

Any thoughts?

Brian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091023/38124ba3/attachment.html>


More information about the Ironpython-users mailing list