In System.Reflection.Emit:
authorSebastien Pouliot <sebastien@ximian.com>
Sat, 24 Oct 2009 15:45:09 +0000 (15:45 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Sat, 24 Oct 2009 15:45:09 +0000 (15:45 -0000)
2009-10-24  Sebastien Pouliot  <sebastien@ximian.com>

* AssemblyBuilder.cs: For Silverlight only AssemblyBuilderAccess.Run
is supported (browser-side) but we still allow other values when
compiling (e.g. smcs) outside the browser (wo coreclr)
* TypeBuilder.cs (GetConstructor): Fix validations

In Test/System.Reflection.Emit:
2009-10-24  Sebastien Pouliot  <sebastien@ximian.com>

* TypeBuilderTest.cs: Validation test cases for GetConstructor

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

mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs

index 0c3a2035f63f5d043e2707b574703e4f1365ee15..1149eddbc24738439dd6bb85a0d1afbe81310b11 100644 (file)
@@ -152,6 +152,13 @@ namespace System.Reflection.Emit
                        // remove Mono specific flag to allow enum check to pass
                        access &= ~COMPILER_ACCESS;
 
+#if NET_2_1 && !MONOTOUCH
+                       // only "Run" is supported by Silverlight
+                       // however SMCS requires more than this but runs outside the CoreCLR sandbox
+                       if (SecurityManager.SecurityEnabled && (access != AssemblyBuilderAccess.Run))
+                               throw new ArgumentException ("access");
+#endif
+
 #if NET_2_0
                        if (!Enum.IsDefined (typeof (AssemblyBuilderAccess), access))
                                throw new ArgumentException (string.Format (CultureInfo.InvariantCulture,
index a5a29bb1f38b5154878e8235d536f90161dc644d..4091edab7f4e37bf0c00546df08320381db5ad07 100644 (file)
@@ -1,3 +1,10 @@
+2009-10-24  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * AssemblyBuilder.cs: For Silverlight only AssemblyBuilderAccess.Run
+       is supported (browser-side) but we still allow other values when
+       compiling (e.g. smcs) outside the browser (wo coreclr)
+       * TypeBuilder.cs (GetConstructor): Fix validations
+
 2009-09-18  Sebastien Pouliot  <sebastien@ximian.com>
 
        * AssemblyBuilder.cs, ConstructorBuilder.cs, MethodBuilder.cs, 
index e0e82f995a4d20b7dab5552dd4e58c8ee34f3b24..fd284ad635c7338115d34dd2f6f6cdca9020f6ce 100644 (file)
@@ -1767,11 +1767,14 @@ namespace System.Reflection.Emit
 
                public static ConstructorInfo GetConstructor (Type type, ConstructorInfo constructor)
                {
+                       if (type == null)
+                               throw new ArgumentException ("Type is not generic", "type");
+
                        ConstructorInfo res = type.GetConstructor (constructor);
                        if (res == null)
-                               throw new System.Exception ("constructor not found");
-                       else
-                               return res;
+                               throw new ArgumentException ("constructor not found");
+
+                       return res;
                }
 
                static bool IsValidGetMethodType (Type type)
index bb76af6ddcb08927c88020f411516ef21341f965..a2b1ff58c52a851bda4ba740ff5aa397c12655b5 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-24  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * TypeBuilderTest.cs: Validation test cases for GetConstructor
+
 2009-09-02 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * TypeBuilderTest.cs: Test for #536243.
index ec938e1387a5f2cb5c6993c41865807e661d9b8e..cc632f9fd70e288948473acdd0252abbfc1d3ec5 100644 (file)
@@ -2185,6 +2185,35 @@ namespace MonoTests.System.Reflection.Emit
 
                        Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
                }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Static_GetConstructor_TypeNull ()
+               {
+                       ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
+                       // null is non-generic (from exception message)
+                       TypeBuilder.GetConstructor (null, ci);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Static_GetConstructor_TypeGeneric ()
+               {
+                       Type t = typeof (List<>).MakeGenericType (typeof (int));
+                       ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
+                       // type is not 'TypeBuilder' (from exception message)
+                       TypeBuilder.GetConstructor (t, ci);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
+               {
+                       TypeBuilder tb = module.DefineType ("XXX");
+                       GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
+                       Type fooOfT = tb.MakeGenericType (typeParams [0]);
+                       TypeBuilder.GetConstructor (fooOfT, null);
+               }
 #endif
 
                [Test] //#536243