[IronPython] Problem calling proper version of function

Dino Viehland dinov at microsoft.com
Wed Sep 3 05:22:46 CEST 2008


We never have strong typing so we'll never see the difference between GetInterface() and GetClass(). Instead we'll always just see that we have a MyClass and do the lookup based upon that.  The worst case scenario here is you'll need to do IMyInterface.MyProperty.GetValue(instance).

OTOH if you can make MyClass or "public string MyProperty" internal then they'd just not be visible to IronPython.  That'd mean we'd pick up the explicit interface implementation as of the IronPython 2.0B4 I believe.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Steve Baer
Sent: Tuesday, September 02, 2008 8:02 PM
To: Users at lists.ironpython.com
Subject: [IronPython] Problem calling proper version of function

This may just be how Python works, but I wanted to check with you guys
first.

Say I have an assembly named MyLibrary that contains the following code:
namespace MyLibrary
{
  public interface IMyInterface
  {
    string MyProperty{ get;}
  }
  public class MyClass : IMyInterface
  {
    string IMyInterface.MyProperty
    {
      get { return "MyInterface version of MyProperty"; }
    }
    public string MyProperty
    {
      get { return "MyClass version of MyProperty"; }
    }
    public static IMyInterface GetInterface(){ return new MyClass();}
    public static MyClass GetClass() { return new MyClass(); }
  }
}
-------------------------------------------------------------
A console application with the following code
  MyLibrary.IMyInterface a = MyLibrary.MyClass.GetInterface();
  Console.WriteLine("MyInterface call = " + a.MyProperty);
  MyLibrary.MyClass b = MyLibrary.MyClass.GetClass();
  Console.WriteLine("MyClass call = " + b.MyProperty);

Will produce the following output:
  MyInterface call = MyInterface version of MyProperty
  MyClass call = MyClass version of MyProperty
-------------------------------------------------------------

Now if I use IronPython and write a script that looks like the following

import clr
clr.AddReference("MyLibrary")
import MyLibrary
a = MyLibrary.MyClass.GetInterface()
print "MyInterface call = ", a.MyProperty
b = MyLibrary.MyClass.GetClass()
print "MyClass call = ", b.MyProperty

The output of this script is
MyInterface call = MyClass version of MyProperty
MyClass call = MyClass version of MyProperty

I've been testing IronPython on our CAD application and everything has been
working great except for this issue. It is actually a pretty big issue for
me because the way I wrapped our C++ SDK for .NET uses this feature quite a
bit. If this is the expected result in python, is there a way to force the
interface version of the property_get function to be called?

Thanks,
-Steve

Steve Baer
Robert McNeel & Associates
www.rhino3d.com
www.mcneel.com

_______________________________________________
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