+2007-05-21 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * TypeBuilder.cs: Changed HasElementTypeImpl to return false on 2.0
+ profile when type is not baked.
+
2007-05-21 Jb Evain <jb@nurv.fr>
* TypeBuilder.cs
throw not_supported ();
}
- protected override bool HasElementTypeImpl () {
+ protected override bool HasElementTypeImpl ()
+ {
+#if NET_2_0
+ // a TypeBuilder can never represent an array, pointer
+ if (!is_created)
+ return false;
+#else
check_created ();
+#endif
return created.HasElementType;
}
+2007-05-21 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * MethodBuilderTest.cs: Split up GetCustomAttributes test and marked
+ the one for a baked type as NotWorking. Added test for
+ SetCustomAttribute with SuppressUnmanagedCodeSecurity attribute.
+ * TypeBuilderTest.cs: Split up HasElementType test and marked the
+ baked variant as NotWorking on the 1.0 profile. Enabled additional
+ test for bug #81640. Added test for SetCustomAttribute with
+ SuppressUnmanagedCodeSecurity attribute.
+
2007-05-16 Gert Driesen <drieseng@users.sourceforge.net>
* TypeBuilderTest.cs: Added GetFields test for bug #81368. Enabled
}
[Test]
- public void TestGetCustomAttributes ()
+ public void TestGetCustomAttributes_Incomplete ()
{
MethodBuilder mb = genClass.DefineMethod (
genMethodName (), 0, typeof (void),
}
}
+ [Test]
+ [Category ("NotWorking")]
+ public void TestGetCustomAttributes_Complete ()
+ {
+ MethodBuilder mb = genClass.DefineMethod (
+ genMethodName (), 0, typeof (void),
+ new Type [1] { typeof (int) });
+ mb.GetILGenerator ().Emit (OpCodes.Ret);
+ genClass.CreateType ();
+
+ try {
+ mb.GetCustomAttributes (true);
+ Assert.Fail ("#1");
+ } catch (NotSupportedException) {
+ }
+
+ try {
+ mb.GetCustomAttributes (null, true);
+ Assert.Fail ("#2");
+ } catch (NotSupportedException) {
+ }
+ }
+
[Test]
public void TestSetCustomAttribute ()
{
}
}
+ [Test]
+ public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
+ {
+ string mname = genMethodName ();
+
+ TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
+ MethodBuilder mb = tb.DefineMethod (mname, MethodAttributes.Public,
+ typeof (void), new Type [] { typeof (int), typeof (string) });
+ ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
+ GetConstructor (new Type [0]);
+ CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
+ attrCtor, new object [0]);
+ Assert.IsTrue ((mb.Attributes & MethodAttributes.HasSecurity) == 0, "#1");
+ mb.SetCustomAttribute (caBuilder);
+ //Assert.IsTrue ((mb.Attributes & MethodAttributes.HasSecurity) == 0, "#2");
+ mb.GetILGenerator ().Emit (OpCodes.Ret);
+ Type emittedType = tb.CreateType ();
+ MethodInfo emittedMethod = emittedType.GetMethod (mname);
+ Assert.AreEqual (MethodAttributes.HasSecurity, emittedMethod.Attributes & MethodAttributes.HasSecurity, "#3");
+ //Assert.IsTrue ((mb.Attributes & MethodAttributes.HasSecurity) == 0, "#4");
+ object [] emittedAttrs = emittedMethod.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
+ Assert.AreEqual (1, emittedAttrs.Length, "#5");
+ }
+
[AttributeUsage (AttributeTargets.Parameter)]
class PrivateAttribute : Attribute
{
}
[Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void TestHasElementType ()
+ public void TestHasElementType_Incomplete ()
{
// According to the MSDN docs, this member works, but in reality, it
// returns a NotSupportedException
TypeBuilder tb = module.DefineType (genTypeName ());
- bool b = tb.HasElementType;
+#if NET_2_0
+ Assert.IsFalse (tb.HasElementType);
+#else
+ try {
+ bool b = tb.HasElementType;
+ Assert.Fail ("#1: " + b);
+ } catch (NotSupportedException ex) {
+ Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+#endif
+ }
+
+ [Test]
+#if ONLY_1_1
+ [Category ("NotWorking")]
+#endif
+ public void TestHasElementType_Complete ()
+ {
+ // According to the MSDN docs, this member works, but in reality, it
+ // returns a NotSupportedException
+ TypeBuilder tb = module.DefineType (genTypeName ());
+ tb.CreateType ();
+#if NET_2_0
+ Assert.IsFalse (tb.HasElementType);
+#else
+ try {
+ bool b = tb.HasElementType;
+ Assert.Fail ("#1: " + b);
+ } catch (NotSupportedException ex) {
+ Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+#endif
}
[Test]
}
[Test] // bug #81640
- [Category ("NotWorking")]
public void TestGetFieldComplete_Type ()
{
TypeBuilder tb = module.DefineType (genTypeName ());
enumBuilder.CreateType ();
}
+ [Test]
+ public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
+ {
+ TypeBuilder tb = module.DefineType (genTypeName ());
+ ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
+ GetConstructor (new Type [0]);
+ CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
+ attrCtor, new object [0]);
+ Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
+ tb.SetCustomAttribute (caBuilder);
+ //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
+ Type emittedType = tb.CreateType ();
+ Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
+ //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
+ object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
+ Assert.AreEqual (1, emittedAttrs.Length, "#5");
+ }
+
private void DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
{
// define the field holding the property value