CustomAttributeBuilderTest.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // CustomAttributeBuilderTest.cs
  2. //
  3. // Author: Vineeth N <[email protected]>
  4. //
  5. // (C) 2004 Ximian, Inc. http://www.ximian.com
  6. //
  7. using System;
  8. using System.Reflection;
  9. using System.Reflection.Emit;
  10. using System.Threading;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Reflection.Emit
  13. {
  14. /// <summary>
  15. /// TestFixture for CustomAttributeBuilderTest.
  16. /// The members to be tested are as follows:
  17. /// 4 constructors:
  18. /// 1) public CustomAttributeBuilder(ConstructorInfo, object[]);
  19. /// 2) public CustomAttributeBuilder(ConstructorInfo, object[], FieldInfo[], object[]);
  20. /// 3) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[]);
  21. /// 4) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
  22. /// and the exceptions that are thrown.
  23. /// In the implementation , it can be seen that the first
  24. /// three type of constructors call the 4th type of ctor, which takes 6 args
  25. /// by filling args and substituting null as required.
  26. /// For testing constructors we have use 4 different test functions,
  27. /// Various exceptions have been checked for 4th type of consturctor.
  28. /// </summary>
  29. [TestFixture]
  30. public class CustomAttributeBuilderTest
  31. {
  32. // the CustomAttribute class is used for testing and it has to be public
  33. //since it will be associated with a class that belongs to another assembly
  34. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Class)]
  35. public class CustomAttribute: Attribute
  36. {
  37. private string attr1;
  38. private string attr2;
  39. public string Feild; //used for testing the second type of constructor
  40. public CustomAttribute () {}
  41. public CustomAttribute (String s1 , String s2)
  42. {
  43. attr1 = s1;
  44. attr2=s2;
  45. }
  46. private CustomAttribute (String s1) {}
  47. static CustomAttribute () {}
  48. public string AttributeOne
  49. {
  50. get { return attr1; }
  51. set { attr1 = value; }
  52. }
  53. public string AttributeTwo
  54. {
  55. get { return attr2; }
  56. //the set is skipped and is used later in testing
  57. }
  58. }
  59. private class TempClass
  60. {
  61. //used for testing the ArgumentException
  62. public string Field;
  63. public string FieldProperty
  64. {
  65. get { return Field; }
  66. set { Field = value; }
  67. }
  68. }
  69. [Test]
  70. public void CtorOneTest ()
  71. {
  72. //test for the constructor with signature--
  73. // public CustomAttributeBuilder(ConstructorInfo, object[]);
  74. /*
  75. * WE build a imaginary type as follows
  76. * class TestType
  77. * {
  78. * [CustomAttribute("one","two")]
  79. * public string Str;
  80. *
  81. * [CustomAttribute("hello","world")]
  82. * public void Print()
  83. * {Console.WriteLine("Hello World"); }
  84. *
  85. * }
  86. * And then check for the validity of attributes in the test functions
  87. */
  88. AssemblyName asmName = new AssemblyName ();
  89. asmName.Name = "TestAssembly.dll";
  90. AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
  91. asmName , AssemblyBuilderAccess.Run);
  92. ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
  93. TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
  94. TypeAttributes.Public);
  95. Type[] ctorParams = new Type[] { typeof (string),typeof (string) };
  96. ConstructorInfo classCtorInfo =
  97. typeof (CustomAttribute).GetConstructor (ctorParams);
  98. CustomAttributeBuilder feildCABuilder = new CustomAttributeBuilder (
  99. classCtorInfo,
  100. new object [] { "one","two" }
  101. ),
  102. methodCABuilder = new CustomAttributeBuilder (
  103. classCtorInfo,
  104. new object [] { "hello","world" }
  105. );
  106. //now let's build a feild of type string and associate a attribute with it
  107. FieldBuilder fieldBuilder= typeBuilder.DefineField ("Str",
  108. typeof (string), FieldAttributes.Public);
  109. fieldBuilder.SetCustomAttribute (feildCABuilder);
  110. //now build a method
  111. MethodBuilder methodBuilder= typeBuilder.DefineMethod ("Print",
  112. MethodAttributes.Public, null, null);
  113. methodBuilder.SetCustomAttribute (methodCABuilder);
  114. ILGenerator methodIL = methodBuilder.GetILGenerator ();
  115. methodIL.EmitWriteLine ("Hello, world!");
  116. methodIL.Emit (OpCodes.Ret);
  117. // create the type
  118. Type myType = typeBuilder.CreateType ();
  119. //Now check for the validity of the attributes.
  120. object testInstance = Activator.CreateInstance (myType);
  121. //check the validity of the attribute associated with Print method
  122. object [] methodAttrs = myType.GetMember ("Print") [0].GetCustomAttributes (true);
  123. Assert.AreEqual (methodAttrs.Length, 1, "#1");
  124. CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;
  125. Assert.AreEqual (methodAttr.AttributeOne, "hello", "#2");
  126. Assert.AreEqual (methodAttr.AttributeTwo, "world", "#3");
  127. //check the validity of the attribute associated with Str feild
  128. object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);
  129. Assert.AreEqual(fieldAttrs.Length, 1, "#4");
  130. CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;
  131. Assert.AreEqual(fieldAttr.AttributeOne, "one", "#5");
  132. Assert.AreEqual(fieldAttr.AttributeTwo, "two", "#6");
  133. }
  134. [Test]
  135. public void CtorTwoTest ()
  136. {
  137. //test for the constructor with signature--
  138. // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], FieldInfo[], Object[]) ;
  139. /*
  140. * WE build a imaginary type as follows
  141. * [CustomAttribute("Test","Type")]
  142. * public class TestType
  143. * {
  144. *
  145. * }
  146. * We also set the "Feild" of class CustomAttribute and the value;
  147. * And then check for the validity of attributes in the test functions
  148. */
  149. AssemblyName asmName = new AssemblyName ();
  150. asmName.Name = "TestAssembly.dll";
  151. AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
  152. asmName, AssemblyBuilderAccess.Run);
  153. ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
  154. TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
  155. TypeAttributes.Public);
  156. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  157. ConstructorInfo classCtorInfo =
  158. typeof (CustomAttribute).GetConstructor (ctorParams);
  159. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  160. classCtorInfo,
  161. new object [] { "Test","Type" },
  162. typeof(CustomAttribute).GetFields(),
  163. new object [] { "TestCase" }
  164. );
  165. typeBuilder.SetCustomAttribute (typeCABuilder);
  166. // create the type
  167. Type myType = typeBuilder.CreateType ();
  168. //Now check for the validity of the attributes.
  169. object testInstance = Activator.CreateInstance (myType);
  170. //check the validity of the attribute associated with Print method
  171. object [] customAttrs = myType.GetCustomAttributes (false);
  172. Assert.AreEqual (customAttrs.Length, 1, "1");
  173. //Custom Attributes of TestType
  174. CustomAttribute attr = customAttrs [0] as CustomAttribute;
  175. Assert.AreEqual (attr.AttributeOne, "Test", "#2");
  176. Assert.AreEqual (attr.AttributeTwo, "Type", "#3");
  177. Assert.AreEqual (attr.Feild, "TestCase", "#4");
  178. }
  179. [Test]
  180. public void CtorThreeTest ()
  181. {
  182. //test for the constructor with signature--
  183. // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], PropertyInfo[], Object[]) ;
  184. /*
  185. * WE build a imaginary type as follows
  186. * [CustomAttribute()]
  187. * public class TestType
  188. * {
  189. *
  190. * }
  191. * We also set the "AttributeOne" of class CustomAttribute by means of the constuctor
  192. * And then check for the validity of attribute state
  193. */
  194. AssemblyName asmName = new AssemblyName ();
  195. asmName.Name = "TestAssembly.dll";
  196. AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
  197. asmName, AssemblyBuilderAccess.Run);
  198. ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
  199. TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
  200. TypeAttributes.Public);
  201. Type [] ctorParams = new Type [] { };
  202. ConstructorInfo classCtorInfo =
  203. typeof (CustomAttribute).GetConstructor (ctorParams);
  204. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  205. classCtorInfo,
  206. new object [] { },
  207. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  208. new object [] { "TestCase" }
  209. );
  210. typeBuilder.SetCustomAttribute (typeCABuilder);
  211. // create the type
  212. Type myType = typeBuilder.CreateType ();
  213. //Now check for the validity of the attributes.
  214. object testInstance = Activator.CreateInstance (myType);
  215. //check the validity of the attribute associated with Print method
  216. object [] customAttrs = myType.GetCustomAttributes (false);
  217. Assert.AreEqual (customAttrs.Length , 1, "#1");
  218. //Custom Attributes of TestType
  219. CustomAttribute attr = customAttrs [0] as CustomAttribute;
  220. Assert.AreEqual(attr.AttributeOne, "TestCase", "#2");
  221. }
  222. [Test]
  223. public void CtorFourTest ()
  224. {
  225. //test for the constructor with signature--
  226. //public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
  227. /*
  228. * WE build a imaginary type as follows
  229. * [CustomAttribute()]
  230. * public class TestType
  231. * {
  232. *
  233. * }
  234. * We also set the "AttributeOne" property ,
  235. * and "Feild" of class CustomAttribute
  236. * by means of the constuctor of CustomAttributeBuilder
  237. * And then check for the validity
  238. */
  239. AssemblyName asmName = new AssemblyName ();
  240. asmName.Name = "TestAssembly.dll";
  241. AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
  242. asmName , AssemblyBuilderAccess.Run);
  243. ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
  244. TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
  245. TypeAttributes.Public);
  246. Type [] ctorParams = new Type [] { };
  247. ConstructorInfo classCtorInfo =
  248. typeof (CustomAttribute).GetConstructor (ctorParams);
  249. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(
  250. classCtorInfo,
  251. new object [] { },
  252. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  253. new object [] { "TestCase" },
  254. typeof(CustomAttribute).GetFields (),
  255. new object [] { "FieldValue" }
  256. );
  257. typeBuilder.SetCustomAttribute (typeCABuilder);
  258. // create the type
  259. Type myType = typeBuilder.CreateType ();
  260. //Now check for the validity of the attributes.
  261. object testInstance = Activator.CreateInstance (myType);
  262. //check the validity of the attribute associated with Print method
  263. object [] customAttrs = myType.GetCustomAttributes (false);
  264. Assert.AreEqual(customAttrs.Length , 1, "#1");
  265. //Custom Attributes of TestType
  266. CustomAttribute attr = customAttrs [0] as CustomAttribute;
  267. Assert.AreEqual (attr.AttributeOne, "TestCase", "#2");
  268. Assert.AreEqual (attr.Feild, "FieldValue", "#3");
  269. }
  270. [Test]
  271. [ExpectedException (typeof (ArgumentException))]
  272. public void ArgumentExceptionTest_1 ()
  273. {
  274. //here the constructor is static
  275. Type [] ctorParams = new Type [] { };
  276. ConstructorInfo classCtorInfo =
  277. typeof (CustomAttribute).GetConstructor (BindingFlags.Static | BindingFlags.NonPublic,
  278. null, ctorParams, null);
  279. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  280. classCtorInfo,
  281. new object [] { },
  282. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  283. new object [] { "TestCase" },
  284. typeof (CustomAttribute).GetFields (),
  285. new object [] { "FieldValue" }
  286. );
  287. }
  288. [Test]
  289. [ExpectedException (typeof (ArgumentException))]
  290. public void ArgumentExceptionTest_2 ()
  291. {
  292. //here the consturctor is private
  293. Type [] ctorParams = new Type[] {typeof(string) };
  294. ConstructorInfo classCtorInfo =
  295. typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |
  296. BindingFlags.NonPublic, null, ctorParams, null);
  297. Assert.IsNotNull (classCtorInfo);
  298. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  299. classCtorInfo,
  300. new object [] { "hello" },
  301. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  302. new object [] { "TestCase" },
  303. typeof (CustomAttribute).GetFields (),
  304. new object [] { "FieldValue" }
  305. );
  306. }
  307. [Test]
  308. [ExpectedException (typeof (ArgumentException))]
  309. public void ArgumentExceptionTest_3 ()
  310. {
  311. // The lengths of the namedProperties and
  312. //propertyValues arrays are different.
  313. Type [] ctorParams = new Type [] { };
  314. ConstructorInfo classCtorInfo =
  315. typeof (CustomAttribute).GetConstructor (ctorParams);
  316. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  317. classCtorInfo,
  318. new object [] { },
  319. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  320. new object [] { "TestCase","extra arg" },//<--here is the error
  321. typeof (CustomAttribute).GetFields (),
  322. new object [] { "FieldValue" }
  323. );
  324. }
  325. [Test]
  326. [ExpectedException (typeof (ArgumentException))]
  327. public void ArgumentExceptionTest_4()
  328. {
  329. //The length of the namedFields and
  330. //namedValues are different
  331. Type [] ctorParams = new Type [] { };
  332. ConstructorInfo classCtorInfo =
  333. typeof (CustomAttribute).GetConstructor (ctorParams);
  334. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  335. classCtorInfo,
  336. new object [] { },
  337. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  338. new object [] { "TestCase" },
  339. typeof (CustomAttribute).GetFields (),
  340. new object [] { }//<--here is the error
  341. );
  342. }
  343. [Test]
  344. [ExpectedException (typeof (ArgumentException))]
  345. public void ArgumentExceptionTest_6 ()
  346. {
  347. //The type of supplied argument does not
  348. //match the type of the parameter declared
  349. //in the constructor.
  350. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  351. ConstructorInfo classCtorInfo =
  352. typeof (CustomAttribute).GetConstructor (ctorParams);
  353. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  354. classCtorInfo,
  355. new object [] { "1", 123 },//<--here is the error,(int instead of string)
  356. new PropertyInfo[]{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  357. new object [] { "TestCase" },
  358. typeof (CustomAttribute).GetFields (),
  359. new object [] { "FeildValue" }
  360. );
  361. }
  362. [Test]
  363. [ExpectedException (typeof (ArgumentException))]
  364. public void ArgumentExceptionTest_7 ()
  365. {
  366. //A property has no setter.(CustomAttribute.AttributeTwo)
  367. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  368. ConstructorInfo classCtorInfo =
  369. typeof (CustomAttribute).GetConstructor (ctorParams);
  370. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  371. classCtorInfo,
  372. new object [] { "1","2" },
  373. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeTwo") },
  374. new object [] { "TestCase" },
  375. typeof (CustomAttribute).GetFields (),
  376. new object [] { "FeildValue" }
  377. );
  378. }
  379. [Test]
  380. [ExpectedException (typeof (ArgumentException))]
  381. public void ArgumentExceptionTest_8 ()
  382. {
  383. //A property doesnot belong to same class
  384. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  385. ConstructorInfo classCtorInfo =
  386. typeof (CustomAttribute).GetConstructor (ctorParams);
  387. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  388. classCtorInfo,
  389. new object [] { "1","2" },
  390. new PropertyInfo [] { typeof (TempClass).GetProperty ("FieldProperty")}, //here is the error
  391. new object [] { "TestCase" },
  392. typeof (CustomAttribute).GetFields (),
  393. new object [] { "FeildValue" }
  394. );
  395. }
  396. [Test]
  397. [ExpectedException (typeof (ArgumentException))]
  398. public void ArgumentExceptionTest_9 ()
  399. {
  400. //A field doesnot belong to same class
  401. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  402. ConstructorInfo classCtorInfo =
  403. typeof (CustomAttribute).GetConstructor (ctorParams);
  404. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  405. classCtorInfo,
  406. new object [] { "1","2" },
  407. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  408. new object [] {"TestCase"},
  409. typeof (TempClass).GetFields (), //<-- fields of TempClass are passed
  410. new object [] { "FeildValue" }
  411. );
  412. }
  413. [Test]
  414. [ExpectedException (typeof (ArgumentException))]
  415. public void ArgumentExceptionTest_10 ()
  416. {
  417. //The types of the property values do
  418. //not match the types of the named properties.
  419. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  420. ConstructorInfo classCtorInfo =
  421. typeof (CustomAttribute).GetConstructor (ctorParams);
  422. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  423. classCtorInfo,
  424. new object [] { "1","2" },
  425. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  426. new object [] { (long)1212121212 }, //<---type mismatch error(long for string)
  427. typeof (CustomAttribute).GetFields (),
  428. new object [] { "FeildValue" }
  429. );
  430. }
  431. [Test]
  432. [ExpectedException (typeof (ArgumentException))]
  433. public void ArgumentExceptionTest_11 ()
  434. {
  435. //The types of the field values do
  436. //not match the types of the named properties.
  437. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  438. ConstructorInfo classCtorInfo =
  439. typeof (CustomAttribute).GetConstructor (ctorParams);
  440. Assert.IsNotNull (classCtorInfo);
  441. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  442. classCtorInfo,
  443. new object [] { "1","2" },
  444. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  445. new object [] { "One" },
  446. typeof (CustomAttribute).GetFields (),
  447. new object []{ 12.1212 } //<---type mismatch error(double for string)
  448. );
  449. }
  450. [Test]
  451. [ExpectedException (typeof (ArgumentNullException))]
  452. public void ArgumentNullException_1 ()
  453. {
  454. //the ctor value array (2nd argument) is null
  455. Type [] ctorParams = new Type [] { typeof (string),typeof (string) };
  456. ConstructorInfo classCtorInfo =
  457. typeof (CustomAttribute).GetConstructor (ctorParams);
  458. Assert.IsNotNull (classCtorInfo);
  459. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  460. classCtorInfo,
  461. null, //<-- here is the error
  462. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  463. new object [] { "One" },
  464. typeof (CustomAttribute).GetFields (),
  465. new object [] { "feild" }
  466. );
  467. }
  468. [Test]
  469. [ExpectedException (typeof (ArgumentNullException))]
  470. public void ArgumentNullException_2 ()
  471. {
  472. //the property value array (4th argument) is null
  473. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  474. ConstructorInfo classCtorInfo =
  475. typeof (CustomAttribute).GetConstructor (ctorParams);
  476. Assert.IsNotNull (classCtorInfo);
  477. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  478. classCtorInfo,
  479. new object [] { "one","two" },
  480. new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
  481. null, // <-- here is the error
  482. typeof (CustomAttribute).GetFields (),
  483. new object [] { "feild" }
  484. );
  485. }
  486. [Test]
  487. [ExpectedException (typeof (ArgumentNullException))]
  488. public void ArgumentNullException_3 ()
  489. {
  490. //the field value array (6th argument) is null
  491. Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
  492. ConstructorInfo classCtorInfo =
  493. typeof (CustomAttribute).GetConstructor (ctorParams);
  494. Assert.IsNotNull (classCtorInfo);
  495. CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
  496. classCtorInfo,
  497. new object [] { "one","two" },
  498. new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
  499. new object [] {"property"},
  500. typeof (CustomAttribute).GetFields (),
  501. null // <-- here is the error
  502. );
  503. }
  504. }
  505. }