[IronPython] IronPython and polymorphism? Help with interfaces
Miha Valencic
miha.valencic at gmail.com
Wed Jan 23 22:06:45 CET 2008
Dino,
thanks for the informative answer with samples. I agree with what you write,
but that was not what I had in mind. Consider this c# code:
IPerson foo = new Person();
foo.Name; // works in c#, because foo is of type IPerson.
in ipy, I can not explicitly define an Interface type like
foo = IPerson(Person())
And even if I pass the IPerson to ipy, ipy will "see" the first
implementation, not the type I am passing. So, If I have something like
this:
locals["foo"] = foo;, where foo is defined as:
IFoo1 foo = new Foo() as IFoo1;
where
Foo: BaseFoo, IFoo1, IFoo2
and BaseFoo is defined as
BaseFoo : IFoo1, IFoo2
and IFoo1 { string Name {get;set;}}
then Python will "see" the object passed in as BaseFoo, as this is the only
implementation (although we want to pass in the "contract", interface
IFoo1).
I know it looks complicated... In short:
If I pass ISomething to c#, I can call it. If I pass ISomething to ipy, it
"knows better" and treats it as BaseSomething or whatever the first class
is. ;)
Maybe a strong-typed method of passing in the locals/globals would help.
Something like anonymous types, perhaps?
IMyInteface myInterface = ....
engine.Execute("print foo.Name", eng.CreateModule(), new { foo = myInterface
});
Miha
On Jan 23, 2008 9:35 PM, Dino Viehland <dinov at exchange.microsoft.com> wrote:
> I agree, we should document it, unfortunately our documentation is still
> woefully inadequate L.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080123/9a813db5/attachment.html>
More information about the Ironpython-users
mailing list