2010-03-11 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 11 Mar 2010 15:00:51 +0000 (15:00 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 11 Mar 2010 15:00:51 +0000 (15:00 -0000)
* TypeBuilder.cs (GetMethod): Allow type to be the typebuilder
* itself.
Add better error checking to GetConstructor and GetField.

Fixes #587106.

svn path=/trunk/mcs/; revision=153468

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs

index 501e13dbd21bc210f74d9265d24cc3d3c62b41f6..6055e30f6869ea332d105353f535c3901e853632 100644 (file)
@@ -1,3 +1,10 @@
+2010-03-11 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * TypeBuilder.cs (GetMethod): Allow type to be the typebuilder itself.
+       Add better error checking to GetConstructor and GetField.
+
+       Fixes #587106.
+
 2010-02-09  Sebastien Pouliot  <sebastien@ximian.com>
 
        * ModuleBuilder.cs: Do not use reflection to create SymbolWriterImpl
index 7a9eb48acabbb0c12f41db45b27e5b89c7dc5bc0..2b74fbeeca1a82c70120d9e325f4e60b506c4e27 100644 (file)
@@ -1795,6 +1795,12 @@ namespace System.Reflection.Emit
                        if (type == null)
                                throw new ArgumentException ("Type is not generic", "type");
 
+                       if (!type.IsGenericType)
+                               throw new ArgumentException ("Type is not a generic type", "type");
+
+                       if (type.IsGenericTypeDefinition)
+                               throw new ArgumentException ("Type cannot be a generic type definition", "type");
+
                        if (constructor == null)
                                throw new NullReferenceException (); //MS raises this instead of an ArgumentNullException
 
@@ -1830,6 +1836,9 @@ namespace System.Reflection.Emit
                        if (!IsValidGetMethodType (type))
                                throw new ArgumentException ("type is not TypeBuilder but " + type.GetType (), "type");
 
+                       if (type is TypeBuilder && type.ContainsGenericParameters)
+                               type = type.MakeGenericType (type.GetGenericArguments ());
+
                        if (!type.IsGenericType)
                                throw new ArgumentException ("type is not a generic type", "type");
 
@@ -1849,6 +1858,12 @@ namespace System.Reflection.Emit
 
                public static FieldInfo GetField (Type type, FieldInfo field)
                {
+                       if (!type.IsGenericType)
+                               throw new ArgumentException ("Type is not a generic type", "type");
+
+                       if (type.IsGenericTypeDefinition)
+                               throw new ArgumentException ("Type cannot be a generic type definition", "type");
+
                        FieldInfo res = type.GetField (field);
                        if (res == null)
                                throw new System.Exception ("field not found");