[IronPython] can't override LayoutEngine property

Jonathan Amsterdam jba at ELLINGTON.com
Fri Apr 27 16:05:07 CEST 2007

Thanks for digging into it.  A fix in the next release will be fine.
Rather than recompile IP, I worked around it by writing a C# class that
overrides the property.

-----Original Message-----
From: Dino Viehland [mailto:dinov at exchange.microsoft.com] 
Sent: Thursday, April 26, 2007 4:45 PM
To: Discussion of IronPython
Subject: Re: [IronPython] can't override LayoutEngine property

Wow, after digging into this some more I gotta say: this is very
interesting and may be a CLR bug.  The short of this is there's a bug
here and there's at least a work around (from the perspective of you can
rebuild IronPython :) ).

In Src\IronPython\Compiler\Generation\NewTypeMaker.cs there's a function
called OverrideSpecialName.  It's signature needs a new parameter:

private void OverrideSpecialName(Type type, MethodInfo mi,
Dictionary<string, bool> specialNames) {

and then that parameter needs to be used for the GetProperties call:

PropertyInfo[] pis = type.GetProperties(BindingFlags.Instance |
BindingFlags.Public | BindingFlags.NonPublic);

There's 1 caller to this function in OverrideVirtualMethods and it just
needs to pass type:

OverrideSpecialName(type, mi, specialNames);

Here's an explanation of what's going on.  We are calling GetMethods()
on Panel which returns the methods for Panel and all of its subtypes -
including Control.  We are then filtering those down to virtual methods
and trying to find the property they are associated with.  At that point
in time we call GetProperties() on the method's declaring type (in this
case, Control) to get all of the properties.  We then go through each
property trying to find the property who has a get or set method that
matches this method (get_LayoutEngine).

What's strange is that we come to a point where we have a
get_LayoutEngine method declared on Control that we grabbed from Panel,
and we have a get_LayoutEngine method declared on Control that we
grabbed from Control's LayoutEngine property.  For some reason these two
methods aren't comparing equal even though they're the exact same

Given that we have a workaround for IronPython I'll open a bug (9908 -
and this should go into the next stable release.

I'll also follow up with the CLR team and see if they believe this is a
bug and if so get that fixed as well.

Thanks for reporting this...  Hopefully the workaround won't be too much
trouble until we get the next release out.

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jonathan
Sent: Thursday, April 26, 2007 12:23 PM
To: users at lists.ironpython.com
Subject: Re: [IronPython] can't override LayoutEngine property

Thanks for your prompt reply.  Unfortunately, your suggestion doesn't
work either (it gives the same result when invoked from C#).  Moreover,
the first way (name = property(...)) worked fine when I just built my
own C# class with its own virtual property.

Date: Thu, 26 Apr 2007 11:04:08 -0700
From: Dino Viehland <dinov at exchange.microsoft.com>
Subject: Re: [IronPython] can't override LayoutEngine property
To: Discussion of IronPython <users at lists.ironpython.com>

<7AD436E4270DD54A94238001769C22278F5F482E0B at DF-GRTDANE-MSG.exchange.corp

Content-Type: text/plain; charset="us-ascii"

I believe currently you need to do:

                def get_MyLayoutEngine(self): return mle

to get the get_ method to override this.  A couple of people have ran
into this and we don't seem to have a bug on it so I've opened bug #9902
to make this more intuitive.

From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jonathan
Sent: Thursday, April 26, 2007 8:23 AM
To: users at lists.ironpython.com
Subject: [IronPython] can't override LayoutEngine property

I'm trying to overrride the LayoutEngine property of Control so I can
implement my own layout engine. I find that this doesn't work in IP.
Accessing the LayoutEngine property in IP works fine, but it doesn't
work from C#.

//////////////////// C# code:

   public class MyCSharpClass
        public static LayoutEngine getLayoutEngine(Panel p)
            return p.LayoutEngine;

//////////////////// Python code:

class MyLayoutEngine(LayoutEngine):
    def Layout(self, parent, eventArgs):

mle = MyLayoutEngine()

class MyPanel(Panel):
    LayoutEngine = property(lambda self: mle)

p = MyPanel()
print "from Python:", p.LayoutEngine
print "from C#:", MyCSharpClass.getLayoutEngine(p)

//////////////////// output:
from Python: <MyLayoutEngine object at 0x000000000000002B>
from C#: System.Windows.Forms.Layout.DefaultLayout

Email transmissions can not be guaranteed to be secure or error-free, as
could be intercepted, corrupted, lost, destroyed, arrive late or
incomplete, or contain
viruses.  The sender therefore does not accept liability for any errors
or omissions in
the contents of this message which arise as a result of email
transmission.  In addition,
the information contained in this email message is intended only for use
of the
individual or entity named above.  If the reader of this message is not
the intended
recipient, or the employee or agent responsible to deliver it to the
intended recipient,
you are hereby notified that any dissemination, distribution, or copying
of this communication,
disclosure of the parties to it, or any action taken or omitted to be
taken in reliance on it,
is strictly prohibited, and may be unlawful.  If you are not the
intended recipient please
delete this email message.

users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list