[IronPython] RuntimeType from PythonType in C# code
dinov at microsoft.com
Thu Apr 9 18:19:17 CEST 2009
There is an implicit conversion from PythonType -> Type. So (Type)(PythonType)o will work here. Alternately you can just strongly type a function in C# as taking a Type and call that from Python and the conversion will happen automatically.
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Alex News
> Sent: Thursday, April 09, 2009 9:14 AM
> To: users at lists.ironpython.com
> Subject: [IronPython] RuntimeType from PythonType in C# code
> I have embedded IronPython 2.01 into my C# application, and am
> extremely impressed by the ease of integration and the
> interoperability with the .NET types. However I am a bit stumped by
> something that probably is quite simple.
> 1) In a python script, I import one of my application types.
> 2) From that script I call a function implemented in C#. I pass in
> the type (not an instance of the type)
> 3) My C# function sees a PythonType. I would like to get the
> associated RuntimeType, but can't figure out how to do so.
> For example (using a system type):
> from System import String
> myfunction(String) # calls C# delegate defined below
> delegate(object o)
> // o is of type PythonType. I would like to get the associated
> System.RuntimeType (in this case System.String)
> I've searched the web, but most of the advice seems outdated:
> PythonType.UnderlyingSystemType is internal, so I can't access it.
> I'm not sure what "Ops" is. I suspect it is related to the namespace
> IronPython.Runtime.Operations, but I can't find an equivalent
> class/function in there (although there is quite a bit there, so I may
> have missed it).
> Any help would be greatly appreciated.
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users