// 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,
+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,
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)
+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.
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