Hi!<br><br>I'm having troubles accessing .NET object properties from ipy. Object<br>is passed to IronPython 1.1 and IronPython breaks with error:<br>Unhandled Exception: System.MissingMemberException: 'Person' object
<br>has no attribute 'Name'<br><br>This is all due to the fact, that this object is based on an<br>interface, which is based on an interface. To make things clearer I've<br>created a simple problem-statement program, which demonstrates the
<br>behavior.<br><br>Problem: IronPython can NOT access class members of an explicitly<br>implemented interface. The program that exhibits this is below, and<br>also on <a href="http://www.mihavalencic.com/temp/Program.txt" target="_blank">
http://www.mihavalencic.com/temp/Program.txt</a> (for easier<br>reading). Just compile it with IronPython.dll and it will break where<br>it shouldn't (IMHO).<br><br>I was searching information on how could I explicitly cast this object
<br>to IPerson (in the example), but could not find anyhing -- Python as a<br>language apparently does not support interfaces.<br><br>Ideas, suggestions are very welcome!<br><br>update: I even tried something like this:<br>
<br>person_explicit = IPerson("Wrapped.person);<br>print person_explicit.Name;<br><br>but I alwyas get the same error: Either the object does not have Name property or that NoneType is not callable.<br><br>Thanks,<br>
Miha.<br><br>The progarm:<br>using System;<br>using IronPython.Hosting;<br>using IronPython.Modules;<br>using System.Collections.Generic;<br><br>namespace ProblemStatement<br>{<br> public interface IPerson<br> {<br>
string Name {get;set;}<br> }<br> public class Person : IPerson<br> {<br> string IPerson.Name<br> {<br> get<br> {<br> return "Default name";<br>
}<br> set<br> {<br> }<br> }<br> }<br><br> public class Wrapper<br> {<br> public IPerson person;<br> public Wrapper(IPerson personIn)<br> {<br>
person = personIn;<br> }<br><br> }<br><br> class Program<br> {<br> static void Main(string[] args)<br> {<br> PythonEngine eng = new PythonEngine();<br> EngineModule mod =
eng.CreateModule();<br> ClrModule clr = eng.Import("clr") as ClrModule;<br> clr.AddReferenceByPartialName("ProblemStatement");<br><br> Dictionary<string, object> locals = new Dictionary<string,
<br>object>();<br><br> locals["Env"] = new Person();<br> Wrapper wrapped = new Wrapper(new Person());<br> locals["Wrapped"] = wrapped;<br><br> // this works
<br> Console.WriteLine(<a href="http://wrapped.person.name/" target="_blank">wrapped.person.Name</a>);<br><br> // this breaks<br> eng.Execute("print Env.Name", mod, locals);<br><br>
// this breaks as well<br> eng.Execute("print <a href="http://Wrapped.person.Name">Wrapped.person.Name</a>");<br> }<br> }<br>}