1 // CustomAttributeBuilderTest.cs
3 // Author: Vineeth N <nvineeth@yahoo.com>
5 // (C) 2004 Ximian, Inc. http://www.ximian.com
9 using System.Reflection;
10 using System.Reflection.Emit;
11 using System.Threading;
12 using NUnit.Framework;
14 namespace MonoTests.System.Reflection.Emit
17 /// TestFixture for CustomAttributeBuilderTest.
18 /// The members to be tested are as follows:
20 /// 1) public CustomAttributeBuilder(ConstructorInfo, object[]);
21 /// 2) public CustomAttributeBuilder(ConstructorInfo, object[], FieldInfo[], object[]);
22 /// 3) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[]);
23 /// 4) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
24 /// and the exceptions that are thrown.
25 /// In the implementation , it can be seen that the first
26 /// three type of constructors call the 4th type of ctor, which takes 6 args
27 /// by filling args and substituting null as required.
28 /// For testing constructors we have use 4 different test functions,
29 /// Various exceptions have been checked for 4th type of consturctor.
33 public class CustomAttributeBuilderTest
35 static string tempDir = Path.Combine (Path.GetTempPath (), typeof (CustomAttributeBuilderTest).FullName);
37 // the CustomAttribute class is used for testing and it has to be public
38 //since it will be associated with a class that belongs to another assembly
40 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Class)]
41 public class CustomAttribute: Attribute
45 public string Feild; //used for testing the second type of constructor
47 public CustomAttribute () {}
48 public CustomAttribute (String s1 , String s2)
54 private CustomAttribute (String s1) {}
55 static CustomAttribute () {}
57 public string AttributeOne
60 set { attr1 = value; }
63 public string AttributeTwo
66 //the set is skipped and is used later in testing
71 private class TempClass
73 //used for testing the ArgumentException
75 public string FieldProperty
78 set { Field = value; }
85 Random AutoRand = new Random ();
86 string basePath = tempDir;
87 while (Directory.Exists (tempDir))
88 tempDir = Path.Combine (basePath, AutoRand.Next ().ToString ());
89 Directory.CreateDirectory (tempDir);
93 public void TearDown ()
96 // This throws an exception under MS.NET, since the directory contains loaded
98 Directory.Delete (tempDir, true);
104 public void CtorOneTest ()
106 //test for the constructor with signature--
107 // public CustomAttributeBuilder(ConstructorInfo, object[]);
109 * WE build a imaginary type as follows
112 * [CustomAttribute("one","two")]
115 * [CustomAttribute("hello","world")]
116 * public void Print()
117 * {Console.WriteLine("Hello World"); }
120 * And then check for the validity of attributes in the test functions
122 AssemblyName asmName = new AssemblyName ();
123 asmName.Name = "TestAssembly.dll";
125 AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
126 asmName , AssemblyBuilderAccess.Run);
128 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
130 TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
131 TypeAttributes.Public);
133 Type[] ctorParams = new Type[] { typeof (string),typeof (string) };
135 ConstructorInfo classCtorInfo =
136 typeof (CustomAttribute).GetConstructor (ctorParams);
138 CustomAttributeBuilder feildCABuilder = new CustomAttributeBuilder (
140 new object [] { "one","two" }
142 methodCABuilder = new CustomAttributeBuilder (
144 new object [] { "hello","world" }
146 //now let's build a feild of type string and associate a attribute with it
147 FieldBuilder fieldBuilder= typeBuilder.DefineField ("Str",
148 typeof (string), FieldAttributes.Public);
149 fieldBuilder.SetCustomAttribute (feildCABuilder);
151 MethodBuilder methodBuilder= typeBuilder.DefineMethod ("Print",
152 MethodAttributes.Public, null, null);
153 methodBuilder.SetCustomAttribute (methodCABuilder);
154 ILGenerator methodIL = methodBuilder.GetILGenerator ();
155 methodIL.EmitWriteLine ("Hello, world!");
156 methodIL.Emit (OpCodes.Ret);
159 Type myType = typeBuilder.CreateType ();
161 //Now check for the validity of the attributes.
162 object testInstance = Activator.CreateInstance (myType);
164 //check the validity of the attribute associated with Print method
166 object [] methodAttrs = myType.GetMember ("Print") [0].GetCustomAttributes (true);
167 Assert.AreEqual (methodAttrs.Length, 1, "#1");
168 CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;
169 Assert.AreEqual (methodAttr.AttributeOne, "hello", "#2");
170 Assert.AreEqual (methodAttr.AttributeTwo, "world", "#3");
172 //check the validity of the attribute associated with Str feild
174 object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);
175 Assert.AreEqual(fieldAttrs.Length, 1, "#4");
176 CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;
177 Assert.AreEqual(fieldAttr.AttributeOne, "one", "#5");
178 Assert.AreEqual(fieldAttr.AttributeTwo, "two", "#6");
182 public void CtorTwoTest ()
184 //test for the constructor with signature--
185 // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], FieldInfo[], Object[]) ;
187 * WE build a imaginary type as follows
188 * [CustomAttribute("Test","Type")]
189 * public class TestType
193 * We also set the "Feild" of class CustomAttribute and the value;
194 * And then check for the validity of attributes in the test functions
197 AssemblyName asmName = new AssemblyName ();
198 asmName.Name = "TestAssembly.dll";
200 AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
201 asmName, AssemblyBuilderAccess.Run);
203 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
205 TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
206 TypeAttributes.Public);
208 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
210 ConstructorInfo classCtorInfo =
211 typeof (CustomAttribute).GetConstructor (ctorParams);
213 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
215 new object [] { "Test","Type" },
216 typeof(CustomAttribute).GetFields(),
217 new object [] { "TestCase" }
220 typeBuilder.SetCustomAttribute (typeCABuilder);
223 Type myType = typeBuilder.CreateType ();
225 //Now check for the validity of the attributes.
226 object testInstance = Activator.CreateInstance (myType);
228 //check the validity of the attribute associated with Print method
229 object [] customAttrs = myType.GetCustomAttributes (false);
230 Assert.AreEqual (customAttrs.Length, 1, "1");
232 //Custom Attributes of TestType
233 CustomAttribute attr = customAttrs [0] as CustomAttribute;
234 Assert.AreEqual (attr.AttributeOne, "Test", "#2");
235 Assert.AreEqual (attr.AttributeTwo, "Type", "#3");
236 Assert.AreEqual (attr.Feild, "TestCase", "#4");
241 public void CtorThreeTest ()
243 //test for the constructor with signature--
244 // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], PropertyInfo[], Object[]) ;
246 * WE build a imaginary type as follows
247 * [CustomAttribute()]
248 * public class TestType
252 * We also set the "AttributeOne" of class CustomAttribute by means of the constuctor
253 * And then check for the validity of attribute state
256 AssemblyName asmName = new AssemblyName ();
257 asmName.Name = "TestAssembly.dll";
259 AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
260 asmName, AssemblyBuilderAccess.Run);
262 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
264 TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
265 TypeAttributes.Public);
267 Type [] ctorParams = new Type [] { };
269 ConstructorInfo classCtorInfo =
270 typeof (CustomAttribute).GetConstructor (ctorParams);
272 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
275 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
276 new object [] { "TestCase" }
279 typeBuilder.SetCustomAttribute (typeCABuilder);
282 Type myType = typeBuilder.CreateType ();
284 //Now check for the validity of the attributes.
285 object testInstance = Activator.CreateInstance (myType);
287 //check the validity of the attribute associated with Print method
288 object [] customAttrs = myType.GetCustomAttributes (false);
289 Assert.AreEqual (customAttrs.Length , 1, "#1");
291 //Custom Attributes of TestType
292 CustomAttribute attr = customAttrs [0] as CustomAttribute;
293 Assert.AreEqual(attr.AttributeOne, "TestCase", "#2");
297 public void CtorFourTest ()
299 //test for the constructor with signature--
300 //public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
302 * WE build a imaginary type as follows
303 * [CustomAttribute()]
304 * public class TestType
308 * We also set the "AttributeOne" property ,
309 * and "Feild" of class CustomAttribute
310 * by means of the constuctor of CustomAttributeBuilder
311 * And then check for the validity
314 AssemblyName asmName = new AssemblyName ();
315 asmName.Name = "TestAssembly.dll";
317 AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
318 asmName , AssemblyBuilderAccess.Run);
320 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
322 TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
323 TypeAttributes.Public);
325 Type [] ctorParams = new Type [] { };
327 ConstructorInfo classCtorInfo =
328 typeof (CustomAttribute).GetConstructor (ctorParams);
330 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(
333 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
334 new object [] { "TestCase" },
335 typeof(CustomAttribute).GetFields (),
336 new object [] { "FieldValue" }
339 typeBuilder.SetCustomAttribute (typeCABuilder);
342 Type myType = typeBuilder.CreateType ();
344 //Now check for the validity of the attributes.
345 object testInstance = Activator.CreateInstance (myType);
347 //check the validity of the attribute associated with Print method
348 object [] customAttrs = myType.GetCustomAttributes (false);
349 Assert.AreEqual(customAttrs.Length , 1, "#1");
351 //Custom Attributes of TestType
352 CustomAttribute attr = customAttrs [0] as CustomAttribute;
353 Assert.AreEqual (attr.AttributeOne, "TestCase", "#2");
354 Assert.AreEqual (attr.Feild, "FieldValue", "#3");
359 [ExpectedException (typeof (ArgumentException))]
360 public void ArgumentExceptionTest_1 ()
362 //here the constructor is static
364 Type [] ctorParams = new Type [] { };
366 ConstructorInfo classCtorInfo =
367 typeof (CustomAttribute).GetConstructor (BindingFlags.Static | BindingFlags.NonPublic,
368 null, ctorParams, null);
370 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
373 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
374 new object [] { "TestCase" },
375 typeof (CustomAttribute).GetFields (),
376 new object [] { "FieldValue" }
382 [ExpectedException (typeof (ArgumentException))]
383 public void ArgumentExceptionTest_2 ()
385 //here the consturctor is private
387 Type [] ctorParams = new Type[] {typeof(string) };
389 ConstructorInfo classCtorInfo =
390 typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |
391 BindingFlags.NonPublic, null, ctorParams, null);
393 Assert.IsNotNull (classCtorInfo);
395 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
397 new object [] { "hello" },
398 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
399 new object [] { "TestCase" },
400 typeof (CustomAttribute).GetFields (),
401 new object [] { "FieldValue" }
407 [ExpectedException (typeof (ArgumentException))]
408 public void ArgumentExceptionTest_3 ()
410 // The lengths of the namedProperties and
411 //propertyValues arrays are different.
413 Type [] ctorParams = new Type [] { };
415 ConstructorInfo classCtorInfo =
416 typeof (CustomAttribute).GetConstructor (ctorParams);
418 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
421 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
422 new object [] { "TestCase","extra arg" },//<--here is the error
423 typeof (CustomAttribute).GetFields (),
424 new object [] { "FieldValue" }
430 [ExpectedException (typeof (ArgumentException))]
431 public void ArgumentExceptionTest_4()
433 //The length of the namedFields and
434 //namedValues are different
436 Type [] ctorParams = new Type [] { };
438 ConstructorInfo classCtorInfo =
439 typeof (CustomAttribute).GetConstructor (ctorParams);
441 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
444 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
445 new object [] { "TestCase" },
446 typeof (CustomAttribute).GetFields (),
447 new object [] { }//<--here is the error
453 [ExpectedException (typeof (ArgumentException))]
454 public void ArgumentExceptionTest_6 ()
456 //The type of supplied argument does not
457 //match the type of the parameter declared
458 //in the constructor.
460 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
462 ConstructorInfo classCtorInfo =
463 typeof (CustomAttribute).GetConstructor (ctorParams);
465 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
467 new object [] { "1", 123 },//<--here is the error,(int instead of string)
468 new PropertyInfo[]{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
469 new object [] { "TestCase" },
470 typeof (CustomAttribute).GetFields (),
471 new object [] { "FeildValue" }
477 [ExpectedException (typeof (ArgumentException))]
478 public void ArgumentExceptionTest_7 ()
480 //A property has no setter.(CustomAttribute.AttributeTwo)
482 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
484 ConstructorInfo classCtorInfo =
485 typeof (CustomAttribute).GetConstructor (ctorParams);
487 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
489 new object [] { "1","2" },
490 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeTwo") },
491 new object [] { "TestCase" },
492 typeof (CustomAttribute).GetFields (),
493 new object [] { "FeildValue" }
499 [ExpectedException (typeof (ArgumentException))]
500 public void ArgumentExceptionTest_8 ()
502 //A property doesnot belong to same class
504 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
506 ConstructorInfo classCtorInfo =
507 typeof (CustomAttribute).GetConstructor (ctorParams);
509 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
511 new object [] { "1","2" },
512 new PropertyInfo [] { typeof (TempClass).GetProperty ("FieldProperty")}, //here is the error
513 new object [] { "TestCase" },
514 typeof (CustomAttribute).GetFields (),
515 new object [] { "FeildValue" }
521 [ExpectedException (typeof (ArgumentException))]
522 public void ArgumentExceptionTest_9 ()
524 //A field doesnot belong to same class
526 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
528 ConstructorInfo classCtorInfo =
529 typeof (CustomAttribute).GetConstructor (ctorParams);
531 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
533 new object [] { "1","2" },
534 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
535 new object [] {"TestCase"},
536 typeof (TempClass).GetFields (), //<-- fields of TempClass are passed
537 new object [] { "FeildValue" }
543 [ExpectedException (typeof (ArgumentException))]
544 public void ArgumentExceptionTest_10 ()
546 //The types of the property values do
547 //not match the types of the named properties.
550 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
552 ConstructorInfo classCtorInfo =
553 typeof (CustomAttribute).GetConstructor (ctorParams);
555 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
557 new object [] { "1","2" },
558 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
559 new object [] { (long)1212121212 }, //<---type mismatch error(long for string)
560 typeof (CustomAttribute).GetFields (),
561 new object [] { "FeildValue" }
567 [ExpectedException (typeof (ArgumentException))]
568 public void ArgumentExceptionTest_11 ()
570 //The types of the field values do
571 //not match the types of the named properties.
573 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
575 ConstructorInfo classCtorInfo =
576 typeof (CustomAttribute).GetConstructor (ctorParams);
578 Assert.IsNotNull (classCtorInfo);
579 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
581 new object [] { "1","2" },
582 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
583 new object [] { "One" },
584 typeof (CustomAttribute).GetFields (),
585 new object []{ 12.1212 } //<---type mismatch error(double for string)
591 [ExpectedException (typeof (ArgumentNullException))]
592 public void ArgumentNullException_1 ()
594 //the ctor value array (2nd argument) is null
595 Type [] ctorParams = new Type [] { typeof (string),typeof (string) };
597 ConstructorInfo classCtorInfo =
598 typeof (CustomAttribute).GetConstructor (ctorParams);
600 Assert.IsNotNull (classCtorInfo);
601 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
603 null, //<-- here is the error
604 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
605 new object [] { "One" },
606 typeof (CustomAttribute).GetFields (),
607 new object [] { "feild" }
613 [ExpectedException (typeof (ArgumentNullException))]
614 public void ArgumentNullException_2 ()
616 //the property value array (4th argument) is null
617 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
619 ConstructorInfo classCtorInfo =
620 typeof (CustomAttribute).GetConstructor (ctorParams);
622 Assert.IsNotNull (classCtorInfo);
623 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
625 new object [] { "one","two" },
626 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
627 null, // <-- here is the error
628 typeof (CustomAttribute).GetFields (),
629 new object [] { "feild" }
635 [ExpectedException (typeof (ArgumentNullException))]
636 public void ArgumentNullException_3 ()
638 //the field value array (6th argument) is null
639 Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
641 ConstructorInfo classCtorInfo =
642 typeof (CustomAttribute).GetConstructor (ctorParams);
644 Assert.IsNotNull (classCtorInfo);
645 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
647 new object [] { "one","two" },
648 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
649 new object [] {"property"},
650 typeof (CustomAttribute).GetFields (),
651 null // <-- here is the error
656 public C (object i) {
661 [ExpectedException (typeof (ArgumentException))]
662 public void ObjectParam_UserDefinedClass ()
664 var cab = new CustomAttributeBuilder(
665 typeof (C).GetConstructors ()[0],
666 new object[] { new C (1) });
671 [ExpectedException (typeof (ArgumentException))]
672 public void ValueTypeParam_Null ()
674 ConstructorInfo classCtorInfo =
675 typeof (CattrD).GetConstructors ()[0];
677 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
678 classCtorInfo, new object [] { null });
682 [ExpectedException (typeof (ArgumentException))]
683 public void ValueTypeArrayParam_Null ()
685 ConstructorInfo classCtorInfo =
686 typeof (CattrE).GetConstructors ()[0];
688 CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
689 classCtorInfo, new object [] { new object[] { null } });
692 public class CattrD : Attribute
694 public CattrD (bool b) {}
697 public class CattrE : Attribute
699 public CattrE (bool[] b) {}
702 public class JaggedAttr : Attribute {
703 public static string[][] Data { get; set; }
705 public JaggedAttr (string[][] data) {
711 public void JaggedArrays () {
712 var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (new AssemblyName ("Foo"), AssemblyBuilderAccess.Save, tempDir);
713 var modb = ab.DefineDynamicModule ("Foo", "Foo.dll");
714 var tb = modb.DefineType ("T");
715 tb.SetCustomAttribute (new
716 CustomAttributeBuilder(typeof (JaggedAttr).GetConstructors ()[0],
717 new object[] { new string[][] { new string[] { "foo" }, new string[] { "bar" } } }));
721 string assemblyPath = Path.Combine (tempDir, "Foo.dll");
722 Type t = Assembly.LoadFrom (assemblyPath).GetType ("T");
723 Assert.AreEqual (1, t.GetCustomAttributes (false).Length);
725 string[][] res = JaggedAttr.Data;
726 Assert.AreEqual (2, res.Length);
727 Assert.AreEqual ("foo", res [0][0]);
728 Assert.AreEqual ("bar", res [1][0]);
731 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
732 internal class NonVisibleCustomAttribute : Attribute
734 public NonVisibleCustomAttribute () {}
737 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
738 public class PublicVisibleCustomAttribute : Attribute
740 public PublicVisibleCustomAttribute () {}
743 private static void AddCustomClassAttribute (TypeBuilder typeBuilder, Type customAttrType)
745 var attribCtorParams = new Type[] {};
746 var attribCtorInfo = customAttrType.GetConstructor(attribCtorParams);
747 var attribBuilder = new CustomAttributeBuilder(attribCtorInfo, new object[] { });
748 typeBuilder.SetCustomAttribute(attribBuilder);
752 public void NonvisibleCustomAttribute () {
755 // [VisiblePublicCustom]
756 // [VisiblePublicCustom]
757 // [NonVisibleCustom]
758 // [VisiblePublicCustom]
759 // class BuiltType { public BuiltType () { } }
761 // And then we try to get all the attributes.
763 // Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=43291
764 var assemblyName = new AssemblyName("Repro43291Asm");
765 var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
766 var moduleBuilder = assemblyBuilder.DefineDynamicModule("Repro43291Mod");
768 var typeBuilder = moduleBuilder.DefineType("BuiltType",
769 TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.BeforeFieldInit);
771 AddCustomClassAttribute (typeBuilder, typeof (PublicVisibleCustomAttribute));
772 AddCustomClassAttribute (typeBuilder, typeof (PublicVisibleCustomAttribute));
773 AddCustomClassAttribute (typeBuilder, typeof (NonVisibleCustomAttribute));
774 AddCustomClassAttribute (typeBuilder, typeof (PublicVisibleCustomAttribute));
776 var createdType = typeBuilder.CreateType ();
778 Assert.IsNotNull (createdType);
780 var obj = Activator.CreateInstance (createdType);
782 Assert.IsNotNull (obj);
784 var attrs = obj.GetType ().GetCustomAttributes (typeof (Attribute), true);
786 Assert.IsNotNull (attrs);
788 Assert.AreEqual (3, attrs.Length);
789 Assert.IsInstanceOfType (typeof (PublicVisibleCustomAttribute), attrs[0]);
790 Assert.IsInstanceOfType (typeof (PublicVisibleCustomAttribute), attrs[1]);
791 Assert.IsInstanceOfType (typeof (PublicVisibleCustomAttribute), attrs[2]);