[IronPython] Reflection.Emit from IronPython: What is theequivalent of typeof() in C# ?

Robert Smallshire robert at smallshire.org.uk
Fri Aug 7 19:51:04 CEST 2009


Hi Shri,

> You can also just use the type like "System.String" to avoid 
> having to create an instance of the type.
>  
> >>> import System
> >>> import clr
> >>> clr.GetClrType(System.String)
> <System.RuntimeType object at 0x000000000000002B [System.String]>

That's the same as the fourth example in my original message and doesn't
work. Prompted by your first sentence I've also tried simply,

  generator.Emit(OpCodes.Newarr, System.String)

but I'm still getting RuntimeType[] rather than String[] in the generated
IL.

Thanks,

Rob

> > Robert Smallshire wrote:
> > > Hello,
> > >
> > > I'm attempting to drive the Reflection.Emit API from
> > IronPython. In C#
> > > typical Reflection.Emit use makes use typeof(...) facility
> > in C#, to
> > > enable the determination of types without needing an
> > instance of that
> > > type.
> > >
> > > For example, to create an array of .NET CTS Strings in IL
> > from C# one
> > > might
> > > do:
> > >
> > > generator.Emit(OpCodes.Newarr, typeof(string));
> > >
> > > where the second argument to Emit is the element type of 
> the array.
> > >
> > > I've tried various alternatives from IronPython, including
> > >
> > > generator.Emit(OpCodes.Newarr, 
> System.Type.GetType('System.String'))
> > > generator.Emit(OpCodes.Newarr, str().GetType()) 
> > > generator.Emit(OpCodes.Newarr, System.String().GetType()) 
> > > generator.Emit(OpCodes.Newarr, clr.GetClrType(System.String))
> > >
> > > however, all of these result in RuntimeType[] rather than
> > String[] in
> > > the generated CIL.
> > >
> > > How do I get typeof(System.String) from IronPython?
> > >
> > > Rob
> > >
> > > Robert Smallshire
> > > robert at smallshire.org.uk
> > > http://smallshire.org.uk/
> > > Currently in Norway (UTC +2 hours)
> > >
> > > _______________________________________________




More information about the Ironpython-users mailing list