[Mono-dev] Porting mcs to IKVM.Reflection

Kornél Pál kornelpal at gmail.com
Fri May 7 04:32:39 EDT 2010


Hi,

Thank you for applying/enhacing the patches. I'll check it out.

This code will work on both of Mono and MS.NET, but will fail without 
the WriteGenericSignature patch:

AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(new 
AssemblyName("myassembly"), AssemblyBuilderAccess.Save);
ModuleBuilder mb = ab.DefineDynamicModule("myassembly", "myassembly.dll");
TypeBuilder tb = mb.DefineType("mytype", TypeAttributes.Public);
tb.DefineGenericParameters(new string[] { "T", "U" });
ConstructorBuilder cb = 
tb.DefineDefaultConstructor(MethodAttributes.Public);
MethodBuilder method = tb.DefineMethod("mymethod", 
MethodAttributes.Static | MethodAttributes.Public, tb, Type.EmptyTypes);
ILGenerator ig = method.GetILGenerator();
ig.DeclareLocal(tb);
ig.Emit(OpCodes.Newobj, cb);
ig.Emit(OpCodes.Stloc_0);
ig.Emit(OpCodes.Ldloc_0);
ig.Emit(OpCodes.Ret);
tb.CreateType();
ab.Save("myassembly.dll");

Although using a generic type definition directly makes little sense, 
neither makes using tb.MakeGenericType(tb.GetGenericArguments()) much 
more sense, since you still can use the latter in a context that has 
fewer generic arguments.

Kornél

Jeroen Frijters wrote:
> Hi Kornél,
> 
> I've fixed most of the things that your patch addressed. I also removed support for the TypeForwardedToAttribute and DefaultParameterValueAttribute pseudo custom attributes (because I realized that supporting them is incompatible with my goal to be a drop in replacement for System.Reflection.Emit).
> 
> One thing I didn't change is WriteGenericSignature, because your change didn't make sense to me. It should not be possible that this method gets called with a generic type definition.
> 
> I have not yet added anything additional for version info unmanaged resources. I need to do more thinking about this.
> 
> Regards,
> Jeroen
> 


More information about the Mono-devel-list mailing list