Hi! On my work towards implementing generics emission in Nemerle I get into following problems:
- MS is adding new methods to TypeBuilder for obtaining members of instanciated generic types: public static MethodInfo GetMethod (Type instanciated, MethodInfo meth) public static ConstructorInfo GetConstructor (Type instanciated, ConstructorInfo cons) public static FieldInfo GetField (Type instanciated, FieldInfo fld) see http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=d507aff5-b1e3-49b4-8178-065a00d2f15e they are already available in Feb CTP, though not documented anywhere. And not suprisingly, I need them... I hacked something in mono sources, so it is partially enough for my experiments now, but it would be nice to have it implemented correctly. I'm not sure what would be the *correct* way of implementing it. I tried iterating on instanciated.GetMethods (), but comparing if member signatures match isn't that easy (for example GetParameters () method sometimes throws exception when used for TypeBuilder) Any suggestions? - There is a new MakeGenericType method in TypeBuilder, which simply replaces BindGenericTypes, which gets obsoleted (attached patch to add this method to TypeBuilder) - I need the HasGenericArguments method from TypeBuilder, which currently in mono is "throw NotImplementedException" - attached patch to make it simply check for presence of generic_params. Kamil Skalski
Index: class/corlib/System/Type.cs =================================================================== --- class/corlib/System/Type.cs (wersja 42625) +++ class/corlib/System/Type.cs (kopia robocza) @@ -1040,6 +1040,11 @@ return res; } + public Type MakeGenericType (Type[] types) + { + return BindGenericParameters (types); + } + public abstract bool IsGenericParameter { get; }
Index: class/corlib/System.Reflection.Emit/TypeBuilder.cs =================================================================== --- class/corlib/System.Reflection.Emit/TypeBuilder.cs (wersja 42625) +++ class/corlib/System.Reflection.Emit/TypeBuilder.cs (kopia robocza) @@ -1381,7 +1381,7 @@ public override bool HasGenericArguments { get { - throw new NotImplementedException (); + return generic_params != null; } }