Can you take a dependency on IronPython.dll? If so you can cast to IPythonType and get the type from there.
The reason __class__ doesn't work is that it's declared on object in Python and C# doesn't see it because it only recognizes .NET members on object. All members declared on CLR types are provide by the accessing language as a principle of the DLR. I'm not sure there's a way to do it w/o depending on .NET. We do declare a public field called ".class" at the IL level but C# (purposefully) won't have a way to access it due to the inconvenient name. It may be possible to create a C# binder and call site (you can use reflector on your dynamic code to see the non-dynamic version of the C# code this produces) which uses the name ".class" but if that works it's probably a bad idea to rely upon it. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Andreas Schlapsi Sent: Tuesday, September 28, 2010 3:12 PM To: users@lists.ironpython.com Subject: [IronPython] Getting Python class of dynamic object from C# Hi! I'd like to get the class name (including the name of the module) of a dynamic object (IronPython object) in C#. I tried to get the class instance with code similar to that: dynamic myobject = item; dynamic itemClass = myobject.__class__; Unfortunately this doesn't work. I could get the class name using the ICustomTypeDescriptor interface, but this doesn't include the module. Is there a way to do this? Andreas
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com