1 //
2 // TypeBuilderTest.cs - NUnit Test Cases for the TypeBuilder class
3 //
4 // Zoltan Varga (vargaz@freemail.hu)
5 //
6 // (C) Ximian, Inc.  http://www.ximian.com
7 //
8 // TODO:
9 //  - implement a mechnanism for easier testing of null argument exceptions
10 //  - with overloaded methods like DefineNestedType (), check the defaults
11 //    on the shorter versions.
12 //  - ToString on enums with the flags attribute set should print all
13 //    values which match, e.g. 0 == AutoLayou,AnsiClass,NotPublic
14 //
15 
16 using System;
17 using System.Collections;
18 using System.Threading;
19 using System.Reflection;
20 using System.Reflection.Emit;
21 using System.IO;
22 using System.Security;
23 using System.Security.Permissions;
24 using System.Runtime.InteropServices;
25 using NUnit.Framework;
26 using System.Runtime.CompilerServices;
27 using System.Collections.Generic;
28 
29 namespace MonoTests.System.Reflection.Emit
30 {
31 	public interface EmptyInterface
32 	{
33 	}
34 
35 	public interface OneMethodInterface
36 	{
foo()37 		void foo ();
38 	}
39 
40 	public class SimpleTestAttribute : Attribute
41 	{
42 	}
43 	public class EmptyIfaceImpl : EmptyInterface
44 	{
45 	}
46 
47 	public class Gen<T> {
48 		public static T field = default(T);
49 	}
50 
51 	[TestFixture]
52 	public class TypeBuilderTest
53 	{
54 		public interface AnInterface
55 		{
56 		}
57 
58 		public interface Foo
59 		{
60 		}
61 
62 		public interface Bar : Foo
63 		{
64 		}
65 
66 		public interface Baz : Bar
67 		{
68 		}
69 
70 		public interface IMoveable
71 		{
72 		}
73 
74 		public interface IThrowable : IMoveable
75 		{
76 		}
77 
78 		public interface ILiquid
79 		{
80 		}
81 
82 		public interface IWater : ILiquid
83 		{
84 		}
85 
86 		public interface IAir
87 		{
88 		}
89 
90 		public interface IDestroyable
91 		{
92 		}
93 
94 		public class Tuple <A,B> {
95 			public A a;
96 			public B b;
97 		}
98 
99 		private AssemblyBuilder assembly;
100 
101 		private ModuleBuilder module;
102 
103 		string tempDir = Path.Combine (Path.GetTempPath (), typeof (TypeBuilderTest).FullName);
104 
105 		static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
106 
107 		[SetUp]
SetUp()108 		protected void SetUp ()
109 		{
110 			Random AutoRand = new Random ();
111 			string basePath = tempDir;
112 			while (Directory.Exists (tempDir))
113 				tempDir = Path.Combine (basePath, AutoRand.Next ().ToString ());
114 			Directory.CreateDirectory (tempDir);
115 
116 			AssemblyName assemblyName = new AssemblyName ();
117 			assemblyName.Name = ASSEMBLY_NAME;
118 
119 			assembly =
120 				Thread.GetDomain ().DefineDynamicAssembly (
121 					assemblyName, AssemblyBuilderAccess.RunAndSave, tempDir);
122 
123 			module = assembly.DefineDynamicModule (ASSEMBLY_NAME, ASSEMBLY_NAME + ".dll");
124 		}
125 
126 		[TearDown]
TearDown()127 		protected void TearDown ()
128 		{
129 			try {
130 				Directory.Delete (tempDir, true);
131 			} catch (DirectoryNotFoundException) {
132 			} catch (IOException) {
133 				// Can happen on Windows if assemblies from this dir are still used
134 			}
135 		}
136 
137 
138 		static int typeIndexer = 0;
139 
140 		// Return a unique type name
genTypeName()141 		private string genTypeName ()
142 		{
143 			return "t" + (typeIndexer++);
144 		}
145 
nullName()146 		private string nullName ()
147 		{
148 			return String.Format ("{0}", (char) 0);
149 		}
150 
151 		[Test]
TestAssembly()152 		public void TestAssembly ()
153 		{
154 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
155 			Assert.AreEqual (assembly, tb.Assembly);
156 		}
157 
158 		[Test]
TestAssemblyQualifiedName()159 		public void TestAssemblyQualifiedName ()
160 		{
161 			TypeBuilder tb = module.DefineType ("A.B.C.D", TypeAttributes.Public);
162 			Assert.AreEqual ("A.B.C.D, " + assembly.GetName ().FullName,
163 				tb.AssemblyQualifiedName);
164 		}
165 
166 		[Test]
TestAttributes()167 		public void TestAttributes ()
168 		{
169 			TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
170 			TypeBuilder tb = module.DefineType (genTypeName (), attrs);
171 			Assert.AreEqual (attrs, tb.Attributes);
172 		}
173 
174 		[Test]
TestBaseTypeClass()175 		public void TestBaseTypeClass ()
176 		{
177 			TypeAttributes attrs = TypeAttributes.Public;
178 			TypeBuilder tb = module.DefineType (genTypeName (), attrs);
179 			Assert.AreEqual (typeof (object), tb.BaseType, "#1");
180 
181 			TypeBuilder tb2 = module.DefineType (genTypeName (), attrs, tb);
182 			Assert.AreEqual (tb, tb2.BaseType, "#2");
183 		}
184 
185 		[Test] // bug #71301
TestBaseTypeInterface()186 		public void TestBaseTypeInterface ()
187 		{
188 			TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
189 			Assert.IsNull (tb3.BaseType);
190 		}
191 
192 		[Test]
TestDeclaringType()193 		public void TestDeclaringType ()
194 		{
195 			TypeAttributes attrs = 0;
196 			TypeBuilder tb = module.DefineType (genTypeName (), attrs);
197 			Assert.IsNull (tb.DeclaringType, "#1");
198 
199 			attrs = TypeAttributes.NestedPublic;
200 			TypeBuilder tb2 = tb.DefineNestedType (genTypeName (), attrs);
201 			TypeBuilder tb3 = tb2.DefineNestedType (genTypeName (), attrs);
202 			Assert.AreEqual (tb3.DeclaringType.DeclaringType, tb, "#2");
203 		}
204 
205 		[Test]
TestFullName()206 		public void TestFullName ()
207 		{
208 			string name = genTypeName ();
209 			TypeAttributes attrs = 0;
210 			TypeBuilder tb = module.DefineType (name, attrs);
211 			Assert.AreEqual (name, tb.FullName, "#1");
212 
213 			string name2 = genTypeName ();
214 			attrs = TypeAttributes.NestedPublic;
215 			TypeBuilder tb2 = tb.DefineNestedType (name2, attrs);
216 
217 			string name3 = genTypeName ();
218 			attrs = TypeAttributes.NestedPublic;
219 			TypeBuilder tb3 = tb2.DefineNestedType (name3, attrs);
220 
221 			Assert.AreEqual (name + "+" + name2 + "+" + name3, tb3.FullName, "#2");
222 		}
223 
224 		[Test]
DefineCtorUsingDefineMethod()225 		public void DefineCtorUsingDefineMethod ()
226 		{
227 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Class);
228 			MethodBuilder mb = tb.DefineMethod(
229 				".ctor", MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
230 				null, null);
231 			ILGenerator ilgen = mb.GetILGenerator();
232 			ilgen.Emit(OpCodes.Ldarg_0);
233 			ilgen.Emit(OpCodes.Call,
234 					   typeof(object).GetConstructor(Type.EmptyTypes));
235 			ilgen.Emit(OpCodes.Ret);
236 			Type t = tb.CreateType();
237 
238 			Assert.AreEqual (1, t.GetConstructors ().Length);
239 		}
240 
241 		[Test]
TestGUIDIncomplete()242 		public void TestGUIDIncomplete ()
243 		{
244 			TypeBuilder tb = module.DefineType (genTypeName ());
245 			try {
246 				Guid g = tb.GUID;
247 				Assert.Fail ("#1");
248 			} catch (NotSupportedException ex) {
249 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
250 				Assert.IsNull (ex.InnerException, "#3");
251 				Assert.IsNotNull (ex.Message, "#4");
252 			}
253 		}
254 
255 		[Test] // bug #71302
256 		[Category ("NotWorking")]
TestGUIDComplete()257 		public void TestGUIDComplete ()
258 		{
259 			TypeBuilder tb = module.DefineType (genTypeName ());
260 			tb.CreateType ();
261 			Assert.IsTrue (tb.GUID != Guid.Empty);
262 		}
263 
264 		[Test]
265 		[Category ("NotWorking")]
TestFixedGUIDComplete()266 		public void TestFixedGUIDComplete ()
267 		{
268 			TypeBuilder tb = module.DefineType (genTypeName ());
269 
270 			Guid guid = Guid.NewGuid ();
271 
272 			ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
273 				new Type [] { typeof (string) });
274 
275 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
276 				new object [] { guid.ToString ("D") }, new FieldInfo [0], new object [0]);
277 
278 			tb.SetCustomAttribute (caBuilder);
279 			tb.CreateType ();
280 			Assert.AreEqual (guid, tb.GUID);
281 		}
282 
283 		[Test]
TestHasElementType_Incomplete()284 		public void TestHasElementType_Incomplete ()
285 		{
286 			// According to the MSDN docs, this member works, but in reality, it
287 			// returns a NotSupportedException
288 			TypeBuilder tb = module.DefineType (genTypeName ());
289 			Assert.IsFalse (tb.HasElementType);
290 		}
291 
292 		[Test]
TestHasElementType_Complete()293 		public void TestHasElementType_Complete ()
294 		{
295 			// According to the MSDN docs, this member works, but in reality, it
296 			// returns a NotSupportedException
297 			TypeBuilder tb = module.DefineType (genTypeName ());
298 			tb.CreateType ();
299 			Assert.IsFalse (tb.HasElementType);
300 		}
301 
302 		[Test] // bug #324692
CreateType_Enum_NoInstanceField()303 		public void CreateType_Enum_NoInstanceField ()
304 		{
305 			TypeBuilder tb = module.DefineType (genTypeName (),
306 				TypeAttributes.Sealed | TypeAttributes.Serializable,
307 				typeof (Enum));
308 
309 			try {
310 				tb.CreateType ();
311 				Assert.Fail ("#1: must throw TypeLoadException");
312 			} catch (TypeLoadException) {
313 			}
314 
315 			Assert.IsTrue (tb.IsCreated (), "#2");
316 		}
317 
318 		[Test] // bug #324692
TestCreateTypeReturnsNullOnSecondCallForBadType()319 		public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
320 		{
321 			TypeBuilder tb = module.DefineType (genTypeName (),
322 				TypeAttributes.Sealed | TypeAttributes.Serializable,
323 				typeof (Enum));
324 
325 			try {
326 				tb.CreateType ();
327 				Assert.Fail ("#A1");
328 			} catch (TypeLoadException ex) {
329 				Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
330 				Assert.IsNull (ex.InnerException, "#A3");
331 				Assert.IsNotNull (ex.Message, "#A4");
332 			}
333 
334 			Assert.IsTrue (tb.IsCreated (), "#B1");
335 			Assert.IsNull (tb.CreateType (), "#B2");
336 			Assert.IsTrue (tb.IsCreated (), "#B3");
337 		}
338 
339 		[Test]
TestEnumWithEmptyInterfaceBuildsOk()340 		public void TestEnumWithEmptyInterfaceBuildsOk ()
341 		{
342 			TypeBuilder tb = module.DefineType (genTypeName (),
343 				TypeAttributes.Sealed | TypeAttributes.Serializable,
344 				typeof (Enum));
345 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
346 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
347 
348 			tb.AddInterfaceImplementation (typeof (EmptyInterface));
349 
350 			try {
351 				tb.CreateType ();
352 			} catch (TypeLoadException) {
353 				Assert.Fail ("#1: must build enum type ok");
354 			}
355 
356 			Assert.IsTrue (tb.IsCreated (), "#2");
357 		}
358 
359 		[Test]
360 		[Category ("NotWorking")]
TestEnumWithNonEmptyInterfaceBuildsFails()361 		public void TestEnumWithNonEmptyInterfaceBuildsFails ()
362 		{
363 			TypeBuilder tb = module.DefineType (genTypeName (),
364 				TypeAttributes.Sealed | TypeAttributes.Serializable,
365 				typeof (Enum));
366 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
367 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
368 
369 			tb.AddInterfaceImplementation (typeof (OneMethodInterface));
370 
371 			try {
372 				tb.CreateType ();
373 				Assert.Fail ("#1: type doesn't have all interface methods");
374 			} catch (TypeLoadException) {
375 			}
376 
377 			Assert.IsTrue (tb.IsCreated (), "#2");
378 		}
379 
380 		[Test]
381 		[Category ("NotWorking")]
TestTypeDontImplementInterfaceMethodBuildsFails()382 		public void TestTypeDontImplementInterfaceMethodBuildsFails ()
383 		{
384 			TypeBuilder tb = module.DefineType (genTypeName (),
385 				TypeAttributes.Sealed | TypeAttributes.Serializable,
386 				typeof (object));
387 
388 			tb.AddInterfaceImplementation (typeof (OneMethodInterface));
389 
390 			try {
391 				tb.CreateType ();
392 				Assert.Fail ("#1: type doesn't have all interface methods");
393 			} catch (TypeLoadException) {
394 			}
395 
396 			Assert.IsTrue (tb.IsCreated (), "#2");
397 		}
398 
399 		[Test]
TestEnumWithSequentialLayoutBuildsFails()400 		public void TestEnumWithSequentialLayoutBuildsFails ()
401 		{
402 			TypeBuilder tb = module.DefineType (genTypeName (),
403 				TypeAttributes.Sealed | TypeAttributes.Serializable |
404 				TypeAttributes.SequentialLayout, typeof (Enum));
405 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
406 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
407 
408 			try {
409 				tb.CreateType ();
410 				Assert.Fail ("#1: type doesn't have all interface methods");
411 			} catch (TypeLoadException) {
412 			}
413 
414 			Assert.IsTrue (tb.IsCreated (), "#2");
415 		}
416 
417 		[Test]
TestEnumWithExplicitLayoutBuildsFails()418 		public void TestEnumWithExplicitLayoutBuildsFails ()
419 		{
420 			TypeBuilder tb = module.DefineType (genTypeName (),
421 				TypeAttributes.Sealed | TypeAttributes.Serializable |
422 				TypeAttributes.ExplicitLayout, typeof (Enum));
423 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
424 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
425 
426 			try {
427 				tb.CreateType ();
428 				Assert.Fail ("#1: type doesn't have all interface methods");
429 			} catch (TypeLoadException) {
430 			}
431 
432 			Assert.IsTrue (tb.IsCreated (), "#2");
433 		}
434 
435 		[Test]
TestEnumWithMethodsBuildFails()436 		public void TestEnumWithMethodsBuildFails ()
437 		{
438 			TypeBuilder tb = module.DefineType ("FooEnum7",
439 				TypeAttributes.Sealed | TypeAttributes.Serializable,
440 				typeof (Enum));
441 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
442 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
443 
444 			MethodBuilder methodBuilder = tb.DefineMethod("mmm",
445 				MethodAttributes.Public | MethodAttributes.Virtual,
446 				null,
447 				new Type[] { });
448 
449 			methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
450 			try {
451 				tb.CreateType ();
452 				Assert.Fail ("#1: enum has method");
453 			} catch (TypeLoadException) {
454 			}
455 
456 			Assert.IsTrue (tb.IsCreated (), "#2");
457 		}
458 
459 		[Test]
TestEnumWithBadTypeValueFieldBuildFails()460 		public void TestEnumWithBadTypeValueFieldBuildFails ()
461 		{
462 			Type[] badTypes = {
463 				typeof (object),
464 				typeof (string),
465 				typeof (DateTime)
466 			};
467 
468 			foreach (Type type in badTypes) {
469 				TypeBuilder tb = module.DefineType (genTypeName (),
470 					TypeAttributes.Sealed | TypeAttributes.Serializable,
471 					typeof (Enum));
472 				tb.DefineField ("value__", type, FieldAttributes.SpecialName |
473 					FieldAttributes.Private | FieldAttributes.RTSpecialName);
474 
475 				try {
476 					tb.CreateType ();
477 					Assert.Fail ("#1: enum using bad type: " + type);
478 				} catch (TypeLoadException) {
479 				}
480 
481 				Assert.IsTrue (tb.IsCreated (), "#2");
482 			}
483 		}
484 
485 		[Test]
TestEnumWithGoodTypeValueFieldBuildOk()486 		public void TestEnumWithGoodTypeValueFieldBuildOk ()
487 		{
488 			Type[] goodTypes = {
489 				typeof (byte),typeof (sbyte),typeof (bool),
490 				typeof (ushort),typeof (short),typeof (char),
491 				typeof (uint),typeof (int),
492 				typeof (ulong),typeof (long),
493 				typeof (UIntPtr),typeof (IntPtr),
494 			};
495 
496 			foreach (Type type in goodTypes) {
497 				TypeBuilder tb = module.DefineType (genTypeName (),
498 					TypeAttributes.Sealed | TypeAttributes.Serializable,
499 					typeof (Enum));
500 				tb.DefineField ("value__", type, FieldAttributes.SpecialName |
501 					FieldAttributes.Private | FieldAttributes.RTSpecialName);
502 
503 				try {
504 					tb.CreateType ();
505 				} catch (TypeLoadException) {
506 					Assert.Fail ("#1: enum using good type: " + type);
507 				}
508 			}
509 		}
510 
511 		[Test]
TestEnumWithMultipleValueFieldsBuildFals()512 		public void TestEnumWithMultipleValueFieldsBuildFals ()
513 		{
514 			TypeBuilder tb = module.DefineType (genTypeName (),
515 				TypeAttributes.Sealed | TypeAttributes.Serializable,
516 				typeof (Enum));
517 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
518 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
519 			tb.DefineField ("value2__", typeof (int), FieldAttributes.SpecialName |
520 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
521 
522 			try {
523 				tb.CreateType ();
524 				Assert.Fail ("#1: invalid enum type");
525 			} catch (TypeLoadException) {
526 			}
527 
528 			Assert.IsTrue (tb.IsCreated (), "#2");
529 		}
530 
531 		[Test]
532 		[Category ("NotWorking")]
TestEnumWithEmptyInterfaceCanBeCasted()533 		public void TestEnumWithEmptyInterfaceCanBeCasted ()
534 		{
535 			TypeBuilder tb = module.DefineType (genTypeName (),
536 				TypeAttributes.Sealed | TypeAttributes.Serializable,
537 				typeof (Enum));
538 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
539 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
540 			tb.AddInterfaceImplementation (typeof (EmptyInterface));
541 
542 			try {
543 				tb.CreateType ();
544 			} catch (TypeLoadException) {
545 				Assert.Fail ("#1: must build enum type ok");
546 			}
547 
548 			try {
549 				EmptyInterface obj = (EmptyInterface) Activator.CreateInstance (tb);
550 				Assert.IsNotNull (obj, "#2");
551 			} catch (TypeLoadException) {
552 				Assert.Fail ("#3: must cast enum to interface");
553 			}
554 		}
555 
556 		[Test]
TestEnumWithValueFieldBuildOk()557 		public void TestEnumWithValueFieldBuildOk ()
558 		{
559 			TypeBuilder tb = module.DefineType (genTypeName (),
560 				TypeAttributes.Sealed | TypeAttributes.Serializable,
561 				typeof (Enum));
562 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
563 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
564 
565 			try {
566 				tb.CreateType ();
567 			} catch (TypeLoadException) {
568 				Assert.Fail ("#1: must build enum type ok");
569 			}
570 		}
571 
572 		[Test]
TestEnumWithLateUnderlyingField()573 		public void TestEnumWithLateUnderlyingField ()
574 		{
575 			TypeBuilder enumToCreate = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (Enum));
576 			enumToCreate.DefineField ("value__", typeof (Int32),
577 				FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
578 
579 			TypeBuilder enumToCreate2 = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (Enum));
580 
581 			TypeBuilder ivTypeBld = module.DefineType (genTypeName (), TypeAttributes.Public);
582 
583 			ConstructorBuilder ivCtor = ivTypeBld.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
584 
585 			ILGenerator ctorIL = ivCtor.GetILGenerator ();
586 
587 			ctorIL.Emit (OpCodes.Ldtoken, typeof (Object));
588 			ctorIL.Emit (OpCodes.Pop);
589 			ctorIL.Emit (OpCodes.Ldtoken, enumToCreate);
590 			ctorIL.Emit (OpCodes.Pop);
591 			ctorIL.Emit (OpCodes.Ldtoken, enumToCreate2);
592 			ctorIL.Emit (OpCodes.Pop);
593 			ctorIL.Emit (OpCodes.Ret);
594 
595 			var ivType = ivTypeBld.CreateType ();
596 
597 			enumToCreate2.DefineField ("value__", typeof (Int32), FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
598 
599 			FieldBuilder fb = enumToCreate2.DefineField ("A", enumToCreate, FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
600 			fb.SetConstant (0);
601 
602 			enumToCreate.CreateType ();
603 			enumToCreate2.CreateType ();
604 		}
605 
606 		[Test]
TestIsAbstract()607 		public void TestIsAbstract ()
608 		{
609 			TypeBuilder tb = module.DefineType (genTypeName ());
610 			Assert.IsFalse (tb.IsAbstract, "#1");
611 
612 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Abstract);
613 			Assert.IsTrue (tb2.IsAbstract, "#2");
614 		}
615 
616 		[Test]
TestIsAnsiClass()617 		public void TestIsAnsiClass ()
618 		{
619 			TypeBuilder tb = module.DefineType (genTypeName ());
620 			Assert.IsTrue (tb.IsAnsiClass, "#1");
621 
622 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
623 			Assert.IsFalse (tb2.IsAnsiClass, "#2");
624 		}
625 
626 		[Test]
TestIsArray()627 		public void TestIsArray ()
628 		{
629 			// How can a TypeBuilder be an array ?
630 			string name = genTypeName ();
631 			TypeBuilder tb = module.DefineType (name);
632 			Assert.IsFalse (tb.IsArray);
633 		}
634 
635 		[Test]
TestIsAutoClass()636 		public void TestIsAutoClass ()
637 		{
638 			TypeBuilder tb = module.DefineType (genTypeName ());
639 			Assert.IsFalse (tb.IsAutoClass, "#1");
640 
641 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.AutoClass);
642 			Assert.IsTrue (tb2.IsAutoClass, "#2");
643 		}
644 
645 		[Test]
TestIsAutoLayout()646 		public void TestIsAutoLayout ()
647 		{
648 			TypeBuilder tb = module.DefineType (genTypeName ());
649 			Assert.IsTrue (tb.IsAutoLayout, "#1");
650 
651 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
652 			Assert.IsFalse (tb2.IsAutoLayout, "#2");
653 		}
654 
655 		[Test]
TestIsByRef()656 		public void TestIsByRef ()
657 		{
658 			// How can a TypeBuilder be ByRef ?
659 			TypeBuilder tb = module.DefineType (genTypeName ());
660 			Assert.IsFalse (tb.IsByRef);
661 		}
662 
663 		[Test]
TestIsClass()664 		public void TestIsClass ()
665 		{
666 			TypeBuilder tb = module.DefineType (genTypeName ());
667 			Assert.IsTrue (tb.IsClass, "#1");
668 
669 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
670 			Assert.IsFalse (tb2.IsClass, "#2");
671 
672 			TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
673 			Assert.IsFalse (tb3.IsClass, "#3");
674 
675 			TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
676 			Assert.IsFalse (tb4.IsClass, "#4");
677 		}
678 
679 		[Test] // bug #71304
TestIsCOMObject()680 		public void TestIsCOMObject ()
681 		{
682 			TypeBuilder tb = module.DefineType (genTypeName ());
683 			Assert.IsFalse (tb.IsCOMObject, "#1");
684 
685 			tb = module.DefineType (genTypeName (), TypeAttributes.Import);
686 			Assert.IsTrue (tb.IsCOMObject, "#2");
687 		}
688 
689 		[Test]
TestIsContextful()690 		public void TestIsContextful ()
691 		{
692 			TypeBuilder tb = module.DefineType (genTypeName ());
693 			Assert.IsFalse (tb.IsContextful, "#1");
694 
695 			TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
696 			Assert.IsTrue (tb2.IsContextful, "#2");
697 		}
698 
699 		[Test]
TestIsEnum()700 		public void TestIsEnum ()
701 		{
702 			TypeBuilder tb = module.DefineType (genTypeName ());
703 			Assert.IsFalse (tb.IsEnum, "#1");
704 
705 			TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ValueType));
706 			Assert.IsFalse (tb2.IsEnum, "#2");
707 
708 			TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (Enum));
709 			Assert.IsTrue (tb3.IsEnum, "#3");
710 		}
711 
712 		[Test]
TestIsExplicitLayout()713 		public void TestIsExplicitLayout ()
714 		{
715 			TypeBuilder tb = module.DefineType (genTypeName ());
716 			Assert.IsFalse (tb.IsExplicitLayout, "#1");
717 
718 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
719 			Assert.IsTrue (tb2.IsExplicitLayout, "#2");
720 		}
721 
722 		[Test]
TestIsImport()723 		public void TestIsImport ()
724 		{
725 			TypeBuilder tb = module.DefineType (genTypeName ());
726 			Assert.IsFalse (tb.IsImport, "#1");
727 
728 			tb = module.DefineType (genTypeName (), TypeAttributes.Import);
729 			Assert.IsTrue (tb.IsImport, "#2");
730 		}
731 
732 		[Test]
TestIsInterface()733 		public void TestIsInterface ()
734 		{
735 			TypeBuilder tb = module.DefineType (genTypeName ());
736 			Assert.IsFalse (tb.IsInterface, "#1");
737 
738 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
739 			Assert.IsTrue (tb2.IsInterface, "#2");
740 
741 			TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
742 			Assert.IsFalse (tb3.IsInterface, "#3");
743 		}
744 
745 		[Test]
TestIsLayoutSequential()746 		public void TestIsLayoutSequential ()
747 		{
748 			TypeBuilder tb = module.DefineType (genTypeName ());
749 			Assert.IsFalse (tb.IsLayoutSequential, "#1");
750 
751 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SequentialLayout);
752 			Assert.IsTrue (tb2.IsLayoutSequential, "#2");
753 		}
754 
755 		[Test]
TestIsMarshalByRef()756 		public void TestIsMarshalByRef ()
757 		{
758 			TypeBuilder tb = module.DefineType (genTypeName ());
759 			Assert.IsFalse (tb.IsMarshalByRef, "#1");
760 
761 			TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (MarshalByRefObject));
762 			Assert.IsTrue (tb2.IsMarshalByRef, "#2");
763 
764 			TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
765 			Assert.IsTrue (tb3.IsMarshalByRef, "#3");
766 		}
767 
768 		// TODO: Visibility properties
769 
770 		[Test]
TestIsPointer()771 		public void TestIsPointer ()
772 		{
773 			// How can this be true?
774 			TypeBuilder tb = module.DefineType (genTypeName ());
775 			Assert.IsFalse (tb.IsPointer);
776 		}
777 
778 		[Test]
TestIsPrimitive()779 		public void TestIsPrimitive ()
780 		{
781 			TypeBuilder tb = module.DefineType ("int");
782 			Assert.IsFalse (tb.IsPrimitive);
783 		}
784 
785 		[Test]
IsSealed()786 		public void IsSealed ()
787 		{
788 			TypeBuilder tb = module.DefineType (genTypeName ());
789 			Assert.IsFalse (tb.IsSealed, "#1");
790 
791 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
792 			Assert.IsTrue (tb2.IsSealed, "#2");
793 		}
794 
795 		[Test]
IsSerializable()796 		public void IsSerializable ()
797 		{
798 			TypeBuilder tb = module.DefineType (genTypeName ());
799 			Assert.IsFalse (tb.IsSerializable, "#1");
800 
801 			ConstructorInfo [] ctors = typeof (SerializableAttribute).GetConstructors (BindingFlags.Instance | BindingFlags.Public);
802 			Assert.IsTrue (ctors.Length > 0, "#2");
803 
804 			tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
805 			Type createdType = tb.CreateType ();
806 
807 			string an = "IsSerializableTestAssembly.dll";
808 			assembly.Save (an);
809 			Assert.IsTrue (createdType.IsSerializable, "#3");
810 			File.Delete (Path.Combine (tempDir, an));
811 		}
812 
813 		[Test]
TestIsSpecialName()814 		public void TestIsSpecialName ()
815 		{
816 			TypeBuilder tb = module.DefineType (genTypeName ());
817 			Assert.IsFalse (tb.IsSpecialName, "#1");
818 
819 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SpecialName);
820 			Assert.IsTrue (tb2.IsSpecialName, "#2");
821 		}
822 
823 		[Test]
TestIsUnicodeClass()824 		public void TestIsUnicodeClass ()
825 		{
826 			TypeBuilder tb = module.DefineType (genTypeName ());
827 			Assert.IsFalse (tb.IsUnicodeClass, "#1");
828 
829 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
830 			Assert.IsTrue (tb2.IsUnicodeClass, "#2");
831 		}
832 
833 		[Test]
TestIsValueType()834 		public void TestIsValueType ()
835 		{
836 			TypeBuilder tb = module.DefineType (genTypeName ());
837 			Assert.IsFalse (tb.IsValueType, "#1");
838 
839 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
840 			Assert.IsFalse (tb2.IsValueType, "#2");
841 
842 			TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
843 			Assert.IsTrue (tb3.IsValueType, "#3");
844 
845 			TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
846 			Assert.IsTrue (tb4.IsValueType, "#4");
847 		}
848 
849 		[Test]
TestMemberType()850 		public void TestMemberType ()
851 		{
852 			TypeBuilder tb = module.DefineType (genTypeName ());
853 			Assert.AreEqual (MemberTypes.TypeInfo, tb.MemberType);
854 		}
855 
856 		[Test]
TestModule()857 		public void TestModule ()
858 		{
859 			TypeBuilder tb = module.DefineType (genTypeName ());
860 			Assert.AreEqual (module, tb.Module);
861 		}
862 
863 		[Test]
TestName()864 		public void TestName ()
865 		{
866 			TypeBuilder tb = module.DefineType ("A");
867 			Assert.AreEqual ("A", tb.Name, "#1");
868 
869 			TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
870 			Assert.AreEqual ("E", tb2.Name, "#2");
871 
872 			TypeBuilder tb3 = tb2.DefineNestedType ("A");
873 			Assert.AreEqual ("A", tb3.Name, "#3");
874 
875 			/* Is .E a valid name ?
876 			TypeBuilder tb4 = module.DefineType (".E");
877 			Assert.AreEqual ("E", tb4.Name);
878 			*/
879 		}
880 
881 		[Test]
TestNamespace()882 		public void TestNamespace ()
883 		{
884 			TypeBuilder tb = module.DefineType ("A");
885 			Assert.AreEqual (string.Empty, tb.Namespace, "#1");
886 
887 			TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
888 			Assert.AreEqual ("A.B.C.D", tb2.Namespace, "#2");
889 
890 			TypeBuilder tb3 = tb2.DefineNestedType ("A");
891 			Assert.AreEqual (string.Empty, tb3.Namespace, "#3");
892 
893 			/* Is .E a valid name ?
894 			TypeBuilder tb4 = module.DefineType (".E");
895 			Assert.AreEqual ("E", tb4.Name);
896 			*/
897 		}
898 
899 		[Test]
TestPackingSize()900 		public void TestPackingSize ()
901 		{
902 			TypeBuilder tb = module.DefineType (genTypeName ());
903 			Assert.AreEqual (PackingSize.Unspecified, tb.PackingSize, "#1");
904 
905 			TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (object),
906 				PackingSize.Size16, 16);
907 			Assert.AreEqual (PackingSize.Size16, tb2.PackingSize, "#2");
908 		}
909 
910 		[Test]
TestReflectedType()911 		public void TestReflectedType ()
912 		{
913 			// It is the same as DeclaringType, but why?
914 			TypeBuilder tb = module.DefineType (genTypeName ());
915 			Assert.IsNull (tb.ReflectedType, "#1");
916 
917 			TypeBuilder tb2 = tb.DefineNestedType (genTypeName ());
918 			Assert.AreEqual (tb, tb2.ReflectedType, "#2");
919 		}
920 
921 		[Test]
SetParent_Parent_Null()922 		public void SetParent_Parent_Null ()
923 		{
924 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class,
925 				typeof (Attribute));
926 			tb.SetParent (null);
927 			Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
928 
929 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
930 				TypeAttributes.Abstract);
931 			tb.SetParent (null);
932 			Assert.IsNull (tb.BaseType, "#B1");
933 
934 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
935 				TypeAttributes.Abstract, typeof (ICloneable));
936 			Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#C1");
937 			tb.SetParent (null);
938 			Assert.IsNull (tb.BaseType, "#C2");
939 
940 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
941 				typeof (IDisposable));
942 			try {
943 				tb.SetParent (null);
944 				Assert.Fail ("#D1");
945 			} catch (InvalidOperationException ex) {
946 				// Interface must be declared abstract
947 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
948 				Assert.IsNull (ex.InnerException, "#D3");
949 				Assert.IsNotNull (ex.Message, "#D4");
950 			}
951 		}
952 
953 		[Test]
SetParent_Parent_Interface()954 		public void SetParent_Parent_Interface ()
955 		{
956 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class);
957 			tb.SetParent (typeof (ICloneable));
958 			Assert.AreEqual (typeof (ICloneable), tb.BaseType);
959 		}
960 
961 		[Test]
TestSetParentIncomplete()962 		public void TestSetParentIncomplete ()
963 		{
964 			TypeBuilder tb = module.DefineType (genTypeName ());
965 			tb.SetParent (typeof (Attribute));
966 			Assert.AreEqual (typeof (Attribute), tb.BaseType, "#1");
967 
968 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
969 				TypeAttributes.Abstract);
970 			tb.SetParent (typeof (IDisposable));
971 			Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#2");
972 
973 			tb = module.DefineType (genTypeName ());
974 			tb.SetParent (typeof (IDisposable));
975 			Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#3");
976 
977 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
978 				TypeAttributes.Abstract, typeof (IDisposable));
979 			tb.SetParent (typeof (ICloneable));
980 			Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#4");
981 
982 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
983 				TypeAttributes.Abstract, typeof (IDisposable));
984 			tb.SetParent (typeof (ICloneable));
985 			Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#5");
986 		}
987 
988 		[Test]
TestSetParentComplete()989 		public void TestSetParentComplete ()
990 		{
991 			TypeBuilder tb = module.DefineType (genTypeName ());
992 			tb.CreateType ();
993 			try {
994 				tb.SetParent (typeof (Attribute));
995 				Assert.Fail ("#1");
996 			} catch (InvalidOperationException ex) {
997 				// Unable to change after type has been created
998 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
999 				Assert.IsNull (ex.InnerException, "#3");
1000 				Assert.IsNotNull (ex.Message, "#4");
1001 			}
1002 		}
1003 
1004 		[Test]
TestSize()1005 		public void TestSize ()
1006 		{
1007 			{
1008 				TypeBuilder tb = module.DefineType (genTypeName ());
1009 				Assert.AreEqual (0, tb.Size, "#1");
1010 				tb.CreateType ();
1011 				Assert.AreEqual (0, tb.Size, "#2");
1012 			}
1013 
1014 			{
1015 				TypeBuilder tb = module.DefineType (genTypeName (), 0, typeof (object),
1016 					PackingSize.Size16, 32);
1017 				Assert.AreEqual (32, tb.Size, "#3");
1018 			}
1019 		}
1020 
1021 		[Test]
TestTypeHandle()1022 		public void TestTypeHandle ()
1023 		{
1024 			TypeBuilder tb = module.DefineType (genTypeName ());
1025 			try {
1026 				RuntimeTypeHandle handle = tb.TypeHandle;
1027 				Assert.Fail ("#1:" + handle);
1028 			} catch (NotSupportedException ex) {
1029 				// The invoked member is not supported in a
1030 				// dynamic module
1031 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1032 				Assert.IsNull (ex.InnerException, "#3");
1033 				Assert.IsNotNull (ex.Message, "#4");
1034 			}
1035 		}
1036 
1037 		[Test]
TestTypeInitializerIncomplete()1038 		public void TestTypeInitializerIncomplete ()
1039 		{
1040 			TypeBuilder tb = module.DefineType (genTypeName ());
1041 			try {
1042 				ConstructorInfo cb = tb.TypeInitializer;
1043 				Assert.Fail ("#1:" + (cb != null));
1044 			} catch (NotSupportedException ex) {
1045 				// The invoked member is not supported in a
1046 				// dynamic module
1047 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1048 				Assert.IsNull (ex.InnerException, "#3");
1049 				Assert.IsNotNull (ex.Message, "#4");
1050 			}
1051 		}
1052 
1053 		[Test]
TestTypeInitializerComplete()1054 		public void TestTypeInitializerComplete ()
1055 		{
1056 			TypeBuilder tb = module.DefineType (genTypeName ());
1057 			tb.CreateType ();
1058 			ConstructorInfo cb = tb.TypeInitializer;
1059 		}
1060 
1061 		[Test]
TestTypeToken()1062 		public void TestTypeToken ()
1063 		{
1064 			TypeBuilder tb = module.DefineType (genTypeName ());
1065 			TypeToken token = tb.TypeToken;
1066 		}
1067 
1068 		[Test]
UnderlyingSystemType()1069 		public void UnderlyingSystemType ()
1070 		{
1071 			TypeBuilder tb;
1072 			Type emitted_type;
1073 
1074 			tb = module.DefineType (genTypeName ());
1075 			Assert.AreSame (tb, tb.UnderlyingSystemType, "#A1");
1076 			emitted_type = tb.CreateType ();
1077 			Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#A2");
1078 
1079 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1080 			Assert.AreSame (tb, tb.UnderlyingSystemType, "#B1");
1081 			emitted_type = tb.CreateType ();
1082 			Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#B2");
1083 
1084 			tb = module.DefineType (genTypeName (), 0, typeof (ValueType));
1085 			Assert.AreSame (tb, tb.UnderlyingSystemType, "#C1");
1086 			emitted_type = tb.CreateType ();
1087 			Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#C2");
1088 
1089 			tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1090 			try {
1091 				Type t = tb.UnderlyingSystemType;
1092 				Assert.Fail ("#D1:" + t);
1093 			} catch (InvalidOperationException ex) {
1094 				// Underlying type information on enumeration
1095 				// is not specified
1096 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1097 				Assert.IsNull (ex.InnerException, "#D3");
1098 				Assert.IsNotNull (ex.Message, "#D4");
1099 			}
1100 			tb.DefineField ("val", typeof (int), FieldAttributes.Private);
1101 			Assert.AreEqual (typeof (int), tb.UnderlyingSystemType, "#D5");
1102 			emitted_type = tb.CreateType ();
1103 			Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#D6");
1104 
1105 			tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1106 			tb.DefineField ("val", typeof (int), FieldAttributes.Static);
1107 			try {
1108 				Type t = tb.UnderlyingSystemType;
1109 				Assert.Fail ("#E1:" + t);
1110 			} catch (InvalidOperationException ex) {
1111 				// Underlying type information on enumeration
1112 				// is not specified
1113 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1114 				Assert.IsNull (ex.InnerException, "#E3");
1115 				Assert.IsNotNull (ex.Message, "#E4");
1116 			}
1117 			tb.DefineField ("foo", typeof (long), FieldAttributes.Private);
1118 			Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E5");
1119 			tb.DefineField ("bar", typeof (short), FieldAttributes.Private);
1120 			Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E6");
1121 			tb.DefineField ("boo", typeof (int), FieldAttributes.Static);
1122 			Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E7");
1123 		}
1124 
1125 		[Test]
AddInterfaceImplementation_InterfaceType_Null()1126 		public void AddInterfaceImplementation_InterfaceType_Null ()
1127 		{
1128 			TypeBuilder tb = module.DefineType (genTypeName ());
1129 			try {
1130 				tb.AddInterfaceImplementation (null);
1131 				Assert.Fail ("#1");
1132 			} catch (ArgumentNullException ex) {
1133 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1134 				Assert.IsNull (ex.InnerException, "#3");
1135 				Assert.IsNotNull (ex.Message, "#4");
1136 				Assert.AreEqual ("interfaceType", ex.ParamName, "#5");
1137 			}
1138 		}
1139 
1140 		[Test]
TestAddInterfaceImplementation()1141 		public void TestAddInterfaceImplementation ()
1142 		{
1143 			TypeBuilder tb = module.DefineType (genTypeName ());
1144 			tb.AddInterfaceImplementation (typeof (AnInterface));
1145 			tb.AddInterfaceImplementation (typeof (AnInterface));
1146 
1147 			Type t = tb.CreateType ();
1148 			Assert.AreEqual (1, tb.GetInterfaces ().Length, "#2");
1149 
1150 			// Can not be called on a created type
1151 			try {
1152 				tb.AddInterfaceImplementation (typeof (AnInterface));
1153 				Assert.Fail ("#3");
1154 			} catch (InvalidOperationException) {
1155 			}
1156 		}
1157 
1158 		[Test]
TestCreateType_Created()1159 		public void TestCreateType_Created ()
1160 		{
1161 			TypeBuilder tb = module.DefineType (genTypeName ());
1162 			Assert.IsFalse (tb.IsCreated (), "#A1");
1163 
1164 			Type emittedType1 = tb.CreateType ();
1165 			Assert.IsTrue (tb.IsCreated (), "#A2");
1166 			Assert.IsNotNull (emittedType1, "#A3");
1167 
1168 			Type emittedType2 = tb.CreateType ();
1169 			Assert.IsNotNull (emittedType2, "#B1");
1170 			Assert.IsTrue (tb.IsCreated (), "#B2");
1171 			Assert.AreSame (emittedType1, emittedType2, "#B3");
1172 		}
1173 
1174 		[Test]
TestDefineConstructor()1175 		public void TestDefineConstructor ()
1176 		{
1177 			TypeBuilder tb = module.DefineType (genTypeName ());
1178 
1179 			ConstructorBuilder cb = tb.DefineConstructor (0, 0, null);
1180 			cb.GetILGenerator ().Emit (OpCodes.Ret);
1181 			tb.CreateType ();
1182 
1183 			// Can not be called on a created type
1184 			try {
1185 				tb.DefineConstructor (0, 0, null);
1186 				Assert.Fail ("#1");
1187 			} catch (InvalidOperationException ex) {
1188 				// Unable to change after type has been created
1189 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1190 				Assert.IsNull (ex.InnerException, "#3");
1191 				Assert.IsNotNull (ex.Message, "#4");
1192 			}
1193 		}
1194 
1195 		[Test]
DefineDefaultConstructor()1196 		public void DefineDefaultConstructor ()
1197 		{
1198 			TypeBuilder tb = module.DefineType (genTypeName ());
1199 			tb.DefineDefaultConstructor (0);
1200 			tb.CreateType ();
1201 
1202 			// Can not be called on a created type, altough the MSDN docs does not mention this
1203 			try {
1204 				tb.DefineDefaultConstructor (0);
1205 				Assert.Fail ("#1");
1206 			} catch (InvalidOperationException ex) {
1207 				// Unable to change after type has been created
1208 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1209 				Assert.IsNull (ex.InnerException, "#3");
1210 				Assert.IsNotNull (ex.Message, "#4");
1211 			}
1212 		}
1213 
1214 		[Test]
1215 		[Category ("InterpreterNotWorking")]
DefineDefaultConstructor_Parent_DefaultCtorInaccessible()1216 		public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1217 		{
1218 			TypeBuilder tb;
1219 
1220 			tb = module.DefineType (genTypeName ());
1221 			tb.DefineDefaultConstructor (MethodAttributes.Private);
1222 			Type parent_type = tb.CreateType ();
1223 
1224 			tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1225 				parent_type);
1226 			tb.DefineDefaultConstructor (MethodAttributes.Public);
1227 			Type emitted_type = tb.CreateType ();
1228 			try {
1229 				Activator.CreateInstance (emitted_type);
1230 				Assert.Fail ("#1");
1231 
1232 				/* MOBILE special case MethodAccessException on reflection invokes and don't wrap them. */
1233 #if MOBILE
1234 			} catch (MethodAccessException mae) {
1235 				Assert.IsNull (mae.InnerException, "#2");
1236 				Assert.IsNotNull (mae.Message, "#3");
1237 				Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#4:" + mae.Message);
1238 				Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#4:" + mae.Message);
1239 			}
1240 #else
1241 			} catch (TargetInvocationException ex) {
1242 				Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1243 				Assert.IsNotNull (ex.InnerException, "#3");
1244 				Assert.IsNotNull (ex.Message, "#4");
1245 
1246 				MethodAccessException mae = ex.InnerException as MethodAccessException;
1247 				Assert.IsNotNull (mae, "#5");
1248 				Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1249 				Assert.IsNull (mae.InnerException, "#7");
1250 				Assert.IsNotNull (mae.Message, "#8");
1251 				Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1252 				Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1253 			}
1254 #endif
1255 		}
1256 
1257 		[Test]
DefineDefaultConstructor_Parent_DefaultCtorMissing()1258 		public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1259 		{
1260 			TypeBuilder tb;
1261 
1262 			tb = module.DefineType (genTypeName ());
1263 			ConstructorBuilder cb = tb.DefineConstructor (
1264 				MethodAttributes.Public,
1265 				CallingConventions.Standard,
1266 				new Type [] { typeof (string) });
1267 			cb.GetILGenerator ().Emit (OpCodes.Ret);
1268 			Type parent_type = tb.CreateType ();
1269 
1270 			tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1271 				parent_type);
1272 			try {
1273 				tb.DefineDefaultConstructor (MethodAttributes.Public);
1274 				Assert.Fail ("#1");
1275 			} catch (NotSupportedException ex) {
1276 				// Parent does not have a default constructor.
1277 				// The default constructor must be explicitly defined
1278 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1279 				Assert.IsNull (ex.InnerException, "#3");
1280 				Assert.IsNotNull (ex.Message, "#4");
1281 			}
1282 		}
1283 
1284 		[Test]
DefineEvent_Name_NullChar()1285 		public void DefineEvent_Name_NullChar ()
1286 		{
1287 			TypeBuilder tb = module.DefineType (genTypeName ());
1288 
1289 			try {
1290 				tb.DefineEvent ("\0test", EventAttributes.None,
1291 					typeof (int));
1292 				Assert.Fail ("#A1");
1293 			} catch (ArgumentException ex) {
1294 				// Illegal name
1295 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1296 				Assert.IsNull (ex.InnerException, "#A3");
1297 				Assert.IsNotNull (ex.Message, "#A4");
1298 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1299 			}
1300 
1301 			EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1302 				typeof (int));
1303 			Assert.IsNotNull (eb, "#B1");
1304 		}
1305 
1306 		[Test]
TestDefineEvent()1307 		public void TestDefineEvent ()
1308 		{
1309 			TypeBuilder tb = module.DefineType (genTypeName ());
1310 
1311 			// Test invalid arguments
1312 			try {
1313 				tb.DefineEvent (null, 0, typeof (int));
1314 				Assert.Fail ("#A1");
1315 			} catch (ArgumentNullException ex) {
1316 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1317 				Assert.IsNull (ex.InnerException, "#A3");
1318 				Assert.IsNotNull (ex.Message, "#A4");
1319 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1320 			}
1321 
1322 			try {
1323 				tb.DefineEvent ("FOO", 0, null);
1324 				Assert.Fail ("#B1");
1325 			} catch (ArgumentNullException ex) {
1326 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1327 				Assert.IsNull (ex.InnerException, "#B3");
1328 				Assert.IsNotNull (ex.Message, "#B4");
1329 				Assert.AreEqual ("type", ex.ParamName, "#B5");
1330 			}
1331 
1332 			try {
1333 				tb.DefineEvent (string.Empty, 0, typeof (int));
1334 				Assert.Fail ("#C1");
1335 			} catch (ArgumentException ex) {
1336 				// Empty name is not legal
1337 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1338 				Assert.IsNull (ex.InnerException, "#C3");
1339 				Assert.IsNotNull (ex.Message, "#C4");
1340 				Assert.AreEqual ("name", ex.ParamName, "#C5");
1341 			}
1342 
1343 			tb.CreateType ();
1344 
1345 			// Can not be called on a created type
1346 			try {
1347 				tb.DefineEvent ("BAR", 0, typeof (int));
1348 				Assert.Fail ("#D1");
1349 			} catch (InvalidOperationException ex) {
1350 				// Unable to change after type has been created
1351 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1352 				Assert.IsNull (ex.InnerException, "#D3");
1353 				Assert.IsNotNull (ex.Message, "#D4");
1354 			}
1355 		}
1356 
1357 		[Test] // DefineField (String, Type, FieldAttributes)
DefineField1()1358 		public void DefineField1 ()
1359 		{
1360 			TypeBuilder tb = module.DefineType (genTypeName ());
1361 
1362 			// Check invalid arguments
1363 			try {
1364 				tb.DefineField (null, typeof (int), 0);
1365 				Assert.Fail ("#A1");
1366 			} catch (ArgumentNullException ex) {
1367 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1368 				Assert.IsNull (ex.InnerException, "#A3");
1369 				Assert.IsNotNull (ex.Message, "#A4");
1370 				Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1371 			}
1372 
1373 			try {
1374 				tb.DefineField (string.Empty, typeof (int), 0);
1375 				Assert.Fail ("#B1");
1376 			} catch (ArgumentException ex) {
1377 				// Empty name is not legal
1378 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1379 				Assert.IsNull (ex.InnerException, "#B3");
1380 				Assert.IsNotNull (ex.Message, "#B4");
1381 				Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1382 			}
1383 
1384 			try {
1385 				// Strangely, 'A<NULL>' is accepted...
1386 				string name = String.Format ("{0}", (char) 0);
1387 				tb.DefineField (name, typeof (int), 0);
1388 				Assert.Fail ("#C1");
1389 			} catch (ArgumentException ex) {
1390 				// Illegal name
1391 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1392 				Assert.IsNull (ex.InnerException, "#C3");
1393 				Assert.IsNotNull (ex.Message, "#C4");
1394 				Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1395 			}
1396 
1397 			try {
1398 				tb.DefineField ("A", typeof (void), 0);
1399 				Assert.Fail ("#D1");
1400 			} catch (ArgumentException ex) {
1401 				// Bad field type in defining field
1402 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1403 				Assert.IsNull (ex.InnerException, "#D3");
1404 				Assert.IsNotNull (ex.Message, "#D4");
1405 				Assert.IsNull (ex.ParamName, "#D5");
1406 			}
1407 
1408 			tb.CreateType ();
1409 
1410 			// Can not be called on a created type
1411 			try {
1412 				tb.DefineField ("B", typeof (int), 0);
1413 				Assert.Fail ("#E1");
1414 			} catch (InvalidOperationException ex) {
1415 				// Unable to change after type has been created
1416 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1417 				Assert.IsNull (ex.InnerException, "#E3");
1418 				Assert.IsNotNull (ex.Message, "#E4");
1419 			}
1420 		}
1421 
1422 		[Test] // DefineField (String, Type, FieldAttributes)
DefineField1_Name_NullChar()1423 		public void DefineField1_Name_NullChar ()
1424 		{
1425 			TypeBuilder tb = module.DefineType (genTypeName ());
1426 
1427 			try {
1428 				tb.DefineField ("\0test", typeof (int),
1429 					FieldAttributes.Private);
1430 				Assert.Fail ("#A1");
1431 			} catch (ArgumentException ex) {
1432 				// Illegal name
1433 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1434 				Assert.IsNull (ex.InnerException, "#A3");
1435 				Assert.IsNotNull (ex.Message, "#A4");
1436 				Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1437 			}
1438 
1439 			FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1440 				FieldAttributes.Private);
1441 			Assert.IsNotNull (fb, "#B1");
1442 			Assert.AreEqual ("te\0st", fb.Name, "#B2");
1443 		}
1444 
1445 		[Test] // DefineField (String, Type, FieldAttributes)
DefineField1_Type_Null()1446 		public void DefineField1_Type_Null ()
1447 		{
1448 			TypeBuilder tb = module.DefineType (genTypeName ());
1449 
1450 			try {
1451 				tb.DefineField ("test", (Type) null,
1452 					FieldAttributes.Private);
1453 				Assert.Fail ("#1");
1454 			} catch (ArgumentNullException ex) {
1455 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1456 				Assert.IsNull (ex.InnerException, "#3");
1457 				Assert.IsNotNull (ex.Message, "#4");
1458 				Assert.AreEqual ("type", ex.ParamName, "#5");
1459 			}
1460 		}
1461 
1462 		[Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
DefineField2_Type_Null()1463 		public void DefineField2_Type_Null ()
1464 		{
1465 			TypeBuilder tb = module.DefineType (genTypeName ());
1466 
1467 			try {
1468 				tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1469 					Type.EmptyTypes, FieldAttributes.Private);
1470 				Assert.Fail ("#1");
1471 			} catch (ArgumentNullException ex) {
1472 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1473 				Assert.IsNull (ex.InnerException, "#3");
1474 				Assert.IsNotNull (ex.Message, "#4");
1475 				Assert.AreEqual ("type", ex.ParamName, "#5");
1476 			}
1477 		}
1478 
1479 		[Test]
TestDefineInitializedData()1480 		public void TestDefineInitializedData ()
1481 		{
1482 			TypeBuilder tb = module.DefineType (genTypeName ());
1483 
1484 			// Check invalid arguments
1485 			try {
1486 				tb.DefineInitializedData (null, new byte [1], 0);
1487 				Assert.Fail ("#A1");
1488 			} catch (ArgumentNullException ex) {
1489 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1490 				Assert.IsNull (ex.InnerException, "#A3");
1491 				Assert.IsNotNull (ex.Message, "#A4");
1492 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1493 			}
1494 
1495 			try {
1496 				tb.DefineInitializedData ("FOO", null, 0);
1497 				Assert.Fail ("#B1");
1498 			} catch (ArgumentNullException ex) {
1499 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1500 				Assert.IsNull (ex.InnerException, "#B3");
1501 				Assert.IsNotNull (ex.Message, "#B4");
1502 				Assert.AreEqual ("data", ex.ParamName, "#B5");
1503 			}
1504 
1505 			try {
1506 				tb.DefineInitializedData (string.Empty, new byte [1], 0);
1507 				Assert.Fail ("#C1");
1508 			} catch (ArgumentException ex) {
1509 				// Empty name is not legal
1510 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1511 				Assert.IsNull (ex.InnerException, "#C3");
1512 				Assert.IsNotNull (ex.Message, "#C4");
1513 				Assert.AreEqual ("name", ex.ParamName, "#C5");
1514 			}
1515 
1516 			// The size of the data is less than or equal to zero ???
1517 			try {
1518 				tb.DefineInitializedData ("BAR", new byte [0], 0);
1519 				Assert.Fail ("#D1");
1520 			} catch (ArgumentException ex) {
1521 				// Data size must be > 0 and < 0x3f0000
1522 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1523 				Assert.IsNull (ex.InnerException, "#D3");
1524 				Assert.IsNotNull (ex.Message, "#D4");
1525 				Assert.IsNull (ex.ParamName, "#D5");
1526 			}
1527 
1528 			try {
1529 				string name = String.Format ("{0}", (char) 0);
1530 				tb.DefineInitializedData (name, new byte [1], 0);
1531 				Assert.Fail ("#E1");
1532 			} catch (ArgumentException ex) {
1533 				// Illegal name
1534 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1535 				Assert.IsNull (ex.InnerException, "#E3");
1536 				Assert.IsNotNull (ex.Message, "#E4");
1537 				Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1538 			}
1539 
1540 			tb.CreateType ();
1541 
1542 			// Can not be called on a created type, altough the MSDN docs does not mention this
1543 			try {
1544 				tb.DefineInitializedData ("BAR2", new byte [1], 0);
1545 				Assert.Fail ("#F1");
1546 			} catch (InvalidOperationException ex) {
1547 				// Unable to change after type has been created
1548 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1549 				Assert.IsNull (ex.InnerException, "#F3");
1550 				Assert.IsNotNull (ex.Message, "#F4");
1551 			}
1552 		}
1553 
1554 		[Test]
DefineUninitializedDataInvalidArgs()1555 		public void DefineUninitializedDataInvalidArgs ()
1556 		{
1557 			TypeBuilder tb = module.DefineType (genTypeName ());
1558 
1559 			try {
1560 				tb.DefineUninitializedData (null, 1, 0);
1561 				Assert.Fail ("#A1");
1562 			} catch (ArgumentNullException ex) {
1563 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1564 				Assert.IsNull (ex.InnerException, "#A3");
1565 				Assert.IsNotNull (ex.Message, "#A4");
1566 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1567 			}
1568 
1569 			try {
1570 				tb.DefineUninitializedData (string.Empty, 1, 0);
1571 				Assert.Fail ("#B1");
1572 			} catch (ArgumentException ex) {
1573 				// Empty name is not legal
1574 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1575 				Assert.IsNull (ex.InnerException, "#B3");
1576 				Assert.IsNotNull (ex.Message, "#B4");
1577 				Assert.AreEqual ("name", ex.ParamName, "#B5");
1578 			}
1579 
1580 			// The size of the data is less than or equal to zero ???
1581 			try {
1582 				tb.DefineUninitializedData ("BAR", 0, 0);
1583 				Assert.Fail ("#C1");
1584 			} catch (ArgumentException ex) {
1585 				// Data size must be > 0 and < 0x3f0000
1586 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1587 				Assert.IsNull (ex.InnerException, "#C3");
1588 				Assert.IsNotNull (ex.Message, "#C4");
1589 				Assert.IsNull (ex.ParamName, "#C5");
1590 			}
1591 
1592 			try {
1593 				string name = String.Format ("{0}", (char) 0);
1594 				tb.DefineUninitializedData (name, 1, 0);
1595 				Assert.Fail ("#D1");
1596 			} catch (ArgumentException ex) {
1597 				// Illegal name
1598 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1599 				Assert.IsNull (ex.InnerException, "#D3");
1600 				Assert.IsNotNull (ex.Message, "#D4");
1601 				Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1602 			}
1603 		}
1604 
1605 		[Test]
DefineUninitializedDataAlreadyCreated()1606 		public void DefineUninitializedDataAlreadyCreated ()
1607 		{
1608 			TypeBuilder tb = module.DefineType (genTypeName ());
1609 			tb.CreateType ();
1610 			try {
1611 				tb.DefineUninitializedData ("BAR2", 1, 0);
1612 				Assert.Fail ("#1");
1613 			} catch (InvalidOperationException ex) {
1614 				// Unable to change after type has been created
1615 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1616 				Assert.IsNull (ex.InnerException, "#3");
1617 				Assert.IsNotNull (ex.Message, "#4");
1618 			}
1619 		}
1620 
1621 		[Test]
DefineUninitializedData()1622 		public void DefineUninitializedData ()
1623 		{
1624 			TypeBuilder tb = module.DefineType (genTypeName ());
1625 
1626 			tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1627 
1628 			Type t = tb.CreateType ();
1629 
1630 			object o = Activator.CreateInstance (t);
1631 
1632 			FieldInfo fi = t.GetField ("foo");
1633 
1634 			object fieldVal = fi.GetValue (o);
1635 
1636 			IntPtr ptr = Marshal.AllocHGlobal (4);
1637 			Marshal.StructureToPtr (fieldVal, ptr, true);
1638 			Marshal.FreeHGlobal (ptr);
1639 		}
1640 
1641 		[Test]
DefineMethod_Name_NullChar()1642 		public void DefineMethod_Name_NullChar ()
1643 		{
1644 			TypeBuilder tb = module.DefineType (genTypeName ());
1645 			try {
1646 				tb.DefineMethod ("\0test", MethodAttributes.Private,
1647 					typeof (string), Type.EmptyTypes);
1648 				Assert.Fail ("#A1");
1649 			} catch (ArgumentException ex) {
1650 				// Illegal name
1651 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1652 				Assert.IsNull (ex.InnerException, "#A3");
1653 				Assert.IsNotNull (ex.Message, "#A4");
1654 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1655 			}
1656 
1657 			MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1658 				typeof (string), Type.EmptyTypes);
1659 			Assert.IsNotNull (mb, "#B1");
1660 			Assert.AreEqual ("te\0st", mb.Name, "#B2");
1661 		}
1662 
1663 		[Test]
TestDefineMethod()1664 		public void TestDefineMethod ()
1665 		{
1666 			TypeBuilder tb = module.DefineType (genTypeName ());
1667 
1668 			// Check invalid arguments
1669 			try {
1670 				tb.DefineMethod (null, 0, null, null);
1671 				Assert.Fail ("#A1");
1672 			} catch (ArgumentNullException ex) {
1673 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1674 				Assert.IsNull (ex.InnerException, "#A3");
1675 				Assert.IsNotNull (ex.Message, "#A4");
1676 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1677 			}
1678 
1679 			try {
1680 				tb.DefineMethod (string.Empty, 0, null, null);
1681 				Assert.Fail ("#B1");
1682 			} catch (ArgumentException ex) {
1683 				// Empty name is not legal
1684 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1685 				Assert.IsNull (ex.InnerException, "#B3");
1686 				Assert.IsNotNull (ex.Message, "#B4");
1687 				Assert.AreEqual ("name", ex.ParamName, "#B5");
1688 			}
1689 
1690 			// Check non-virtual methods on an interface
1691 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1692 			try {
1693 				tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1694 				Assert.Fail ("#C1");
1695 			} catch (ArgumentException ex) {
1696 				// Interface method must be abstract and virtual
1697 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1698 				Assert.IsNull (ex.InnerException, "#C3");
1699 				Assert.IsNotNull (ex.Message, "#C4");
1700 				Assert.IsNull (ex.ParamName, "#C5");
1701 			}
1702 
1703 			// Check static methods on an interface
1704 			tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1705 							  typeof (void),
1706 							  Type.EmptyTypes);
1707 
1708 			tb.CreateType ();
1709 			// Can not be called on a created type
1710 			try {
1711 				tb.DefineMethod ("bar", 0, null, null);
1712 				Assert.Fail ("#D1");
1713 			} catch (InvalidOperationException ex) {
1714 				// Unable to change after type has been created
1715 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1716 				Assert.IsNull (ex.InnerException, "#D3");
1717 				Assert.IsNotNull (ex.Message, "#D4");
1718 			}
1719 		}
1720 
1721 		[Test] // bug #327484
1722 		[Category ("NotWorking")]
TestDefineMethod_Abstract()1723 		public void TestDefineMethod_Abstract ()
1724 		{
1725 			TypeBuilder tb = module.DefineType (genTypeName ());
1726 			tb.DefineMethod ("Run", MethodAttributes.Public |
1727 				MethodAttributes.Abstract | MethodAttributes.Virtual,
1728 				typeof (void), Type.EmptyTypes);
1729 
1730 			try {
1731 				tb.CreateType ();
1732 				Assert.Fail ("#A1");
1733 			} catch (InvalidOperationException ex) {
1734 				// Type must be declared abstract if any of its
1735 				// methods are abstract
1736 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1737 				Assert.IsNull (ex.InnerException, "#A3");
1738 				Assert.IsNotNull (ex.Message, "#A4");
1739 			}
1740 
1741 			tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1742 			tb.DefineMethod ("Run", MethodAttributes.Public |
1743 				MethodAttributes.Abstract, typeof (void),
1744 				Type.EmptyTypes);
1745 
1746 			try {
1747 				tb.CreateType ();
1748 				Assert.Fail ("#B1");
1749 			} catch (TypeLoadException ex) {
1750 				// Non-virtual abstract method
1751 				Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1752 				Assert.IsNull (ex.InnerException, "#B3");
1753 				Assert.IsNotNull (ex.Message, "#B4");
1754 			}
1755 
1756 			tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1757 				TypeAttributes.Public);
1758 			tb.DefineMethod ("Run", MethodAttributes.Public |
1759 				MethodAttributes.Abstract | MethodAttributes.Virtual,
1760 				typeof (void), Type.EmptyTypes);
1761 			Type emittedType = tb.CreateType ();
1762 
1763 			MethodInfo mi1 = emittedType.GetMethod ("Run");
1764 			Assert.IsNotNull (mi1, "#C1");
1765 			Assert.IsTrue (mi1.IsAbstract, "#C2");
1766 
1767 			MethodInfo mi2 = tb.GetMethod ("Run");
1768 			Assert.IsNotNull (mi2, "#D1");
1769 			Assert.IsTrue (mi2.IsAbstract, "#D2");
1770 		}
1771 
1772 		// TODO: DefineMethodOverride
1773 
1774 		[Test]
TestDefineNestedType()1775 		public void TestDefineNestedType ()
1776 		{
1777 			TypeBuilder tb = module.DefineType (genTypeName ());
1778 
1779 			// Check invalid arguments
1780 			try {
1781 				tb.DefineNestedType (null);
1782 				Assert.Fail ("#A1");
1783 			} catch (ArgumentNullException ex) {
1784 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1785 				Assert.IsNull (ex.InnerException, "#A3");
1786 				Assert.IsNotNull (ex.Message, "#A4");
1787 				Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1788 			}
1789 
1790 			try {
1791 				tb.DefineNestedType (string.Empty);
1792 				Assert.Fail ("#B1");
1793 			} catch (ArgumentException ex) {
1794 				// Empty name is not legal
1795 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1796 				Assert.IsNull (ex.InnerException, "#B3");
1797 				Assert.IsNotNull (ex.Message, "#B4");
1798 				Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1799 			}
1800 
1801 			try {
1802 				tb.DefineNestedType (nullName ());
1803 				Assert.Fail ("#C1");
1804 			} catch (ArgumentException ex) {
1805 				// Illegal name
1806 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1807 				Assert.IsNull (ex.InnerException, "#C3");
1808 				Assert.IsNotNull (ex.Message, "#C4");
1809 				Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1810 			}
1811 
1812 			// If I fix the code so this works then mcs breaks -> how can mcs
1813 			// works under MS .NET in the first place ???
1814 			/*
1815 			try {
1816 				tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1817 				Fail ("Nested visibility must be specified.");
1818 			}
1819 			catch (ArgumentException) {
1820 			}
1821 			*/
1822 
1823 			try {
1824 				tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1825 									 new Type [1]);
1826 				Assert.Fail ("#D1");
1827 			} catch (ArgumentNullException ex) {
1828 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1829 				Assert.IsNull (ex.InnerException, "#D3");
1830 				Assert.IsNotNull (ex.Message, "#D4");
1831 				Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1832 			}
1833 
1834 			// I think this should reject non-interfaces, but it does not
1835 			tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1836 								 new Type [1] { typeof (object) });
1837 
1838 			// Normal invocation
1839 			tb.DefineNestedType ("Nest");
1840 
1841 			tb.CreateType ();
1842 
1843 			// According to the MSDN docs, this cannnot be called after the type
1844 			// is created, but it works.
1845 			tb.DefineNestedType ("Nest2");
1846 
1847 			// According to the MSDN docs, a Sealed class can't contain nested
1848 			// types, but this is not true
1849 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1850 			tb2.DefineNestedType ("AA");
1851 
1852 			// According to the MSDN docs, interfaces can only contain interfaces,
1853 			// but this is not true
1854 			TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1855 
1856 			tb3.DefineNestedType ("AA");
1857 
1858 			// Check shorter versions
1859 			{
1860 				TypeBuilder nested = tb.DefineNestedType ("N1");
1861 
1862 				Assert.AreEqual ("N1", nested.Name, "#E1");
1863 				Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1864 				Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1865 				Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1866 			}
1867 
1868 			// TODO:
1869 		}
1870 
1871 		[Test]
NestedTypeSave()1872 		public void NestedTypeSave () {
1873 			var tb = module.DefineType (genTypeName ());
1874 
1875 			var tbuilder = tb.DefineNestedType ("Test.CodeGen", TypeAttributes.Public | TypeAttributes.Class);
1876 			var entryp = tbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), null);
1877 			var ilg = entryp.GetILGenerator (128);
1878 			ilg.Emit (OpCodes.Ldtoken, tb);
1879 			ilg.Emit (OpCodes.Pop);
1880 			ilg.Emit (OpCodes.Ret);
1881 
1882 			tbuilder.CreateType ();
1883 			tb.CreateType ();
1884 
1885 			assembly.Save (ASSEMBLY_NAME + ".dll");
1886 		}
1887 
1888 		[Test]
DefinePInvokeMethod_Name_NullChar()1889 		public void DefinePInvokeMethod_Name_NullChar ()
1890 		{
1891 			TypeBuilder tb = module.DefineType (genTypeName ());
1892 			try {
1893 				tb.DefinePInvokeMethod ("\0test", "B", "C",
1894 					MethodAttributes.Private, CallingConventions.Standard,
1895 					typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1896 					CharSet.Unicode);
1897 				Assert.Fail ("#A1");
1898 			} catch (ArgumentException ex) {
1899 				// Illegal name
1900 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1901 				Assert.IsNull (ex.InnerException, "#A3");
1902 				Assert.IsNotNull (ex.Message, "#A4");
1903 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1904 			}
1905 
1906 			MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1907 				MethodAttributes.Private, CallingConventions.Standard,
1908 				typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1909 				CharSet.Unicode);
1910 			Assert.IsNotNull (mb, "#B1");
1911 			Assert.AreEqual ("te\0st", mb.Name, "#B2");
1912 		}
1913 
1914 		[Test]
TestDefinePInvokeMethod()1915 		public void TestDefinePInvokeMethod ()
1916 		{
1917 			TypeBuilder tb = module.DefineType (genTypeName ());
1918 
1919 			tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1920 
1921 			// Try invalid parameters
1922 			try {
1923 				tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1924 				Assert.Fail ("#A1");
1925 			} catch (ArgumentNullException ex) {
1926 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1927 				Assert.IsNull (ex.InnerException, "#A3");
1928 				Assert.IsNotNull (ex.Message, "#A4");
1929 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1930 			}
1931 			// etc...
1932 
1933 			// Try invalid attributes
1934 			try {
1935 				tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1936 				Assert.Fail ("#B1");
1937 			} catch (ArgumentException ex) {
1938 				// PInvoke methods must be static and native and
1939 				// cannot be abstract
1940 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1941 				Assert.IsNull (ex.InnerException, "#B3");
1942 				Assert.IsNotNull (ex.Message, "#B4");
1943 				Assert.IsNull (ex.ParamName, "#B5");
1944 			}
1945 
1946 			// Try an interface parent
1947 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1948 
1949 			try {
1950 				tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1951 				Assert.Fail ("#C1");
1952 			} catch (ArgumentException ex) {
1953 				// PInvoke methods cannot exist on interfaces
1954 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1955 				Assert.IsNull (ex.InnerException, "#B3");
1956 				Assert.IsNotNull (ex.Message, "#B4");
1957 				Assert.IsNull (ex.ParamName, "#B5");
1958 			}
1959 		}
1960 
1961 		[Test]
DefineProperty_Name_NullChar()1962 		public void DefineProperty_Name_NullChar ()
1963 		{
1964 			TypeBuilder tb = module.DefineType (genTypeName ());
1965 
1966 			try {
1967 				tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
1968 				Assert.Fail ("#A1");
1969 			} catch (ArgumentException ex) {
1970 				// Illegal name
1971 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1972 				Assert.IsNull (ex.InnerException, "#A3");
1973 				Assert.IsNotNull (ex.Message, "#A4");
1974 				Assert.AreEqual ("name", ex.ParamName, "#A5");
1975 			}
1976 
1977 			PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
1978 				typeof (string), Type.EmptyTypes);
1979 			Assert.IsNotNull (pb, "#B1");
1980 			Assert.AreEqual ("te\0st", pb.Name, "#B2");
1981 		}
1982 
1983 		[Test]
DefineProperty_ParameterTypes_ItemNull()1984 		public void DefineProperty_ParameterTypes_ItemNull ()
1985 		{
1986 			TypeBuilder tb = module.DefineType (genTypeName ());
1987 
1988 			try {
1989 				tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
1990 				Assert.Fail ("#1");
1991 			} catch (ArgumentNullException ex) {
1992 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1993 				Assert.IsNull (ex.InnerException, "#3");
1994 				Assert.IsNotNull (ex.Message, "#4");
1995 			}
1996 		}
1997 
1998 		[Test]
DefineProperty_ReturnType_Null()1999 		public void DefineProperty_ReturnType_Null ()
2000 		{
2001 			TypeBuilder tb = module.DefineType (genTypeName ());
2002 			tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
2003 		}
2004 
2005 		[Test]
GetMethod_WorksWithTypeBuilderParameter()2006 		public void GetMethod_WorksWithTypeBuilderParameter () {
2007 			TypeBuilder tb = module.DefineType (genTypeName ());
2008 			var garg = tb.DefineGenericParameters ("T") [0];
2009 			MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2010 
2011 			var mi = TypeBuilder.GetMethod (tb, mb);
2012 			var decl = mi.DeclaringType;
2013 
2014 			Assert.IsTrue (decl.IsGenericType, "#1");
2015 			Assert.IsFalse (decl.IsGenericTypeDefinition, "#2");
2016 			Assert.AreEqual (tb, decl.GetGenericTypeDefinition (), "#3");
2017 			Assert.AreEqual (garg, decl.GetGenericArguments () [0], "#4");
2018 		}
2019 
2020 		[Test]
GetConstructor_FailWithTypeBuilderParameter()2021 		public void GetConstructor_FailWithTypeBuilderParameter () {
2022 			TypeBuilder tb = module.DefineType (genTypeName ());
2023 			var garg = tb.DefineGenericParameters ("T") [0];
2024 			var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2025 
2026 			try {
2027 				TypeBuilder.GetConstructor (tb, cb);
2028 				Assert.Fail ("#1");
2029 			} catch (ArgumentException ex) {
2030 				Assert.AreEqual ("type", ex.ParamName, "#2");
2031 			}
2032 		}
2033 
2034 		[Test]
GetField_FailWithTypeBuilderParameter()2035 		public void GetField_FailWithTypeBuilderParameter () {
2036 			TypeBuilder tb = module.DefineType (genTypeName ());
2037 			var garg = tb.DefineGenericParameters ("T") [0];
2038 			var fb = tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
2039 
2040 			try {
2041 				TypeBuilder.GetField (tb, fb);
2042 				Assert.Fail ("#1");
2043 			} catch (ArgumentException ex) {
2044 				Assert.AreEqual ("type", ex.ParamName, "#2");
2045 			}
2046 		}
2047 
2048 		[Test]
GetMethod_RejectMethodFromInflatedTypeBuilder()2049 		public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
2050 			TypeBuilder tb = module.DefineType (genTypeName ());
2051 			tb.DefineGenericParameters ("T");
2052 			MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2053 
2054 			Type ginst = tb.MakeGenericType (typeof (int));
2055 
2056 			MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2057 			try {
2058 				TypeBuilder.GetMethod (ginst, mi);
2059 				Assert.Fail ("#1");
2060 			} catch (ArgumentException ex) {
2061 				Assert.AreEqual ("method", ex.ParamName, "#5");
2062 			}
2063 		}
2064 
2065 		[Test]
GetMethod_WorkWithInstancesOfCreatedTypeBuilder()2066 		public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2067 			TypeBuilder tb = module.DefineType (genTypeName ());
2068 			tb.DefineGenericParameters ("T");
2069 			MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2070 			ILGenerator ig = mb.GetILGenerator ();
2071 			ig.Emit (OpCodes.Ret);
2072 
2073 			tb.CreateType ();
2074 
2075 			MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2076 			Assert.IsNotNull (mi);
2077 		}
2078 
2079 		[Test]
2080 		[Category ("NotDotNet")]
2081 		[Category ("NotWorking")]
GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext()2082 		public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2083 			AssemblyName assemblyName = new AssemblyName ();
2084 			assemblyName.Name = ASSEMBLY_NAME;
2085 
2086 			assembly =
2087 				Thread.GetDomain ().DefineDynamicAssembly (
2088 					assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, tempDir);
2089 
2090 			module = assembly.DefineDynamicModule ("module1");
2091 
2092 			TypeBuilder tb = module.DefineType (genTypeName ());
2093 			tb.DefineGenericParameters ("T");
2094 			MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2095 
2096 			Type ginst = tb.MakeGenericType (typeof (int));
2097 
2098 			MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2099 
2100 			try {
2101 				TypeBuilder.GetMethod (ginst, mi);
2102 			} catch (ArgumentException ex) {
2103 				Assert.Fail ("#1");
2104 			}
2105 		}
2106 
2107 
2108 		[Test]
2109 		// Test that changes made to the method builder after a call to GetMethod ()
2110 		// are visible
TestGetMethod()2111 		public void TestGetMethod ()
2112 		{
2113 			TypeBuilder tb = module.DefineType (genTypeName ());
2114 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2115 
2116 			ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2117 			ILGenerator ig;
2118 			ig = cb.GetILGenerator ();
2119 			ig.Emit (OpCodes.Ret);
2120 
2121 			Type fooOfT = tb.MakeGenericType (typeParams [0]);
2122 
2123 			// Create a method builder but do not emit IL yet
2124 			MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2125 
2126 			Type t = tb.MakeGenericType (typeof (int));
2127 
2128 			MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2129 
2130 			ig = mb.GetILGenerator ();
2131 			ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2132 			ig.Emit (OpCodes.Ret);
2133 
2134 			// Finish the method
2135 			ig = mb1.GetILGenerator ();
2136 			ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2137 			ig.Emit (OpCodes.Ret);
2138 
2139 			Type t2 = tb.CreateType ();
2140 
2141 			Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2142 		}
2143 
2144 		[Test]
TestGetConstructor()2145 		public void TestGetConstructor ()
2146 		{
2147 			TypeBuilder tb = module.DefineType (genTypeName ());
2148 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2149 
2150 			ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2151 			ILGenerator ig;
2152 
2153 			Type t = tb.MakeGenericType (typeof (int));
2154 
2155 			MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2156 
2157 			ig = mb.GetILGenerator ();
2158 
2159 			ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2160 
2161 			ig.Emit (OpCodes.Newobj, ci);
2162 			ig.Emit (OpCodes.Ret);
2163 
2164 			// Finish the ctorbuilder
2165 			ig = cb.GetILGenerator ();
2166 			ig.Emit(OpCodes.Ldarg_0);
2167 			ig.Emit(OpCodes.Call, tb.BaseType.GetConstructor(Type.EmptyTypes));
2168 			ig.Emit (OpCodes.Ret);
2169 
2170 			Type t2 = tb.CreateType ();
2171 
2172 			Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2173 		}
2174 
2175 		[Test]
2176 		[ExpectedException (typeof (ArgumentException))]
Static_GetConstructor_TypeNull()2177 		public void Static_GetConstructor_TypeNull ()
2178 		{
2179 			ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2180 			// null is non-generic (from exception message)
2181 			TypeBuilder.GetConstructor (null, ci);
2182 		}
2183 
2184 		[Test]
2185 		[ExpectedException (typeof (ArgumentException))]
Static_GetConstructor_TypeGeneric()2186 		public void Static_GetConstructor_TypeGeneric ()
2187 		{
2188 			Type t = typeof (List<>).MakeGenericType (typeof (int));
2189 			ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2190 			// type is not 'TypeBuilder' (from exception message)
2191 			TypeBuilder.GetConstructor (t, ci);
2192 		}
2193 
2194 		[Test]
Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull()2195 		public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
2196 		{
2197 			TypeBuilder tb = module.DefineType ("XXX");
2198 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2199 			Type fooOfT = tb.MakeGenericType (typeParams [0]);
2200 			try {
2201 				TypeBuilder.GetConstructor (fooOfT, null);
2202 				Assert.Fail ("Expected NullReferenceException");
2203 			}
2204 			catch (NullReferenceException) {
2205 			}
2206 		}
2207 
2208 		[Test] //#536243
CreateTypeThrowsForMethodsWithBadLabels()2209 		public void CreateTypeThrowsForMethodsWithBadLabels ()
2210 		{
2211 			TypeBuilder tb = module.DefineType (genTypeName ());
2212 
2213 			MethodBuilder mb = tb.DefineMethod("F", MethodAttributes.Public, typeof(string), null);
2214 			ILGenerator il_gen = mb.GetILGenerator ();
2215 			il_gen.DefineLabel ();
2216 			il_gen.Emit (OpCodes.Leave, new Label ());
2217 			try {
2218 				tb.CreateType ();
2219 				Assert.Fail ();
2220 			} catch (ArgumentException) {}
2221 		}
2222 
2223 		[Test]
2224 		[Category ("NotWorking")]
TestIsDefinedIncomplete()2225 		public void TestIsDefinedIncomplete ()
2226 		{
2227 			TypeBuilder tb = module.DefineType (genTypeName ());
2228 			try {
2229 				tb.IsDefined (typeof (int), true);
2230 				Assert.Fail ("#1");
2231 			} catch (NotSupportedException ex) {
2232 				// The invoked member is not supported in a
2233 				// dynamic module
2234 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2235 				Assert.IsNull (ex.InnerException, "#3");
2236 				Assert.IsNotNull (ex.Message, "#4");
2237 			}
2238 		}
2239 
2240 		[Test]
TestIsDefinedComplete()2241 		public void TestIsDefinedComplete ()
2242 		{
2243 			TypeBuilder tb = module.DefineType (genTypeName ());
2244 
2245 			ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2246 				new Type [] { typeof (string) });
2247 
2248 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2249 				new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2250 
2251 			tb.SetCustomAttribute (caBuilder);
2252 			tb.CreateType ();
2253 			Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2254 		}
2255 
2256 		[Test]
2257 		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
IsDefined_AttributeType_Null()2258 		public void IsDefined_AttributeType_Null ()
2259 		{
2260 			TypeBuilder tb = module.DefineType (genTypeName ());
2261 			tb.CreateType ();
2262 
2263 			try {
2264 				tb.IsDefined ((Type) null, false);
2265 				Assert.Fail ("#1");
2266 			} catch (ArgumentNullException ex) {
2267 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2268 				Assert.IsNull (ex.InnerException, "#3");
2269 				Assert.IsNotNull (ex.Message, "#4");
2270 				Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2271 			}
2272 		}
2273 
2274 		[Test] // GetConstructor (Type [])
GetConstructor1_Incomplete()2275 		public void GetConstructor1_Incomplete ()
2276 		{
2277 			TypeBuilder tb = module.DefineType (genTypeName ());
2278 			ConstructorBuilder cb = tb.DefineConstructor (
2279 				MethodAttributes.Public,
2280 				CallingConventions.Standard,
2281 				Type.EmptyTypes);
2282 			cb.GetILGenerator ().Emit (OpCodes.Ret);
2283 
2284 			try {
2285 				tb.GetConstructor (Type.EmptyTypes);
2286 				Assert.Fail ("#1");
2287 			} catch (NotSupportedException ex) {
2288 				// The invoked member is not supported in a
2289 				// dynamic module
2290 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2291 				Assert.IsNull (ex.InnerException, "#3");
2292 				Assert.IsNotNull (ex.Message, "#4");
2293 			}
2294 		}
2295 
2296 		[Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
GetConstructor2_Complete()2297 		public void GetConstructor2_Complete ()
2298 		{
2299 			BindingFlags flags;
2300 			ConstructorInfo ctor;
2301 
2302 			TypeBuilder redType = module.DefineType (genTypeName (),
2303 				TypeAttributes.Public);
2304 			CreateMembers (redType, "Red", true);
2305 
2306 			TypeBuilder greenType = module.DefineType (genTypeName (),
2307 				TypeAttributes.Public, redType);
2308 			CreateMembers (greenType, "Green", false);
2309 			ConstructorBuilder cb = greenType.DefineConstructor (
2310 				MethodAttributes.Public,
2311 				CallingConventions.Standard,
2312 				Type.EmptyTypes);
2313 			cb.GetILGenerator ().Emit (OpCodes.Ret);
2314 
2315 			redType.CreateType ();
2316 			greenType.CreateType ();
2317 
2318 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
2319 
2320 			ctor = greenType.GetConstructor (flags, null,
2321 				new Type [] { typeof (int), typeof (int) },
2322 				new ParameterModifier [0]);
2323 			Assert.IsNull (ctor, "#A1");
2324 
2325 			ctor = greenType.GetConstructor (flags, null,
2326 				new Type [] { typeof (string) },
2327 				new ParameterModifier [0]);
2328 			Assert.IsNull (ctor, "#A2");
2329 
2330 			ctor = greenType.GetConstructor (flags, null,
2331 				new Type [] { typeof (string), typeof (string) },
2332 				new ParameterModifier [0]);
2333 			Assert.IsNull (ctor, "#A3");
2334 
2335 			ctor = greenType.GetConstructor (flags, null,
2336 				new Type [] { typeof (int) },
2337 				new ParameterModifier [0]);
2338 			Assert.IsNull (ctor, "#A4");
2339 
2340 			ctor = greenType.GetConstructor (flags, null,
2341 				new Type [] { typeof (int), typeof (bool) },
2342 				new ParameterModifier [0]);
2343 			Assert.IsNull (ctor, "#A5");
2344 
2345 			ctor = greenType.GetConstructor (flags, null,
2346 				new Type [] { typeof (string), typeof (int) },
2347 				new ParameterModifier [0]);
2348 			Assert.IsNull (ctor, "#A6");
2349 
2350 			ctor = greenType.GetConstructor (flags, null,
2351 				Type.EmptyTypes,
2352 				new ParameterModifier [0]);
2353 			Assert.IsNull (ctor, "#A7");
2354 
2355 			ctor = redType.GetConstructor (flags, null,
2356 				new Type [] { typeof (int), typeof (int) },
2357 				new ParameterModifier [0]);
2358 			Assert.IsNotNull (ctor, "#A8a");
2359 			Assert.IsTrue (ctor.IsPrivate, "#A8b");
2360 			Assert.IsFalse (ctor.IsStatic, "#A8c");
2361 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2362 			Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2363 
2364 			ctor = redType.GetConstructor (flags, null,
2365 				new Type [] { typeof (string) },
2366 				new ParameterModifier [0]);
2367 			Assert.IsNotNull (ctor, "#A9a");
2368 			Assert.IsTrue (ctor.IsFamily, "#A9b");
2369 			Assert.IsFalse (ctor.IsStatic, "#A9c");
2370 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2371 			Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2372 
2373 			ctor = redType.GetConstructor (flags, null,
2374 				new Type [] { typeof (string), typeof (string) },
2375 				new ParameterModifier [0]);
2376 			Assert.IsNotNull (ctor, "#A10a");
2377 			Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2378 			Assert.IsFalse (ctor.IsStatic, "#A10c");
2379 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2380 			Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2381 
2382 			ctor = redType.GetConstructor (flags, null,
2383 				new Type [] { typeof (int) },
2384 				new ParameterModifier [0]);
2385 			Assert.IsNotNull (ctor, "#A11a");
2386 			Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2387 			Assert.IsFalse (ctor.IsStatic, "#A11c");
2388 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2389 			Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2390 
2391 			ctor = redType.GetConstructor (flags, null,
2392 				new Type [] { typeof (int), typeof (bool) },
2393 				new ParameterModifier [0]);
2394 			Assert.IsNull (ctor, "#A12");
2395 
2396 			ctor = redType.GetConstructor (flags, null,
2397 				new Type [] { typeof (string), typeof (int) },
2398 				new ParameterModifier [0]);
2399 			Assert.IsNotNull (ctor, "#A13a");
2400 			Assert.IsTrue (ctor.IsAssembly, "#A13b");
2401 			Assert.IsFalse (ctor.IsStatic, "#A13c");
2402 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2403 			Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2404 
2405 			ctor = redType.GetConstructor (flags, null,
2406 				Type.EmptyTypes,
2407 				new ParameterModifier [0]);
2408 			Assert.IsNull (ctor, "#A14");
2409 
2410 			flags = BindingFlags.Instance | BindingFlags.Public;
2411 
2412 			ctor = greenType.GetConstructor (flags, null,
2413 				new Type [] { typeof (int), typeof (int) },
2414 				new ParameterModifier [0]);
2415 			Assert.IsNull (ctor, "#B1");
2416 
2417 			ctor = greenType.GetConstructor (flags, null,
2418 				new Type [] { typeof (string) },
2419 				new ParameterModifier [0]);
2420 			Assert.IsNull (ctor, "#B2");
2421 
2422 			ctor = greenType.GetConstructor (flags, null,
2423 				new Type [] { typeof (string), typeof (string) },
2424 				new ParameterModifier [0]);
2425 			Assert.IsNull (ctor, "#B3");
2426 
2427 			ctor = greenType.GetConstructor (flags, null,
2428 				new Type [] { typeof (int) },
2429 				new ParameterModifier [0]);
2430 			Assert.IsNull (ctor, "#B4");
2431 
2432 			ctor = greenType.GetConstructor (flags, null,
2433 				new Type [] { typeof (int), typeof (bool) },
2434 				new ParameterModifier [0]);
2435 			Assert.IsNull (ctor, "#B5");
2436 
2437 			ctor = greenType.GetConstructor (flags, null,
2438 				new Type [] { typeof (string), typeof (int) },
2439 				new ParameterModifier [0]);
2440 			Assert.IsNull (ctor, "#B6");
2441 
2442 			ctor = greenType.GetConstructor (flags, null,
2443 				Type.EmptyTypes,
2444 				new ParameterModifier [0]);
2445 			Assert.IsNotNull (ctor, "#B7a");
2446 			Assert.IsTrue (ctor.IsPublic, "#B7b");
2447 			Assert.IsFalse (ctor.IsStatic, "#B7c");
2448 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2449 			Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2450 
2451 			ctor = redType.GetConstructor (flags, null,
2452 				new Type [] { typeof (int), typeof (int) },
2453 				new ParameterModifier [0]);
2454 			Assert.IsNull (ctor, "#B8");
2455 
2456 			ctor = redType.GetConstructor (flags, null,
2457 				new Type [] { typeof (string) },
2458 				new ParameterModifier [0]);
2459 			Assert.IsNull (ctor, "#B9");
2460 
2461 			ctor = redType.GetConstructor (flags, null,
2462 				new Type [] { typeof (string), typeof (string) },
2463 				new ParameterModifier [0]);
2464 			Assert.IsNull (ctor, "#B10");
2465 
2466 			ctor = redType.GetConstructor (flags, null,
2467 				new Type [] { typeof (int) },
2468 				new ParameterModifier [0]);
2469 			Assert.IsNull (ctor, "#B11");
2470 
2471 			ctor = redType.GetConstructor (flags, null,
2472 				new Type [] { typeof (int), typeof (bool) },
2473 				new ParameterModifier [0]);
2474 			Assert.IsNotNull (ctor, "#B12a");
2475 			Assert.IsTrue (ctor.IsPublic, "#B12b");
2476 			Assert.IsFalse (ctor.IsStatic, "#B12c");
2477 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2478 			Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2479 
2480 			ctor = redType.GetConstructor (flags, null,
2481 				new Type [] { typeof (string), typeof (int) },
2482 				new ParameterModifier [0]);
2483 			Assert.IsNull (ctor, "#B13");
2484 
2485 			ctor = redType.GetConstructor (flags, null,
2486 				Type.EmptyTypes,
2487 				new ParameterModifier [0]);
2488 			Assert.IsNull (ctor, "#B14");
2489 
2490 			flags = BindingFlags.Static | BindingFlags.Public;
2491 
2492 			ctor = greenType.GetConstructor (flags, null,
2493 				new Type [] { typeof (int), typeof (int) },
2494 				new ParameterModifier [0]);
2495 			Assert.IsNull (ctor, "#C1");
2496 
2497 			ctor = greenType.GetConstructor (flags, null,
2498 				new Type [] { typeof (string) },
2499 				new ParameterModifier [0]);
2500 			Assert.IsNull (ctor, "#C2");
2501 
2502 			ctor = greenType.GetConstructor (flags, null,
2503 				new Type [] { typeof (string), typeof (string) },
2504 				new ParameterModifier [0]);
2505 			Assert.IsNull (ctor, "#C3");
2506 
2507 			ctor = greenType.GetConstructor (flags, null,
2508 				new Type [] { typeof (int) },
2509 				new ParameterModifier [0]);
2510 			Assert.IsNull (ctor, "#C4");
2511 
2512 			ctor = greenType.GetConstructor (flags, null,
2513 				new Type [] { typeof (int), typeof (bool) },
2514 				new ParameterModifier [0]);
2515 			Assert.IsNull (ctor, "#C5");
2516 
2517 			ctor = greenType.GetConstructor (flags, null,
2518 				new Type [] { typeof (string), typeof (int) },
2519 				new ParameterModifier [0]);
2520 			Assert.IsNull (ctor, "#C6");
2521 
2522 			ctor = greenType.GetConstructor (flags, null,
2523 				Type.EmptyTypes,
2524 				new ParameterModifier [0]);
2525 			Assert.IsNull (ctor, "#C7");
2526 
2527 			ctor = redType.GetConstructor (flags, null,
2528 				new Type [] { typeof (int), typeof (int) },
2529 				new ParameterModifier [0]);
2530 			Assert.IsNull (ctor, "#C8");
2531 
2532 			ctor = redType.GetConstructor (flags, null,
2533 				new Type [] { typeof (string) },
2534 				new ParameterModifier [0]);
2535 			Assert.IsNull (ctor, "#C9");
2536 
2537 			ctor = redType.GetConstructor (flags, null,
2538 				new Type [] { typeof (string), typeof (string) },
2539 				new ParameterModifier [0]);
2540 			Assert.IsNull (ctor, "#C10");
2541 
2542 			ctor = redType.GetConstructor (flags, null,
2543 				new Type [] { typeof (int) },
2544 				new ParameterModifier [0]);
2545 			Assert.IsNull (ctor, "#C11a");
2546 
2547 			ctor = redType.GetConstructor (flags, null,
2548 				new Type [] { typeof (int), typeof (bool) },
2549 				new ParameterModifier [0]);
2550 			Assert.IsNull (ctor, "#C12");
2551 
2552 			ctor = redType.GetConstructor (flags, null,
2553 				new Type [] { typeof (string), typeof (int) },
2554 				new ParameterModifier [0]);
2555 			Assert.IsNull (ctor, "#C13");
2556 
2557 			ctor = redType.GetConstructor (flags, null,
2558 				Type.EmptyTypes,
2559 				new ParameterModifier [0]);
2560 			Assert.IsNull (ctor, "#C14");
2561 
2562 			flags = BindingFlags.Static | BindingFlags.NonPublic;
2563 
2564 			ctor = greenType.GetConstructor (flags, null,
2565 				new Type [] { typeof (int), typeof (int) },
2566 				new ParameterModifier [0]);
2567 			Assert.IsNull (ctor, "#D1");
2568 
2569 			ctor = greenType.GetConstructor (flags, null,
2570 				new Type [] { typeof (string) },
2571 				new ParameterModifier [0]);
2572 			Assert.IsNull (ctor, "#D2");
2573 
2574 			ctor = greenType.GetConstructor (flags, null,
2575 				new Type [] { typeof (string), typeof (string) },
2576 				new ParameterModifier [0]);
2577 			Assert.IsNull (ctor, "#D3");
2578 
2579 			ctor = greenType.GetConstructor (flags, null,
2580 				new Type [] { typeof (int) },
2581 				new ParameterModifier [0]);
2582 			Assert.IsNull (ctor, "#D4");
2583 
2584 			ctor = greenType.GetConstructor (flags, null,
2585 				new Type [] { typeof (int), typeof (bool) },
2586 				new ParameterModifier [0]);
2587 			Assert.IsNull (ctor, "#D5");
2588 
2589 			ctor = greenType.GetConstructor (flags, null,
2590 				new Type [] { typeof (string), typeof (int) },
2591 				new ParameterModifier [0]);
2592 			Assert.IsNull (ctor, "#D6");
2593 
2594 			ctor = greenType.GetConstructor (flags, null,
2595 				Type.EmptyTypes,
2596 				new ParameterModifier [0]);
2597 			Assert.IsNull (ctor, "#D7");
2598 
2599 			ctor = redType.GetConstructor (flags, null,
2600 				new Type [] { typeof (int), typeof (int) },
2601 				new ParameterModifier [0]);
2602 			Assert.IsNull (ctor, "#D8");
2603 
2604 			ctor = redType.GetConstructor (flags, null,
2605 				new Type [] { typeof (string) },
2606 				new ParameterModifier [0]);
2607 			Assert.IsNull (ctor, "#D9");
2608 
2609 			ctor = redType.GetConstructor (flags, null,
2610 				new Type [] { typeof (string), typeof (string) },
2611 				new ParameterModifier [0]);
2612 			Assert.IsNull (ctor, "#D10");
2613 
2614 			ctor = redType.GetConstructor (flags, null,
2615 				new Type [] { typeof (int) },
2616 				new ParameterModifier [0]);
2617 			Assert.IsNull (ctor, "#D11");
2618 
2619 			ctor = redType.GetConstructor (flags, null,
2620 				new Type [] { typeof (int), typeof (bool) },
2621 				new ParameterModifier [0]);
2622 			Assert.IsNull (ctor, "#D12");
2623 
2624 			ctor = redType.GetConstructor (flags, null,
2625 				new Type [] { typeof (string), typeof (int) },
2626 				new ParameterModifier [0]);
2627 			Assert.IsNull (ctor, "#D13");
2628 
2629 			ctor = redType.GetConstructor (flags, null,
2630 				Type.EmptyTypes,
2631 				new ParameterModifier [0]);
2632 			Assert.IsNotNull (ctor, "#D14a");
2633 			Assert.IsTrue (ctor.IsPrivate, "#D14b");
2634 			Assert.IsTrue (ctor.IsStatic, "#B14c");
2635 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2636 			Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2637 
2638 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
2639 				BindingFlags.FlattenHierarchy;
2640 
2641 			ctor = greenType.GetConstructor (flags, null,
2642 				new Type [] { typeof (int), typeof (int) },
2643 				new ParameterModifier [0]);
2644 			Assert.IsNull (ctor, "#E1");
2645 
2646 			ctor = greenType.GetConstructor (flags, null,
2647 				new Type [] { typeof (string) },
2648 				new ParameterModifier [0]);
2649 			Assert.IsNull (ctor, "#E2");
2650 
2651 			ctor = greenType.GetConstructor (flags, null,
2652 				new Type [] { typeof (string), typeof (string) },
2653 				new ParameterModifier [0]);
2654 			Assert.IsNull (ctor, "#E3");
2655 
2656 			ctor = greenType.GetConstructor (flags, null,
2657 				new Type [] { typeof (int) },
2658 				new ParameterModifier [0]);
2659 			Assert.IsNull (ctor, "#E4");
2660 
2661 			ctor = greenType.GetConstructor (flags, null,
2662 				new Type [] { typeof (int), typeof (bool) },
2663 				new ParameterModifier [0]);
2664 			Assert.IsNull (ctor, "#E5");
2665 
2666 			ctor = greenType.GetConstructor (flags, null,
2667 				new Type [] { typeof (string), typeof (int) },
2668 				new ParameterModifier [0]);
2669 			Assert.IsNull (ctor, "#E6");
2670 
2671 			ctor = greenType.GetConstructor (flags, null,
2672 				Type.EmptyTypes,
2673 				new ParameterModifier [0]);
2674 			Assert.IsNull (ctor, "#E7");
2675 
2676 			ctor = redType.GetConstructor (flags, null,
2677 				new Type [] { typeof (int), typeof (int) },
2678 				new ParameterModifier [0]);
2679 			Assert.IsNotNull (ctor, "#E8a");
2680 			Assert.IsTrue (ctor.IsPrivate, "#E8b");
2681 			Assert.IsFalse (ctor.IsStatic, "#E8c");
2682 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2683 			Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2684 
2685 			ctor = redType.GetConstructor (flags, null,
2686 				new Type [] { typeof (string) },
2687 				new ParameterModifier [0]);
2688 			Assert.IsNotNull (ctor, "#E9a");
2689 			Assert.IsTrue (ctor.IsFamily, "#E9b");
2690 			Assert.IsFalse (ctor.IsStatic, "#E9c");
2691 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2692 			Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2693 
2694 			ctor = redType.GetConstructor (flags, null,
2695 				new Type [] { typeof (string), typeof (string) },
2696 				new ParameterModifier [0]);
2697 			Assert.IsNotNull (ctor, "#E10a");
2698 			Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2699 			Assert.IsFalse (ctor.IsStatic, "#E10c");
2700 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2701 			Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2702 
2703 			ctor = redType.GetConstructor (flags, null,
2704 				new Type [] { typeof (int) },
2705 				new ParameterModifier [0]);
2706 			Assert.IsNotNull (ctor, "#E11a");
2707 			Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2708 			Assert.IsFalse (ctor.IsStatic, "#E11c");
2709 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2710 			Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2711 
2712 			ctor = redType.GetConstructor (flags, null,
2713 				new Type [] { typeof (int), typeof (bool) },
2714 				new ParameterModifier [0]);
2715 			Assert.IsNull (ctor, "#E12");
2716 
2717 			ctor = redType.GetConstructor (flags, null,
2718 				new Type [] { typeof (string), typeof (int) },
2719 				new ParameterModifier [0]);
2720 			Assert.IsNotNull (ctor, "#E13a");
2721 			Assert.IsTrue (ctor.IsAssembly, "#E13b");
2722 			Assert.IsFalse (ctor.IsStatic, "#E13c");
2723 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2724 			Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2725 
2726 			ctor = redType.GetConstructor (flags, null,
2727 				Type.EmptyTypes,
2728 				new ParameterModifier [0]);
2729 			Assert.IsNull (ctor, "#E14");
2730 
2731 			flags = BindingFlags.Instance | BindingFlags.Public |
2732 				BindingFlags.FlattenHierarchy;
2733 
2734 			ctor = greenType.GetConstructor (flags, null,
2735 				new Type [] { typeof (int), typeof (int) },
2736 				new ParameterModifier [0]);
2737 			Assert.IsNull (ctor, "#F1");
2738 
2739 			ctor = greenType.GetConstructor (flags, null,
2740 				new Type [] { typeof (string) },
2741 				new ParameterModifier [0]);
2742 			Assert.IsNull (ctor, "#F2");
2743 
2744 			ctor = greenType.GetConstructor (flags, null,
2745 				new Type [] { typeof (string), typeof (string) },
2746 				new ParameterModifier [0]);
2747 			Assert.IsNull (ctor, "#F3");
2748 
2749 			ctor = greenType.GetConstructor (flags, null,
2750 				new Type [] { typeof (int) },
2751 				new ParameterModifier [0]);
2752 			Assert.IsNull (ctor, "#F4");
2753 
2754 			ctor = greenType.GetConstructor (flags, null,
2755 				new Type [] { typeof (int), typeof (bool) },
2756 				new ParameterModifier [0]);
2757 			Assert.IsNull (ctor, "#F5");
2758 
2759 			ctor = greenType.GetConstructor (flags, null,
2760 				new Type [] { typeof (string), typeof (int) },
2761 				new ParameterModifier [0]);
2762 			Assert.IsNull (ctor, "#F6");
2763 
2764 			ctor = greenType.GetConstructor (flags, null,
2765 				Type.EmptyTypes,
2766 				new ParameterModifier [0]);
2767 			Assert.IsNotNull (ctor, "#F7a");
2768 			Assert.IsTrue (ctor.IsPublic, "#F7b");
2769 			Assert.IsFalse (ctor.IsStatic, "#F7c");
2770 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2771 			Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2772 
2773 			ctor = redType.GetConstructor (flags, null,
2774 				new Type [] { typeof (int), typeof (int) },
2775 				new ParameterModifier [0]);
2776 			Assert.IsNull (ctor, "#F8");
2777 
2778 			ctor = redType.GetConstructor (flags, null,
2779 				new Type [] { typeof (string) },
2780 				new ParameterModifier [0]);
2781 			Assert.IsNull (ctor, "#F9");
2782 
2783 			ctor = redType.GetConstructor (flags, null,
2784 				new Type [] { typeof (string), typeof (string) },
2785 				new ParameterModifier [0]);
2786 			Assert.IsNull (ctor, "#F10");
2787 
2788 			ctor = redType.GetConstructor (flags, null,
2789 				new Type [] { typeof (int) },
2790 				new ParameterModifier [0]);
2791 			Assert.IsNull (ctor, "#F11");
2792 
2793 			ctor = redType.GetConstructor (flags, null,
2794 				new Type [] { typeof (int), typeof (bool) },
2795 				new ParameterModifier [0]);
2796 			Assert.IsNotNull (ctor, "#F12a");
2797 			Assert.IsTrue (ctor.IsPublic, "#F12b");
2798 			Assert.IsFalse (ctor.IsStatic, "#F12c");
2799 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2800 			Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2801 
2802 			ctor = redType.GetConstructor (flags, null,
2803 				new Type [] { typeof (string), typeof (int) },
2804 				new ParameterModifier [0]);
2805 			Assert.IsNull (ctor, "#F13");
2806 
2807 			ctor = redType.GetConstructor (flags, null,
2808 				Type.EmptyTypes,
2809 				new ParameterModifier [0]);
2810 			Assert.IsNull (ctor, "#F14");
2811 
2812 			flags = BindingFlags.Static | BindingFlags.Public |
2813 				BindingFlags.FlattenHierarchy;
2814 
2815 			ctor = greenType.GetConstructor (flags, null,
2816 				new Type [] { typeof (int), typeof (int) },
2817 				new ParameterModifier [0]);
2818 			Assert.IsNull (ctor, "#G1");
2819 
2820 			ctor = greenType.GetConstructor (flags, null,
2821 				new Type [] { typeof (string) },
2822 				new ParameterModifier [0]);
2823 			Assert.IsNull (ctor, "#G2");
2824 
2825 			ctor = greenType.GetConstructor (flags, null,
2826 				new Type [] { typeof (string), typeof (string) },
2827 				new ParameterModifier [0]);
2828 			Assert.IsNull (ctor, "#G3");
2829 
2830 			ctor = greenType.GetConstructor (flags, null,
2831 				new Type [] { typeof (int) },
2832 				new ParameterModifier [0]);
2833 			Assert.IsNull (ctor, "#G4");
2834 
2835 			ctor = greenType.GetConstructor (flags, null,
2836 				new Type [] { typeof (int), typeof (bool) },
2837 				new ParameterModifier [0]);
2838 			Assert.IsNull (ctor, "#G5");
2839 
2840 			ctor = greenType.GetConstructor (flags, null,
2841 				new Type [] { typeof (string), typeof (int) },
2842 				new ParameterModifier [0]);
2843 			Assert.IsNull (ctor, "#G6");
2844 
2845 			ctor = greenType.GetConstructor (flags, null,
2846 				Type.EmptyTypes,
2847 				new ParameterModifier [0]);
2848 			Assert.IsNull (ctor, "#G7");
2849 
2850 			ctor = redType.GetConstructor (flags, null,
2851 				new Type [] { typeof (int), typeof (int) },
2852 				new ParameterModifier [0]);
2853 			Assert.IsNull (ctor, "#G8");
2854 
2855 			ctor = redType.GetConstructor (flags, null,
2856 				new Type [] { typeof (string) },
2857 				new ParameterModifier [0]);
2858 			Assert.IsNull (ctor, "#G9");
2859 
2860 			ctor = redType.GetConstructor (flags, null,
2861 				new Type [] { typeof (string), typeof (string) },
2862 				new ParameterModifier [0]);
2863 			Assert.IsNull (ctor, "#G10");
2864 
2865 			ctor = redType.GetConstructor (flags, null,
2866 				new Type [] { typeof (int) },
2867 				new ParameterModifier [0]);
2868 			Assert.IsNull (ctor, "#G11");
2869 
2870 			ctor = redType.GetConstructor (flags, null,
2871 				new Type [] { typeof (int), typeof (bool) },
2872 				new ParameterModifier [0]);
2873 			Assert.IsNull (ctor, "#G12");
2874 
2875 			ctor = redType.GetConstructor (flags, null,
2876 				new Type [] { typeof (string), typeof (int) },
2877 				new ParameterModifier [0]);
2878 			Assert.IsNull (ctor, "#G13");
2879 
2880 			ctor = redType.GetConstructor (flags, null,
2881 				Type.EmptyTypes,
2882 				new ParameterModifier [0]);
2883 			Assert.IsNull (ctor, "#G14");
2884 
2885 			flags = BindingFlags.Static | BindingFlags.NonPublic |
2886 				BindingFlags.FlattenHierarchy;
2887 
2888 			ctor = greenType.GetConstructor (flags, null,
2889 				new Type [] { typeof (int), typeof (int) },
2890 				new ParameterModifier [0]);
2891 			Assert.IsNull (ctor, "#H1");
2892 
2893 			ctor = greenType.GetConstructor (flags, null,
2894 				new Type [] { typeof (string) },
2895 				new ParameterModifier [0]);
2896 			Assert.IsNull (ctor, "#H2");
2897 
2898 			ctor = greenType.GetConstructor (flags, null,
2899 				new Type [] { typeof (string), typeof (string) },
2900 				new ParameterModifier [0]);
2901 			Assert.IsNull (ctor, "#H3");
2902 
2903 			ctor = greenType.GetConstructor (flags, null,
2904 				new Type [] { typeof (int) },
2905 				new ParameterModifier [0]);
2906 			Assert.IsNull (ctor, "#H4");
2907 
2908 			ctor = greenType.GetConstructor (flags, null,
2909 				new Type [] { typeof (int), typeof (bool) },
2910 				new ParameterModifier [0]);
2911 			Assert.IsNull (ctor, "#H5");
2912 
2913 			ctor = greenType.GetConstructor (flags, null,
2914 				new Type [] { typeof (string), typeof (int) },
2915 				new ParameterModifier [0]);
2916 			Assert.IsNull (ctor, "#H6");
2917 
2918 			ctor = greenType.GetConstructor (flags, null,
2919 				Type.EmptyTypes,
2920 				new ParameterModifier [0]);
2921 			Assert.IsNull (ctor, "#H7");
2922 
2923 			ctor = redType.GetConstructor (flags, null,
2924 				new Type [] { typeof (int), typeof (int) },
2925 				new ParameterModifier [0]);
2926 			Assert.IsNull (ctor, "#H8");
2927 
2928 			ctor = redType.GetConstructor (flags, null,
2929 				new Type [] { typeof (string) },
2930 				new ParameterModifier [0]);
2931 			Assert.IsNull (ctor, "#H9");
2932 
2933 			ctor = redType.GetConstructor (flags, null,
2934 				new Type [] { typeof (string), typeof (string) },
2935 				new ParameterModifier [0]);
2936 			Assert.IsNull (ctor, "#H10");
2937 
2938 			ctor = redType.GetConstructor (flags, null,
2939 				new Type [] { typeof (int) },
2940 				new ParameterModifier [0]);
2941 			Assert.IsNull (ctor, "#H11");
2942 
2943 			ctor = redType.GetConstructor (flags, null,
2944 				new Type [] { typeof (int), typeof (bool) },
2945 				new ParameterModifier [0]);
2946 			Assert.IsNull (ctor, "#H12");
2947 
2948 			ctor = redType.GetConstructor (flags, null,
2949 				new Type [] { typeof (string), typeof (int) },
2950 				new ParameterModifier [0]);
2951 			Assert.IsNull (ctor, "#H13");
2952 
2953 			ctor = redType.GetConstructor (flags, null,
2954 				Type.EmptyTypes,
2955 				new ParameterModifier [0]);
2956 			Assert.IsNotNull (ctor, "#H14");
2957 			Assert.IsTrue (ctor.IsPrivate, "#H14b");
2958 			Assert.IsTrue (ctor.IsStatic, "#H14c");
2959 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2960 			Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2961 
2962 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
2963 				BindingFlags.DeclaredOnly;
2964 
2965 			ctor = greenType.GetConstructor (flags, null,
2966 				new Type [] { typeof (int), typeof (int) },
2967 				new ParameterModifier [0]);
2968 			Assert.IsNull (ctor, "#I1");
2969 
2970 			ctor = greenType.GetConstructor (flags, null,
2971 				new Type [] { typeof (string) },
2972 				new ParameterModifier [0]);
2973 			Assert.IsNull (ctor, "#I2");
2974 
2975 			ctor = greenType.GetConstructor (flags, null,
2976 				new Type [] { typeof (string), typeof (string) },
2977 				new ParameterModifier [0]);
2978 			Assert.IsNull (ctor, "#I3");
2979 
2980 			ctor = greenType.GetConstructor (flags, null,
2981 				new Type [] { typeof (int) },
2982 				new ParameterModifier [0]);
2983 			Assert.IsNull (ctor, "#I4");
2984 
2985 			ctor = greenType.GetConstructor (flags, null,
2986 				new Type [] { typeof (int), typeof (bool) },
2987 				new ParameterModifier [0]);
2988 			Assert.IsNull (ctor, "#I5");
2989 
2990 			ctor = greenType.GetConstructor (flags, null,
2991 				new Type [] { typeof (string), typeof (int) },
2992 				new ParameterModifier [0]);
2993 			Assert.IsNull (ctor, "#I6");
2994 
2995 			ctor = greenType.GetConstructor (flags, null,
2996 				Type.EmptyTypes,
2997 				new ParameterModifier [0]);
2998 			Assert.IsNull (ctor, "#I7");
2999 
3000 			ctor = redType.GetConstructor (flags, null,
3001 				new Type [] { typeof (int), typeof (int) },
3002 				new ParameterModifier [0]);
3003 			Assert.IsNotNull (ctor, "#I8a");
3004 			Assert.IsTrue (ctor.IsPrivate, "#I8b");
3005 			Assert.IsFalse (ctor.IsStatic, "#I8c");
3006 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
3007 			Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
3008 
3009 			ctor = redType.GetConstructor (flags, null,
3010 				new Type [] { typeof (string) },
3011 				new ParameterModifier [0]);
3012 			Assert.IsNotNull (ctor, "#I9a");
3013 			Assert.IsTrue (ctor.IsFamily, "#I9b");
3014 			Assert.IsFalse (ctor.IsStatic, "#I9c");
3015 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
3016 			Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
3017 
3018 			ctor = redType.GetConstructor (flags, null,
3019 				new Type [] { typeof (string), typeof (string) },
3020 				new ParameterModifier [0]);
3021 			Assert.IsNotNull (ctor, "#I10a");
3022 			Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
3023 			Assert.IsFalse (ctor.IsStatic, "#I10c");
3024 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
3025 			Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
3026 
3027 			ctor = redType.GetConstructor (flags, null,
3028 				new Type [] { typeof (int) },
3029 				new ParameterModifier [0]);
3030 			Assert.IsNotNull (ctor, "#I11a");
3031 			Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
3032 			Assert.IsFalse (ctor.IsStatic, "#I11c");
3033 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
3034 			Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
3035 
3036 			ctor = redType.GetConstructor (flags, null,
3037 				new Type [] { typeof (int), typeof (bool) },
3038 				new ParameterModifier [0]);
3039 			Assert.IsNull (ctor, "#I12");
3040 
3041 			ctor = redType.GetConstructor (flags, null,
3042 				new Type [] { typeof (string), typeof (int) },
3043 				new ParameterModifier [0]);
3044 			Assert.IsNotNull (ctor, "#I13a");
3045 			Assert.IsTrue (ctor.IsAssembly, "#I13b");
3046 			Assert.IsFalse (ctor.IsStatic, "#I13c");
3047 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
3048 			Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
3049 
3050 			ctor = redType.GetConstructor (flags, null,
3051 				Type.EmptyTypes,
3052 				new ParameterModifier [0]);
3053 			Assert.IsNull (ctor, "#I14");
3054 
3055 			flags = BindingFlags.Instance | BindingFlags.Public |
3056 				BindingFlags.DeclaredOnly;
3057 
3058 			ctor = greenType.GetConstructor (flags, null,
3059 				new Type [] { typeof (int), typeof (int) },
3060 				new ParameterModifier [0]);
3061 			Assert.IsNull (ctor, "#J1");
3062 
3063 			ctor = greenType.GetConstructor (flags, null,
3064 				new Type [] { typeof (string) },
3065 				new ParameterModifier [0]);
3066 			Assert.IsNull (ctor, "#J2");
3067 
3068 			ctor = greenType.GetConstructor (flags, null,
3069 				new Type [] { typeof (string), typeof (string) },
3070 				new ParameterModifier [0]);
3071 			Assert.IsNull (ctor, "#J3");
3072 
3073 			ctor = greenType.GetConstructor (flags, null,
3074 				new Type [] { typeof (int) },
3075 				new ParameterModifier [0]);
3076 			Assert.IsNull (ctor, "#J4");
3077 
3078 			ctor = greenType.GetConstructor (flags, null,
3079 				new Type [] { typeof (int), typeof (bool) },
3080 				new ParameterModifier [0]);
3081 			Assert.IsNull (ctor, "#J5");
3082 
3083 			ctor = greenType.GetConstructor (flags, null,
3084 				new Type [] { typeof (string), typeof (int) },
3085 				new ParameterModifier [0]);
3086 			Assert.IsNull (ctor, "#J6");
3087 
3088 			ctor = greenType.GetConstructor (flags, null,
3089 				Type.EmptyTypes,
3090 				new ParameterModifier [0]);
3091 			Assert.IsNotNull (ctor, "#J7a");
3092 			Assert.IsTrue (ctor.IsPublic, "#J7b");
3093 			Assert.IsFalse (ctor.IsStatic, "#J7c");
3094 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3095 			Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3096 
3097 			ctor = redType.GetConstructor (flags, null,
3098 				new Type [] { typeof (int), typeof (int) },
3099 				new ParameterModifier [0]);
3100 			Assert.IsNull (ctor, "#J8");
3101 
3102 			ctor = redType.GetConstructor (flags, null,
3103 				new Type [] { typeof (string) },
3104 				new ParameterModifier [0]);
3105 			Assert.IsNull (ctor, "#J9");
3106 
3107 			ctor = redType.GetConstructor (flags, null,
3108 				new Type [] { typeof (string), typeof (string) },
3109 				new ParameterModifier [0]);
3110 			Assert.IsNull (ctor, "#J10");
3111 
3112 			ctor = redType.GetConstructor (flags, null,
3113 				new Type [] { typeof (int) },
3114 				new ParameterModifier [0]);
3115 			Assert.IsNull (ctor, "#J11");
3116 
3117 			ctor = redType.GetConstructor (flags, null,
3118 				new Type [] { typeof (int), typeof (bool) },
3119 				new ParameterModifier [0]);
3120 			Assert.IsNotNull (ctor, "#J12a");
3121 			Assert.IsTrue (ctor.IsPublic, "#J12b");
3122 			Assert.IsFalse (ctor.IsStatic, "#J12c");
3123 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3124 			Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3125 
3126 			ctor = redType.GetConstructor (flags, null,
3127 				new Type [] { typeof (string), typeof (int) },
3128 				new ParameterModifier [0]);
3129 			Assert.IsNull (ctor, "#J13");
3130 
3131 			ctor = redType.GetConstructor (flags, null,
3132 				Type.EmptyTypes,
3133 				new ParameterModifier [0]);
3134 			Assert.IsNull (ctor, "#J14");
3135 
3136 			flags = BindingFlags.Static | BindingFlags.Public |
3137 				BindingFlags.DeclaredOnly;
3138 
3139 			ctor = greenType.GetConstructor (flags, null,
3140 				new Type [] { typeof (int), typeof (int) },
3141 				new ParameterModifier [0]);
3142 			Assert.IsNull (ctor, "#K1");
3143 
3144 			ctor = greenType.GetConstructor (flags, null,
3145 				new Type [] { typeof (string) },
3146 				new ParameterModifier [0]);
3147 			Assert.IsNull (ctor, "#K2");
3148 
3149 			ctor = greenType.GetConstructor (flags, null,
3150 				new Type [] { typeof (string), typeof (string) },
3151 				new ParameterModifier [0]);
3152 			Assert.IsNull (ctor, "#K3");
3153 
3154 			ctor = greenType.GetConstructor (flags, null,
3155 				new Type [] { typeof (int) },
3156 				new ParameterModifier [0]);
3157 			Assert.IsNull (ctor, "#K4");
3158 
3159 			ctor = greenType.GetConstructor (flags, null,
3160 				new Type [] { typeof (int), typeof (bool) },
3161 				new ParameterModifier [0]);
3162 			Assert.IsNull (ctor, "#K5");
3163 
3164 			ctor = greenType.GetConstructor (flags, null,
3165 				new Type [] { typeof (string), typeof (int) },
3166 				new ParameterModifier [0]);
3167 			Assert.IsNull (ctor, "#K6");
3168 
3169 			ctor = greenType.GetConstructor (flags, null,
3170 				Type.EmptyTypes,
3171 				new ParameterModifier [0]);
3172 			Assert.IsNull (ctor, "#K7");
3173 
3174 			ctor = redType.GetConstructor (flags, null,
3175 				new Type [] { typeof (int), typeof (int) },
3176 				new ParameterModifier [0]);
3177 			Assert.IsNull (ctor, "#K8");
3178 
3179 			ctor = redType.GetConstructor (flags, null,
3180 				new Type [] { typeof (string) },
3181 				new ParameterModifier [0]);
3182 			Assert.IsNull (ctor, "#K9");
3183 
3184 			ctor = redType.GetConstructor (flags, null,
3185 				new Type [] { typeof (string), typeof (string) },
3186 				new ParameterModifier [0]);
3187 			Assert.IsNull (ctor, "#K10");
3188 
3189 			ctor = redType.GetConstructor (flags, null,
3190 				new Type [] { typeof (int) },
3191 				new ParameterModifier [0]);
3192 			Assert.IsNull (ctor, "#K11");
3193 
3194 			ctor = redType.GetConstructor (flags, null,
3195 				new Type [] { typeof (int), typeof (bool) },
3196 				new ParameterModifier [0]);
3197 			Assert.IsNull (ctor, "#K12");
3198 
3199 			ctor = redType.GetConstructor (flags, null,
3200 				new Type [] { typeof (string), typeof (int) },
3201 				new ParameterModifier [0]);
3202 			Assert.IsNull (ctor, "#K13");
3203 
3204 			ctor = redType.GetConstructor (flags, null,
3205 				Type.EmptyTypes,
3206 				new ParameterModifier [0]);
3207 			Assert.IsNull (ctor, "#K14");
3208 
3209 			flags = BindingFlags.Static | BindingFlags.NonPublic |
3210 				BindingFlags.DeclaredOnly;
3211 
3212 			ctor = greenType.GetConstructor (flags, null,
3213 				new Type [] { typeof (int), typeof (int) },
3214 				new ParameterModifier [0]);
3215 			Assert.IsNull (ctor, "#L1");
3216 
3217 			ctor = greenType.GetConstructor (flags, null,
3218 				new Type [] { typeof (string) },
3219 				new ParameterModifier [0]);
3220 			Assert.IsNull (ctor, "#L2");
3221 
3222 			ctor = greenType.GetConstructor (flags, null,
3223 				new Type [] { typeof (string), typeof (string) },
3224 				new ParameterModifier [0]);
3225 			Assert.IsNull (ctor, "#L3");
3226 
3227 			ctor = greenType.GetConstructor (flags, null,
3228 				new Type [] { typeof (int) },
3229 				new ParameterModifier [0]);
3230 			Assert.IsNull (ctor, "#L4");
3231 
3232 			ctor = greenType.GetConstructor (flags, null,
3233 				new Type [] { typeof (int), typeof (bool) },
3234 				new ParameterModifier [0]);
3235 			Assert.IsNull (ctor, "#L5");
3236 
3237 			ctor = greenType.GetConstructor (flags, null,
3238 				new Type [] { typeof (string), typeof (int) },
3239 				new ParameterModifier [0]);
3240 			Assert.IsNull (ctor, "#L6");
3241 
3242 			ctor = greenType.GetConstructor (flags, null,
3243 				Type.EmptyTypes,
3244 				new ParameterModifier [0]);
3245 			Assert.IsNull (ctor, "#L7");
3246 
3247 			ctor = redType.GetConstructor (flags, null,
3248 				new Type [] { typeof (int), typeof (int) },
3249 				new ParameterModifier [0]);
3250 			Assert.IsNull (ctor, "#L8");
3251 
3252 			ctor = redType.GetConstructor (flags, null,
3253 				new Type [] { typeof (string) },
3254 				new ParameterModifier [0]);
3255 			Assert.IsNull (ctor, "#L9");
3256 
3257 			ctor = redType.GetConstructor (flags, null,
3258 				new Type [] { typeof (string), typeof (string) },
3259 				new ParameterModifier [0]);
3260 			Assert.IsNull (ctor, "#L10");
3261 
3262 			ctor = redType.GetConstructor (flags, null,
3263 				new Type [] { typeof (int) },
3264 				new ParameterModifier [0]);
3265 			Assert.IsNull (ctor, "#L11");
3266 
3267 			ctor = redType.GetConstructor (flags, null,
3268 				new Type [] { typeof (int), typeof (bool) },
3269 				new ParameterModifier [0]);
3270 			Assert.IsNull (ctor, "#L12");
3271 
3272 			ctor = redType.GetConstructor (flags, null,
3273 				new Type [] { typeof (string), typeof (int) },
3274 				new ParameterModifier [0]);
3275 			Assert.IsNull (ctor, "#L13");
3276 
3277 			ctor = redType.GetConstructor (flags, null,
3278 				Type.EmptyTypes,
3279 				new ParameterModifier [0]);
3280 			Assert.IsNotNull (ctor, "#L14a");
3281 			Assert.IsTrue (ctor.IsPrivate, "#L14b");
3282 			Assert.IsTrue (ctor.IsStatic, "#L14c");
3283 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3284 			Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3285 
3286 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
3287 				BindingFlags.Public;
3288 
3289 			ctor = greenType.GetConstructor (flags, null,
3290 				new Type [] { typeof (int), typeof (int) },
3291 				new ParameterModifier [0]);
3292 			Assert.IsNull (ctor, "#M1");
3293 
3294 			ctor = greenType.GetConstructor (flags, null,
3295 				new Type [] { typeof (string) },
3296 				new ParameterModifier [0]);
3297 			Assert.IsNull (ctor, "#M2");
3298 
3299 			ctor = greenType.GetConstructor (flags, null,
3300 				new Type [] { typeof (string), typeof (string) },
3301 				new ParameterModifier [0]);
3302 			Assert.IsNull (ctor, "#M3");
3303 
3304 			ctor = greenType.GetConstructor (flags, null,
3305 				new Type [] { typeof (int) },
3306 				new ParameterModifier [0]);
3307 			Assert.IsNull (ctor, "#M4");
3308 
3309 			ctor = greenType.GetConstructor (flags, null,
3310 				new Type [] { typeof (int), typeof (bool) },
3311 				new ParameterModifier [0]);
3312 			Assert.IsNull (ctor, "#M5");
3313 
3314 			ctor = greenType.GetConstructor (flags, null,
3315 				new Type [] { typeof (string), typeof (int) },
3316 				new ParameterModifier [0]);
3317 			Assert.IsNull (ctor, "#M6");
3318 
3319 			ctor = greenType.GetConstructor (flags, null,
3320 				Type.EmptyTypes,
3321 				new ParameterModifier [0]);
3322 			Assert.IsNotNull (ctor, "#M7a");
3323 			Assert.IsTrue (ctor.IsPublic, "#M7b");
3324 			Assert.IsFalse (ctor.IsStatic, "#M7c");
3325 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3326 			Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3327 
3328 			ctor = redType.GetConstructor (flags, null,
3329 				new Type [] { typeof (int), typeof (int) },
3330 				new ParameterModifier [0]);
3331 			Assert.IsNotNull (ctor, "#M8a");
3332 			Assert.IsTrue (ctor.IsPrivate, "#M8b");
3333 			Assert.IsFalse (ctor.IsStatic, "#M8c");
3334 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3335 			Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3336 
3337 			ctor = redType.GetConstructor (flags, null,
3338 				new Type [] { typeof (string) },
3339 				new ParameterModifier [0]);
3340 			Assert.IsNotNull (ctor, "#M9a");
3341 			Assert.IsTrue (ctor.IsFamily, "#M9b");
3342 			Assert.IsFalse (ctor.IsStatic, "#M9c");
3343 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3344 			Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3345 
3346 			ctor = redType.GetConstructor (flags, null,
3347 				new Type [] { typeof (string), typeof (string) },
3348 				new ParameterModifier [0]);
3349 			Assert.IsNotNull (ctor, "#M10a");
3350 			Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3351 			Assert.IsFalse (ctor.IsStatic, "#M10c");
3352 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3353 			Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3354 
3355 			ctor = redType.GetConstructor (flags, null,
3356 				new Type [] { typeof (int) },
3357 				new ParameterModifier [0]);
3358 			Assert.IsNotNull (ctor, "#M11a");
3359 			Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3360 			Assert.IsFalse (ctor.IsStatic, "#M11c");
3361 			Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3362 			Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3363 
3364 			ctor = redType.GetConstructor (flags, null,
3365 				new Type [] { typeof (int), typeof (bool) },
3366 				new ParameterModifier [0]);
3367 			Assert.IsNotNull (ctor, "#M12a");
3368 			Assert.IsTrue (ctor.IsPublic, "#M12b");
3369 			Assert.IsFalse (ctor.IsStatic, "#M12c");
3370 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3371 			Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3372 
3373 			ctor = redType.GetConstructor (flags, null,
3374 				new Type [] { typeof (string), typeof (int) },
3375 				new ParameterModifier [0]);
3376 			Assert.IsNotNull (ctor, "#M13a");
3377 			Assert.IsTrue (ctor.IsAssembly, "#M13b");
3378 			Assert.IsFalse (ctor.IsStatic, "#M13c");
3379 			Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3380 			Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3381 
3382 			ctor = redType.GetConstructor (flags, null,
3383 				Type.EmptyTypes,
3384 				new ParameterModifier [0]);
3385 			Assert.IsNull (ctor, "#M14");
3386 
3387 			flags = BindingFlags.Static | BindingFlags.NonPublic |
3388 				BindingFlags.Public;
3389 
3390 			ctor = greenType.GetConstructor (flags, null,
3391 				new Type [] { typeof (int), typeof (int) },
3392 				new ParameterModifier [0]);
3393 			Assert.IsNull (ctor, "#N1");
3394 
3395 			ctor = greenType.GetConstructor (flags, null,
3396 				new Type [] { typeof (string) },
3397 				new ParameterModifier [0]);
3398 			Assert.IsNull (ctor, "#N2");
3399 
3400 			ctor = greenType.GetConstructor (flags, null,
3401 				new Type [] { typeof (string), typeof (string) },
3402 				new ParameterModifier [0]);
3403 			Assert.IsNull (ctor, "#N3");
3404 
3405 			ctor = greenType.GetConstructor (flags, null,
3406 				new Type [] { typeof (int) },
3407 				new ParameterModifier [0]);
3408 			Assert.IsNull (ctor, "#N4");
3409 
3410 			ctor = greenType.GetConstructor (flags, null,
3411 				new Type [] { typeof (int), typeof (bool) },
3412 				new ParameterModifier [0]);
3413 			Assert.IsNull (ctor, "#N5");
3414 
3415 			ctor = greenType.GetConstructor (flags, null,
3416 				new Type [] { typeof (string), typeof (int) },
3417 				new ParameterModifier [0]);
3418 			Assert.IsNull (ctor, "#N6");
3419 
3420 			ctor = greenType.GetConstructor (flags, null,
3421 				Type.EmptyTypes,
3422 				new ParameterModifier [0]);
3423 			Assert.IsNull (ctor, "#N7");
3424 
3425 			ctor = redType.GetConstructor (flags, null,
3426 				new Type [] { typeof (int), typeof (int) },
3427 				new ParameterModifier [0]);
3428 			Assert.IsNull (ctor, "#N8");
3429 
3430 			ctor = redType.GetConstructor (flags, null,
3431 				new Type [] { typeof (string) },
3432 				new ParameterModifier [0]);
3433 			Assert.IsNull (ctor, "#N9");
3434 
3435 			ctor = redType.GetConstructor (flags, null,
3436 				new Type [] { typeof (string), typeof (string) },
3437 				new ParameterModifier [0]);
3438 			Assert.IsNull (ctor, "#N10");
3439 
3440 			ctor = redType.GetConstructor (flags, null,
3441 				new Type [] { typeof (int) },
3442 				new ParameterModifier [0]);
3443 			Assert.IsNull (ctor, "#N11");
3444 
3445 			ctor = redType.GetConstructor (flags, null,
3446 				new Type [] { typeof (int), typeof (bool) },
3447 				new ParameterModifier [0]);
3448 			Assert.IsNull (ctor, "#N12");
3449 
3450 			ctor = redType.GetConstructor (flags, null,
3451 				new Type [] { typeof (string), typeof (int) },
3452 				new ParameterModifier [0]);
3453 			Assert.IsNull (ctor, "#N13");
3454 
3455 			ctor = redType.GetConstructor (flags, null,
3456 				Type.EmptyTypes,
3457 				new ParameterModifier [0]);
3458 			Assert.IsNotNull (ctor, "#N14a");
3459 			Assert.IsTrue (ctor.IsPrivate, "#N14b");
3460 			Assert.IsTrue (ctor.IsStatic, "#N14c");
3461 			Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3462 			Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3463 		}
3464 
3465 		[Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
GetConstructor2_Incomplete()3466 		public void GetConstructor2_Incomplete ()
3467 		{
3468 			TypeBuilder tb = module.DefineType (genTypeName ());
3469 			ConstructorBuilder cb = tb.DefineConstructor (
3470 				MethodAttributes.Public,
3471 				CallingConventions.Standard,
3472 				Type.EmptyTypes);
3473 			cb.GetILGenerator ().Emit (OpCodes.Ret);
3474 
3475 			try {
3476 				tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3477 					null, Type.EmptyTypes, new ParameterModifier [0]);
3478 				Assert.Fail ("#1");
3479 			} catch (NotSupportedException ex) {
3480 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3481 				Assert.IsNull (ex.InnerException, "#3");
3482 				Assert.IsNotNull (ex.Message, "#4");
3483 			}
3484 		}
3485 
3486 		[Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
GetConstructor3_Incomplete()3487 		public void GetConstructor3_Incomplete ()
3488 		{
3489 			TypeBuilder tb = module.DefineType (genTypeName ());
3490 			ConstructorBuilder cb = tb.DefineConstructor (
3491 				MethodAttributes.Public,
3492 				CallingConventions.Standard,
3493 				Type.EmptyTypes);
3494 			cb.GetILGenerator ().Emit (OpCodes.Ret);
3495 
3496 			try {
3497 				tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3498 					null, CallingConventions.Standard, Type.EmptyTypes,
3499 					new ParameterModifier [0]);
3500 				Assert.Fail ("#1");
3501 			} catch (NotSupportedException ex) {
3502 				// The invoked member is not supported in a
3503 				// dynamic module
3504 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3505 				Assert.IsNull (ex.InnerException, "#3");
3506 				Assert.IsNotNull (ex.Message, "#4");
3507 			}
3508 		}
3509 
3510 		[Test] // GetConstructors ()
3511 		[Category ("NotWorking")] // mcs depends on this
GetConstructors1_Incomplete()3512 		public void GetConstructors1_Incomplete ()
3513 		{
3514 			TypeBuilder tb = module.DefineType (genTypeName ());
3515 			ConstructorBuilder cb = tb.DefineConstructor (
3516 				MethodAttributes.Public,
3517 				CallingConventions.Standard,
3518 				Type.EmptyTypes);
3519 			cb.GetILGenerator ().Emit (OpCodes.Ret);
3520 
3521 			try {
3522 				tb.GetConstructors ();
3523 				Assert.Fail ("#1");
3524 			} catch (NotSupportedException ex) {
3525 				// The invoked member is not supported in a
3526 				// dynamic module
3527 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3528 				Assert.IsNull (ex.InnerException, "#3");
3529 				Assert.IsNotNull (ex.Message, "#4");
3530 			}
3531 		}
3532 
3533 		[Test] // GetConstructors (BindingFlags)
GetConstructors2_Complete()3534 		public void GetConstructors2_Complete ()
3535 		{
3536 			BindingFlags flags;
3537 			ConstructorInfo [] ctors;
3538 
3539 			TypeBuilder redType = module.DefineType (genTypeName (),
3540 				TypeAttributes.Public);
3541 			CreateMembers (redType, "Red", true);
3542 
3543 			TypeBuilder greenType = module.DefineType (genTypeName (),
3544 				TypeAttributes.Public, redType);
3545 			CreateMembers (greenType, "Green", false);
3546 			ConstructorBuilder cb = greenType.DefineConstructor (
3547 				MethodAttributes.Public,
3548 				CallingConventions.Standard,
3549 				Type.EmptyTypes);
3550 			cb.GetILGenerator ().Emit (OpCodes.Ret);
3551 
3552 			redType.CreateType ();
3553 			greenType.CreateType ();
3554 
3555 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
3556 
3557 			ctors = greenType.GetConstructors (flags);
3558 			Assert.AreEqual (0, ctors.Length, "#A1");
3559 
3560 			ctors = redType.GetConstructors (flags);
3561 			Assert.AreEqual (5, ctors.Length, "#A2");
3562 			Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3563 			Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3564 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3565 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3566 			Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3567 			Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3568 			Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3569 			Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3570 			Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3571 			Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3572 			Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3573 			Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3574 			Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3575 			Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3576 			Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3577 			Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3578 			Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3579 			Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3580 			Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3581 			Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3582 
3583 			flags = BindingFlags.Instance | BindingFlags.Public;
3584 
3585 			ctors = greenType.GetConstructors (flags);
3586 			Assert.AreEqual (1, ctors.Length, "#B1");
3587 			Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3588 			Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3589 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3590 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3591 
3592 			ctors = redType.GetConstructors (flags);
3593 			Assert.AreEqual (1, ctors.Length, "#B3");
3594 			Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3595 			Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3596 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3597 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3598 
3599 			flags = BindingFlags.Static | BindingFlags.Public;
3600 
3601 			ctors = greenType.GetConstructors (flags);
3602 			Assert.AreEqual (0, ctors.Length, "#C1");
3603 
3604 			ctors = redType.GetConstructors (flags);
3605 			Assert.AreEqual (0, ctors.Length, "#C2");
3606 
3607 			flags = BindingFlags.Static | BindingFlags.NonPublic;
3608 
3609 			ctors = greenType.GetConstructors (flags);
3610 			Assert.AreEqual (0, ctors.Length, "#D1");
3611 
3612 			ctors = redType.GetConstructors (flags);
3613 			Assert.AreEqual (1, ctors.Length, "#D2");
3614 			Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3615 			Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3616 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3617 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3618 
3619 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
3620 				BindingFlags.FlattenHierarchy;
3621 
3622 			ctors = greenType.GetConstructors (flags);
3623 			Assert.AreEqual (0, ctors.Length, "#E1");
3624 
3625 			ctors = redType.GetConstructors (flags);
3626 			Assert.AreEqual (5, ctors.Length, "#E2");
3627 			Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3628 			Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3629 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3630 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3631 			Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3632 			Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3633 			Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3634 			Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3635 			Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3636 			Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3637 			Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3638 			Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3639 			Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3640 			Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3641 			Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3642 			Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3643 			Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3644 			Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3645 			Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3646 			Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3647 
3648 			flags = BindingFlags.Instance | BindingFlags.Public |
3649 				BindingFlags.FlattenHierarchy;
3650 
3651 			ctors = greenType.GetConstructors (flags);
3652 			Assert.AreEqual (1, ctors.Length, "#F1");
3653 			Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3654 			Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3655 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3656 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3657 
3658 			ctors = redType.GetConstructors (flags);
3659 			Assert.AreEqual (1, ctors.Length, "#F3");
3660 			Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3661 			Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3662 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3663 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3664 
3665 			flags = BindingFlags.Static | BindingFlags.Public |
3666 				BindingFlags.FlattenHierarchy;
3667 
3668 			ctors = greenType.GetConstructors (flags);
3669 			Assert.AreEqual (0, ctors.Length, "#G1");
3670 
3671 			ctors = redType.GetConstructors (flags);
3672 			Assert.AreEqual (0, ctors.Length, "#G2");
3673 
3674 			flags = BindingFlags.Static | BindingFlags.NonPublic |
3675 				BindingFlags.FlattenHierarchy;
3676 
3677 			ctors = greenType.GetConstructors (flags);
3678 			Assert.AreEqual (0, ctors.Length, "#H1");
3679 
3680 			ctors = redType.GetConstructors (flags);
3681 			Assert.AreEqual (1, ctors.Length, "#H2");
3682 			Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3683 			Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3684 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3685 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3686 
3687 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
3688 				BindingFlags.DeclaredOnly;
3689 
3690 			ctors = greenType.GetConstructors (flags);
3691 			Assert.AreEqual (0, ctors.Length, "#I1");
3692 
3693 			ctors = redType.GetConstructors (flags);
3694 			Assert.AreEqual (5, ctors.Length, "#I2");
3695 			Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3696 			Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3697 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3698 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3699 			Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3700 			Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3701 			Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3702 			Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3703 			Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3704 			Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3705 			Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3706 			Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3707 			Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3708 			Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3709 			Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3710 			Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3711 			Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3712 			Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3713 			Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3714 			Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3715 
3716 			flags = BindingFlags.Instance | BindingFlags.Public |
3717 				BindingFlags.DeclaredOnly;
3718 
3719 			ctors = greenType.GetConstructors (flags);
3720 			Assert.AreEqual (1, ctors.Length, "#J1");
3721 			Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3722 			Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3723 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3724 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3725 
3726 			ctors = redType.GetConstructors (flags);
3727 			Assert.AreEqual (1, ctors.Length, "#J3");
3728 			Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3729 			Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3730 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3731 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3732 
3733 			flags = BindingFlags.Static | BindingFlags.Public |
3734 				BindingFlags.DeclaredOnly;
3735 
3736 			ctors = greenType.GetConstructors (flags);
3737 			Assert.AreEqual (0, ctors.Length, "#K1");
3738 
3739 			ctors = redType.GetConstructors (flags);
3740 			Assert.AreEqual (0, ctors.Length, "#K2");
3741 
3742 			flags = BindingFlags.Static | BindingFlags.NonPublic |
3743 				BindingFlags.DeclaredOnly;
3744 
3745 			ctors = greenType.GetConstructors (flags);
3746 			Assert.AreEqual (0, ctors.Length, "#L1");
3747 
3748 			ctors = redType.GetConstructors (flags);
3749 			Assert.AreEqual (1, ctors.Length, "#L2");
3750 			Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3751 			Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3752 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3753 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3754 
3755 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
3756 				BindingFlags.Public;
3757 
3758 			ctors = greenType.GetConstructors (flags);
3759 			Assert.AreEqual (1, ctors.Length, "#M1");
3760 			Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3761 			Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3762 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3763 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3764 
3765 			ctors = redType.GetConstructors (flags);
3766 			Assert.AreEqual (6, ctors.Length, "#M3");
3767 			Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3768 			Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3769 			Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3770 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3771 			Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3772 			Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3773 			Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3774 			Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3775 			Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3776 			Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3777 			Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3778 			Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3779 			Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3780 			Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3781 			Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3782 			Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3783 			Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3784 			Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3785 			Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3786 			Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3787 			Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3788 			Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3789 			Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3790 			Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3791 
3792 			flags = BindingFlags.Static | BindingFlags.NonPublic |
3793 				BindingFlags.Public;
3794 
3795 			ctors = greenType.GetConstructors (flags);
3796 			Assert.AreEqual (0, ctors.Length, "#N1");
3797 
3798 			ctors = redType.GetConstructors (flags);
3799 			Assert.AreEqual (1, ctors.Length, "#N2");
3800 			Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3801 			Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3802 			Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3803 			Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3804 		}
3805 
3806 		[Test] // GetConstructors (BindingFlags)
3807 		[Category ("NotWorking")] // mcs depends on this
GetConstructors2_Incomplete()3808 		public void GetConstructors2_Incomplete ()
3809 		{
3810 			TypeBuilder tb = module.DefineType (genTypeName ());
3811 			ConstructorBuilder cb = tb.DefineConstructor (
3812 				MethodAttributes.Public,
3813 				CallingConventions.Standard,
3814 				Type.EmptyTypes);
3815 			cb.GetILGenerator ().Emit (OpCodes.Ret);
3816 
3817 			try {
3818 				tb.GetConstructors (BindingFlags.Public |
3819 					BindingFlags.Instance);
3820 				Assert.Fail ("#1");
3821 			} catch (NotSupportedException ex) {
3822 				// The invoked member is not supported in a
3823 				// dynamic module
3824 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3825 				Assert.IsNull (ex.InnerException, "#3");
3826 				Assert.IsNotNull (ex.Message, "#4");
3827 			}
3828 		}
3829 
3830 		[Test]
TestGetCustomAttributesIncomplete()3831 		public void TestGetCustomAttributesIncomplete ()
3832 		{
3833 			TypeBuilder tb = module.DefineType (genTypeName ());
3834 			try {
3835 				tb.GetCustomAttributes (false);
3836 				Assert.Fail ("#1");
3837 			} catch (NotSupportedException ex) {
3838 				// The invoked member is not supported in a
3839 				// dynamic module
3840 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3841 				Assert.IsNull (ex.InnerException, "#3");
3842 				Assert.IsNotNull (ex.Message, "#4");
3843 			}
3844 		}
3845 
3846 		[Test]
TestGetCustomAttributesComplete()3847 		public void TestGetCustomAttributesComplete ()
3848 		{
3849 			TypeBuilder tb = module.DefineType (genTypeName ());
3850 
3851 			ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3852 				new Type [] { typeof (string) });
3853 
3854 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3855 				new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3856 
3857 			tb.SetCustomAttribute (caBuilder);
3858 			tb.CreateType ();
3859 
3860 			Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3861 		}
3862 
3863 		[Test]
TestGetCustomAttributesOfTypeIncomplete()3864 		public void TestGetCustomAttributesOfTypeIncomplete ()
3865 		{
3866 			TypeBuilder tb = module.DefineType (genTypeName ());
3867 			try {
3868 				tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3869 				Assert.Fail ("#1");
3870 			} catch (NotSupportedException ex) {
3871 				// The invoked member is not supported in a
3872 				// dynamic module
3873 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3874 				Assert.IsNull (ex.InnerException, "#3");
3875 				Assert.IsNotNull (ex.Message, "#4");
3876 			}
3877 		}
3878 
3879 		[Test]
TestGetCustomAttributesOfTypeComplete()3880 		public void TestGetCustomAttributesOfTypeComplete ()
3881 		{
3882 			TypeBuilder tb = module.DefineType (genTypeName ());
3883 
3884 			ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3885 				new Type [] { typeof (string) });
3886 
3887 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3888 				new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3889 
3890 			tb.SetCustomAttribute (caBuilder);
3891 			tb.CreateType ();
3892 
3893 			Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3894 			Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3895 		}
3896 
3897 		[Test]
TestGetCustomAttributesOfNullTypeComplete()3898 		public void TestGetCustomAttributesOfNullTypeComplete ()
3899 		{
3900 			TypeBuilder tb = module.DefineType (genTypeName ());
3901 			tb.CreateType ();
3902 			try {
3903 				tb.GetCustomAttributes (null, false);
3904 				Assert.Fail ("#1");
3905 			} catch (ArgumentNullException ex) {
3906 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3907 				Assert.IsNull (ex.InnerException, "#3");
3908 				Assert.IsNotNull (ex.Message, "#4");
3909 				Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3910 			}
3911 		}
3912 
3913 		[Test]
3914 		[Ignore ("mcs depends on this")]
TestGetEventsIncomplete()3915 		public void TestGetEventsIncomplete ()
3916 		{
3917 			TypeBuilder tb = module.DefineType (genTypeName ());
3918 			try {
3919 				tb.GetEvents ();
3920 				Assert.Fail ("#1");
3921 			} catch (NotSupportedException ex) {
3922 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3923 				Assert.IsNull (ex.InnerException, "#3");
3924 				Assert.IsNotNull (ex.Message, "#4");
3925 				throw;
3926 			}
3927 		}
3928 
3929 		[Test]
TestGetEventsComplete()3930 		public void TestGetEventsComplete ()
3931 		{
3932 			TypeBuilder tb = module.DefineType (genTypeName ());
3933 
3934 			MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3935 				typeof (void), new Type [] { typeof (Object) });
3936 			onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3937 
3938 			// create public event
3939 			EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3940 				typeof (ResolveEventHandler));
3941 			eventbuilder.SetRaiseMethod (onclickMethod);
3942 
3943 			Type emittedType = tb.CreateType ();
3944 
3945 			Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3946 			Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3947 		}
3948 
3949 
3950 		[Test]
3951 		[Ignore ("mcs depends on this")]
TestGetEventsFlagsIncomplete()3952 		public void TestGetEventsFlagsIncomplete ()
3953 		{
3954 			TypeBuilder tb = module.DefineType (genTypeName ());
3955 			try {
3956 				tb.GetEvents (BindingFlags.Public);
3957 				Assert.Fail ("#1");
3958 			} catch (NotSupportedException ex) {
3959 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3960 				Assert.IsNull (ex.InnerException, "#3");
3961 				Assert.IsNotNull (ex.Message, "#4");
3962 				throw;
3963 			}
3964 		}
3965 
3966 		[Test]
TestGetEventsFlagsComplete()3967 		public void TestGetEventsFlagsComplete ()
3968 		{
3969 			TypeBuilder tb = module.DefineType (genTypeName ());
3970 
3971 			MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3972 				typeof (void), new Type [] { typeof (Object) });
3973 			onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3974 
3975 			// create public event
3976 			EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3977 				typeof (ResolveEventHandler));
3978 			changeEvent.SetRaiseMethod (onchangeMethod);
3979 
3980 			// create non-public event
3981 			EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3982 				typeof (ResolveEventHandler));
3983 
3984 			Type emittedType = tb.CreateType ();
3985 
3986 			Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3987 			Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3988 			Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3989 			Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
3990 				emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3991 			Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
3992 				emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3993 			Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
3994 				emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3995 		}
3996 
3997 		[Test]
TestGetEventsFlagsComplete_Inheritance()3998 		public void TestGetEventsFlagsComplete_Inheritance ()
3999 		{
4000 			EventInfo [] events;
4001 			BindingFlags flags;
4002 
4003 			TypeBuilder blueType = module.DefineType (genTypeName (),
4004 				TypeAttributes.Public);
4005 			CreateMembers (blueType, "Blue", false);
4006 
4007 			TypeBuilder redType = module.DefineType (genTypeName (),
4008 				TypeAttributes.Public, blueType);
4009 			CreateMembers (redType, "Red", false);
4010 
4011 			TypeBuilder greenType = module.DefineType (genTypeName (),
4012 				TypeAttributes.Public, redType);
4013 			CreateMembers (greenType, "Green", false);
4014 
4015 			blueType.CreateType ();
4016 			redType.CreateType ();
4017 			greenType.CreateType ();
4018 
4019 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
4020 			events = greenType.GetEvents (flags);
4021 
4022 			Assert.AreEqual (13, events.Length, "#A1");
4023 			Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
4024 			Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
4025 			Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
4026 			Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
4027 			Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
4028 			Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
4029 			Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
4030 			Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
4031 			Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
4032 			Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
4033 			Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
4034 			Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
4035 			Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
4036 
4037 			flags = BindingFlags.Instance | BindingFlags.Public;
4038 			events = greenType.GetEvents (flags);
4039 
4040 			Assert.AreEqual (3, events.Length, "#B1");
4041 			Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
4042 			Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
4043 			Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
4044 
4045 			flags = BindingFlags.Static | BindingFlags.Public;
4046 			events = greenType.GetEvents (flags);
4047 
4048 			Assert.AreEqual (1, events.Length, "#C1");
4049 			Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
4050 
4051 			flags = BindingFlags.Static | BindingFlags.NonPublic;
4052 			events = greenType.GetEvents (flags);
4053 
4054 			Assert.AreEqual (5, events.Length, "#D1");
4055 			Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
4056 			Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
4057 			Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
4058 			Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4059 			Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4060 
4061 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4062 				BindingFlags.FlattenHierarchy;
4063 			events = greenType.GetEvents (flags);
4064 
4065 			Assert.AreEqual (13, events.Length, "#E1");
4066 			Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4067 			Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4068 			Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4069 			Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4070 			Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4071 			Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4072 			Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4073 			Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4074 			Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4075 			Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4076 			Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4077 			Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4078 			Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4079 
4080 			flags = BindingFlags.Instance | BindingFlags.Public |
4081 				BindingFlags.FlattenHierarchy;
4082 			events = greenType.GetEvents (flags);
4083 
4084 			Assert.AreEqual (3, events.Length, "#F1");
4085 			Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4086 			Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4087 			Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4088 
4089 			flags = BindingFlags.Static | BindingFlags.Public |
4090 				BindingFlags.FlattenHierarchy;
4091 			events = greenType.GetEvents (flags);
4092 
4093 			Assert.AreEqual (3, events.Length, "#G1");
4094 			Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4095 			Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4096 			Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4097 
4098 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4099 				BindingFlags.FlattenHierarchy;
4100 			events = greenType.GetEvents (flags);
4101 
4102 			Assert.AreEqual (13, events.Length, "#H1");
4103 			Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4104 			Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4105 			Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4106 			Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4107 			Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4108 			Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4109 			Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4110 			Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4111 			Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4112 			Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4113 			Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4114 			Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4115 			Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4116 
4117 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4118 				BindingFlags.DeclaredOnly;
4119 			events = greenType.GetEvents (flags);
4120 
4121 			Assert.AreEqual (5, events.Length, "#I1");
4122 			Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4123 			Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4124 			Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4125 			Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4126 			Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4127 
4128 			flags = BindingFlags.Instance | BindingFlags.Public |
4129 				BindingFlags.DeclaredOnly;
4130 			events = greenType.GetEvents (flags);
4131 
4132 			Assert.AreEqual (1, events.Length, "#J1");
4133 			Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4134 
4135 			flags = BindingFlags.Static | BindingFlags.Public |
4136 				BindingFlags.DeclaredOnly;
4137 			events = greenType.GetEvents (flags);
4138 
4139 			Assert.AreEqual (1, events.Length, "#K1");
4140 			Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4141 
4142 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4143 				BindingFlags.DeclaredOnly;
4144 			events = greenType.GetEvents (flags);
4145 
4146 			Assert.AreEqual (5, events.Length, "#L1");
4147 			Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4148 			Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4149 			Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4150 			Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4151 			Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4152 
4153 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4154 				BindingFlags.Public;
4155 			events = greenType.GetEvents (flags);
4156 
4157 			Assert.AreEqual (16, events.Length, "#M1");
4158 			Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4159 			Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4160 			Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4161 			Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4162 			Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4163 			Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4164 			Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4165 			Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4166 			Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4167 			Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4168 			Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4169 			Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4170 			Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4171 			Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4172 			Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4173 			Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4174 
4175 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4176 				BindingFlags.Public;
4177 			events = greenType.GetEvents (flags);
4178 
4179 			Assert.AreEqual (6, events.Length, "#N1");
4180 			Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4181 			Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4182 			Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4183 			Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4184 			Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4185 			Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4186 		}
4187 
4188 		[Test]
4189 		[Ignore ("mcs depends on this")]
TestGetEventIncomplete()4190 		public void TestGetEventIncomplete ()
4191 		{
4192 			TypeBuilder tb = module.DefineType (genTypeName ());
4193 			try {
4194 				tb.GetEvent ("FOO");
4195 				Assert.Fail ("#1");
4196 			} catch (NotSupportedException ex) {
4197 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4198 				Assert.IsNull (ex.InnerException, "#3");
4199 				Assert.IsNotNull (ex.Message, "#4");
4200 				throw;
4201 			}
4202 		}
4203 
4204 		[Test]
TestGetEventComplete()4205 		public void TestGetEventComplete ()
4206 		{
4207 			TypeBuilder tb = module.DefineType (genTypeName ());
4208 
4209 			MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4210 				typeof (void), new Type [] { typeof (Object) });
4211 			onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4212 
4213 			EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4214 				typeof (ResolveEventHandler));
4215 			eventbuilder.SetRaiseMethod (onclickMethod);
4216 
4217 			Type emittedType = tb.CreateType ();
4218 
4219 			Assert.IsNotNull (tb.GetEvent ("Change"));
4220 			Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4221 			Assert.IsNull (tb.GetEvent ("NotChange"));
4222 			Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4223 		}
4224 
4225 		[Test]
4226 		[Ignore ("mcs depends on this")]
TestGetEventFlagsIncomplete()4227 		public void TestGetEventFlagsIncomplete ()
4228 		{
4229 			TypeBuilder tb = module.DefineType (genTypeName ());
4230 			try {
4231 				tb.GetEvent ("FOO", BindingFlags.Public);
4232 				Assert.Fail ("#1");
4233 			} catch (NotSupportedException ex) {
4234 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4235 				Assert.IsNull (ex.InnerException, "#3");
4236 				Assert.IsNotNull (ex.Message, "#4");
4237 				throw;
4238 			}
4239 		}
4240 
4241 		[Test]
TestGetEventFlagsComplete()4242 		public void TestGetEventFlagsComplete ()
4243 		{
4244 			TypeBuilder tb = module.DefineType (genTypeName ());
4245 
4246 			MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4247 				typeof (void), new Type [] { typeof (Object) });
4248 			onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4249 
4250 			EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4251 				typeof (ResolveEventHandler));
4252 			eventbuilder.SetRaiseMethod (onclickMethod);
4253 
4254 			Type emittedType = tb.CreateType ();
4255 
4256 			Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4257 			Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4258 				emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4259 			Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4260 			Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4261 				emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4262 		}
4263 
4264 		[Test]
TestGetEventFlagsComplete_Inheritance()4265 		public void TestGetEventFlagsComplete_Inheritance ()
4266 		{
4267 			BindingFlags flags;
4268 
4269 			TypeBuilder blueType = module.DefineType (genTypeName (),
4270 				TypeAttributes.Public);
4271 			CreateMembers (blueType, "Blue", false);
4272 
4273 			TypeBuilder redType = module.DefineType (genTypeName (),
4274 				TypeAttributes.Public, blueType);
4275 			CreateMembers (redType, "Red", false);
4276 
4277 			TypeBuilder greenType = module.DefineType (genTypeName (),
4278 				TypeAttributes.Public, redType);
4279 			CreateMembers (greenType, "Green", false);
4280 
4281 			blueType.CreateType ();
4282 			redType.CreateType ();
4283 			greenType.CreateType ();
4284 
4285 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
4286 
4287 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4288 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4289 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4290 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4291 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4292 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4293 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4294 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4295 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4296 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4297 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4298 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4299 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4300 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4301 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4302 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4303 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4304 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4305 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4306 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4307 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4308 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4309 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4310 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4311 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4312 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4313 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4314 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4315 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4316 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4317 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4318 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4319 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4320 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4321 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4322 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4323 
4324 			flags = BindingFlags.Instance | BindingFlags.Public;
4325 
4326 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4327 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4328 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4329 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4330 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4331 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4332 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4333 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4334 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4335 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4336 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4337 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4338 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4339 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4340 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4341 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4342 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4343 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4344 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4345 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4346 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4347 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4348 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4349 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4350 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4351 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4352 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4353 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4354 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4355 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4356 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4357 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4358 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4359 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4360 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4361 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4362 
4363 			flags = BindingFlags.Static | BindingFlags.Public;
4364 
4365 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4366 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4367 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4368 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4369 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4370 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4371 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4372 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4373 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4374 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4375 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4376 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4377 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4378 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4379 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4380 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4381 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4382 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4383 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4384 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4385 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4386 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4387 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4388 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4389 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4390 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4391 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4392 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4393 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4394 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4395 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4396 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4397 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4398 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4399 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4400 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4401 
4402 			flags = BindingFlags.Static | BindingFlags.NonPublic;
4403 
4404 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4405 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4406 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4407 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4408 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4409 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4410 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4411 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4412 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4413 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4414 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4415 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4416 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4417 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4418 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4419 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4420 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4421 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4422 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4423 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4424 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4425 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4426 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4427 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4428 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4429 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4430 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4431 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4432 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4433 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4434 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4435 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4436 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4437 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4438 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4439 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4440 
4441 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4442 				BindingFlags.FlattenHierarchy;
4443 
4444 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4445 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4446 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4447 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4448 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4449 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4450 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4451 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4452 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4453 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4454 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4455 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4456 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4457 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4458 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4459 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4460 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4461 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4462 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4463 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4464 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4465 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4466 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4467 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4468 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4469 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4470 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4471 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4472 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4473 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4474 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4475 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4476 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4477 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4478 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4479 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4480 
4481 			flags = BindingFlags.Instance | BindingFlags.Public |
4482 				BindingFlags.FlattenHierarchy;
4483 
4484 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4485 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4486 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4487 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4488 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4489 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4490 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4491 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4492 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4493 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4494 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4495 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4496 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4497 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4498 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4499 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4500 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4501 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4502 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4503 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4504 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4505 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4506 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4507 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4508 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4509 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4510 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4511 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4512 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4513 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4514 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4515 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4516 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4517 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4518 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4519 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4520 
4521 			flags = BindingFlags.Static | BindingFlags.Public |
4522 				BindingFlags.FlattenHierarchy;
4523 
4524 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4525 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4526 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4527 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4528 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4529 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4530 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4531 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4532 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4533 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4534 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4535 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4536 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4537 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4538 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4539 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4540 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4541 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4542 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4543 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4544 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4545 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4546 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4547 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4548 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4549 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4550 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4551 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4552 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4553 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4554 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4555 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4556 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4557 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4558 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4559 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4560 
4561 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4562 				BindingFlags.FlattenHierarchy;
4563 
4564 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4565 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4566 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4567 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4568 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4569 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4570 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4571 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4572 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4573 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4574 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4575 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4576 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4577 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4578 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4579 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4580 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4581 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4582 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4583 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4584 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4585 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4586 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4587 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4588 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4589 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4590 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4591 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4592 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4593 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4594 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4595 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4596 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4597 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4598 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4599 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4600 
4601 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4602 				BindingFlags.DeclaredOnly;
4603 
4604 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4605 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4606 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4607 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4608 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4609 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4610 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4611 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4612 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4613 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4614 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4615 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4616 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4617 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4618 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4619 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4620 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4621 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4622 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4623 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4624 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4625 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4626 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4627 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4628 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4629 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4630 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4631 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4632 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4633 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4634 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4635 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4636 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4637 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4638 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4639 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4640 
4641 			flags = BindingFlags.Instance | BindingFlags.Public |
4642 				BindingFlags.DeclaredOnly;
4643 
4644 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4645 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4646 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4647 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4648 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4649 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4650 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4651 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4652 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4653 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4654 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4655 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4656 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4657 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4658 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4659 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4660 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4661 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4662 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4663 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4664 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4665 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4666 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4667 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4668 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4669 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4670 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4671 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4672 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4673 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4674 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4675 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4676 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4677 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4678 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4679 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4680 
4681 			flags = BindingFlags.Static | BindingFlags.Public |
4682 				BindingFlags.DeclaredOnly;
4683 
4684 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4685 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4686 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4687 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4688 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4689 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4690 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4691 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4692 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4693 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4694 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4695 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4696 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4697 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4698 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4699 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4700 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4701 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4702 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4703 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4704 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4705 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4706 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4707 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4708 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4709 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4710 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4711 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4712 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4713 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4714 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4715 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4716 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4717 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4718 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4719 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4720 
4721 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4722 				BindingFlags.DeclaredOnly;
4723 
4724 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4725 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4726 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4727 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4728 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4729 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4730 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4731 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4732 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4733 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4734 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4735 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4736 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4737 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4738 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4739 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4740 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4741 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4742 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4743 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4744 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4745 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4746 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4747 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4748 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4749 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4750 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4751 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4752 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4753 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4754 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4755 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4756 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4757 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4758 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4759 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4760 
4761 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
4762 				BindingFlags.Public;
4763 
4764 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4765 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4766 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4767 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4768 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4769 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4770 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4771 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4772 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4773 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4774 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4775 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4776 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4777 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4778 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4779 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4780 			Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4781 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4782 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4783 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4784 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4785 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4786 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4787 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4788 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4789 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4790 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4791 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4792 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4793 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4794 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4795 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4796 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4797 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4798 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4799 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4800 
4801 			flags = BindingFlags.Static | BindingFlags.NonPublic |
4802 				BindingFlags.Public;
4803 
4804 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4805 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4806 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4807 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4808 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4809 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4810 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4811 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4812 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4813 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4814 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4815 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4816 			Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4817 			Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4818 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4819 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4820 			Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4821 			Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4822 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4823 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4824 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4825 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4826 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4827 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4828 			Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4829 			Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4830 			Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4831 			Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4832 			Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4833 			Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4834 			Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4835 			Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4836 			Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4837 			Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4838 			Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4839 			Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4840 		}
4841 
4842 		[Test]
4843 		[Category ("NotWorking")] // mcs depends on this
TestGetFieldsIncomplete_MS()4844 		public void TestGetFieldsIncomplete_MS ()
4845 		{
4846 			TypeBuilder tb = module.DefineType (genTypeName ());
4847 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4848 			try {
4849 				tb.GetFields ();
4850 				Assert.Fail ("#1");
4851 			} catch (NotSupportedException ex) {
4852 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4853 				Assert.IsNull (ex.InnerException, "#3");
4854 				Assert.IsNotNull (ex.Message, "#4");
4855 			}
4856 		}
4857 
4858 		[Test]
4859 		[Category ("NotDotNet")] // mcs depends on this
TestGetFieldsIncomplete_Mono()4860 		public void TestGetFieldsIncomplete_Mono ()
4861 		{
4862 			TypeBuilder tb = module.DefineType (genTypeName ());
4863 			tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4864 			tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4865 			tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4866 			tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4867 
4868 			FieldInfo [] fields = tb.GetFields ();
4869 			Assert.AreEqual (2, fields.Length, "#A1");
4870 			Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4871 			Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4872 
4873 			tb = module.DefineType (genTypeName ());
4874 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4875 			tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4876 			tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4877 			tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4878 			tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4879 			tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4880 
4881 			fields = tb.GetFields ();
4882 			Assert.AreEqual (4, fields.Length, "#B1");
4883 			Assert.AreEqual ("First", fields [0].Name, "#B2");
4884 			Assert.AreEqual ("Second", fields [1].Name, "#B3");
4885 			Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4886 			Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4887 		}
4888 
4889 		[Test]
TestGetFieldsComplete()4890 		public void TestGetFieldsComplete ()
4891 		{
4892 			TypeBuilder tb = module.DefineType (genTypeName ());
4893 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4894 
4895 			Type emittedType = tb.CreateType ();
4896 			FieldInfo [] dynamicFields = tb.GetFields ();
4897 			FieldInfo [] emittedFields = emittedType.GetFields ();
4898 
4899 			Assert.AreEqual (1, dynamicFields.Length, "#A1");
4900 			Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4901 			Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4902 			Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4903 
4904 			// bug #81638
4905 			object value = Activator.CreateInstance (emittedType);
4906 			emittedFields [0].SetValue (value, 5);
4907 			Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4908 			Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4909 			dynamicFields [0].SetValue (value, 4);
4910 			Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4911 			Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4912 		}
4913 
4914 		[Test] // bug #82625 / 325292
TestGetFieldsComplete_Generic()4915 		public void TestGetFieldsComplete_Generic ()
4916 		{
4917 			// FIXME: merge this with TestGetFieldsComplete when
4918 			// bug #82625 is fixed
4919 
4920 			TypeBuilder tb;
4921 			Type emittedType;
4922 			FieldInfo [] dynamicFields;
4923 			FieldInfo [] emittedFields;
4924 
4925 			tb = module.DefineType (genTypeName ());
4926 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4927 			tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4928 			tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4929 			tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4930 			tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4931 			tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4932 
4933 			emittedType = tb.CreateType ();
4934 			dynamicFields = tb.GetFields ();
4935 			emittedFields = emittedType.GetFields ();
4936 
4937 			Assert.AreEqual (4, dynamicFields.Length, "#C1");
4938 			Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4939 			Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4940 			Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4941 			Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4942 			Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4943 			Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4944 			Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4945 			Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4946 
4947 			Assert.AreEqual (4, emittedFields.Length, "#D1");
4948 			Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4949 			Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4950 			Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4951 			Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4952 			Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4953 			Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4954 			Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4955 			Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4956 		}
4957 
4958 		[Test]
4959 		[Category ("NotWorking")] // mcs depends on this
TestGetFieldsFlagsIncomplete_MS()4960 		public void TestGetFieldsFlagsIncomplete_MS ()
4961 		{
4962 			TypeBuilder tb = module.DefineType (genTypeName ());
4963 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4964 			try {
4965 				tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4966 				Assert.Fail ("#1");
4967 			} catch (NotSupportedException ex) {
4968 				// The invoked member is not supported in a
4969 				// dynamic module
4970 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4971 				Assert.IsNull (ex.InnerException, "#3");
4972 				Assert.IsNotNull (ex.Message, "#4");
4973 			}
4974 		}
4975 
4976 		[Test]
4977 		[Category ("NotDotNet")] // mcs depends on this
TestGetFieldsFlagsIncomplete_Mono()4978 		public void TestGetFieldsFlagsIncomplete_Mono ()
4979 		{
4980 			FieldInfo [] fields;
4981 
4982 			TypeBuilder tb = module.DefineType (genTypeName ());
4983 			tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4984 			tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4985 			tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4986 			tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4987 
4988 			fields = tb.GetFields (BindingFlags.Public |
4989 				BindingFlags.NonPublic | BindingFlags.Instance);
4990 			Assert.AreEqual (2, fields.Length, "#A1");
4991 			Assert.AreEqual ("name", fields [0].Name, "#A2");
4992 			Assert.AreEqual ("Sex", fields [1].Name, "#A3");
4993 
4994 			fields = tb.GetFields (BindingFlags.Public |
4995 				BindingFlags.Instance | BindingFlags.Static);
4996 			Assert.AreEqual (2, fields.Length, "#B1");
4997 			Assert.AreEqual ("Sex", fields [0].Name, "#B2");
4998 			Assert.AreEqual ("MALE", fields [1].Name, "#B3");
4999 
5000 			fields = tb.GetFields (BindingFlags.Public |
5001 				BindingFlags.NonPublic | BindingFlags.Instance |
5002 				BindingFlags.Static);
5003 			Assert.AreEqual (4, fields.Length, "#C1");
5004 			Assert.AreEqual ("name", fields [0].Name, "#C2");
5005 			Assert.AreEqual ("Sex", fields [1].Name, "#C3");
5006 			Assert.AreEqual ("MALE", fields [2].Name, "#C4");
5007 			Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
5008 		}
5009 
5010 		[Test]
TestGetFieldsFlagsComplete()5011 		public void TestGetFieldsFlagsComplete ()
5012 		{
5013 			TypeBuilder tb = module.DefineType (genTypeName ());
5014 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5015 
5016 			Type emittedType = tb.CreateType ();
5017 
5018 			Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
5019 			Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
5020 				emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
5021 			Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5022 			Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
5023 				emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5024 		}
5025 
5026 		[Test]
TestGetFieldsFlagsComplete_Inheritance()5027 		public void TestGetFieldsFlagsComplete_Inheritance ()
5028 		{
5029 			FieldInfo [] fields;
5030 			BindingFlags flags;
5031 
5032 			TypeBuilder blueType = module.DefineType (genTypeName (),
5033 				TypeAttributes.Public);
5034 			CreateMembers (blueType, "Blue", false);
5035 
5036 			TypeBuilder redType = module.DefineType (genTypeName (),
5037 				TypeAttributes.Public, blueType);
5038 			CreateMembers (redType, "Red", false);
5039 
5040 			TypeBuilder greenType = module.DefineType (genTypeName (),
5041 				TypeAttributes.Public, redType);
5042 			CreateMembers (greenType, "Green", false);
5043 
5044 			blueType.CreateType ();
5045 			redType.CreateType ();
5046 			greenType.CreateType ();
5047 
5048 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
5049 			fields = greenType.GetFields (flags);
5050 
5051 			Assert.AreEqual (13, fields.Length, "#A1");
5052 			Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
5053 			Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
5054 			Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
5055 			Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
5056 			Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
5057 			Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
5058 			Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5059 			Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5060 			Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5061 			Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5062 			Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5063 			Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5064 			Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5065 
5066 			flags = BindingFlags.Instance | BindingFlags.Public;
5067 			fields = greenType.GetFields (flags);
5068 
5069 			Assert.AreEqual (3, fields.Length, "#B1");
5070 			Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5071 			Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5072 			Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5073 
5074 			flags = BindingFlags.Static | BindingFlags.Public;
5075 			fields = greenType.GetFields (flags);
5076 
5077 			Assert.AreEqual (1, fields.Length, "#C1");
5078 			Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5079 
5080 			flags = BindingFlags.Static | BindingFlags.NonPublic;
5081 			fields = greenType.GetFields (flags);
5082 
5083 			Assert.AreEqual (5, fields.Length, "#D1");
5084 			Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5085 			Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5086 			Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5087 			Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5088 			Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5089 
5090 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5091 				BindingFlags.FlattenHierarchy;
5092 			fields = greenType.GetFields (flags);
5093 
5094 			Assert.AreEqual (13, fields.Length, "#E1");
5095 			Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5096 			Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5097 			Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5098 			Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5099 			Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5100 			Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5101 			Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5102 			Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5103 			Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5104 			Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5105 			Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5106 			Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5107 			Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5108 
5109 			flags = BindingFlags.Instance | BindingFlags.Public |
5110 				BindingFlags.FlattenHierarchy;
5111 			fields = greenType.GetFields (flags);
5112 
5113 			Assert.AreEqual (3, fields.Length, "#F1");
5114 			Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5115 			Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5116 			Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5117 
5118 			flags = BindingFlags.Static | BindingFlags.Public |
5119 				BindingFlags.FlattenHierarchy;
5120 			fields = greenType.GetFields (flags);
5121 
5122 			Assert.AreEqual (3, fields.Length, "#G1");
5123 			Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5124 			Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5125 			Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5126 
5127 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5128 				BindingFlags.FlattenHierarchy;
5129 			fields = greenType.GetFields (flags);
5130 
5131 			Assert.AreEqual (13, fields.Length, "#H1");
5132 			Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5133 			Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5134 			Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5135 			Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5136 			Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5137 			Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5138 			Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5139 			Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5140 			Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5141 			Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5142 			Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5143 			Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5144 			Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5145 
5146 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5147 				BindingFlags.DeclaredOnly;
5148 			fields = greenType.GetFields (flags);
5149 
5150 			Assert.AreEqual (5, fields.Length, "#I1");
5151 			Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5152 			Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5153 			Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5154 			Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5155 			Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5156 
5157 			flags = BindingFlags.Instance | BindingFlags.Public |
5158 				BindingFlags.DeclaredOnly;
5159 			fields = greenType.GetFields (flags);
5160 
5161 			Assert.AreEqual (1, fields.Length, "#J1");
5162 			Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5163 
5164 			flags = BindingFlags.Static | BindingFlags.Public |
5165 				BindingFlags.DeclaredOnly;
5166 			fields = greenType.GetFields (flags);
5167 
5168 			Assert.AreEqual (1, fields.Length, "#K1");
5169 			Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5170 
5171 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5172 				BindingFlags.DeclaredOnly;
5173 			fields = greenType.GetFields (flags);
5174 
5175 			Assert.AreEqual (5, fields.Length, "#L1");
5176 			Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5177 			Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5178 			Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5179 			Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5180 			Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5181 
5182 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5183 				BindingFlags.Public;
5184 			fields = greenType.GetFields (flags);
5185 
5186 			Assert.AreEqual (16, fields.Length, "#M1");
5187 			Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5188 			Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5189 			Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5190 			Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5191 			Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5192 			Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5193 			Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5194 			Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5195 			Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5196 			Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5197 			Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5198 			Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5199 			Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5200 			Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5201 			Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5202 			Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5203 
5204 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5205 				BindingFlags.Public;
5206 			fields = greenType.GetFields (flags);
5207 
5208 			Assert.AreEqual (6, fields.Length, "#N1");
5209 			Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5210 			Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5211 			Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5212 			Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5213 			Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5214 			Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5215 		}
5216 
5217 		[Test]
5218 		[Category ("NotWorking")] // mcs depends on this
TestGetFieldIncomplete_MS()5219 		public void TestGetFieldIncomplete_MS ()
5220 		{
5221 			TypeBuilder tb = module.DefineType (genTypeName ());
5222 			tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5223 			try {
5224 				tb.GetField ("test");
5225 				Assert.Fail ("#1");
5226 			} catch (NotSupportedException ex) {
5227 				// The invoked member is not supported in a
5228 				// dynamic module
5229 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5230 				Assert.IsNull (ex.InnerException, "#3");
5231 				Assert.IsNotNull (ex.Message, "#4");
5232 			}
5233 		}
5234 
5235 		[Test]
5236 		[Category ("NotDotNet")] // mcs depends on this
TestGetFieldIncomplete_Mono()5237 		public void TestGetFieldIncomplete_Mono ()
5238 		{
5239 			TypeBuilder tb = module.DefineType (genTypeName ());
5240 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5241 			tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5242 
5243 			FieldInfo field = tb.GetField ("TestField");
5244 			Assert.IsNotNull (field, "#A1");
5245 			Assert.AreEqual ("TestField", field.Name, "#A2");
5246 			Assert.IsTrue (field is FieldBuilder, "#A3");
5247 
5248 			Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5249 			Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5250 		}
5251 
5252 		[Test]
TestGetFieldComplete()5253 		public void TestGetFieldComplete ()
5254 		{
5255 			TypeBuilder tb = module.DefineType (genTypeName ());
5256 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5257 
5258 			Type emittedType = tb.CreateType ();
5259 
5260 			FieldInfo dynamicField = tb.GetField ("TestField");
5261 			FieldInfo emittedField = emittedType.GetField ("TestField");
5262 			Assert.IsNotNull (dynamicField, "#A1");
5263 			Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5264 			Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5265 			Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5266 			Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5267 
5268 			// bug #81638
5269 			object value = Activator.CreateInstance (emittedType);
5270 			emittedField.SetValue (value, 5);
5271 			Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5272 			Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5273 			dynamicField.SetValue (value, 4);
5274 			Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5275 			Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5276 		}
5277 
5278 		[Test] // bug #81640
TestGetFieldComplete_Type()5279 		public void TestGetFieldComplete_Type ()
5280 		{
5281 			TypeBuilder tb = module.DefineType (genTypeName ());
5282 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5283 			Type emittedType = tb.CreateType ();
5284 			FieldInfo dynamicField = tb.GetField ("TestField");
5285 			Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5286 
5287 			object value = Activator.CreateInstance (emittedType);
5288 			Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5289 		}
5290 
5291 		[Test]
5292 		[Category ("NotWorking")] // mcs depends on this
TestGetFieldFlagsIncomplete_MS()5293 		public void TestGetFieldFlagsIncomplete_MS ()
5294 		{
5295 			TypeBuilder tb = module.DefineType (genTypeName ());
5296 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5297 			tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5298 			try {
5299 				tb.GetField ("test", BindingFlags.Public);
5300 				Assert.Fail ("#1");
5301 			} catch (NotSupportedException ex) {
5302 				// The invoked member is not supported in a
5303 				// dynamic module
5304 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5305 				Assert.IsNull (ex.InnerException, "#3");
5306 				Assert.IsNotNull (ex.Message, "#4");
5307 			}
5308 		}
5309 
5310 		[Test]
5311 		[Category ("NotDotNet")] // mcs depends on this
TestGetFieldFlagsIncomplete_Mono()5312 		public void TestGetFieldFlagsIncomplete_Mono ()
5313 		{
5314 			TypeBuilder tb = module.DefineType (genTypeName ());
5315 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5316 			tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5317 
5318 			FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5319 				| BindingFlags.Instance);
5320 			Assert.IsNotNull (field, "#A1");
5321 			Assert.AreEqual ("TestField", field.Name, "#A2");
5322 			Assert.IsTrue (field is FieldBuilder, "#A3");
5323 
5324 			field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5325 				BindingFlags.Instance);
5326 			Assert.IsNotNull (field, "#B1");
5327 			Assert.AreEqual ("OtherField", field.Name, "#B2");
5328 			Assert.IsTrue (field is FieldBuilder, "#B3");
5329 
5330 			Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5331 				BindingFlags.Instance), "#C1");
5332 			Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5333 				BindingFlags.Static), "#C2");
5334 			Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5335 				BindingFlags.Instance), "#C3");
5336 			Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5337 				BindingFlags.Static), "#C4");
5338 			Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5339 				BindingFlags.Instance), "#C5");
5340 			Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5341 				BindingFlags.Instance), "#C6");
5342 		}
5343 
5344 		[Test]
TestGetFieldFlagsComplete()5345 		public void TestGetFieldFlagsComplete ()
5346 		{
5347 			TypeBuilder tb = module.DefineType (genTypeName ());
5348 			tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5349 
5350 			Type emittedType = tb.CreateType ();
5351 
5352 			Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5353 			Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5354 				emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5355 			Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5356 			Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5357 				emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5358 		}
5359 
5360 		[Test]
TestGetFieldFlagsComplete_Inheritance()5361 		public void TestGetFieldFlagsComplete_Inheritance ()
5362 		{
5363 			BindingFlags flags;
5364 
5365 			TypeBuilder blueType = module.DefineType (genTypeName (),
5366 				TypeAttributes.Public);
5367 			CreateMembers (blueType, "Blue", false);
5368 
5369 			TypeBuilder redType = module.DefineType (genTypeName (),
5370 				TypeAttributes.Public, blueType);
5371 			CreateMembers (redType, "Red", false);
5372 
5373 			TypeBuilder greenType = module.DefineType (genTypeName (),
5374 				TypeAttributes.Public, redType);
5375 			CreateMembers (greenType, "Green", false);
5376 
5377 			blueType.CreateType ();
5378 			redType.CreateType ();
5379 			greenType.CreateType ();
5380 
5381 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
5382 
5383 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5384 			Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5385 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5386 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5387 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5388 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5389 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5390 			Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5391 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5392 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5393 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5394 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5395 			Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5396 			Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5397 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5398 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5399 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5400 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5401 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5402 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5403 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5404 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5405 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5406 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5407 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5408 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5409 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5410 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5411 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5412 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5413 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5414 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5415 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5416 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5417 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5418 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5419 
5420 			flags = BindingFlags.Instance | BindingFlags.Public;
5421 
5422 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5423 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5424 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5425 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5426 			Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5427 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5428 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5429 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5430 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5431 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5432 			Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5433 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5434 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5435 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5436 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5437 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5438 			Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5439 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5440 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5441 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5442 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5443 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5444 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5445 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5446 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5447 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5448 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5449 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5450 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5451 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5452 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5453 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5454 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5455 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5456 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5457 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5458 
5459 			flags = BindingFlags.Static | BindingFlags.Public;
5460 
5461 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5462 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5463 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5464 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5465 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5466 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5467 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5468 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5469 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5470 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5471 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5472 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5473 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5474 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5475 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5476 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5477 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5478 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5479 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5480 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5481 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5482 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5483 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5484 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5485 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5486 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5487 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5488 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5489 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5490 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5491 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5492 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5493 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5494 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5495 			Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5496 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5497 
5498 			flags = BindingFlags.Static | BindingFlags.NonPublic;
5499 
5500 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5501 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5502 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5503 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5504 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5505 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5506 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5507 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5508 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5509 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5510 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5511 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5512 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5513 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5514 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5515 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5516 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5517 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5518 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5519 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5520 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5521 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5522 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5523 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5524 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5525 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5526 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5527 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5528 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5529 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5530 			Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5531 			Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5532 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5533 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5534 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5535 			Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5536 
5537 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5538 				BindingFlags.FlattenHierarchy;
5539 
5540 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5541 			Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5542 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5543 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5544 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5545 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5546 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5547 			Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5548 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5549 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5550 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5551 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5552 			Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5553 			Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5554 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5555 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5556 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5557 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5558 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5559 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5560 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5561 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5562 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5563 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5564 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5565 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5566 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5567 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5568 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5569 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5570 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5571 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5572 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5573 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5574 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5575 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5576 
5577 			flags = BindingFlags.Instance | BindingFlags.Public |
5578 				BindingFlags.FlattenHierarchy;
5579 
5580 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5581 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5582 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5583 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5584 			Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5585 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5586 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5587 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5588 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5589 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5590 			Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5591 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5592 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5593 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5594 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5595 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5596 			Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5597 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5598 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5599 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5600 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5601 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5602 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5603 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5604 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5605 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5606 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5607 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5608 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5609 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5610 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5611 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5612 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5613 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5614 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5615 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5616 
5617 			flags = BindingFlags.Static | BindingFlags.Public |
5618 				BindingFlags.FlattenHierarchy;
5619 
5620 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5621 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5622 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5623 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5624 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5625 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5626 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5627 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5628 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5629 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5630 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5631 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5632 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5633 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5634 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5635 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5636 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5637 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5638 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5639 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5640 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5641 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5642 			Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5643 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5644 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5645 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5646 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5647 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5648 			Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5649 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5650 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5651 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5652 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5653 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5654 			Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5655 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5656 
5657 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5658 				BindingFlags.FlattenHierarchy;
5659 
5660 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5661 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5662 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5663 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5664 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5665 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5666 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5667 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5668 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5669 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5670 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5671 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5672 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5673 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5674 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5675 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5676 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5677 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5678 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5679 			Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5680 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5681 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5682 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5683 			Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5684 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5685 			Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5686 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5687 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5688 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5689 			Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5690 			Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5691 			Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5692 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5693 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5694 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5695 			Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5696 
5697 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5698 				BindingFlags.DeclaredOnly;
5699 
5700 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5701 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5702 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5703 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5704 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5705 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5706 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5707 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5708 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5709 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5710 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5711 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5712 			Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5713 			Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5714 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5715 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5716 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5717 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5718 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5719 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5720 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5721 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5722 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5723 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5724 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5725 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5726 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5727 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5728 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5729 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5730 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5731 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5732 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5733 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5734 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5735 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5736 
5737 			flags = BindingFlags.Instance | BindingFlags.Public |
5738 				BindingFlags.DeclaredOnly;
5739 
5740 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5741 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5742 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5743 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5744 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5745 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5746 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5747 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5748 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5749 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5750 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5751 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5752 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5753 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5754 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5755 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5756 			Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5757 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5758 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5759 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5760 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5761 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5762 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5763 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5764 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5765 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5766 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5767 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5768 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5769 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5770 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5771 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5772 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5773 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5774 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5775 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5776 
5777 			flags = BindingFlags.Static | BindingFlags.Public |
5778 				BindingFlags.DeclaredOnly;
5779 
5780 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5781 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5782 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5783 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5784 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5785 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5786 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5787 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5788 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5789 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5790 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5791 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5792 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5793 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5794 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5795 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5796 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5797 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5798 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5799 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5800 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5801 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5802 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5803 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5804 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5805 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5806 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5807 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5808 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5809 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5810 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5811 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5812 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5813 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5814 			Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5815 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5816 
5817 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5818 				BindingFlags.DeclaredOnly;
5819 
5820 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5821 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5822 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5823 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5824 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5825 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5826 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5827 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5828 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5829 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5830 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5831 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5832 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5833 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5834 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5835 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5836 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5837 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5838 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5839 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5840 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5841 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5842 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5843 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5844 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5845 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5846 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5847 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5848 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5849 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5850 			Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5851 			Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5852 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5853 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5854 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5855 			Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5856 
5857 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
5858 				BindingFlags.Public;
5859 
5860 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5861 			Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5862 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5863 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5864 			Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5865 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5866 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5867 			Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5868 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5869 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5870 			Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5871 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5872 			Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5873 			Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5874 			Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5875 			Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5876 			Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5877 			Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5878 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5879 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5880 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5881 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5882 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5883 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5884 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5885 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5886 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5887 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5888 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5889 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5890 			Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5891 			Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5892 			Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5893 			Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5894 			Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5895 			Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5896 
5897 			flags = BindingFlags.Static | BindingFlags.NonPublic |
5898 				BindingFlags.Public;
5899 
5900 			Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5901 			Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5902 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5903 			Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5904 			Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5905 			Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5906 			Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5907 			Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5908 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5909 			Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5910 			Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5911 			Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5912 			Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5913 			Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5914 			Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5915 			Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5916 			Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5917 			Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5918 			Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5919 			Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5920 			Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5921 			Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5922 			Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5923 			Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5924 			Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5925 			Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5926 			Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5927 			Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5928 			Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5929 			Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5930 			Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5931 			Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5932 			Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5933 			Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5934 			Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5935 			Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5936 		}
5937 
5938 		[Test]
5939 		[Category ("NotDotNet")] // mcs depends on this
TestGetPropertiesIncomplete_Mono()5940 		public void TestGetPropertiesIncomplete_Mono ()
5941 		{
5942 			TypeBuilder tb = module.DefineType (genTypeName ());
5943 			DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5944 			DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5945 			DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5946 
5947 			PropertyInfo [] properties = tb.GetProperties ();
5948 			Assert.AreEqual (2, properties.Length, "#1");
5949 			Assert.AreEqual ("Name", properties [0].Name, "#2");
5950 			Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5951 		}
5952 
5953 		[Test]
5954 		[Category ("NotWorking")] // mcs depends on this
TestGetPropertiesIncomplete_MS()5955 		public void TestGetPropertiesIncomplete_MS ()
5956 		{
5957 			TypeBuilder tb = module.DefineType (genTypeName ());
5958 			DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5959 			DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5960 			DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5961 
5962 			try {
5963 				tb.GetProperties ();
5964 				Assert.Fail ("#1");
5965 			} catch (NotSupportedException ex) {
5966 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5967 				Assert.IsNull (ex.InnerException, "#3");
5968 				Assert.IsNotNull (ex.Message, "#4");
5969 			}
5970 		}
5971 
5972 		[Test]
TestGetPropertiesComplete()5973 		public void TestGetPropertiesComplete ()
5974 		{
5975 			TypeBuilder tb = module.DefineType (genTypeName ());
5976 			DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5977 
5978 			Type emittedType = tb.CreateType ();
5979 
5980 			Assert.AreEqual (1, tb.GetProperties ().Length);
5981 			Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
5982 		}
5983 
5984 		[Test]
5985 		[Category ("NotDotNet")] // mcs depends on this
TestGetPropertiesFlagsIncomplete_Mono()5986 		public void TestGetPropertiesFlagsIncomplete_Mono ()
5987 		{
5988 			PropertyInfo [] properties;
5989 
5990 			TypeBuilder tb = module.DefineType (genTypeName ());
5991 			DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5992 			DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5993 			DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5994 
5995 			properties = tb.GetProperties (BindingFlags.Public |
5996 				BindingFlags.NonPublic | BindingFlags.Instance);
5997 			Assert.AreEqual (3, properties.Length, "#A1");
5998 			Assert.AreEqual ("Name", properties [0].Name, "#A2");
5999 			Assert.AreEqual ("Income", properties [1].Name, "#A3");
6000 			Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
6001 
6002 			properties = tb.GetProperties (BindingFlags.Public |
6003 				BindingFlags.Instance);
6004 			Assert.AreEqual (2, properties.Length, "#B1");
6005 			Assert.AreEqual ("Name", properties [0].Name, "#B2");
6006 			Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
6007 
6008 			properties = tb.GetProperties (BindingFlags.NonPublic |
6009 				BindingFlags.Instance);
6010 			Assert.AreEqual (1, properties.Length, "#C1");
6011 			Assert.AreEqual ("Income", properties [0].Name, "#C2");
6012 		}
6013 
6014 		[Test]
6015 		[Category ("NotWorking")] // mcs depends on this
TestGetPropertiesFlagsIncomplete_MS()6016 		public void TestGetPropertiesFlagsIncomplete_MS ()
6017 		{
6018 			TypeBuilder tb = module.DefineType (genTypeName ());
6019 			DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
6020 			DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
6021 			DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
6022 
6023 			try {
6024 				tb.GetProperties (BindingFlags.Public);
6025 				Assert.Fail ("#1");
6026 			} catch (NotSupportedException ex) {
6027 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6028 				Assert.IsNull (ex.InnerException, "#3");
6029 				Assert.IsNotNull (ex.Message, "#4");
6030 			}
6031 		}
6032 
6033 		[Test]
TestGetPropertiesFlagsComplete()6034 		public void TestGetPropertiesFlagsComplete ()
6035 		{
6036 			TypeBuilder tb = module.DefineType (genTypeName ());
6037 			DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6038 
6039 			Type emittedType = tb.CreateType ();
6040 
6041 			Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6042 			Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
6043 				emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6044 			Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6045 			Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
6046 				emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6047 		}
6048 
6049 		[Test]
TestGetPropertiesFlagsComplete_Inheritance()6050 		public void TestGetPropertiesFlagsComplete_Inheritance ()
6051 		{
6052 			PropertyInfo [] props;
6053 			BindingFlags flags;
6054 
6055 			TypeBuilder blueType = module.DefineType (genTypeName (),
6056 				TypeAttributes.Public);
6057 			CreateMembers (blueType, "Blue", false);
6058 
6059 			TypeBuilder redType = module.DefineType (genTypeName (),
6060 				TypeAttributes.Public, blueType);
6061 			CreateMembers (redType, "Red", false);
6062 
6063 			TypeBuilder greenType = module.DefineType (genTypeName (),
6064 				TypeAttributes.Public, redType);
6065 			CreateMembers (greenType, "Green", false);
6066 
6067 			blueType.CreateType ();
6068 			redType.CreateType ();
6069 			greenType.CreateType ();
6070 
6071 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
6072 			props = greenType.GetProperties (flags);
6073 
6074 			Assert.AreEqual (13, props.Length, "#A1");
6075 			Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6076 			Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6077 			Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6078 			Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6079 			Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6080 			Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6081 			Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6082 			Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6083 			Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6084 			Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6085 			Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6086 			Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6087 			Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6088 
6089 			flags = BindingFlags.Instance | BindingFlags.Public;
6090 			props = greenType.GetProperties (flags);
6091 
6092 			Assert.AreEqual (3, props.Length, "#B1");
6093 			Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6094 			Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6095 			Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6096 
6097 			flags = BindingFlags.Static | BindingFlags.Public;
6098 			props = greenType.GetProperties (flags);
6099 
6100 			Assert.AreEqual (1, props.Length, "#C1");
6101 			Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6102 
6103 			flags = BindingFlags.Static | BindingFlags.NonPublic;
6104 			props = greenType.GetProperties (flags);
6105 
6106 			Assert.AreEqual (5, props.Length, "#D1");
6107 			Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6108 			Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6109 			Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6110 			Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6111 			Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6112 
6113 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6114 				BindingFlags.FlattenHierarchy;
6115 			props = greenType.GetProperties (flags);
6116 
6117 			Assert.AreEqual (13, props.Length, "#E1");
6118 			Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6119 			Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6120 			Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6121 			Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6122 			Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6123 			Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6124 			Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6125 			Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6126 			Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6127 			Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6128 			Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6129 			Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6130 			Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6131 
6132 			flags = BindingFlags.Instance | BindingFlags.Public |
6133 				BindingFlags.FlattenHierarchy;
6134 			props = greenType.GetProperties (flags);
6135 
6136 			Assert.AreEqual (3, props.Length, "#F1");
6137 			Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6138 			Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6139 			Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6140 
6141 			flags = BindingFlags.Static | BindingFlags.Public |
6142 				BindingFlags.FlattenHierarchy;
6143 			props = greenType.GetProperties (flags);
6144 
6145 			Assert.AreEqual (3, props.Length, "#G1");
6146 			Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6147 			Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6148 			Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6149 
6150 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6151 				BindingFlags.FlattenHierarchy;
6152 			props = greenType.GetProperties (flags);
6153 
6154 			Assert.AreEqual (13, props.Length, "#H1");
6155 			Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6156 			Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6157 			Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6158 			Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6159 			Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6160 			Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6161 			Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6162 			Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6163 			Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6164 			Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6165 			Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6166 			Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6167 			Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6168 
6169 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6170 				BindingFlags.DeclaredOnly;
6171 			props = greenType.GetProperties (flags);
6172 
6173 			Assert.AreEqual (5, props.Length, "#I1");
6174 			Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6175 			Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6176 			Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6177 			Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6178 			Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6179 
6180 			flags = BindingFlags.Instance | BindingFlags.Public |
6181 				BindingFlags.DeclaredOnly;
6182 			props = greenType.GetProperties (flags);
6183 
6184 			Assert.AreEqual (1, props.Length, "#J1");
6185 			Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6186 
6187 			flags = BindingFlags.Static | BindingFlags.Public |
6188 				BindingFlags.DeclaredOnly;
6189 			props = greenType.GetProperties (flags);
6190 
6191 			Assert.AreEqual (1, props.Length, "#K1");
6192 			Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6193 
6194 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6195 				BindingFlags.DeclaredOnly;
6196 			props = greenType.GetProperties (flags);
6197 
6198 			Assert.AreEqual (5, props.Length, "#L1");
6199 			Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6200 			Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6201 			Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6202 			Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6203 			Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6204 
6205 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6206 				BindingFlags.Public;
6207 			props = greenType.GetProperties (flags);
6208 
6209 			Assert.AreEqual (16, props.Length, "#M1");
6210 			Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6211 			Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6212 			Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6213 			Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6214 			Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6215 			Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6216 			Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6217 			Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6218 			Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6219 			Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6220 			Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6221 			Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6222 			Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6223 			Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6224 			Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6225 			Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6226 
6227 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6228 				BindingFlags.Public;
6229 			props = greenType.GetProperties (flags);
6230 
6231 			Assert.AreEqual (6, props.Length, "#N1");
6232 			Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6233 			Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6234 			Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6235 			Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6236 			Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6237 			Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6238 		}
6239 
6240 		[Test]
TestGetPropertyIncomplete()6241 		public void TestGetPropertyIncomplete ()
6242 		{
6243 			TypeBuilder tb = module.DefineType (genTypeName ());
6244 			try {
6245 				tb.GetProperty ("test");
6246 				Assert.Fail ("#1");
6247 			} catch (NotSupportedException ex) {
6248 				// The invoked member is not supported in a
6249 				// dynamic module
6250 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6251 				Assert.IsNull (ex.InnerException, "#3");
6252 				Assert.IsNotNull (ex.Message, "#4");
6253 			}
6254 		}
6255 
6256 		[Test]
TestGetPropertyComplete()6257 		public void TestGetPropertyComplete ()
6258 		{
6259 			TypeBuilder tb = module.DefineType (genTypeName ());
6260 			DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6261 
6262 			Type emittedType = tb.CreateType ();
6263 
6264 			Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6265 			Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6266 
6267 			try {
6268 				tb.GetProperty ("CustomerName");
6269 				Assert.Fail ("#1");
6270 			} catch (NotSupportedException ex) {
6271 				// The invoked member is not supported in a
6272 				// dynamic module
6273 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6274 				Assert.IsNull (ex.InnerException, "#3");
6275 				Assert.IsNotNull (ex.Message, "#4");
6276 			}
6277 		}
6278 
6279 		[Test]
TestGetPropertyFlagsIncomplete()6280 		public void TestGetPropertyFlagsIncomplete ()
6281 		{
6282 			TypeBuilder tb = module.DefineType (genTypeName ());
6283 			try {
6284 				tb.GetProperty ("test", BindingFlags.Public);
6285 				Assert.Fail ("#1");
6286 			} catch (NotSupportedException ex) {
6287 				// The invoked member is not supported in a
6288 				// dynamic module
6289 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6290 				Assert.IsNull (ex.InnerException, "#3");
6291 				Assert.IsNotNull (ex.Message, "#4");
6292 			}
6293 		}
6294 
6295 		[Test]
TestGetPropertyFlagsComplete()6296 		public void TestGetPropertyFlagsComplete ()
6297 		{
6298 			TypeBuilder tb = module.DefineType (genTypeName ());
6299 			DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6300 
6301 			Type emittedType = tb.CreateType ();
6302 
6303 			Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6304 				BindingFlags.Public));
6305 			Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6306 				BindingFlags.NonPublic));
6307 
6308 			try {
6309 				tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6310 				Assert.Fail ("#1");
6311 			} catch (NotSupportedException ex) {
6312 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6313 				Assert.IsNull (ex.InnerException, "#3");
6314 				Assert.IsNotNull (ex.Message, "#4");
6315 			}
6316 		}
6317 
6318 		[Test]
TestGetMethodFlagsComplete()6319 		public void TestGetMethodFlagsComplete ()
6320 		{
6321 			BindingFlags flags;
6322 
6323 			TypeBuilder blueType = module.DefineType (genTypeName (),
6324 				TypeAttributes.Public);
6325 			CreateMembers (blueType, "Blue", false);
6326 
6327 			TypeBuilder redType = module.DefineType (genTypeName (),
6328 				TypeAttributes.Public, blueType);
6329 			CreateMembers (redType, "Red", false);
6330 
6331 			TypeBuilder greenType = module.DefineType (genTypeName (),
6332 				TypeAttributes.Public, redType);
6333 			CreateMembers (greenType, "Green", false);
6334 
6335 			blueType.CreateType ();
6336 			redType.CreateType ();
6337 			greenType.CreateType ();
6338 
6339 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
6340 
6341 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6342 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6343 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6344 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6345 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6346 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6347 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6348 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6349 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6350 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6351 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6352 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6353 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6354 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6355 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6356 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6357 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6358 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6359 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6360 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6361 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6362 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6363 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6364 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6365 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6366 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6367 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6368 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6369 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6370 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6371 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6372 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6373 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6374 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6375 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6376 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6377 
6378 			flags = BindingFlags.Instance | BindingFlags.Public;
6379 
6380 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6381 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6382 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6383 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6384 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6385 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6386 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6387 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6388 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6389 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6390 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6391 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6392 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6393 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6394 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6395 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6396 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6397 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6398 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6399 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6400 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6401 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6402 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6403 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6404 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6405 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6406 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6407 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6408 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6409 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6410 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6411 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6412 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6413 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6414 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6415 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6416 
6417 			flags = BindingFlags.Static | BindingFlags.Public;
6418 
6419 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6420 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6421 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6422 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6423 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6424 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6425 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6426 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6427 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6428 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6429 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6430 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6431 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6432 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6433 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6434 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6435 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6436 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6437 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6438 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6439 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6440 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6441 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6442 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6443 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6444 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6445 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6446 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6447 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6448 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6449 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6450 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6451 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6452 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6453 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6454 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6455 
6456 			flags = BindingFlags.Static | BindingFlags.NonPublic;
6457 
6458 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6459 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6460 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6461 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6462 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6463 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6464 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6465 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6466 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6467 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6468 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6469 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6470 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6471 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6472 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6473 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6474 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6475 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6476 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6477 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6478 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6479 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6480 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6481 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6482 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6483 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6484 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6485 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6486 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6487 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6488 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6489 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6490 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6491 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6492 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6493 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6494 
6495 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6496 				BindingFlags.FlattenHierarchy;
6497 
6498 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6499 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6500 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6501 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6502 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6503 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6504 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6505 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6506 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6507 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6508 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6509 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6510 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6511 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6512 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6513 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6514 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6515 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6516 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6517 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6518 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6519 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6520 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6521 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6522 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6523 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6524 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6525 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6526 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6527 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6528 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6529 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6530 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6531 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6532 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6533 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6534 
6535 			flags = BindingFlags.Instance | BindingFlags.Public |
6536 				BindingFlags.FlattenHierarchy;
6537 
6538 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6539 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6540 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6541 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6542 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6543 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6544 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6545 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6546 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6547 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6548 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6549 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6550 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6551 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6552 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6553 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6554 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6555 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6556 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6557 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6558 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6559 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6560 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6561 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6562 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6563 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6564 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6565 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6566 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6567 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6568 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6569 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6570 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6571 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6572 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6573 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6574 
6575 			flags = BindingFlags.Static | BindingFlags.Public |
6576 				BindingFlags.FlattenHierarchy;
6577 
6578 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6579 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6580 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6581 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6582 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6583 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6584 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6585 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6586 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6587 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6588 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6589 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6590 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6591 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6592 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6593 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6594 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6595 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6596 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6597 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6598 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6599 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6600 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6601 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6602 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6603 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6604 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6605 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6606 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6607 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6608 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6609 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6610 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6611 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6612 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6613 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6614 
6615 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6616 				BindingFlags.FlattenHierarchy;
6617 
6618 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6619 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6620 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6621 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6622 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6623 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6624 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6625 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6626 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6627 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6628 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6629 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6630 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6631 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6632 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6633 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6634 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6635 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6636 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6637 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6638 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6639 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6640 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6641 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6642 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6643 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6644 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6645 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6646 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6647 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6648 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6649 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6650 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6651 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6652 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6653 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6654 
6655 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6656 				BindingFlags.DeclaredOnly;
6657 
6658 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6659 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6660 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6661 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6662 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6663 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6664 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6665 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6666 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6667 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6668 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6669 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6670 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6671 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6672 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6673 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6674 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6675 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6676 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6677 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6678 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6679 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6680 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6681 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6682 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6683 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6684 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6685 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6686 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6687 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6688 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6689 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6690 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6691 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6692 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6693 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6694 
6695 			flags = BindingFlags.Instance | BindingFlags.Public |
6696 				BindingFlags.DeclaredOnly;
6697 
6698 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6699 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6700 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6701 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6702 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6703 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6704 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6705 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6706 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6707 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6708 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6709 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6710 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6711 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6712 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6713 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6714 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6715 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6716 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6717 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6718 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6719 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6720 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6721 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6722 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6723 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6724 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6725 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6726 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6727 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6728 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6729 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6730 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6731 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6732 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6733 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6734 
6735 			flags = BindingFlags.Static | BindingFlags.Public |
6736 				BindingFlags.DeclaredOnly;
6737 
6738 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6739 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6740 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6741 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6742 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6743 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6744 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6745 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6746 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6747 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6748 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6749 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6750 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6751 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6752 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6753 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6754 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6755 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6756 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6757 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6758 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6759 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6760 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6761 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6762 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6763 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6764 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6765 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6766 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6767 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6768 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6769 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6770 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6771 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6772 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6773 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6774 
6775 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6776 				BindingFlags.DeclaredOnly;
6777 
6778 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6779 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6780 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6781 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6782 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6783 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6784 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6785 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6786 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6787 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6788 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6789 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6790 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6791 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6792 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6793 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6794 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6795 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6796 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6797 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6798 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6799 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6800 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6801 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6802 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6803 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6804 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6805 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6806 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6807 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6808 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6809 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6810 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6811 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6812 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6813 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6814 
6815 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
6816 				BindingFlags.Public;
6817 
6818 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6819 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6820 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6821 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6822 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6823 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6824 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6825 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6826 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6827 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6828 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6829 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6830 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6831 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6832 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6833 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6834 			Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6835 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6836 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6837 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6838 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6839 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6840 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6841 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6842 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6843 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6844 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6845 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6846 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6847 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6848 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6849 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6850 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6851 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6852 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6853 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6854 
6855 			flags = BindingFlags.Static | BindingFlags.NonPublic |
6856 				BindingFlags.Public;
6857 
6858 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6859 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6860 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6861 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6862 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6863 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6864 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6865 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6866 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6867 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6868 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6869 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6870 			Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6871 			Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6872 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6873 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6874 			Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6875 			Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6876 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6877 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6878 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6879 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6880 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6881 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6882 			Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6883 			Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6884 			Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6885 			Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6886 			Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6887 			Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6888 			Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6889 			Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6890 			Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6891 			Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6892 			Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6893 			Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6894 		}
6895 
6896 		[Test]
6897 		[Category ("NotDotNet")] // mcs depends on this
TestGetMethodsIncomplete_Mono()6898 		public void TestGetMethodsIncomplete_Mono ()
6899 		{
6900 			MethodBuilder mb;
6901 			ILGenerator ilgen;
6902 
6903 			TypeBuilder tb = module.DefineType (genTypeName (),
6904 				TypeAttributes.Abstract);
6905 			mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6906 				typeof (void), Type.EmptyTypes);
6907 			ilgen = mb.GetILGenerator ();
6908 			ilgen.Emit (OpCodes.Ret);
6909 
6910 			mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6911 				typeof (void), Type.EmptyTypes);
6912 			ilgen = mb.GetILGenerator ();
6913 			ilgen.Emit (OpCodes.Ret);
6914 
6915 			mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6916 				MethodAttributes.Static,
6917 				typeof (void), Type.EmptyTypes);
6918 			ilgen = mb.GetILGenerator ();
6919 			ilgen.Emit (OpCodes.Ret);
6920 
6921 			mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6922 				MethodAttributes.Abstract | MethodAttributes.Virtual,
6923 				typeof (void), Type.EmptyTypes);
6924 
6925 			MethodInfo [] methods = tb.GetMethods ();
6926 			Assert.AreEqual (7, methods.Length, "#A");
6927 
6928 			Assert.AreEqual ("Equals", methods [0].Name, "#B1");
6929 			Assert.IsFalse (methods [0].IsStatic, "#B2");
6930 			Assert.IsFalse (methods [0].IsAbstract, "#B3");
6931 
6932 			Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
6933 			Assert.IsFalse (methods [1].IsStatic, "#C2");
6934 			Assert.IsFalse (methods [1].IsAbstract, "#C3");
6935 
6936 			Assert.AreEqual ("GetType", methods [2].Name, "#D1");
6937 			Assert.IsFalse (methods [2].IsStatic, "#D2");
6938 			Assert.IsFalse (methods [2].IsAbstract, "#D3");
6939 
6940 			Assert.AreEqual ("ToString", methods [3].Name, "#E1");
6941 			Assert.IsFalse (methods [3].IsStatic, "#E2");
6942 			Assert.IsFalse (methods [3].IsAbstract, "#E3");
6943 
6944 			Assert.AreEqual ("Hello", methods [4].Name, "#F1");
6945 			Assert.IsFalse (methods [4].IsStatic, "#F2");
6946 			Assert.IsFalse (methods [4].IsAbstract, "#F3");
6947 
6948 			Assert.AreEqual ("Execute", methods [5].Name, "#G1");
6949 			Assert.IsTrue (methods [5].IsStatic, "#G2");
6950 			Assert.IsFalse (methods [5].IsAbstract, "#G3");
6951 
6952 			Assert.AreEqual ("Init", methods [6].Name, "#H1");
6953 			Assert.IsFalse (methods [6].IsStatic, "#H2");
6954 			Assert.IsTrue (methods [6].IsAbstract, "#H3");
6955 		}
6956 
6957 		[Test]
6958 		[Category ("NotWorking")] // mcs depends on this
TestGetMethodsIncomplete_MS()6959 		public void TestGetMethodsIncomplete_MS ()
6960 		{
6961 			MethodBuilder mb;
6962 			ILGenerator ilgen;
6963 
6964 			TypeBuilder tb = module.DefineType (genTypeName (),
6965 				TypeAttributes.Abstract);
6966 			mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6967 				typeof (void), Type.EmptyTypes);
6968 			ilgen = mb.GetILGenerator ();
6969 			ilgen.Emit (OpCodes.Ret);
6970 
6971 			mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6972 				typeof (void), Type.EmptyTypes);
6973 			ilgen = mb.GetILGenerator ();
6974 			ilgen.Emit (OpCodes.Ret);
6975 
6976 			mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6977 				MethodAttributes.Static,
6978 				typeof (void), Type.EmptyTypes);
6979 			ilgen = mb.GetILGenerator ();
6980 			ilgen.Emit (OpCodes.Ret);
6981 
6982 			mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6983 				MethodAttributes.Abstract | MethodAttributes.Virtual,
6984 				typeof (void), Type.EmptyTypes);
6985 
6986 			try {
6987 				tb.GetMethods ();
6988 				Assert.Fail ("#1");
6989 			} catch (NotSupportedException ex) {
6990 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6991 				Assert.IsNull (ex.InnerException, "#3");
6992 				Assert.IsNotNull (ex.Message, "#4");
6993 			}
6994 		}
6995 
6996 		[Test]
TestGetMethodsComplete()6997 		public void TestGetMethodsComplete ()
6998 		{
6999 			MethodBuilder mb;
7000 			ILGenerator ilgen;
7001 			MethodInfo mi;
7002 
7003 			TypeBuilder tb = module.DefineType (genTypeName (),
7004 				TypeAttributes.Abstract);
7005 			mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7006 				typeof (string), Type.EmptyTypes);
7007 			ilgen = mb.GetILGenerator ();
7008 			ilgen.Emit (OpCodes.Ldstr, "Hi! ");
7009 			ilgen.Emit (OpCodes.Ldarg_1);
7010 			MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7011 				new Type [] { typeof (string), typeof (string) });
7012 			ilgen.Emit (OpCodes.Call, infoMethod);
7013 			ilgen.Emit (OpCodes.Ret);
7014 
7015 			mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7016 				typeof (void), Type.EmptyTypes);
7017 			ilgen = mb.GetILGenerator ();
7018 			ilgen.Emit (OpCodes.Ret);
7019 
7020 			mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7021 				MethodAttributes.Static,
7022 				typeof (void), Type.EmptyTypes);
7023 			ilgen = mb.GetILGenerator ();
7024 			ilgen.Emit (OpCodes.Ret);
7025 
7026 			mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7027 				MethodAttributes.Abstract | MethodAttributes.Virtual,
7028 				typeof (void), Type.EmptyTypes);
7029 
7030 			Type emittedType = tb.CreateType ();
7031 
7032 			MethodInfo [] methods = emittedType.GetMethods ();
7033 			Assert.AreEqual (7, methods.Length, "#A1");
7034 			Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
7035 
7036 			mi = GetMethodByName (methods, "Hello");
7037 			Assert.IsNotNull (mi, "#B1");
7038 			Assert.IsFalse (mi.IsStatic, "#B2");
7039 			Assert.IsFalse (mi.IsAbstract, "#B3");
7040 
7041 			mi = GetMethodByName (methods, "Execute");
7042 			Assert.IsNotNull (mi, "#C1");
7043 			Assert.IsTrue (mi.IsStatic, "#C2");
7044 			Assert.IsFalse (mi.IsAbstract, "#C3");
7045 
7046 			mi = GetMethodByName (methods, "Init");
7047 			Assert.IsNotNull (mi, "#D1");
7048 			Assert.IsFalse (mi.IsStatic, "#D2");
7049 			Assert.IsTrue (mi.IsAbstract, "#D3");
7050 
7051 			mi = GetMethodByName (methods, "GetType");
7052 			Assert.IsNotNull (mi, "#E1");
7053 			Assert.IsFalse (methods [3].IsStatic, "#E2");
7054 			Assert.IsFalse (methods [3].IsAbstract, "#E3");
7055 
7056 			mi = GetMethodByName (methods, "ToString");
7057 			Assert.IsNotNull (mi, "#F1");
7058 			Assert.IsFalse (mi.IsStatic, "#F2");
7059 			Assert.IsFalse (mi.IsAbstract, "#F3");
7060 
7061 			mi = GetMethodByName (methods, "Equals");
7062 			Assert.IsNotNull (mi, "#G1");
7063 			Assert.IsFalse (mi.IsStatic, "#G2");
7064 			Assert.IsFalse (mi.IsAbstract, "#G3");
7065 
7066 			mi = GetMethodByName (methods, "GetHashCode");
7067 			Assert.IsNotNull (mi, "#H1");
7068 			Assert.IsFalse (mi.IsStatic, "#H2");
7069 			Assert.IsFalse (mi.IsAbstract, "#H3");
7070 		}
7071 
7072 		[Test]
7073 		[Category ("NotDotNet")] // mcs depends on this
TestGetMethodsFlagsIncomplete_Inheritance()7074 		public void TestGetMethodsFlagsIncomplete_Inheritance ()
7075 		{
7076 			MethodInfo [] methods;
7077 			BindingFlags flags;
7078 
7079 			TypeBuilder blueType = module.DefineType (genTypeName (),
7080 				TypeAttributes.Public);
7081 			CreateMembers (blueType, "Blue", false);
7082 
7083 			TypeBuilder redType = module.DefineType (genTypeName (),
7084 				TypeAttributes.Public, blueType);
7085 			CreateMembers (redType, "Red", false);
7086 
7087 			TypeBuilder greenType = module.DefineType (genTypeName (),
7088 				TypeAttributes.Public, redType);
7089 			CreateMembers (greenType, "Green", false);
7090 
7091 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
7092 			methods = greenType.GetMethods (flags);
7093 
7094 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7095 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7096 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7097 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7098 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7099 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7100 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7101 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7102 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7103 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7104 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7105 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7106 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7107 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7108 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7109 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7110 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7111 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7112 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7113 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7114 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7115 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7116 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7117 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7118 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7119 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7120 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7121 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7122 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7123 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7124 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7125 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7126 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7127 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7128 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7129 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7130 
7131 			flags = BindingFlags.Instance | BindingFlags.Public;
7132 			methods = greenType.GetMethods (flags);
7133 
7134 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7135 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7136 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7137 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7138 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7139 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7140 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7141 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7142 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7143 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7144 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7145 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7146 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7147 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7148 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7149 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7150 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7151 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7152 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7153 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7154 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7155 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7156 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7157 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7158 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7159 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7160 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7161 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7162 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7163 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7164 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7165 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7166 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7167 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7168 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7169 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7170 
7171 			flags = BindingFlags.Static | BindingFlags.Public;
7172 			methods = greenType.GetMethods (flags);
7173 
7174 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7175 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7176 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7177 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7178 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7179 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7180 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7181 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7182 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7183 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7184 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7185 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7186 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7187 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7188 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7189 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7190 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7191 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7192 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7193 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7194 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7195 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7196 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7197 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7198 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7199 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7200 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7201 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7202 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7203 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7204 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7205 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7206 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7207 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7208 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7209 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7210 
7211 			flags = BindingFlags.Static | BindingFlags.NonPublic;
7212 			methods = greenType.GetMethods (flags);
7213 
7214 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7215 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7216 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7217 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7218 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7219 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7220 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7221 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7222 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7223 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7224 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7225 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7226 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7227 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7228 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7229 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7230 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7231 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7232 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7233 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7234 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7235 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7236 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7237 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7238 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7239 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7240 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7241 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7242 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7243 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7244 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7245 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7246 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7247 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7248 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7249 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7250 
7251 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
7252 				BindingFlags.FlattenHierarchy;
7253 			methods = greenType.GetMethods (flags);
7254 
7255 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7256 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7257 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7258 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7259 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7260 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7261 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7262 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7263 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7264 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7265 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7266 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7267 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7268 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7269 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7270 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7271 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7272 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7273 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7274 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7275 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7276 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7277 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7278 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7279 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7280 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7281 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7282 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7283 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7284 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7285 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7286 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7287 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7288 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7289 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7290 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7291 
7292 			flags = BindingFlags.Instance | BindingFlags.Public |
7293 				BindingFlags.FlattenHierarchy;
7294 			methods = greenType.GetMethods (flags);
7295 
7296 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7297 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7298 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7299 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7300 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7301 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7302 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7303 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7304 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7305 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7306 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7307 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7308 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7309 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7310 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7311 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7312 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7313 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7314 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7315 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7316 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7317 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7318 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7319 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7320 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7321 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7322 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7323 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7324 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7325 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7326 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7327 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7328 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7329 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7330 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7331 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7332 
7333 			flags = BindingFlags.Static | BindingFlags.Public |
7334 				BindingFlags.FlattenHierarchy;
7335 			methods = greenType.GetMethods (flags);
7336 
7337 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7338 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7339 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7340 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7341 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7342 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7343 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7344 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7345 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7346 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7347 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7348 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7349 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7350 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7351 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7352 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7353 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7354 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7355 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7356 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7357 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7358 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7359 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7360 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7361 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7362 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7363 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7364 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7365 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7366 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7367 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7368 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7369 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7370 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7371 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7372 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7373 
7374 			flags = BindingFlags.Static | BindingFlags.NonPublic |
7375 				BindingFlags.FlattenHierarchy;
7376 			methods = greenType.GetMethods (flags);
7377 
7378 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7379 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7380 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7381 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7382 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7383 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7384 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7385 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7386 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7387 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7388 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7389 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7390 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7391 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7392 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7393 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7394 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7395 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7396 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7397 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7398 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7399 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7400 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7401 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7402 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7403 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7404 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7405 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7406 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7407 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7408 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7409 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7410 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7411 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7412 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7413 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7414 
7415 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
7416 				BindingFlags.DeclaredOnly;
7417 			methods = greenType.GetMethods (flags);
7418 
7419 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7420 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7421 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7422 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7423 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7424 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7425 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7426 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7427 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7428 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7429 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7430 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7431 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7432 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7433 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7434 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7435 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7436 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7437 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7438 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7439 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7440 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7441 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7442 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7443 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7444 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7445 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7446 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7447 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7448 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7449 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7450 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7451 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7452 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7453 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7454 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7455 
7456 			flags = BindingFlags.Instance | BindingFlags.Public |
7457 				BindingFlags.DeclaredOnly;
7458 			methods = greenType.GetMethods (flags);
7459 
7460 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7461 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7462 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7463 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7464 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7465 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7466 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7467 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7468 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7469 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7470 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7471 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7472 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7473 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7474 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7475 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7476 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7477 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7478 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7479 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7480 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7481 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7482 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7483 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7484 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7485 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7486 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7487 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7488 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7489 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7490 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7491 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7492 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7493 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7494 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7495 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7496 
7497 			flags = BindingFlags.Static | BindingFlags.Public |
7498 				BindingFlags.DeclaredOnly;
7499 			methods = greenType.GetMethods (flags);
7500 
7501 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7502 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7503 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7504 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7505 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7506 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7507 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7508 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7509 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7510 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7511 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7512 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7513 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7514 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7515 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7516 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7517 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7518 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7519 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7520 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7521 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7522 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7523 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7524 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7525 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7526 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7527 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7528 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7529 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7530 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7531 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7532 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7533 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7534 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7535 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7536 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7537 
7538 			flags = BindingFlags.Static | BindingFlags.NonPublic |
7539 				BindingFlags.DeclaredOnly;
7540 			methods = greenType.GetMethods (flags);
7541 
7542 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7543 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7544 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7545 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7546 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7547 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7548 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7549 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7550 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7551 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7552 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7553 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7554 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7555 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7556 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7557 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7558 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7559 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7560 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7561 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7562 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7563 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7564 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7565 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7566 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7567 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7568 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7569 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7570 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7571 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7572 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7573 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7574 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7575 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7576 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7577 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7578 
7579 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
7580 				BindingFlags.Public;
7581 			methods = greenType.GetMethods (flags);
7582 
7583 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7584 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7585 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7586 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7587 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7588 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7589 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7590 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7591 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7592 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7593 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7594 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7595 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7596 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7597 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7598 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7599 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7600 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7601 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7602 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7603 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7604 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7605 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7606 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7607 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7608 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7609 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7610 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7611 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7612 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7613 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7614 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7615 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7616 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7617 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7618 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7619 
7620 			flags = BindingFlags.Static | BindingFlags.NonPublic |
7621 				BindingFlags.Public;
7622 			methods = greenType.GetMethods (flags);
7623 
7624 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7625 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7626 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7627 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7628 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7629 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7630 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7631 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7632 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7633 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7634 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7635 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7636 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7637 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7638 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7639 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7640 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7641 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7642 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7643 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7644 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7645 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7646 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7647 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7648 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7649 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7650 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7651 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7652 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7653 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7654 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7655 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7656 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7657 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7658 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7659 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7660 		}
7661 
7662 		[Test]
7663 		[Category ("NotDotNet")] // mcs depends on this
TestGetMethodsFlagsIncomplete_Mono()7664 		public void TestGetMethodsFlagsIncomplete_Mono ()
7665 		{
7666 			MethodBuilder mb;
7667 			ILGenerator ilgen;
7668 			MethodInfo [] methods;
7669 
7670 			TypeBuilder tb = module.DefineType (genTypeName (),
7671 				TypeAttributes.Abstract);
7672 			mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7673 				typeof (void), Type.EmptyTypes);
7674 			ilgen = mb.GetILGenerator ();
7675 			ilgen.Emit (OpCodes.Ret);
7676 
7677 			mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7678 				typeof (void), Type.EmptyTypes);
7679 			ilgen = mb.GetILGenerator ();
7680 			ilgen.Emit (OpCodes.Ret);
7681 
7682 			mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7683 				MethodAttributes.Static,
7684 				typeof (void), Type.EmptyTypes);
7685 			ilgen = mb.GetILGenerator ();
7686 			ilgen.Emit (OpCodes.Ret);
7687 
7688 			mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7689 				MethodAttributes.Abstract | MethodAttributes.Virtual,
7690 				typeof (void), Type.EmptyTypes);
7691 
7692 			methods = tb.GetMethods (BindingFlags.Public |
7693 				BindingFlags.Instance);
7694 			Assert.AreEqual (6, methods.Length, "#A1");
7695 			Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7696 			Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7697 			Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7698 			Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7699 			Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7700 
7701 			methods = tb.GetMethods (BindingFlags.Public |
7702 				BindingFlags.Instance | BindingFlags.DeclaredOnly);
7703 			Assert.AreEqual (2, methods.Length, "#B1");
7704 			Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7705 			Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7706 
7707 			methods = tb.GetMethods (BindingFlags.Public |
7708 				BindingFlags.Instance | BindingFlags.Static);
7709 			Assert.AreEqual (7, methods.Length, "#C1");
7710 			Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7711 			Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7712 			Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7713 			Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7714 			Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7715 			Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7716 
7717 			methods = tb.GetMethods (BindingFlags.NonPublic |
7718 				BindingFlags.Instance | BindingFlags.DeclaredOnly);
7719 			Assert.AreEqual (1, methods.Length, "#D1");
7720 			Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7721 		}
7722 
7723 
7724 		[Test]
7725 		[Category ("NotWorking")] // mcs depends on this
TestGetMethodsFlagsIncomplete_MS()7726 		public void TestGetMethodsFlagsIncomplete_MS ()
7727 		{
7728 			MethodBuilder mb;
7729 			ILGenerator ilgen;
7730 
7731 			TypeBuilder tb = module.DefineType (genTypeName (),
7732 				TypeAttributes.Abstract);
7733 			mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7734 				typeof (void), Type.EmptyTypes);
7735 			ilgen = mb.GetILGenerator ();
7736 			ilgen.Emit (OpCodes.Ret);
7737 
7738 			mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7739 				typeof (void), Type.EmptyTypes);
7740 			ilgen = mb.GetILGenerator ();
7741 			ilgen.Emit (OpCodes.Ret);
7742 
7743 			mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7744 				MethodAttributes.Static,
7745 				typeof (void), Type.EmptyTypes);
7746 			ilgen = mb.GetILGenerator ();
7747 			ilgen.Emit (OpCodes.Ret);
7748 
7749 			mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7750 				MethodAttributes.Abstract | MethodAttributes.Virtual,
7751 				typeof (void), Type.EmptyTypes);
7752 
7753 			try {
7754 				tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7755 				Assert.Fail ("#1");
7756 			} catch (NotSupportedException ex) {
7757 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7758 				Assert.IsNull (ex.InnerException, "#3");
7759 				Assert.IsNotNull (ex.Message, "#4");
7760 			}
7761 		}
7762 
7763 		[Test]
TestGetMethodsFlagsComplete()7764 		public void TestGetMethodsFlagsComplete ()
7765 		{
7766 			TypeBuilder tb = module.DefineType (genTypeName ());
7767 			MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7768 				MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7769 			ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7770 			helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7771 			helloMethodIL.Emit (OpCodes.Ldarg_1);
7772 			MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7773 				new Type [] { typeof (string), typeof (string) });
7774 			helloMethodIL.Emit (OpCodes.Call, infoMethod);
7775 			helloMethodIL.Emit (OpCodes.Ret);
7776 
7777 			Type emittedType = tb.CreateType ();
7778 
7779 			Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7780 			Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7781 				emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7782 			Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7783 			Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7784 				emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7785 		}
7786 
7787 		[Test]
TestGetMethodsFlagsComplete_Inheritance()7788 		public void TestGetMethodsFlagsComplete_Inheritance ()
7789 		{
7790 			MethodInfo [] methods;
7791 			BindingFlags flags;
7792 
7793 			TypeBuilder blueType = module.DefineType (genTypeName (),
7794 				TypeAttributes.Public);
7795 			CreateMembers (blueType, "Blue", false);
7796 
7797 			TypeBuilder redType = module.DefineType (genTypeName (),
7798 				TypeAttributes.Public, blueType);
7799 			CreateMembers (redType, "Red", false);
7800 
7801 			TypeBuilder greenType = module.DefineType (genTypeName (),
7802 				TypeAttributes.Public, redType);
7803 			CreateMembers (greenType, "Green", false);
7804 
7805 			blueType.CreateType ();
7806 			redType.CreateType ();
7807 			greenType.CreateType ();
7808 
7809 			flags = BindingFlags.Instance | BindingFlags.NonPublic;
7810 			methods = greenType.GetMethods (flags);
7811 
7812 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7813 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7814 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7815 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7816 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7817 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7818 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7819 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7820 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7821 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7822 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7823 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7824 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7825 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7826 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7827 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7828 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7829 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7830 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7831 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7832 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7833 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7834 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7835 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7836 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7837 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7838 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7839 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7840 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7841 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7842 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7843 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7844 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7845 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7846 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7847 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7848 
7849 			flags = BindingFlags.Instance | BindingFlags.Public;
7850 			methods = greenType.GetMethods (flags);
7851 
7852 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7853 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7854 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7855 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7856 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7857 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7858 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7859 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7860 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7861 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7862 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7863 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7864 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7865 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7866 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7867 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7868 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7869 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7870 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7871 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7872 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7873 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7874 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7875 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7876 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7877 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7878 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7879 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7880 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7881 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7882 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7883 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7884 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7885 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7886 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7887 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7888 
7889 			flags = BindingFlags.Static | BindingFlags.Public;
7890 			methods = greenType.GetMethods (flags);
7891 
7892 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7893 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7894 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7895 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7896 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7897 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7898 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7899 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7900 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7901 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7902 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7903 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7904 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7905 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7906 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7907 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7908 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7909 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7910 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7911 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7912 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7913 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7914 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7915 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7916 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7917 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7918 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7919 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7920 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7921 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7922 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7923 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7924 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7925 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7926 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7927 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7928 
7929 			flags = BindingFlags.Static | BindingFlags.NonPublic;
7930 			methods = greenType.GetMethods (flags);
7931 
7932 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7933 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7934 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7935 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7936 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7937 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7938 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7939 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7940 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7941 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7942 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7943 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7944 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7945 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7946 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7947 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7948 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7949 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7950 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7951 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7952 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7953 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7954 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7955 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7956 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7957 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7958 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7959 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7960 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7961 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7962 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7963 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7964 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7965 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7966 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7967 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7968 
7969 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
7970 				BindingFlags.FlattenHierarchy;
7971 			methods = greenType.GetMethods (flags);
7972 
7973 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7974 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7975 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7976 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7977 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7978 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7979 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7980 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7981 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7982 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7983 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7984 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7985 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7986 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7987 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7988 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7989 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7990 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7991 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7992 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7993 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7994 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7995 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7996 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7997 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7998 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7999 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
8000 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
8001 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
8002 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
8003 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
8004 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
8005 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
8006 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
8007 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
8008 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
8009 
8010 			flags = BindingFlags.Instance | BindingFlags.Public |
8011 				BindingFlags.FlattenHierarchy;
8012 			methods = greenType.GetMethods (flags);
8013 
8014 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
8015 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
8016 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
8017 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
8018 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
8019 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
8020 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
8021 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
8022 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
8023 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
8024 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
8025 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
8026 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
8027 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
8028 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
8029 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
8030 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
8031 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
8032 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
8033 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
8034 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
8035 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
8036 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
8037 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
8038 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
8039 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
8040 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
8041 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
8042 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
8043 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
8044 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
8045 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
8046 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
8047 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
8048 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
8049 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
8050 
8051 			flags = BindingFlags.Static | BindingFlags.Public |
8052 				BindingFlags.FlattenHierarchy;
8053 			methods = greenType.GetMethods (flags);
8054 
8055 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
8056 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
8057 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
8058 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8059 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8060 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8061 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8062 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8063 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8064 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8065 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8066 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8067 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8068 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8069 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8070 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8071 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8072 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8073 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8074 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8075 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8076 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8077 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8078 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8079 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8080 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8081 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8082 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8083 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8084 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8085 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8086 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8087 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8088 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8089 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8090 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8091 
8092 			flags = BindingFlags.Static | BindingFlags.NonPublic |
8093 				BindingFlags.FlattenHierarchy;
8094 			methods = greenType.GetMethods (flags);
8095 
8096 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8097 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8098 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8099 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8100 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8101 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8102 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8103 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8104 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8105 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8106 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8107 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8108 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8109 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8110 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8111 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8112 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8113 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8114 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8115 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8116 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8117 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8118 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8119 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8120 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8121 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8122 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8123 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8124 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8125 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8126 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8127 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8128 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8129 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8130 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8131 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8132 
8133 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
8134 				BindingFlags.DeclaredOnly;
8135 			methods = greenType.GetMethods (flags);
8136 
8137 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8138 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8139 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8140 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8141 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8142 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8143 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8144 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8145 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8146 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8147 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8148 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8149 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8150 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8151 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8152 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8153 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8154 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8155 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8156 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8157 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8158 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8159 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8160 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8161 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8162 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8163 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8164 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8165 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8166 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8167 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8168 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8169 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8170 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8171 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8172 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8173 
8174 			flags = BindingFlags.Instance | BindingFlags.Public |
8175 				BindingFlags.DeclaredOnly;
8176 			methods = greenType.GetMethods (flags);
8177 
8178 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8179 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8180 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8181 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8182 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8183 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8184 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8185 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8186 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8187 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8188 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8189 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8190 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8191 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8192 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8193 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8194 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8195 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8196 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8197 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8198 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8199 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8200 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8201 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8202 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8203 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8204 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8205 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8206 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8207 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8208 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8209 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8210 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8211 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8212 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8213 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8214 
8215 			flags = BindingFlags.Static | BindingFlags.Public |
8216 				BindingFlags.DeclaredOnly;
8217 			methods = greenType.GetMethods (flags);
8218 
8219 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8220 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8221 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8222 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8223 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8224 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8225 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8226 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8227 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8228 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8229 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8230 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8231 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8232 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8233 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8234 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8235 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8236 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8237 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8238 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8239 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8240 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8241 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8242 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8243 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8244 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8245 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8246 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8247 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8248 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8249 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8250 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8251 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8252 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8253 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8254 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8255 
8256 			flags = BindingFlags.Static | BindingFlags.NonPublic |
8257 				BindingFlags.DeclaredOnly;
8258 			methods = greenType.GetMethods (flags);
8259 
8260 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8261 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8262 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8263 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8264 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8265 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8266 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8267 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8268 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8269 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8270 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8271 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8272 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8273 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8274 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8275 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8276 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8277 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8278 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8279 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8280 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8281 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8282 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8283 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8284 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8285 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8286 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8287 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8288 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8289 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8290 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8291 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8292 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8293 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8294 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8295 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8296 
8297 			flags = BindingFlags.Instance | BindingFlags.NonPublic |
8298 				BindingFlags.Public;
8299 			methods = greenType.GetMethods (flags);
8300 
8301 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8302 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8303 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8304 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8305 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8306 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8307 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8308 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8309 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8310 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8311 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8312 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8313 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8314 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8315 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8316 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8317 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8318 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8319 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8320 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8321 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8322 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8323 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8324 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8325 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8326 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8327 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8328 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8329 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8330 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8331 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8332 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8333 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8334 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8335 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8336 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8337 
8338 			flags = BindingFlags.Static | BindingFlags.NonPublic |
8339 				BindingFlags.Public;
8340 			methods = greenType.GetMethods (flags);
8341 
8342 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8343 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8344 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8345 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8346 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8347 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8348 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8349 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8350 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8351 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8352 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8353 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8354 			Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8355 			Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8356 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8357 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8358 			Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8359 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8360 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8361 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8362 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8363 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8364 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8365 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8366 			Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8367 			Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8368 			Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8369 			Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8370 			Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8371 			Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8372 			Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8373 			Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8374 			Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8375 			Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8376 			Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8377 			Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8378 		}
8379 
8380 		[Test]
TestGetMemberIncomplete()8381 		public void TestGetMemberIncomplete ()
8382 		{
8383 			TypeBuilder tb = module.DefineType (genTypeName ());
8384 			try {
8385 				tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8386 				Assert.Fail ("#1");
8387 			} catch (NotSupportedException ex) {
8388 				// The invoked member is not supported in a
8389 				// dynamic module
8390 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8391 				Assert.IsNull (ex.InnerException, "#3");
8392 				Assert.IsNotNull (ex.Message, "#4");
8393 			}
8394 		}
8395 
8396 		[Test]
TestGetMemberComplete()8397 		public void TestGetMemberComplete ()
8398 		{
8399 			TypeBuilder tb = module.DefineType (genTypeName ());
8400 			tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8401 
8402 			Type emittedType = tb.CreateType ();
8403 
8404 			Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8405 			Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8406 		}
8407 
8408 		[Test]
TestGetMembersIncomplete()8409 		public void TestGetMembersIncomplete ()
8410 		{
8411 			TypeBuilder tb = module.DefineType (genTypeName ());
8412 			try {
8413 				tb.GetMembers ();
8414 				Assert.Fail ("#1");
8415 			} catch (NotSupportedException ex) {
8416 				// The invoked member is not supported in a
8417 				// dynamic module
8418 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8419 				Assert.IsNull (ex.InnerException, "#3");
8420 				Assert.IsNotNull (ex.Message, "#4");
8421 			}
8422 		}
8423 
8424 		[Test]
TestGetMembersComplete()8425 		public void TestGetMembersComplete ()
8426 		{
8427 			TypeBuilder tb = module.DefineType (genTypeName ());
8428 			Type emittedType = tb.CreateType ();
8429 
8430 			Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8431 		}
8432 
8433 		[Test]
TestGetMembersFlagsIncomplete()8434 		public void TestGetMembersFlagsIncomplete ()
8435 		{
8436 			TypeBuilder tb = module.DefineType (genTypeName ());
8437 			try {
8438 				tb.GetMembers (BindingFlags.Public);
8439 				Assert.Fail ("#1");
8440 			} catch (NotSupportedException ex) {
8441 				// The invoked member is not supported in a
8442 				// dynamic module
8443 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8444 				Assert.IsNull (ex.InnerException, "#3");
8445 				Assert.IsNotNull (ex.Message, "#4");
8446 			}
8447 		}
8448 
8449 		[Test]
TestGetMembersFlagsComplete()8450 		public void TestGetMembersFlagsComplete ()
8451 		{
8452 			TypeBuilder tb = module.DefineType (genTypeName ());
8453 			tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8454 
8455 			Type emittedType = tb.CreateType ();
8456 
8457 			Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8458 			Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8459 				emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8460 			Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8461 				emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8462 		}
8463 
8464 		[Test]
TestGetInterfaceIncomplete()8465 		public void TestGetInterfaceIncomplete ()
8466 		{
8467 			TypeBuilder tb = module.DefineType (genTypeName ());
8468 			try {
8469 				tb.GetInterface ("FOO", true);
8470 				Assert.Fail ("#1");
8471 			} catch (NotSupportedException ex) {
8472 				// The invoked member is not supported in a
8473 				// dynamic module
8474 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8475 				Assert.IsNull (ex.InnerException, "#3");
8476 				Assert.IsNotNull (ex.Message, "#4");
8477 			}
8478 		}
8479 
8480 		[Test]
TestGetInterfaces()8481 		public void TestGetInterfaces ()
8482 		{
8483 			TypeBuilder tb = module.DefineType (genTypeName ());
8484 			Type [] interfaces = tb.GetInterfaces ();
8485 			Assert.AreEqual (0, interfaces.Length);
8486 
8487 			TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8488 			Type emittedInterface = tbInterface.CreateType ();
8489 
8490 			tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8491 			interfaces = tb.GetInterfaces ();
8492 			Assert.AreEqual (1, interfaces.Length);
8493 		}
8494 
8495 		[Test]
8496 		[Category ("MobileNotWorking")] // Not available in the 2.1 profile
TestAddDeclarativeSecurityAlreadyCreated()8497 		public void TestAddDeclarativeSecurityAlreadyCreated ()
8498 		{
8499 			TypeBuilder tb = module.DefineType (genTypeName ());
8500 			tb.CreateType ();
8501 
8502 			PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8503 			try {
8504 				tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8505 				Assert.Fail ("#1");
8506 			} catch (InvalidOperationException ex) {
8507 				// Unable to change after type has been created
8508 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8509 				Assert.IsNull (ex.InnerException, "#3");
8510 				Assert.IsNotNull (ex.Message, "#4");
8511 			}
8512 		}
8513 
8514 		[Test]
8515 		[Category ("MobileNotWorking")] // Not available in the 2.1 profile
TestAddDeclarativeSecurityNullPermissionSet()8516 		public void TestAddDeclarativeSecurityNullPermissionSet ()
8517 		{
8518 			TypeBuilder tb = module.DefineType (genTypeName ());
8519 			try {
8520 				tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8521 				Assert.Fail ("#1");
8522 			} catch (ArgumentNullException ex) {
8523 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8524 				Assert.IsNull (ex.InnerException, "#3");
8525 				Assert.IsNotNull (ex.Message, "#4");
8526 				Assert.AreEqual ("pset", ex.ParamName, "#5");
8527 			}
8528 
8529 		}
8530 
8531 		[Test]
8532 		[Category ("MobileNotWorking")] // Not available in the 2.1 profile
TestAddDeclarativeSecurityInvalidAction()8533 		public void TestAddDeclarativeSecurityInvalidAction ()
8534 		{
8535 			TypeBuilder tb = module.DefineType (genTypeName ());
8536 
8537 			SecurityAction [] actions = new SecurityAction [] {
8538 			SecurityAction.RequestMinimum,
8539 			SecurityAction.RequestOptional,
8540 			SecurityAction.RequestRefuse };
8541 			PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8542 
8543 			foreach (SecurityAction action in actions) {
8544 				try {
8545 					tb.AddDeclarativeSecurity (action, set);
8546 					Assert.Fail ();
8547 				} catch (ArgumentOutOfRangeException) {
8548 				}
8549 			}
8550 		}
8551 
8552 		[Test]
8553 		[Category ("MobileNotWorking")] // Not available in the 2.1 profile
TestAddDeclarativeSecurityDuplicateAction()8554 		public void TestAddDeclarativeSecurityDuplicateAction ()
8555 		{
8556 			TypeBuilder tb = module.DefineType (genTypeName ());
8557 
8558 			PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8559 			tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8560 			try {
8561 				tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8562 				Assert.Fail ("#1");
8563 			} catch (InvalidOperationException ex) {
8564 				// Multiple permission sets specified with the
8565 				// same SecurityAction
8566 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8567 				Assert.IsNull (ex.InnerException, "#3");
8568 				Assert.IsNotNull (ex.Message, "#4");
8569 			}
8570 		}
8571 
8572 		[Test]
TestEnums()8573 		public void TestEnums ()
8574 		{
8575 			TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8576 			TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8577 														 typeof (Enum));
8578 			enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8579 			// add value__ field, see DefineEnum method of ModuleBuilder
8580 			enumToCreate.DefineField ("value__", typeof (Int32),
8581 				FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8582 
8583 			// add enum entries
8584 			FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8585 				FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8586 			fb.SetConstant ((Int32) 0);
8587 
8588 			fb = enumToCreate.DefineField ("B", enumToCreate,
8589 				FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8590 			fb.SetConstant ((Int32) 1);
8591 
8592 			fb = enumToCreate.DefineField ("C", enumToCreate,
8593 				FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8594 			fb.SetConstant ((Int32) 2);
8595 
8596 			Type enumType = enumToCreate.CreateType ();
8597 
8598 			object enumVal = Enum.ToObject (enumType, (Int32) 3);
8599 
8600 			Assert.AreEqual ("B, C", enumVal.ToString ());
8601 			Assert.AreEqual (3, (Int32) enumVal);
8602 		}
8603 
8604 		[Test]
DefineEnum()8605 		public void DefineEnum ()
8606 		{
8607 			TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8608 														 TypeAttributes.Public);
8609 			EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8610 														 TypeAttributes.Public, typeof (int));
8611 			typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8612 			enumBuilder.CreateType ();
8613 			typeBuilder.CreateType ();
8614 		}
8615 
8616 		[Test]
8617 		[Category ("NotWorking")]
DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder()8618 		public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8619 		{
8620 			TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8621 														 TypeAttributes.Public);
8622 			EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8623 														 TypeAttributes.Public, typeof (int));
8624 			typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8625 			try {
8626 				typeBuilder.CreateType ();
8627 				Assert.Fail ("#1");
8628 			} catch (TypeLoadException) {
8629 				// Could not load type '...' from assembly
8630 				// 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8631 			}
8632 			Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8633 			Assert.IsNull (typeBuilder.CreateType (), "#3");
8634 		}
8635 
8636 		[Test]
SetCustomAttribute_SuppressUnmanagedCodeSecurity()8637 		public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8638 		{
8639 			TypeBuilder tb = module.DefineType (genTypeName ());
8640 			ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8641 				GetConstructor (Type.EmptyTypes);
8642 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8643 				attrCtor, new object [0]);
8644 			Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8645 			tb.SetCustomAttribute (caBuilder);
8646 			//Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8647 			Type emittedType = tb.CreateType ();
8648 			Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8649 			//Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8650 			object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8651 			Assert.AreEqual (1, emittedAttrs.Length, "#5");
8652 		}
8653 
DefineStringProperty(TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)8654 		private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8655 		{
8656 			// define the field holding the property value
8657 			FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8658 				typeof (string), FieldAttributes.Private);
8659 
8660 			PropertyBuilder propertyBuilder = tb.DefineProperty (
8661 				propertyName, PropertyAttributes.HasDefault, typeof (string),
8662 				new Type [] { typeof (string) });
8663 
8664 			// First, we'll define the behavior of the "get" property for CustomerName as a method.
8665 			MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8666 									methodAttribs,
8667 									typeof (string),
8668 									new Type [] { });
8669 
8670 			ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8671 
8672 			getIL.Emit (OpCodes.Ldarg_0);
8673 			getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8674 			getIL.Emit (OpCodes.Ret);
8675 
8676 			// Now, we'll define the behavior of the "set" property for CustomerName.
8677 			MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8678 									methodAttribs,
8679 									null,
8680 									new Type [] { typeof (string) });
8681 
8682 			ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8683 
8684 			setIL.Emit (OpCodes.Ldarg_0);
8685 			setIL.Emit (OpCodes.Ldarg_1);
8686 			setIL.Emit (OpCodes.Stfld, fieldBuilder);
8687 			setIL.Emit (OpCodes.Ret);
8688 
8689 			// Last, we must map the two methods created above to our PropertyBuilder to
8690 			// their corresponding behaviors, "get" and "set" respectively.
8691 			propertyBuilder.SetGetMethod (getMethodBuilder);
8692 			propertyBuilder.SetSetMethod (setMethodBuilder);
8693 			return propertyBuilder;
8694 		}
8695 
8696 		static int handler_called = 0;
8697 
8698 		[Test]
TestTypeResolve()8699 		public void TestTypeResolve ()
8700 		{
8701 			string typeName = genTypeName ();
8702 
8703 			ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8704 			AppDomain.CurrentDomain.TypeResolve += handler;
8705 			handler_called = 0;
8706 			Type t = Type.GetType (typeName);
8707 			Assert.AreEqual (typeName, t.Name);
8708 			Assert.AreEqual (1, handler_called);
8709 			AppDomain.CurrentDomain.TypeResolve -= handler;
8710 		}
8711 
TypeResolve(object sender, ResolveEventArgs args)8712 		Assembly TypeResolve (object sender, ResolveEventArgs args)
8713 		{
8714 			TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8715 			tb.CreateType ();
8716 			handler_called++;
8717 			return tb.Assembly;
8718 		}
8719 
8720 		[Test]
IsAssignableFrom_Created()8721 		public void IsAssignableFrom_Created ()
8722 		{
8723 			TypeBuilder tb = module.DefineType (genTypeName (),
8724 				TypeAttributes.Public, typeof (MemoryStream),
8725 				new Type [] { typeof (IThrowable), typeof (Bar) });
8726 			tb.AddInterfaceImplementation (typeof (IDestroyable));
8727 			Type emitted_type = tb.CreateType ();
8728 
8729 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8730 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8731 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8732 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8733 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8734 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8735 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8736 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8737 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8738 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8739 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8740 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8741 			Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8742 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8743 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8744 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8745 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8746 			Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8747 
8748 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8749 			Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8750 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8751 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8752 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8753 			Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8754 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8755 			Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8756 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8757 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8758 
8759 			Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8760 			Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8761 			Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8762 			Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8763 			Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8764 
8765 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8766 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8767 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8768 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8769 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8770 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8771 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8772 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8773 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8774 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8775 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8776 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8777 			Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8778 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8779 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8780 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8781 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8782 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8783 
8784 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8785 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8786 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8787 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8788 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8789 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8790 			Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8791 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8792 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8793 			Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8794 
8795 			Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8796 				tb.FullName + "[]")), "#F1");
8797 			Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8798 				tb.FullName + "[]")), "#F2");
8799 			Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8800 				tb.FullName + "[]")), "#F3");
8801 
8802 			TypeBuilder tb2 = module.DefineType (genTypeName (),
8803 				TypeAttributes.Public, tb,
8804 				new Type [] { typeof (IAir) });
8805 			Type emitted_type2 = tb2.CreateType ();
8806 
8807 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8808 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8809 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8810 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8811 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8812 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8813 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8814 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8815 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8816 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8817 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8818 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8819 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8820 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8821 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8822 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8823 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8824 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8825 
8826 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8827 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8828 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8829 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8830 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8831 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8832 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8833 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8834 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8835 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8836 
8837 			Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
8838 			Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
8839 			Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
8840 			Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
8841 			Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
8842 			Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
8843 			Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
8844 			Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
8845 			Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
8846 			Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
8847 			Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
8848 			Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
8849 			Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
8850 			Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
8851 
8852 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
8853 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
8854 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
8855 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
8856 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
8857 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
8858 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
8859 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
8860 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
8861 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
8862 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
8863 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
8864 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
8865 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
8866 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
8867 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
8868 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
8869 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
8870 
8871 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
8872 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
8873 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
8874 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
8875 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
8876 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
8877 			Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
8878 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
8879 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
8880 			Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
8881 
8882 			Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8883 				tb2.FullName + "[]")), "#L1");
8884 			Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8885 				tb2.FullName + "[]")), "#L2");
8886 			Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8887 				tb2.FullName + "[]")), "#L3");
8888 
8889 			TypeBuilder tb3 = module.DefineType (genTypeName (),
8890 				TypeAttributes.Public, tb2,
8891 				new Type [] { typeof (IWater) });
8892 			Type emitted_type3 = tb3.CreateType ();
8893 
8894 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
8895 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
8896 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
8897 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
8898 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
8899 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
8900 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
8901 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
8902 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
8903 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
8904 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
8905 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
8906 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
8907 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
8908 			Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
8909 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
8910 			Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
8911 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
8912 
8913 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
8914 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
8915 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
8916 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
8917 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
8918 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
8919 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
8920 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
8921 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
8922 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
8923 
8924 			Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
8925 			Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
8926 			Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
8927 			Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
8928 			Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
8929 			Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
8930 			Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
8931 			Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
8932 			Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
8933 			Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
8934 			Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
8935 			Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
8936 			Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
8937 			Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
8938 			Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
8939 			Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
8940 			Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
8941 			Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
8942 			Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
8943 			Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
8944 			Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
8945 			Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
8946 
8947 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
8948 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
8949 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
8950 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
8951 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
8952 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
8953 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
8954 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
8955 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
8956 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
8957 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
8958 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
8959 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
8960 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
8961 			Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
8962 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
8963 			Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
8964 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
8965 
8966 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
8967 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
8968 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
8969 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
8970 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
8971 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
8972 			Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
8973 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
8974 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
8975 			Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
8976 
8977 			Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8978 				tb3.FullName + "[]")), "#R1");
8979 			Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8980 				tb3.FullName + "[]")), "#R2");
8981 			Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8982 				tb3.FullName + "[]")), "#R3");
8983 
8984 			TypeBuilder tb4 = module.DefineType (genTypeName (),
8985 				TypeAttributes.Public, null,
8986 				new Type [] { typeof (IWater) });
8987 			tb4.DefineGenericParameters ("T");
8988 
8989 			Type inst = tb4.MakeGenericType (typeof (int));
8990 			Type emitted_type4 = tb4.CreateType ();
8991 			Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
8992 			// This returns True if CreateType () is called _before_ MakeGenericType...
8993 			//Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
8994 		}
8995 
8996 		[Test]
IsAssignableFrom_NotCreated()8997 		public void IsAssignableFrom_NotCreated ()
8998 		{
8999 			TypeBuilder tb = module.DefineType (genTypeName (),
9000 				TypeAttributes.Public, typeof (MemoryStream),
9001 				new Type [] {
9002 					typeof (IThrowable), typeof (Bar),
9003 					typeof (IComparable)
9004 					});
9005 
9006 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9007 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9008 			//Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
9009 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
9010 			Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
9011 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
9012 			Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
9013 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
9014 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
9015 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
9016 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
9017 			Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
9018 
9019 			//Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
9020 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
9021 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
9022 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
9023 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
9024 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
9025 
9026 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
9027 			Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
9028 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
9029 			Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
9030 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
9031 			Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
9032 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
9033 			Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
9034 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
9035 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
9036 
9037 			Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
9038 			Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
9039 
9040 			TypeBuilder tb2 = module.DefineType (genTypeName (),
9041 				TypeAttributes.Public, tb,
9042 				new Type[] { typeof (IAir) });
9043 
9044 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
9045 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
9046 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
9047 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
9048 			Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
9049 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
9050 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
9051 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
9052 			Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
9053 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
9054 			Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
9055 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
9056 
9057 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#F1");
9058 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
9059 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#F3");
9060 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
9061 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
9062 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9063 
9064 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9065 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9066 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9067 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9068 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9069 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9070 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9071 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9072 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9073 			Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9074 
9075 			Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9076 			Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9077 			Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9078 
9079 			TypeBuilder tb3 = module.DefineType (genTypeName (),
9080 				TypeAttributes.Public, tb2,
9081 				new Type[] { typeof (IWater) });
9082 
9083 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9084 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9085 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9086 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9087 			Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9088 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9089 			Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9090 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9091 			Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9092 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9093 			//Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9094 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9095 
9096 			Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9097 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9098 			Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9099 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9100 			Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9101 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9102 
9103 			Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9104 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9105 			Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9106 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9107 			Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9108 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9109 			Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9110 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9111 			Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9112 			Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9113 
9114 			Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9115 			Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9116 			Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9117 			Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9118 			Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9119 		}
9120 
9121 		[Test]
9122 		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono()9123 		public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9124 		{
9125 			TypeBuilder tb = module.DefineType (genTypeName (),
9126 				TypeAttributes.Public, typeof (FormatException),
9127 				new Type [] { typeof (IThrowable) });
9128 			tb.AddInterfaceImplementation (typeof (IDestroyable));
9129 
9130 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9131 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9132 
9133 			Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9134 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9135 		}
9136 
9137 		[Test]
9138 		[Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS()9139 		public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9140 		{
9141 			TypeBuilder tb = module.DefineType (genTypeName (),
9142 				TypeAttributes.Public, typeof (FormatException),
9143 				new Type [] { typeof (IThrowable) });
9144 			tb.AddInterfaceImplementation (typeof (IDestroyable));
9145 
9146 			Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9147 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9148 
9149 			Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9150 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9151 		}
9152 
9153 
9154 		[Test]
9155 		// Casts don't work with unfinished types
9156 		[Category ("NotWorking")]
9157 		[Category ("NotDotNet")]
IsAssignableFrom_NotCreated_Array()9158 		public void IsAssignableFrom_NotCreated_Array ()
9159 		{
9160 			TypeBuilder tb = module.DefineType (genTypeName (),
9161 				TypeAttributes.Public, typeof (FormatException),
9162 				new Type [] {
9163 					typeof (IThrowable), typeof (Bar),
9164 					typeof (IComparable)
9165 					});
9166 
9167 			Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9168 				tb.FullName + "[]")), "#1");
9169 			Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9170 				tb.FullName + "[]")), "#2");
9171 			Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9172 				tb.FullName + "[]")), "#3");
9173 		}
9174 
9175 		[Test]
9176 		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
IsAssignableFrom_NotCreated_BaseInterface_Mono()9177 		public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9178 		{
9179 			TypeBuilder tb = module.DefineType (genTypeName (),
9180 				TypeAttributes.Public, typeof (FormatException),
9181 				new Type [] {
9182 					typeof (IThrowable), typeof (Bar),
9183 					typeof (IComparable)
9184 					});
9185 
9186 			Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9187 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9188 		}
9189 
9190 		[Test]
9191 		[Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
IsAssignableFrom_NotCreated_BaseInterface_MS()9192 		public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9193 		{
9194 			TypeBuilder tb = module.DefineType (genTypeName (),
9195 				TypeAttributes.Public, typeof (FormatException),
9196 				new Type [] {
9197 					typeof (IThrowable), typeof (Bar),
9198 					typeof (IComparable)
9199 					});
9200 
9201 			Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9202 			Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9203 		}
9204 
9205 		[Test]
CreateType_EmptyMethodBody()9206 		public void CreateType_EmptyMethodBody ()
9207 		{
9208 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9209 
9210 			tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9211 			try {
9212 				tb.CreateType ();
9213 				Assert.Fail ("#1");
9214 			} catch (InvalidOperationException ex) {
9215 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9216 				Assert.IsNull (ex.InnerException, "#3");
9217 				Assert.IsNotNull (ex.Message, "#4");
9218 			}
9219 		}
9220 
9221 		[Test]
CreateType_EmptyCtorBody()9222 		public void CreateType_EmptyCtorBody ()
9223 		{
9224 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9225 
9226 			tb.DefineConstructor (0, CallingConventions.Standard, null);
9227 			try {
9228 				tb.CreateType ();
9229 				Assert.Fail ("#1");
9230 			} catch (InvalidOperationException ex) {
9231 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9232 				Assert.IsNull (ex.InnerException, "#3");
9233 				Assert.IsNotNull (ex.Message, "#4");
9234 			}
9235 		}
9236 
9237 		[Test]
9238 		[Category ("NotWorking")]
CreateType_Interface_ParentInvalid()9239 		public void CreateType_Interface_ParentInvalid ()
9240 		{
9241 			TypeBuilder tb;
9242 
9243 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9244 				typeof (Exception));
9245 			Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9246 			try {
9247 				tb.CreateType ();
9248 				Assert.Fail ("#A2");
9249 			} catch (TypeLoadException ex) {
9250 				// Could not load interface 't5' from assembly '...'
9251 				// because it must extend from Object
9252 				Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9253 				Assert.IsNull (ex.InnerException, "#A4");
9254 				Assert.IsNotNull (ex.Message, "#A5");
9255 				Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9256 				Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9257 			}
9258 
9259 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9260 				typeof (object));
9261 			Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9262 			try {
9263 				tb.CreateType ();
9264 				Assert.Fail ("#B2");
9265 			} catch (TypeLoadException ex) {
9266 				// Failure has occurred while loading a type
9267 				Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9268 				Assert.IsNull (ex.InnerException, "#B4");
9269 				Assert.IsNotNull (ex.Message, "#B5");
9270 			}
9271 
9272 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9273 				typeof (EmptyInterface));
9274 			Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9275 			try {
9276 				tb.CreateType ();
9277 				Assert.Fail ("#C2");
9278 			} catch (TypeLoadException ex) {
9279 				// Could not load interface 't5' from assembly '...'
9280 				// because the parent type is an interface
9281 				Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9282 				Assert.IsNull (ex.InnerException, "#C4");
9283 				Assert.IsNotNull (ex.Message, "#C5");
9284 				Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9285 				Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9286 			}
9287 		}
9288 
9289 		[Test]
CreateType_Parent_DefaultCtorMissing()9290 		public void CreateType_Parent_DefaultCtorMissing ()
9291 		{
9292 			TypeBuilder tb;
9293 
9294 			tb = module.DefineType (genTypeName ());
9295 			ConstructorBuilder cb = tb.DefineConstructor (
9296 				MethodAttributes.Public,
9297 				CallingConventions.Standard,
9298 				new Type [] { typeof (string) });
9299 			cb.GetILGenerator ().Emit (OpCodes.Ret);
9300 			Type parent_type = tb.CreateType ();
9301 
9302 			tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9303 				parent_type);
9304 			try {
9305 				tb.CreateType ();
9306 				Assert.Fail ("#1");
9307 			} catch (NotSupportedException ex) {
9308 				// Parent does not have a default constructor.
9309 				// The default constructor must be explicitly defined
9310 				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9311 				Assert.IsNull (ex.InnerException, "#3");
9312 				Assert.IsNotNull (ex.Message, "#4");
9313 			}
9314 		}
9315 
9316 		[Test]
CreateType_Parent_Null()9317 		public void CreateType_Parent_Null ()
9318 		{
9319 			TypeBuilder tb;
9320 			Type emitted_type;
9321 
9322 			tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9323 			Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9324 			emitted_type = tb.CreateType ();
9325 			Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9326 
9327 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9328 			Assert.IsNull (tb.BaseType, "#B1");
9329 			emitted_type = tb.CreateType ();
9330 			Assert.IsNull (emitted_type.BaseType, "#B2");
9331 		}
9332 
9333 		[Test]
9334 		[Category ("NotWorking")]
DefineGenericParameters_AlreadyDefined()9335 		public void DefineGenericParameters_AlreadyDefined ()
9336 		{
9337 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9338 			tb.DefineGenericParameters ("K");
9339 			try {
9340 				tb.DefineGenericParameters ("V");
9341 				Assert.Fail ("#1");
9342 			} catch (InvalidOperationException ex) {
9343 				// Operation is not valid due to the current
9344 				// state of the object
9345 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9346 				Assert.IsNull (ex.InnerException, "#3");
9347 				Assert.IsNotNull (ex.Message, "#4");
9348 			}
9349 		}
9350 
9351 		[Test]
DefineGenericParameters_Names_Empty()9352 		public void DefineGenericParameters_Names_Empty ()
9353 		{
9354 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9355 
9356 			try {
9357 				tb.DefineGenericParameters (new string [0]);
9358 				Assert.Fail ("#1");
9359 			} catch (ArgumentException ex) {
9360 				// Value does not fall within the expected range
9361 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9362 				Assert.IsNull (ex.InnerException, "#3");
9363 				Assert.IsNotNull (ex.Message, "#4");
9364 				Assert.IsNull (ex.ParamName, "#5");
9365 			}
9366 		}
9367 
9368 		[Test]
DefineGenericParameters_Names_Null()9369 		public void DefineGenericParameters_Names_Null ()
9370 		{
9371 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9372 
9373 			try {
9374 				tb.DefineGenericParameters ((string []) null);
9375 				Assert.Fail ("#A1");
9376 			} catch (ArgumentNullException ex) {
9377 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9378 				Assert.IsNull (ex.InnerException, "#A3");
9379 				Assert.IsNotNull (ex.Message, "#A4");
9380 				Assert.AreEqual ("names", ex.ParamName, "#A5");
9381 			}
9382 
9383 			try {
9384 				tb.DefineGenericParameters ("K", null, "V");
9385 				Assert.Fail ("#B1");
9386 			} catch (ArgumentNullException ex) {
9387 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9388 				Assert.IsNull (ex.InnerException, "#B3");
9389 				Assert.IsNotNull (ex.Message, "#B4");
9390 				Assert.AreEqual ("names", ex.ParamName, "#B5");
9391 			}
9392 		}
9393 
9394 		[Test]
GenericType()9395 		public void GenericType ()
9396 		{
9397 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9398 			tb.DefineGenericParameters ("T");
9399 
9400 			Assert.IsTrue (tb.IsGenericType, "#A1");
9401 			Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9402 			Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9403 			Assert.IsFalse (tb.IsGenericParameter, "#A4");
9404 
9405 			Type[] args = tb.GetGenericArguments ();
9406 			Assert.IsFalse (args [0].IsGenericType, "#B1");
9407 			Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9408 			Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9409 			Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9410 		}
9411 
9412 		[Test]
MakeGenericType()9413 		public void MakeGenericType ()
9414 		{
9415 			TypeBuilder tb;
9416 			Type generic_type;
9417 
9418 			tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9419 			tb.DefineGenericParameters ("T");
9420 
9421 			generic_type = tb.MakeGenericType (typeof (int));
9422 			Assert.IsTrue (generic_type.IsGenericType, "#A1");
9423 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9424 			Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9425 			Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9426 
9427 			generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9428 			Assert.IsTrue (generic_type.IsGenericType, "#B1");
9429 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9430 			Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9431 			Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9432 
9433 			tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9434 				| TypeAttributes.Abstract | TypeAttributes.Public);
9435 			tb.DefineGenericParameters ("T");
9436 
9437 			generic_type = tb.MakeGenericType (typeof (int));
9438 			Assert.IsTrue (generic_type.IsGenericType, "#C1");
9439 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9440 			Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9441 			Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9442 
9443 			generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9444 			Assert.IsTrue (generic_type.IsGenericType, "#D1");
9445 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9446 			Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9447 			Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9448 		}
9449 
9450 		[Test]
MakeGenericType_NoGenericTypeDefinition()9451 		public void MakeGenericType_NoGenericTypeDefinition ()
9452 		{
9453 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9454 			try {
9455 				tb.MakeGenericType (typeof (int));
9456 				Assert.Fail ("#1");
9457 			} catch (InvalidOperationException ex) {
9458 				// Operation is not valid due to the current
9459 				// state of the object
9460 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9461 				Assert.IsNull (ex.InnerException, "#3");
9462 				Assert.IsNotNull (ex.Message, "#4");
9463 			}
9464 		}
9465 
9466 		[Test]
9467 		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
MakeGenericType_TypeArguments_Null_Mono()9468 		public void MakeGenericType_TypeArguments_Null_Mono ()
9469 		{
9470 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9471 			tb.DefineGenericParameters ("K", "V");
9472 
9473 			try {
9474 				tb.MakeGenericType ((Type []) null);
9475 				Assert.Fail ("#A1");
9476 			} catch (ArgumentNullException ex) {
9477 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9478 				Assert.IsNull (ex.InnerException, "#A3");
9479 				Assert.IsNotNull (ex.Message, "#A4");
9480 				Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9481 			}
9482 
9483 			try {
9484 				tb.MakeGenericType (typeof (string), (Type) null);
9485 				Assert.Fail ("#B1");
9486 			} catch (ArgumentNullException ex) {
9487 				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9488 				Assert.IsNull (ex.InnerException, "#B3");
9489 				Assert.IsNotNull (ex.Message, "#B4");
9490 				Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9491 			}
9492 		}
9493 
9494 		[Test]
9495 		[Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
MakeGenericType_TypeArguments_Null_MS()9496 		public void MakeGenericType_TypeArguments_Null_MS ()
9497 		{
9498 			Type generic_type;
9499 			Type [] type_args;
9500 
9501 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9502 			tb.DefineGenericParameters ("K", "V");
9503 
9504 			generic_type = tb.MakeGenericType ((Type []) null);
9505 			Assert.IsNotNull (generic_type, "#A1");
9506 			Assert.IsTrue (generic_type.IsGenericType, "#A2");
9507 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9508 			type_args = generic_type.GetGenericArguments ();
9509 			Assert.IsNull (type_args, "#A4");
9510 
9511 			generic_type  = tb.MakeGenericType (typeof (string), (Type) null);
9512 			Assert.IsNotNull (generic_type, "#B1");
9513 			Assert.IsTrue (generic_type.IsGenericType, "#B2");
9514 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9515 			type_args = generic_type.GetGenericArguments ();
9516 			Assert.IsNotNull (type_args, "#B4");
9517 			Assert.AreEqual (2, type_args.Length, "#B5");
9518 			Assert.AreEqual (typeof (string), type_args [0], "#B6");
9519 			Assert.IsNull (type_args [1], "#B7");
9520 		}
9521 
9522 		[Test]
9523 		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
MakeGenericType_TypeArguments_Mismatch_Mono()9524 		public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9525 		{
9526 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9527 			tb.DefineGenericParameters ("K", "V");
9528 			try {
9529 				tb.MakeGenericType (typeof (int));
9530 				Assert.Fail ("#1");
9531 			} catch (ArgumentException ex) {
9532 				// The type or method has 2 generic prarameter(s)
9533 				// but 1 generic argument(s) were provided. A
9534 				// generic argument must be provided for each
9535 				// generic parameter
9536 				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9537 				Assert.IsNull (ex.InnerException, "#3");
9538 				Assert.IsNotNull (ex.Message, "#4");
9539 				Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9540 			}
9541 		}
9542 
9543 		[Test]
9544 		[Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
MakeGenericType_TypeArguments_Mismatch_MS()9545 		public void MakeGenericType_TypeArguments_Mismatch_MS ()
9546 		{
9547 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9548 			tb.DefineGenericParameters ("K", "V");
9549 
9550 			Type generic_type = tb.MakeGenericType (typeof (int));
9551 			Assert.IsTrue (generic_type.IsGenericType, "#1");
9552 			Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9553 			Type [] type_args = generic_type.GetGenericArguments ();
9554 			Assert.IsNotNull (type_args, "#3");
9555 			Assert.AreEqual (1, type_args.Length, "#4");
9556 			Assert.AreEqual (typeof (int), type_args [0], "#5");
9557 		}
9558 
9559 		[Test]
MakeArrayType_Complete()9560 		public void MakeArrayType_Complete ()
9561 		{
9562 			// reference type
9563 			TypeBuilder tb = module.DefineType (genTypeName (),
9564 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9565 				typeof (ContextBoundObject));
9566 			Type emittedType = tb.CreateType ();
9567 			Type arrayType = tb.MakeArrayType ();
9568 			Assert.IsTrue (arrayType.IsArray, "#A1");
9569 			Assert.IsTrue (arrayType.HasElementType, "#A2");
9570 			Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9571 			Assert.IsFalse (tb.HasElementType, "#A4");
9572 			Assert.IsTrue (tb.IsCreated (), "#A5");
9573 
9574 			// value type
9575 			tb = module.DefineType (genTypeName (),
9576 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9577 				typeof (ValueType));
9578 			emittedType = tb.CreateType ();
9579 			arrayType = tb.MakeArrayType ();
9580 			Assert.IsTrue (arrayType.IsArray, "#B1");
9581 			Assert.IsTrue (arrayType.HasElementType, "#B2");
9582 			Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9583 			Assert.IsFalse (tb.HasElementType, "#B4");
9584 			Assert.IsTrue (tb.IsCreated (), "#B5");
9585 
9586 			tb = module.DefineType (genTypeName (),
9587 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9588 				typeof (Enum));
9589 			tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9590 				FieldAttributes.Private | FieldAttributes.RTSpecialName);
9591 			emittedType = tb.CreateType ();
9592 			arrayType = tb.MakeArrayType ();
9593 			Assert.IsTrue (arrayType.IsArray, "#C1");
9594 			Assert.IsTrue (arrayType.HasElementType, "#C2");
9595 			Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9596 			Assert.IsFalse (tb.HasElementType, "#C4");
9597 			Assert.IsTrue (tb.IsCreated (), "#C5");
9598 		}
9599 
9600 		[Test] // bug #82015
MakeArrayType_Incomplete()9601 		public void MakeArrayType_Incomplete ()
9602 		{
9603 			// reference type
9604 			TypeBuilder tb = module.DefineType (genTypeName (),
9605 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9606 				typeof (ContextBoundObject));
9607 			Type arrayType = tb.MakeArrayType ();
9608 			Assert.IsTrue (arrayType.IsArray, "#A1");
9609 			Assert.IsTrue (arrayType.HasElementType, "#A2");
9610 			Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9611 			Assert.IsFalse (tb.HasElementType, "#A4");
9612 			Assert.IsFalse (tb.IsCreated (), "#A5");
9613 
9614 			// value type
9615 			tb = module.DefineType (genTypeName (),
9616 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9617 				typeof (ValueType));
9618 			arrayType = tb.MakeArrayType ();
9619 			Assert.IsTrue (arrayType.IsArray, "#B1");
9620 			Assert.IsTrue (arrayType.HasElementType, "#B2");
9621 			Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9622 			Assert.IsFalse (tb.HasElementType, "#B4");
9623 			Assert.IsFalse (tb.IsCreated (), "#B5");
9624 
9625 			// enum
9626 			tb = module.DefineType (genTypeName (),
9627 				TypeAttributes.Sealed | TypeAttributes.Serializable,
9628 				typeof (Enum));
9629 			arrayType = tb.MakeArrayType ();
9630 			Assert.IsTrue (arrayType.IsArray, "#C1");
9631 			Assert.IsTrue (arrayType.HasElementType, "#C2");
9632 			Assert.IsFalse (tb.HasElementType, "#C3");
9633 			Assert.IsFalse (tb.IsCreated (), "#C4");
9634 		}
9635 
9636 		[Test]
GetCustomAttributes_InflatedType()9637 		public void GetCustomAttributes_InflatedType ()
9638 		{
9639 			TypeBuilder tb = module.DefineType (genTypeName ());
9640 			tb.DefineGenericParameters (new string[] { "FOO" });
9641 
9642 			ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9643 				new Type [] { typeof (string) });
9644 
9645 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9646 				new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9647 
9648 			tb.SetCustomAttribute (caBuilder);
9649 			Type t = tb.CreateType ();
9650 
9651 			Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9652 
9653 			Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9654 		}
9655 
9656 		[Test]
GetField()9657 		public void GetField ()
9658 		{
9659 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9660 			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9661 
9662 			ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9663 
9664 			FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9665 
9666 			Type t = tb.MakeGenericType (typeof (int));
9667 
9668 			// Chect that calling MakeArrayType () does not initialize the class
9669 			// (bug #351172)
9670 			t.MakeArrayType ();
9671 
9672 			// Check that the instantiation of a type builder contains live data
9673 			TypeBuilder.GetField (t, fb1);
9674 			FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9675 			FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9676 
9677 			MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9678 			ILGenerator ilgen = mb.GetILGenerator ();
9679 			ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9680 			ilgen.Emit (OpCodes.Dup);
9681 			ilgen.Emit (OpCodes.Ldc_I4, 42);
9682 			ilgen.Emit (OpCodes.Stfld, fi2);
9683 			ilgen.Emit (OpCodes.Ldfld, fi2);
9684 			ilgen.Emit (OpCodes.Ret);
9685 
9686 			// Check GetField on a type instantiated with type parameters
9687 			Type t3 = tb.MakeGenericType (typeParams [0]);
9688 			FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9689 			FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9690 
9691 			MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9692 			ILGenerator ilgen3 = mb3.GetILGenerator ();
9693 			ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9694 			ilgen3.Emit (OpCodes.Ldfld, fi3);
9695 			ilgen3.Emit (OpCodes.Ret);
9696 
9697 			Type created = tb.CreateType ();
9698 
9699 			Type inst = created.MakeGenericType (typeof (object));
9700 
9701 			Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9702 
9703 			Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9704 		}
9705 
9706 		[Test] //bug #354047
CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition()9707 		public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9708 		{
9709 			TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9710 			GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9711 			Type t = tb.CreateType ();
9712 
9713 			Type inst = tb.MakeGenericType (typeParams [0]);
9714 			Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9715 		}
9716 
9717 		[Test] //bug #354047
CreatedTypeAndTypeBuilderOwnTheirGenericArguments()9718 		public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9719 		{
9720 			TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9721 			GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9722 			Type t = tb.CreateType ();
9723 
9724 			Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9725 			Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9726 		}
9727 
9728 		[Test] //bug #354047
CreatedTypeAndTypeBuilderDontShareGenericArguments()9729 		public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9730 		{
9731 			TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9732 			GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9733 			Type t = tb.CreateType ();
9734 
9735 			Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9736 		}
9737 
9738 		[Test] //bug #399047
FieldOnTypeBuilderInstDontInflateWhenEncoded()9739 		public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9740 				assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, tempDir);
9741 
9742 				module = assembly.DefineDynamicModule ("Instance.exe");
9743 
9744                 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9745                 Type T = G.DefineGenericParameters ("T") [0];
9746 				ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9747                 Type GObj = G.MakeGenericType (new Type [] { T });
9748 
9749                 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9750 
9751                 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9752 
9753                 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9754                 Type TATest = Test.DefineGenericParameters ("TA") [0];
9755                 {
9756                         Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9757 
9758                         ILGenerator il = Test.GetILGenerator ();
9759 
9760                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9761                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9762                         il.Emit (OpCodes.Pop);
9763 
9764                         il.Emit (OpCodes.Ret);
9765                 }
9766 
9767  				MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9768 				{
9769 					ILGenerator il = main.GetILGenerator ();
9770 					il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9771 					il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9772 					il.Emit (OpCodes.Ret);
9773 				}
9774 
9775 				assembly.SetEntryPoint (main);
9776                 G.CreateType ();
9777                 var PCreated = P.CreateType ();
9778 
9779                 assembly.Save ("Instance.exe");
9780 
9781 		PCreated.InvokeMember ("Main", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, null);
9782 		}
9783 
9784 		[Test]
FieldWithInitializedDataWorksWithCompilerRuntimeHelpers()9785 		public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9786 		{
9787 			TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9788 			FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9789 			tb.CreateType ();
9790 
9791 			assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
9792 			module = assembly.DefineDynamicModule ("Instance.exe");
9793 
9794 			TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9795 			MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9796 			ILGenerator il = mb.GetILGenerator ();
9797 
9798 			il.Emit (OpCodes.Ldc_I4_1);
9799 			il.Emit (OpCodes.Newarr, typeof (int));
9800 			il.Emit (OpCodes.Dup);
9801 			il.Emit (OpCodes.Ldtoken, fb);
9802 			il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9803 			il.Emit (OpCodes.Ret);
9804 
9805 			Type t = tb2.CreateType ();
9806 			int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9807 			//Console.WriteLine (res[0]);
9808 		}
9809 
9810 		[Test]
FieldWithInitializedDataWorksWithCompilerRuntimeHelpers2()9811 		public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers2 ()
9812 		{
9813 			TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9814 			var garg = tb.DefineGenericParameters ("T") [0];
9815 			FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9816 			tb.CreateType ();
9817 
9818 			assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
9819 			module = assembly.DefineDynamicModule ("Instance.exe");
9820 
9821 			TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9822 			MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9823 			ILGenerator il = mb.GetILGenerator ();
9824 
9825 			il.Emit (OpCodes.Ldc_I4_1);
9826 			il.Emit (OpCodes.Newarr, typeof (int));
9827 			il.Emit (OpCodes.Dup);
9828 			il.Emit (OpCodes.Ldtoken, fb);
9829 			il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9830 			il.Emit (OpCodes.Ret);
9831 
9832 			Type t = tb2.CreateType ();
9833 			int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9834 			//Console.WriteLine (res[0]);
9835 		}
9836 
9837 		public interface IDelegateFactory
9838 		{
Create(Delegate del)9839 			Delegate Create (Delegate del);
9840 		}
9841 
9842 		[Test]
CreateType_Ctor_NoBody()9843 		public void CreateType_Ctor_NoBody ()
9844 		{
9845 			TypeBuilder tb = module.DefineType (genTypeName ());
9846 			tb.DefineConstructor (MethodAttributes.Public,
9847 				CallingConventions.Standard,
9848 				new Type [] { typeof (string) });
9849 			try {
9850 				tb.CreateType ();
9851 				Assert.Fail ("#1");
9852 			} catch (InvalidOperationException ex) {
9853 				// Method '.ctor' does not have a method body
9854 				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9855 				Assert.IsNull (ex.InnerException, "#3");
9856 				Assert.IsNotNull (ex.Message, "#4");
9857 				Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9858 			}
9859 		}
9860 
9861 		[Test] //bug #361689
CreateTypeFailsWithInvalidMethodOverride()9862 		public void CreateTypeFailsWithInvalidMethodOverride ()
9863 		{
9864 			TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9865 
9866 			MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
9867 			ILGenerator gen = mc.GetILGenerator ();
9868 			gen.Emit (OpCodes.Ldarg_0);
9869 			gen.Emit (OpCodes.Ret);
9870 			tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
9871 			try {
9872 				tb.CreateType ();
9873 				Assert.Fail ("#1 create type did not throw TypeLoadException");
9874 			} catch (TypeLoadException) {
9875 
9876 			}
9877 		}
9878 
9879 		[Test] //bug #349194
IsAssignableToWorksWithInterfacesOnParent()9880 		public void IsAssignableToWorksWithInterfacesOnParent ()
9881 		{
9882             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9883 			TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
9884 
9885 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9886 			Type t = tb.CreateType ();
9887 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9888 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
9889 
9890 
9891 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9892 			Type t2 = tb2.CreateType ();
9893 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9894 			Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
9895 		}
9896 
9897 
9898 		[Test] //bug #430508
MakeGenericTypeRespectBaseType()9899 		public void MakeGenericTypeRespectBaseType ()
9900 		{
9901             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9902 			EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
9903 
9904 			MethodBuilder mb = tb.DefineMethod ("Test",
9905 												MethodAttributes.Public,
9906 												typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
9907 												new Type [0]);
9908 			ILGenerator il = mb.GetILGenerator();
9909 			il.Emit (OpCodes.Ldnull);
9910 			il.Emit (OpCodes.Ret);
9911 
9912 			Type e = eb.CreateType ();
9913 			Type c = tb.CreateType ();
9914 
9915 			Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
9916 		}
9917 
9918 		[Test]
GetCustomAttrOnFieldOfInflatedType()9919 		public void GetCustomAttrOnFieldOfInflatedType ()
9920 		{
9921 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9922 			tb.DefineGenericParameters ("T");
9923 
9924 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9925 				typeof (SimpleTestAttribute).GetConstructors ()[0],
9926 				new object [0]);
9927 
9928 			FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9929 			field.SetCustomAttribute (caBuilder);
9930 
9931 			Type t = tb.CreateType ();
9932 
9933 			FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9934 			object[] cattrs = fi.GetCustomAttributes (false);
9935 			Assert.AreEqual (1, cattrs.Length);
9936 
9937 			fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9938 			cattrs = fi.GetCustomAttributes (false);
9939 			Assert.AreEqual (1, cattrs.Length);
9940 		}
9941 
9942 		[Test]
GetCustomAttrOnPropertyOfInflatedType()9943 		public void GetCustomAttrOnPropertyOfInflatedType ()
9944 		{
9945 			TypeBuilder tb = module.DefineType (genTypeName ());
9946 			tb.DefineGenericParameters ("T");
9947 
9948 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9949 				typeof (SimpleTestAttribute).GetConstructors ()[0],
9950 				new object [0]);
9951 
9952 			PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
9953 			property.SetCustomAttribute (caBuilder);
9954 
9955 			Type t = tb.CreateType ();
9956 
9957 			PropertyInfo pi = t.GetProperties ()[0];
9958 			object[] cattrs = pi.GetCustomAttributes (false);
9959 			Assert.AreEqual (1, cattrs.Length);
9960 
9961 			pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
9962 			cattrs = pi.GetCustomAttributes (false);
9963 			Assert.AreEqual (1, cattrs.Length);
9964 		}
9965 
9966 		[Test]
GetCustomAttrOnEventOfInflatedType()9967 		public void GetCustomAttrOnEventOfInflatedType ()
9968 		{
9969 			TypeBuilder tb = module.DefineType (genTypeName ());
9970 			tb.DefineGenericParameters ("T");
9971 
9972 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9973 				typeof (SimpleTestAttribute).GetConstructors ()[0],
9974 				new object [0]);
9975 
9976 			EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
9977 			evt.SetCustomAttribute (caBuilder);
9978 
9979 			Type t = tb.CreateType ();
9980 
9981 			EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9982 			object[] cattrs = ei.GetCustomAttributes (false);
9983 			Assert.AreEqual (1, cattrs.Length);
9984 
9985 			ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9986 			cattrs = ei.GetCustomAttributes (false);
9987 			Assert.AreEqual (1, cattrs.Length);
9988 		}
9989 
TestDoubleInitializationOfMonoGenericClass()9990 		public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
9991 		{
9992 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9993 			tb.DefineGenericParameters ("T");
9994 
9995 			CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9996 				typeof (SimpleTestAttribute).GetConstructors ()[0],
9997 				new object [0]);
9998 
9999 			FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
10000 			field.SetCustomAttribute (caBuilder);
10001 
10002 
10003 			tb.MakeGenericType (typeof (int)).GetMethods ();
10004 			tb.MakeGenericType (typeof (double)).GetMethods ();
10005 
10006 			Type t = tb.CreateType ();
10007 
10008 			t.MakeGenericType (typeof (int)).GetMethods ();
10009 			t.MakeGenericType (typeof (double)).GetMethods ();
10010 		}
10011 
10012 		[Test]
TestGenericFieldAccess()10013 		public void TestGenericFieldAccess () // bug #467415
10014 		{
10015 			AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
10016 			AppDomain domain = AppDomain.CurrentDomain;
10017 			AssemblyBuilder demoAssembly =
10018 				domain.DefineDynamicAssembly(asmName,
10019 						AssemblyBuilderAccess.RunAndSave);
10020 
10021 			// Define the module that contains the code. For an
10022 			// assembly with one module, the module name is the
10023 			// assembly name plus a file extension.
10024 			ModuleBuilder demoModule =
10025 				demoAssembly.DefineDynamicModule(asmName.Name,
10026 						asmName.Name+".dll");
10027 
10028 			TypeBuilder demoType =
10029 				demoModule.DefineType("DemoType", TypeAttributes.Public);
10030 
10031 			MethodBuilder factory =
10032 				demoType.DefineMethod("Factory",
10033 						MethodAttributes.Public | MethodAttributes.Static);
10034 
10035 			string[] typeParameterNames = {"T"};
10036 			GenericTypeParameterBuilder[] typeParameters =
10037 				factory.DefineGenericParameters(typeParameterNames);
10038 
10039 			GenericTypeParameterBuilder T = typeParameters[0];
10040 
10041 			Type[] parms = {};
10042 			factory.SetParameters(parms);
10043 
10044 			factory.SetReturnType(T);
10045 
10046 			ILGenerator ilgen = factory.GetILGenerator();
10047 
10048 			Type G = typeof(Gen<>);
10049 			Type GT = G.MakeGenericType (T);
10050 			FieldInfo GF = G.GetField("field");
10051 			FieldInfo GTF = TypeBuilder.GetField(GT, GF);
10052 
10053 			ilgen.Emit(OpCodes.Ldsfld, GTF);
10054 			ilgen.Emit(OpCodes.Ret);
10055 
10056 			// Complete the type.
10057 			Type dt = demoType.CreateType();
10058 			// Save the assembly, so it can be examined with Ildasm.exe.
10059 			//demoAssembly.Save(asmName.Name+".dll");
10060 
10061 			MethodInfo m = dt.GetMethod("Factory");
10062 			MethodInfo bound = m.MakeGenericMethod(typeof(int));
10063 
10064 			// Display a string representing the bound method.
10065 			//Console.WriteLine(bound);
10066 
10067 			object[] parameters = {};
10068 			int result = (int)(bound.Invoke(null, parameters));
10069 
10070 			Assert.AreEqual (0, result, "#1");
10071 		}
10072 
GetMethodByName(MethodInfo [] methods, string name)10073 		static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
10074 		{
10075 			foreach (MethodInfo mi in methods)
10076 				if (mi.Name == name)
10077 					return mi;
10078 			return null;
10079 		}
10080 
CreateMembers(TypeBuilder tb, string suffix, bool defineCtors)10081 		void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
10082 		{
10083 			ConstructorBuilder cb;
10084 			MethodBuilder mb;
10085 			PropertyBuilder pb;
10086 			EventBuilder eb;
10087 			ILGenerator ilgen;
10088 
10089 			if (defineCtors) {
10090 				//
10091 				// instance constructors
10092 				//
10093 				cb = tb.DefineConstructor (MethodAttributes.Private,
10094 					CallingConventions.Standard,
10095 					new Type [] { typeof (int), typeof (int) });
10096 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10097 
10098 				cb = tb.DefineConstructor (MethodAttributes.Family,
10099 					CallingConventions.Standard,
10100 					new Type [] { typeof (string) });
10101 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10102 
10103 				cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10104 					CallingConventions.Standard,
10105 					new Type [] { typeof (string), typeof (string) });
10106 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10107 
10108 				cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10109 					CallingConventions.Standard,
10110 					new Type [] { typeof (int) });
10111 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10112 
10113 				cb = tb.DefineConstructor (MethodAttributes.Public,
10114 					CallingConventions.Standard,
10115 					new Type [] { typeof (int), typeof (bool) });
10116 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10117 
10118 				cb = tb.DefineConstructor (MethodAttributes.Assembly,
10119 					CallingConventions.Standard,
10120 					new Type [] { typeof (string), typeof (int) });
10121 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10122 
10123 				//
10124 				// static constructors
10125 				//
10126 
10127 				cb = tb.DefineConstructor (MethodAttributes.Private |
10128 					MethodAttributes.Static,
10129 					CallingConventions.Standard,
10130 					Type.EmptyTypes);
10131 				cb.GetILGenerator ().Emit (OpCodes.Ret);
10132 			}
10133 
10134 			//
10135 			// instance methods
10136 			//
10137 
10138 			mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10139 				MethodAttributes.Private, typeof (void),
10140 				Type.EmptyTypes);
10141 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10142 
10143 			mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10144 				MethodAttributes.Family, typeof (void),
10145 				Type.EmptyTypes);
10146 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10147 
10148 			mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10149 				MethodAttributes.FamANDAssem, typeof (void),
10150 				Type.EmptyTypes);
10151 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10152 
10153 			mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10154 				MethodAttributes.FamORAssem, typeof (void),
10155 				Type.EmptyTypes);
10156 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10157 
10158 			mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10159 				MethodAttributes.Public, typeof (void),
10160 				Type.EmptyTypes);
10161 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10162 
10163 			mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10164 				MethodAttributes.Assembly, typeof (void),
10165 				Type.EmptyTypes);
10166 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10167 
10168 			//
10169 			// static methods
10170 			//
10171 
10172 			mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10173 				MethodAttributes.Private | MethodAttributes.Static,
10174 				typeof (void), Type.EmptyTypes);
10175 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10176 
10177 			mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10178 				MethodAttributes.Family | MethodAttributes.Static,
10179 				typeof (void), Type.EmptyTypes);
10180 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10181 
10182 			mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10183 				MethodAttributes.FamANDAssem | MethodAttributes.Static,
10184 				typeof (void), Type.EmptyTypes);
10185 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10186 
10187 			mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10188 				MethodAttributes.FamORAssem | MethodAttributes.Static,
10189 				typeof (void), Type.EmptyTypes);
10190 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10191 
10192 			mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10193 				MethodAttributes.Public | MethodAttributes.Static,
10194 				typeof (void), Type.EmptyTypes);
10195 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10196 
10197 			mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10198 				MethodAttributes.Assembly | MethodAttributes.Static,
10199 				typeof (void), Type.EmptyTypes);
10200 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10201 
10202 			//
10203 			// instance fields
10204 			//
10205 
10206 			tb.DefineField ("privateInstance" + suffix,
10207 				typeof (string), FieldAttributes.Private);
10208 			tb.DefineField ("familyInstance" + suffix,
10209 				typeof (string), FieldAttributes.Family);
10210 			tb.DefineField ("famANDAssemInstance" + suffix,
10211 				typeof (string), FieldAttributes.FamANDAssem);
10212 			tb.DefineField ("famORAssemInstance" + suffix,
10213 				typeof (string), FieldAttributes.FamORAssem);
10214 			tb.DefineField ("publicInstance" + suffix,
10215 				typeof (string), FieldAttributes.Public);
10216 			tb.DefineField ("assemblyInstance" + suffix,
10217 				typeof (string), FieldAttributes.Assembly);
10218 
10219 			//
10220 			// static fields
10221 			//
10222 
10223 			tb.DefineField ("privateStatic" + suffix,
10224 				typeof (string), FieldAttributes.Private |
10225 				FieldAttributes.Static);
10226 			tb.DefineField ("familyStatic" + suffix,
10227 				typeof (string), FieldAttributes.Family |
10228 				FieldAttributes.Static);
10229 			tb.DefineField ("famANDAssemStatic" + suffix,
10230 				typeof (string), FieldAttributes.FamANDAssem |
10231 				FieldAttributes.Static);
10232 			tb.DefineField ("famORAssemStatic" + suffix,
10233 				typeof (string), FieldAttributes.FamORAssem |
10234 				FieldAttributes.Static);
10235 			tb.DefineField ("publicStatic" + suffix,
10236 				typeof (string), FieldAttributes.Public |
10237 				FieldAttributes.Static);
10238 			tb.DefineField ("assemblyStatic" + suffix,
10239 				typeof (string), FieldAttributes.Assembly |
10240 				FieldAttributes.Static);
10241 
10242 			//
10243 			// instance properties
10244 			//
10245 
10246 			pb = tb.DefineProperty ("PrivateInstance" + suffix,
10247 				PropertyAttributes.None, typeof (string),
10248 				Type.EmptyTypes);
10249 			mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10250 				MethodAttributes.Private, typeof (string),
10251 				Type.EmptyTypes);
10252 			ilgen = mb.GetILGenerator ();
10253 			ilgen.Emit (OpCodes.Ldnull);
10254 			ilgen.Emit (OpCodes.Ret);
10255 			pb.SetGetMethod (mb);
10256 
10257 			pb = tb.DefineProperty ("FamilyInstance" + suffix,
10258 				PropertyAttributes.None, typeof (string),
10259 				Type.EmptyTypes);
10260 			mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10261 				MethodAttributes.Family, typeof (string),
10262 				Type.EmptyTypes);
10263 			ilgen = mb.GetILGenerator ();
10264 			ilgen.Emit (OpCodes.Ldnull);
10265 			ilgen.Emit (OpCodes.Ret);
10266 			pb.SetGetMethod (mb);
10267 
10268 			pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10269 				PropertyAttributes.None, typeof (string),
10270 				Type.EmptyTypes);
10271 			mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10272 				MethodAttributes.FamANDAssem, typeof (string),
10273 				Type.EmptyTypes);
10274 			ilgen = mb.GetILGenerator ();
10275 			ilgen.Emit (OpCodes.Ldnull);
10276 			ilgen.Emit (OpCodes.Ret);
10277 			pb.SetGetMethod (mb);
10278 
10279 			pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10280 				PropertyAttributes.None, typeof (string),
10281 				Type.EmptyTypes);
10282 			mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10283 				MethodAttributes.FamORAssem, typeof (string),
10284 				Type.EmptyTypes);
10285 			ilgen = mb.GetILGenerator ();
10286 			ilgen.Emit (OpCodes.Ldnull);
10287 			ilgen.Emit (OpCodes.Ret);
10288 			pb.SetGetMethod (mb);
10289 
10290 			pb = tb.DefineProperty ("PublicInstance" + suffix,
10291 				PropertyAttributes.None, typeof (string),
10292 				Type.EmptyTypes);
10293 			mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10294 				MethodAttributes.Public, typeof (string),
10295 				Type.EmptyTypes);
10296 			ilgen = mb.GetILGenerator ();
10297 			ilgen.Emit (OpCodes.Ldnull);
10298 			ilgen.Emit (OpCodes.Ret);
10299 			pb.SetGetMethod (mb);
10300 
10301 			pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10302 				PropertyAttributes.None, typeof (string),
10303 				Type.EmptyTypes);
10304 			mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10305 				MethodAttributes.Assembly, typeof (string),
10306 				Type.EmptyTypes);
10307 			ilgen = mb.GetILGenerator ();
10308 			ilgen.Emit (OpCodes.Ldnull);
10309 			ilgen.Emit (OpCodes.Ret);
10310 			pb.SetGetMethod (mb);
10311 
10312 			//
10313 			// static properties
10314 			//
10315 
10316 			pb = tb.DefineProperty ("PrivateStatic" + suffix,
10317 				PropertyAttributes.None, typeof (string),
10318 				Type.EmptyTypes);
10319 			mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10320 				MethodAttributes.Private | MethodAttributes.Static,
10321 				typeof (string), Type.EmptyTypes);
10322 			ilgen = mb.GetILGenerator ();
10323 			ilgen.Emit (OpCodes.Ldnull);
10324 			ilgen.Emit (OpCodes.Ret);
10325 			pb.SetGetMethod (mb);
10326 
10327 			pb = tb.DefineProperty ("FamilyStatic" + suffix,
10328 				PropertyAttributes.None, typeof (string),
10329 				Type.EmptyTypes);
10330 			mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10331 				MethodAttributes.Family | MethodAttributes.Static,
10332 				typeof (string), Type.EmptyTypes);
10333 			ilgen = mb.GetILGenerator ();
10334 			ilgen.Emit (OpCodes.Ldnull);
10335 			ilgen.Emit (OpCodes.Ret);
10336 			pb.SetGetMethod (mb);
10337 
10338 			pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10339 				PropertyAttributes.None, typeof (string),
10340 				Type.EmptyTypes);
10341 			mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10342 				MethodAttributes.FamANDAssem | MethodAttributes.Static,
10343 				typeof (string), Type.EmptyTypes);
10344 			ilgen = mb.GetILGenerator ();
10345 			ilgen.Emit (OpCodes.Ldnull);
10346 			ilgen.Emit (OpCodes.Ret);
10347 			pb.SetGetMethod (mb);
10348 
10349 			pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10350 				PropertyAttributes.None, typeof (string),
10351 				Type.EmptyTypes);
10352 			mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10353 				MethodAttributes.FamORAssem | MethodAttributes.Static,
10354 				typeof (string), Type.EmptyTypes);
10355 			ilgen = mb.GetILGenerator ();
10356 			ilgen.Emit (OpCodes.Ldnull);
10357 			ilgen.Emit (OpCodes.Ret);
10358 			pb.SetGetMethod (mb);
10359 
10360 			pb = tb.DefineProperty ("PublicStatic" + suffix,
10361 				PropertyAttributes.None, typeof (string),
10362 				Type.EmptyTypes);
10363 			mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10364 				MethodAttributes.Public | MethodAttributes.Static,
10365 				typeof (string), Type.EmptyTypes);
10366 			ilgen = mb.GetILGenerator ();
10367 			ilgen.Emit (OpCodes.Ldnull);
10368 			ilgen.Emit (OpCodes.Ret);
10369 			pb.SetGetMethod (mb);
10370 
10371 			pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10372 				PropertyAttributes.None, typeof (string),
10373 				Type.EmptyTypes);
10374 			mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10375 				MethodAttributes.Assembly | MethodAttributes.Static,
10376 				typeof (string), Type.EmptyTypes);
10377 			ilgen = mb.GetILGenerator ();
10378 			ilgen.Emit (OpCodes.Ldnull);
10379 			ilgen.Emit (OpCodes.Ret);
10380 			pb.SetGetMethod (mb);
10381 
10382 			//
10383 			// instance events
10384 			//
10385 
10386 			eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10387 				EventAttributes.None, typeof (EventHandler));
10388 			mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10389 				MethodAttributes.Private, typeof (void),
10390 				Type.EmptyTypes);
10391 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10392 			eb.SetAddOnMethod (mb);
10393 
10394 			eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10395 				EventAttributes.None, typeof (EventHandler));
10396 			mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10397 				MethodAttributes.Family, typeof (void),
10398 				Type.EmptyTypes);
10399 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10400 			eb.SetAddOnMethod (mb);
10401 
10402 			eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10403 				EventAttributes.None, typeof (EventHandler));
10404 			mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10405 				MethodAttributes.FamANDAssem, typeof (void),
10406 				Type.EmptyTypes);
10407 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10408 			eb.SetAddOnMethod (mb);
10409 
10410 			eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10411 				EventAttributes.None, typeof (EventHandler));
10412 			mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10413 				MethodAttributes.FamORAssem, typeof (void),
10414 				Type.EmptyTypes);
10415 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10416 			eb.SetAddOnMethod (mb);
10417 
10418 			eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10419 				EventAttributes.None, typeof (EventHandler));
10420 			mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10421 				MethodAttributes.Public, typeof (void),
10422 				Type.EmptyTypes);
10423 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10424 			eb.SetAddOnMethod (mb);
10425 
10426 			eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10427 				EventAttributes.None, typeof (EventHandler));
10428 			mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10429 				MethodAttributes.Family, typeof (void),
10430 				Type.EmptyTypes);
10431 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10432 			eb.SetAddOnMethod (mb);
10433 
10434 			//
10435 			// static events
10436 			//
10437 
10438 			eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10439 				EventAttributes.None, typeof (EventHandler));
10440 			mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10441 				MethodAttributes.Private | MethodAttributes.Static,
10442 				typeof (void), Type.EmptyTypes);
10443 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10444 			eb.SetAddOnMethod (mb);
10445 
10446 			eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10447 				EventAttributes.None, typeof (EventHandler));
10448 			mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10449 				MethodAttributes.Family | MethodAttributes.Static,
10450 				typeof (void), Type.EmptyTypes);
10451 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10452 			eb.SetAddOnMethod (mb);
10453 
10454 			eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10455 				EventAttributes.None, typeof (EventHandler));
10456 			mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10457 				MethodAttributes.FamANDAssem | MethodAttributes.Static,
10458 				typeof (void), Type.EmptyTypes);
10459 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10460 			eb.SetAddOnMethod (mb);
10461 
10462 			eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10463 				EventAttributes.None, typeof (EventHandler));
10464 			mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10465 				MethodAttributes.FamORAssem | MethodAttributes.Static,
10466 				typeof (void), Type.EmptyTypes);
10467 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10468 			eb.SetAddOnMethod (mb);
10469 
10470 			eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10471 				EventAttributes.None, typeof (EventHandler));
10472 			mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10473 				MethodAttributes.Public | MethodAttributes.Static,
10474 				typeof (void), Type.EmptyTypes);
10475 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10476 			eb.SetAddOnMethod (mb);
10477 
10478 			eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10479 				EventAttributes.None, typeof (EventHandler));
10480 			mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10481 				MethodAttributes.Family | MethodAttributes.Static,
10482 				typeof (void), Type.EmptyTypes);
10483 			mb.GetILGenerator ().Emit (OpCodes.Ret);
10484 			eb.SetAddOnMethod (mb);
10485 		}
10486 
10487 		static TypeBuilder Resolve1_Tb;
10488 		static bool Resolve1_Called;
10489 
10490 		public class Lookup<T>
10491 		{
10492 			public static Type t = typeof(T);
10493 		}
10494 
Resolve1(object sender, ResolveEventArgs args)10495 		Assembly Resolve1 (object sender, ResolveEventArgs args) {
10496 			Resolve1_Called = true;
10497 			Resolve1_Tb.CreateType ();
10498 			return Resolve1_Tb.Assembly;
10499 		}
10500 
10501 		[Test]
TypeResolveGenericInstances()10502 		public void TypeResolveGenericInstances () {
10503 			// Test that TypeResolve is called for generic instances (#483852)
10504 			TypeBuilder tb1 = null;
10505 
10506 			AppDomain.CurrentDomain.TypeResolve += Resolve1;
10507 
10508 			tb1 = module.DefineType("Foo");
10509 			Resolve1_Tb = tb1;
10510 			FieldInfo field = TypeBuilder.GetField(typeof(Lookup<>).MakeGenericType(tb1), typeof(Lookup<>).GetField("t"));
10511 			TypeBuilder tb2 = module.DefineType("Bar");
10512 			ConstructorBuilder cb = tb2.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
10513 			ILGenerator ilgen = cb.GetILGenerator();
10514 
10515 			ilgen.Emit(OpCodes.Ldarg_0);
10516 			ilgen.Emit(OpCodes.Call, tb2.BaseType.GetConstructor(Type.EmptyTypes));
10517 
10518 			ilgen.Emit(OpCodes.Ldsfld, field);
10519 			ilgen.Emit(OpCodes.Pop);
10520 			ilgen.Emit(OpCodes.Ret);
10521 			Activator.CreateInstance(tb2.CreateType());
10522 
10523 			Assert.IsTrue (Resolve1_Called);
10524 		}
10525 
10526 		[Test]
CreateConcreteTypeWithAbstractMethod()10527 		public void CreateConcreteTypeWithAbstractMethod ()
10528 		{
10529 			TypeBuilder tb = module.DefineType (genTypeName ());
10530 			tb.DefineMethod("method", MethodAttributes.Abstract | MethodAttributes.Public, typeof (void), Type.EmptyTypes);
10531 			try {
10532 				tb.CreateType ();
10533 				Assert.Fail ("#1");
10534 			} catch (InvalidOperationException) {}
10535 		}
10536 
10537 		[Test]
ConcreteTypeDontLeakGenericParamFromItSelf()10538 		public void ConcreteTypeDontLeakGenericParamFromItSelf ()
10539 		{
10540             var tb = module.DefineType (genTypeName ());
10541 			var gps = tb.DefineGenericParameters ("T");
10542             var mb = tb.DefineMethod ("m", MethodAttributes.Public | MethodAttributes.Static);
10543             mb.SetParameters (gps);
10544             mb.GetILGenerator ().Emit (OpCodes.Ret);
10545 
10546             var ti = tb.CreateType ();
10547             var mi = ti.GetMethod ("m");
10548 			var arg0 = mi.GetParameters () [0].ParameterType;
10549 
10550 			Assert.AreNotSame (arg0, gps [0], "#1");
10551 		}
10552 
10553 		[Test]
ConcreteTypeDontLeakGenericParamFromMethods()10554 		public void ConcreteTypeDontLeakGenericParamFromMethods ()
10555 		{
10556             var tb = module.DefineType (genTypeName ());
10557             var mb = tb.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Static);
10558             var gps = mb.DefineGenericParameters ("T");
10559             mb.SetParameters (gps);
10560             mb.GetILGenerator ().Emit (OpCodes.Ret);
10561 
10562             var ti = tb.CreateType ();
10563             var mi = ti.GetMethod ("m");
10564  			var arg0 = mi.GetParameters () [0].ParameterType;
10565 
10566 			Assert.AreNotSame (arg0, gps [0], "#1");
10567 		}
10568 
10569 		[Test]
DeclaringMethodReturnsNull()10570 		public void DeclaringMethodReturnsNull ()
10571 		{
10572 			TypeBuilder tb = module.DefineType (genTypeName ());
10573 			Assert.IsNull (tb.DeclaringMethod, null, "#1");
10574 		}
10575 
10576 		[Test]
GenericParameterPositionReturns0()10577 		public void GenericParameterPositionReturns0 ()
10578 		{
10579 			TypeBuilder tb = module.DefineType (genTypeName ());
10580 			Assert.AreEqual (0, tb.GenericParameterPosition, "#1");
10581 		}
10582 
10583 		[Test]
GetGenericTypeDefinitionBehavior()10584 		public void GetGenericTypeDefinitionBehavior ()
10585 		{
10586 			TypeBuilder tb = module.DefineType (genTypeName ());
10587 			try {
10588 				tb.GetGenericTypeDefinition ();
10589 				Assert.Fail ("#1");
10590 			} catch (InvalidOperationException) {}
10591 
10592 			tb.DefineGenericParameters ("T");
10593 			Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#2");
10594 
10595 			tb.CreateType ();
10596 			Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#3");
10597 		}
10598 
10599 		[Test]
GetElementTypeNotSupported()10600 		public void GetElementTypeNotSupported ()
10601 		{
10602 			TypeBuilder tb = module.DefineType (genTypeName ());
10603 			try {
10604 				tb.GetElementType ();
10605 				Assert.Fail ("#1");
10606 			} catch (NotSupportedException) {}
10607 		}
10608 
10609 		[Test]
GenericParameterAttributesReturnsNone()10610 		public void GenericParameterAttributesReturnsNone ()
10611 		{
10612 			TypeBuilder tb = module.DefineType (genTypeName ());
10613 			Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#1");
10614 
10615 			tb.DefineGenericParameters ("T");
10616 			Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#2");
10617 
10618 			tb.CreateType ();
10619 			Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#3");
10620 		}
10621 
10622 		[Test]
GetGenericArgumentsReturnsNullForNonGenericTypeBuilder()10623 		public void GetGenericArgumentsReturnsNullForNonGenericTypeBuilder ()
10624 		{
10625 			TypeBuilder tb = module.DefineType (genTypeName ());
10626 			Assert.IsNull (tb.GetGenericArguments (), "#1");
10627 		}
10628 
10629 		public interface IFaceA {}
10630 		public interface IFaceB : IFaceA {}
10631 		[Test]
GetInterfacesAfterCreate()10632 		public void GetInterfacesAfterCreate ()
10633 		{
10634 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type[] { typeof (IFaceB) });
10635 
10636 			Type[] ifaces = tb.GetInterfaces ();
10637 			Assert.AreEqual (1, ifaces.Length, "#1");
10638 			Assert.AreEqual (typeof (IFaceB), ifaces [0], "#2");
10639 
10640 			tb.CreateType ();
10641 			ifaces = tb.GetInterfaces ();
10642 			Assert.AreEqual (2, ifaces.Length, "#3");
10643 			//Interfaces can come in any particular order
10644 			if (ifaces [0] == typeof (IFaceB)) {
10645 				Assert.AreEqual (typeof (IFaceB), ifaces [0], "#4");
10646 				Assert.AreEqual (typeof (IFaceA), ifaces [1], "#5");
10647 			} else {
10648 				Assert.AreEqual (typeof (IFaceB), ifaces [1], "#4");
10649 				Assert.AreEqual (typeof (IFaceA), ifaces [0], "#5");
10650 			}
10651 		}
10652 
10653 		public interface MB_Iface
10654 		{
Test()10655 		    int Test ();
10656 		}
10657 
10658 		public class MB_Impl : MB_Iface
10659 		{
Test()10660 		    public virtual int Test () { return 1; }
10661 		}
10662 		[Test]
MethodOverrideBodyMustBelongToTypeBuilder()10663 		public void MethodOverrideBodyMustBelongToTypeBuilder ()
10664 		{
10665 			TypeBuilder tb = module.DefineType (genTypeName ());
10666 			MethodInfo md = typeof (MB_Iface).GetMethod("Test");
10667             MethodInfo md2 = typeof (MB_Impl).GetMethod("Test");
10668 			try {
10669             	tb.DefineMethodOverride (md, md2);
10670             	Assert.Fail ("#1");
10671 			} catch (ArgumentException) {}
10672 		}
10673 
10674 		[Test]
GetConstructorsThrowWhenIncomplete()10675 		public void GetConstructorsThrowWhenIncomplete ()
10676 		{
10677 			TypeBuilder tb = module.DefineType (genTypeName ());
10678 			try {
10679 				tb.GetConstructors (BindingFlags.Instance);
10680 				Assert.Fail ("#1");
10681 			} catch (NotSupportedException) { }
10682 
10683 			tb.CreateType ();
10684 			Assert.IsNotNull (tb.GetConstructors (BindingFlags.Instance), "#2");
10685 		}
10686 
10687 		[Test]
GetEventsThrowWhenIncomplete()10688 		public void GetEventsThrowWhenIncomplete ()
10689 		{
10690 			TypeBuilder tb = module.DefineType (genTypeName ());
10691 			try {
10692 				tb.GetEvents (BindingFlags.Instance);
10693 				Assert.Fail ("#1");
10694 			} catch (NotSupportedException) { }
10695 
10696 			tb.CreateType ();
10697 			Assert.IsNotNull (tb.GetEvents (BindingFlags.Instance), "#2");
10698 		}
10699 
10700 		[Test]
GetNestedTypeCreatedAfterTypeIsCreated()10701 		public void GetNestedTypeCreatedAfterTypeIsCreated ()
10702 		{
10703 			TypeBuilder tb = module.DefineType (genTypeName ());
10704 			TypeBuilder nested = tb.DefineNestedType ("Bar", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10705 			tb.CreateType ();
10706 			Assert.IsNull (tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#1");
10707 			Type res = nested.CreateType ();
10708 			Assert.AreEqual (res, tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#2");
10709 
10710 			TypeBuilder nested2 = tb.DefineNestedType ("Bar2", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10711 			Assert.IsNull (tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#3");
10712 			res = nested2.CreateType ();
10713 			Assert.AreEqual (res, tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#4");
10714 		}
10715 
10716 
10717 		[Test]
IsDefinedThrowWhenIncomplete()10718 		public void IsDefinedThrowWhenIncomplete ()
10719 		{
10720 			TypeBuilder tb = module.DefineType (genTypeName ());
10721 			try {
10722 				tb.IsDefined (typeof (string), true);
10723 				Assert.Fail ("#1");
10724 			} catch (NotSupportedException) { }
10725 
10726 			tb.CreateType ();
10727 			Assert.IsNotNull (tb.IsDefined (typeof (string), true), "#2");
10728 		}
10729 
10730 		[Test] //Bug #594728
IsSubclassOfWorksIfSetParentIsCalledOnParent()10731 		public void IsSubclassOfWorksIfSetParentIsCalledOnParent ()
10732 		{
10733 			var tb_a = module.DefineType ("A", TypeAttributes.Public);
10734 			var tb_b = module.DefineType ("B", TypeAttributes.Public);
10735 
10736 			tb_b.SetParent (tb_a);
10737 			tb_a.SetParent (typeof (Attribute));
10738 
10739 			Assert.IsTrue (tb_b.IsSubclassOf (tb_a), "#1");
10740 			Assert.IsTrue (tb_b.IsSubclassOf (typeof (Attribute)), "#2");
10741 			Assert.IsFalse (tb_a.IsSubclassOf (tb_b), "#3");
10742 
10743 
10744 			var a = tb_a.CreateType ();
10745 			var b = tb_b.CreateType ();
10746 
10747 			Assert.IsTrue (b.IsSubclassOf (a), "#4");
10748 			Assert.IsTrue (b.IsSubclassOf (typeof (Attribute)), "#5");
10749 			Assert.IsFalse (a.IsSubclassOf (b), "#6");
10750 		}
10751 
10752 		[Test]
DefinedDefaultConstructorWorksWithGenericBaseType()10753 		public void DefinedDefaultConstructorWorksWithGenericBaseType ()
10754 		{
10755 			AssemblyName assemblyName = new AssemblyName ("a");
10756 			AssemblyBuilder ass = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.RunAndSave);
10757 			var mb = ass.DefineDynamicModule ("a.dll");
10758 
10759 			var tb = mb.DefineType ("Base");
10760 			tb.DefineGenericParameters ("F");
10761 
10762 			var inst = tb.MakeGenericType (typeof (int));
10763 			var tb2 = mb.DefineType ("Child", TypeAttributes.Public, inst);
10764 
10765 			tb.CreateType ();
10766 			var res = tb2.CreateType ();
10767 
10768 			Assert.IsNotNull (res, "#1");
10769 			Assert.AreEqual (1, res.GetConstructors ().Length, "#2");
10770 		}
10771 
10772 		/*
10773 		 * Tests for passing user types to Ref.Emit. Currently these only test
10774 		 * whenever the runtime code can handle them without crashing, since we
10775 		 * don't support user types yet.
10776 		 * These tests are disabled for windows since the MS runtime trips on them.
10777 		 */
10778 		[Test]
10779 		[Category ("NotDotNet")] //Proper UT handling is a mono extension to SRE bugginess
UserTypes()10780 		public void UserTypes () {
10781 			TypeDelegator t = new TypeDelegator (typeof (int));
10782 
10783 			try {
10784 				/* Parent */
10785 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10786 			} catch {
10787 			}
10788 
10789 			try {
10790 				/* Interfaces */
10791 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10792 				tb.CreateType ();
10793 			} catch {
10794 			}
10795 
10796 			try {
10797 				/* Fields */
10798 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10799 				tb.DefineField ("Foo", t, FieldAttributes.Public);
10800 				tb.CreateType ();
10801 			} catch {
10802 			}
10803 
10804 			try {
10805 				/* Custom modifiers on fields */
10806 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10807 				tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10808 				tb.CreateType ();
10809 			} catch {
10810 			}
10811 /* this is mono only
10812 			try {
10813 				UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10814 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10815 				FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10816 				fb.SetMarshal (m);
10817 				tb.CreateType ();
10818 			} catch {
10819 			}
10820 */
10821 			try {
10822 				/* Properties */
10823 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10824 				tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10825 				tb.CreateType ();
10826 			} catch {
10827 			}
10828 
10829 			try {
10830 				/* Custom modifiers on properties */
10831 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10832 				// FIXME: These seems to be ignored
10833 				tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10834 				tb.CreateType ();
10835 			} catch {
10836 			}
10837 
10838 			try {
10839 				/* Method return types */
10840 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10841 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10842 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10843 				tb.CreateType ();
10844 			} catch {
10845 			}
10846 
10847 			try {
10848 				/* Custom modifiers on method return types */
10849 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10850 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10851 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10852 				tb.CreateType ();
10853 			} catch {
10854 			}
10855 
10856 			try {
10857 				/* Method parameters */
10858 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10859 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10860 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10861 				tb.CreateType ();
10862 			} catch {
10863 			}
10864 
10865 			try {
10866 				/* Custom modifiers on method parameters */
10867 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10868 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), null, null, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10869 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10870 				tb.CreateType ();
10871 			} catch {
10872 			}
10873 
10874 			try {
10875 				/* Ctor parameters */
10876 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10877 				ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10878 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10879 				tb.CreateType ();
10880 			} catch {
10881 			}
10882 
10883 			try {
10884 				/* Custom modifiers on ctor parameters */
10885 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10886 				ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10887 				mb.GetILGenerator ().Emit (OpCodes.Ret);
10888 				tb.CreateType ();
10889 			} catch {
10890 			}
10891 
10892 			try {
10893 				/* SignatureHelper arguments */
10894 				SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10895 				sighelper.AddArgument (t, false);
10896 				byte[] arr = sighelper.GetSignature ();
10897 			} catch {
10898 			}
10899 
10900 			try {
10901 				SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10902 				sighelper.AddArgument (t, false);
10903 				byte[] arr = sighelper.GetSignature ();
10904 			} catch {
10905 			}
10906 
10907 			try {
10908 				/* Custom modifiers on SignatureHelper arguments */
10909 				SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10910 				sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10911 				byte[] arr = sighelper.GetSignature ();
10912 			} catch {
10913 			}
10914 
10915 			try {
10916 				/* Custom modifiers on SignatureHelper arguments */
10917 				SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10918 				sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10919 				byte[] arr = sighelper.GetSignature ();
10920 			} catch {
10921 			}
10922 
10923 			/* Arguments to ILGenerator methods */
10924 			try {
10925 				/* Emit () */
10926 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10927 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10928 				ILGenerator ig = mb.GetILGenerator ();
10929 				ig.Emit (OpCodes.Ldnull);
10930 				ig.Emit (OpCodes.Castclass, t);
10931 				ig.Emit (OpCodes.Pop);
10932 				ig.Emit (OpCodes.Ret);
10933 				tb.CreateType ();
10934 			} catch {
10935 			}
10936 
10937 			try {
10938 				/* DeclareLocal () */
10939 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10940 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10941 				ILGenerator ig = mb.GetILGenerator ();
10942 				ig.DeclareLocal (t);
10943 				ig.Emit (OpCodes.Ret);
10944 				tb.CreateType ();
10945 			} catch {
10946 			}
10947 
10948 			try {
10949 				/* BeginExceptionCatchBlock () */
10950 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10951 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10952 				ILGenerator ig = mb.GetILGenerator ();
10953 				ig.BeginExceptionBlock ();
10954 				ig.BeginCatchBlock (t);
10955 				ig.Emit (OpCodes.Ret);
10956 				tb.CreateType ();
10957 			} catch {
10958 			}
10959 
10960 			try {
10961 				/* EmitCalli () */
10962 				TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10963 				MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10964 				ILGenerator ig = mb.GetILGenerator ();
10965 				ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
10966 				ig.Emit (OpCodes.Ret);
10967 				tb.CreateType ();
10968 			} catch {
10969 			}
10970 		}
10971 
10972 		//Test for #572660
10973         [Test]
10974         [Category ("MobileNotWorking")] // Mono.CompilerServices.SymbolWriter not available in XA
CircularArrayType()10975         public void CircularArrayType()
10976         {
10977 			var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndSave);
10978 			var moduleBuilder = assemblyBuilder.DefineDynamicModule("Test", "Test.dll", true);
10979 			var typeBuilder = moduleBuilder.DefineType("Foo", TypeAttributes.Public);
10980 			var fieldBuilder = typeBuilder.DefineField("Foos", typeBuilder.MakeArrayType(), FieldAttributes.Public);
10981 
10982 			var fooType = typeBuilder.CreateType();
10983 			Assert.AreSame(fooType.MakeArrayType(), fooType.GetField("Foos").FieldType);
10984         }
10985 
10986 
10987 		[Test] //Test for #422113
10988 		[ExpectedException (typeof (TypeLoadException))]
CreateInstanceOfIncompleteType()10989 		public void CreateInstanceOfIncompleteType ()
10990 		{
10991 			TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class, null, new Type[] { typeof (IComparable) });
10992 			Type proxyType = tb.CreateType();
10993 			Activator.CreateInstance(proxyType);
10994 		}
10995 
10996 		[Test] //Test for #640780
StaticMethodNotUsedInIfaceVtable()10997 		public void StaticMethodNotUsedInIfaceVtable ()
10998 		{
10999 			TypeBuilder tb1 = module.DefineType("Interface", TypeAttributes.Interface | TypeAttributes.Abstract);
11000 			tb1.DefineTypeInitializer().GetILGenerator().Emit(OpCodes.Ret);
11001 			tb1.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract);
11002 			tb1.CreateType();
11003 
11004 			TypeBuilder tb2 = module.DefineType("Class", TypeAttributes.Sealed);
11005 			tb2.AddInterfaceImplementation(tb1);
11006 			tb2.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual)
11007 			    .GetILGenerator().Emit(OpCodes.Ret);
11008 			tb2.DefineDefaultConstructor(MethodAttributes.Public);
11009 
11010 			Activator.CreateInstance(tb2.CreateType());
11011 		}
11012 
11013 		[Test] //Test for #648391
GetConstructorCheckCtorDeclaringType()11014 		public void GetConstructorCheckCtorDeclaringType ()
11015 		{
11016 			TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
11017 			string[] typeParamNames = { "TFirst" };
11018 			GenericTypeParameterBuilder[] typeParams = myType.DefineGenericParameters (typeParamNames);
11019 			var ctor = myType.DefineDefaultConstructor (MethodAttributes.Public);
11020 			var ctori = TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (int)), ctor);
11021 			try {
11022 				TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (bool)), ctori);
11023 				Assert.Fail ("#1");
11024 			} catch (ArgumentException) {
11025 				//OK
11026 			}
11027 		}
11028 
11029 		[Test] //Test for #649237
GetFieldCheckFieldDeclaringType()11030 		public void GetFieldCheckFieldDeclaringType () {
11031 			TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
11032 			myType.DefineGenericParameters ( "TFirst");
11033 			TypeBuilder otherType = module.DefineType ("Sample2", TypeAttributes.Public);
11034 			otherType.DefineGenericParameters ( "TFirst");
11035 
11036 			var field = myType.DefineField ("field", typeof (object), FieldAttributes.Public);
11037 
11038 			try {
11039 				TypeBuilder.GetField (otherType.MakeGenericType (typeof (int)), field);
11040 				Assert.Fail ("#1");
11041 			} catch (ArgumentException) {
11042 				//OK
11043 			}
11044 		}
11045 
11046 		[Test]
TypeWithFieldRVAWorksUnderSgen()11047 		public void TypeWithFieldRVAWorksUnderSgen () {
11048 	        AssemblyName an = new AssemblyName("MAIN");
11049 	        AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an,
11050 	            AssemblyBuilderAccess.Run, ".");
11051 	        ModuleBuilder mob = ab.DefineDynamicModule("MAIN");
11052 	        TypeBuilder tb = mob.DefineType("MAIN", TypeAttributes.Public |
11053 	            TypeAttributes.Sealed | TypeAttributes.Abstract |
11054 	            TypeAttributes.Class | TypeAttributes.BeforeFieldInit);
11055 
11056 	        byte[] source = new byte[] { 42 };
11057 	        FieldBuilder fb = tb.DefineInitializedData("A0", source, 0);
11058 
11059 	        MethodBuilder mb = tb.DefineMethod("EVAL", MethodAttributes.Static |
11060 	            MethodAttributes.Public, typeof(byte[]), new Type[] { });
11061 	        ILGenerator il = mb.GetILGenerator();
11062 
11063 	        il.Emit(OpCodes.Ldc_I4_1);
11064 	        il.Emit(OpCodes.Newarr, typeof(byte));
11065 	        il.Emit(OpCodes.Dup);
11066 	        il.Emit(OpCodes.Ldtoken, fb);
11067 	        il.Emit(OpCodes.Call, typeof(RuntimeHelpers).GetMethod("InitializeArray"));
11068 	        il.Emit(OpCodes.Ret);
11069 
11070 	        Type t = tb.CreateType();
11071 
11072 	        GC.Collect();
11073 
11074 	        byte[] res = (byte[]) t.InvokeMember("EVAL", BindingFlags.Public |
11075 	            BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
11076 	            new object[] { });
11077 
11078 	        Assert.AreEqual (42, res[0]);
11079 	    }
11080 
11081 
11082 		[Test]
Ldfld_Regress_9531()11083 		public void Ldfld_Regress_9531 () {
11084 			Build<Example<int>> ();
11085 		}
11086 
Build()11087 		void Build<T> () {
11088             var base_class = typeof(T);
11089 
11090             var builder = module.DefineType(genTypeName (),
11091                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11092                 base_class);
11093 
11094             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11095 
11096             var cb = builder.DefineConstructor(
11097                 MethodAttributes.Public | MethodAttributes.SpecialName,
11098                 CallingConventions.HasThis,
11099                 new[] { typeof(string) });
11100 
11101             var il = cb.GetILGenerator();
11102 
11103             if (field == null)
11104             {
11105                 throw new InvalidOperationException("wtf");
11106             }
11107 
11108             il.Emit(OpCodes.Ldarg_0);
11109             il.Emit(OpCodes.Ldarg_1);
11110             il.Emit(OpCodes.Stfld, field);
11111             il.Emit(OpCodes.Ret);
11112 
11113             builder.CreateType();
11114 		}
11115 
11116 		public class Example<T> {
11117 			public string Field;
11118 			public T Field2;
11119 		}
11120 
11121 		[Test]
11122 		[Category ("AndroidNotWorking")]
11123 		// It's not possible to save the assembly in the current directory on Android and AssemblyBuilder.DefineDynamicModule will not
11124 		// allow a full path to the assembly to be passed to it. Trying to change the current directory before saving will not work either as
11125 		// FileStream will then prepend / to the file name (perhaps it's another bug) and write access to the filesystem root is, obviously, denied
Ldfld_Encoding_10122()11126 		public void Ldfld_Encoding_10122 () {
11127 			Build2<Example<int>> ();
11128 		}
11129 
Build2()11130 		void Build2<T> () {
11131 			var base_class = typeof(T);
11132 
11133 	        string AssemblyName = genTypeName ();
11134 	        string AssemblyFileName = AssemblyName + ".dll";
11135 
11136 			var assemblyBuilderAccess = AssemblyBuilderAccess.Save;
11137 			var assemblyName = new AssemblyName(AssemblyName);
11138 			var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
11139 			var moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName, AssemblyFileName);
11140 
11141 
11142 			var builder = moduleBuilder.DefineType("Wrapped",
11143                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11144                 base_class);
11145 
11146             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11147 
11148             var cb = builder.DefineConstructor(
11149                 MethodAttributes.Public | MethodAttributes.SpecialName,
11150                 CallingConventions.HasThis,
11151                 new[] { typeof(string) });
11152 
11153             var il = cb.GetILGenerator();
11154 
11155             if (field == null)
11156             {
11157                 throw new InvalidOperationException("wtf");
11158             }
11159 
11160             il.Emit(OpCodes.Ldarg_0);
11161             il.Emit(OpCodes.Ldarg_1);
11162             il.Emit(OpCodes.Stfld, field);
11163             il.Emit(OpCodes.Ret);
11164 
11165             builder.CreateType();
11166 
11167 			assemblyBuilder.Save (AssemblyFileName);
11168 
11169 			var fromDisk = Assembly.Load (AssemblyName);
11170 			Console.WriteLine (fromDisk);
11171 			var t = fromDisk.GetType ("Wrapped");
11172 			Activator.CreateInstance (t, new object[] { "string"});
11173 		}
11174 
11175 		public interface IFace16096 {
Bar()11176 			object Bar ();
11177 		}
11178 
11179 		[Test]
MemberRef_Caching_16096()11180 		public void MemberRef_Caching_16096 () {
11181 			var outer_class = module.DefineType(
11182 				"container",
11183 				TypeAttributes.Class | TypeAttributes.Public,
11184 				typeof(object));
11185 
11186 			var builder = outer_class.DefineNestedType(
11187 				"bind@32-1",
11188 				TypeAttributes.Class | TypeAttributes.Public,
11189 				typeof(object));
11190 
11191 			builder.AddInterfaceImplementation (typeof (IFace16096));
11192 
11193 			var ctor = builder.DefineDefaultConstructor (MethodAttributes.Public);
11194 			var field = builder.DefineField ("Field", typeof (object), FieldAttributes.Public);
11195 			var g_args = builder.DefineGenericParameters("b","a");
11196 			var method = builder.DefineMethod ("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof (object), new Type [0]);
11197 
11198 			var il = method.GetILGenerator();
11199 			il.Emit (OpCodes.Ldarg_0);
11200 			il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (builder.MakeGenericType (g_args), field));
11201 			il.Emit (OpCodes.Pop);
11202 			il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (builder.MakeGenericType (g_args), ctor));
11203 			il.Emit (OpCodes.Ret);
11204 
11205 			var type = builder.CreateType ();
11206 
11207 			/*Build a gshared instance. */
11208 			var ginst = type.MakeGenericType (typeof (List<char>), typeof (object));
11209 			var ins = (IFace16096)Activator.CreateInstance (ginst);
11210 
11211 			/* This will trigger the runtime to cache the MEMBER_REF to the .ctor as it won't have a context. */
11212 			var ins2 = ins.Bar ();
11213 			Assert.IsNotNull (ins2);
11214 
11215 			/* Build an unsharable version. */
11216 			var ginst2 = type.MakeGenericType (typeof (List<char>), typeof (char));
11217 			var ins3 = (IFace16096)Activator.CreateInstance (ginst2);
11218 
11219 			/* This will trigger the runtime to use the cached version, which is wrong as it's an open type. */
11220 			var ins4 = ins3.Bar ();
11221 			Assert.IsNotNull (ins4);
11222 		}
11223 
11224 		[Test]
CircularReferences()11225 		public void CircularReferences () {
11226 			// A: C<D<A>>
11227 			var a_type = module.DefineType(
11228 				"A",
11229 				TypeAttributes.Class,
11230 				typeof(object));
11231 
11232 			var cba = a_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11233 			cba.GetILGenerator ().Emit (OpCodes.Ret);
11234 
11235 			var c_type = module.DefineType(
11236 				"B",
11237 				TypeAttributes.Class,
11238 				typeof(object));
11239 			var cbb = c_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11240 			cbb.GetILGenerator ().Emit (OpCodes.Ret);
11241 			c_type.DefineGenericParameters ("d_a_param");
11242 
11243 			var d_type = module.DefineType(
11244 				"D",
11245 				TypeAttributes.Class,
11246 				typeof(object));
11247 			var cbd = d_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11248 			cbd.GetILGenerator ().Emit (OpCodes.Ret);
11249 			d_type.DefineGenericParameters ("a_param");
11250 
11251 
11252 			var d_instantiated = c_type.MakeGenericType (d_type.MakeGenericType (a_type));
11253 			a_type.SetParent (d_instantiated);
11254 			a_type.CreateType ();
11255 
11256 			Assert.IsNotNull (a_type);
11257 		}
11258 
11259 		// #22059
11260 		[Test]
11261 		[ExpectedException (typeof (TypeLoadException))]
PrivateIface()11262 		public void PrivateIface ()
11263 		{
11264 			TypeBuilder tb = module.DefineType ("Sample", TypeAttributes.Public, typeof (object), new[] { typeof (IFoo) });
11265             tb.CreateType();
11266 		}
11267 
11268 		interface IFoo {
11269 		}
11270 
11271 		[Test]
GenericFieldInCreatedType()11272 		public void GenericFieldInCreatedType () {
11273 			/*
11274 			 * Regression test for #47867.
11275 			 * We construct the following, but only call CreateType on R.
11276 			 *
11277 			 * public class S<T> {
11278 			 *   public T t;
11279 			 * }
11280 			 * public class R {
11281 			 *   public static S<R> sr;
11282 			 * }
11283 			 */
11284 			var aname = new AssemblyName ("example1");
11285 			var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11286 			var mb = ab.DefineDynamicModule (aname.Name);
11287 			var tbS = mb.DefineType ("S", TypeAttributes.Public);
11288 			tbS.DefineGenericParameters (new String [] { "T" });
11289 			var tbR = mb.DefineType ("R", TypeAttributes.Public);
11290 			tbR.DefineField ("sr", tbS.MakeGenericType(new Type[] { tbR }), FieldAttributes.Public | FieldAttributes.Static);
11291 
11292 			Type r = tbR.CreateType ();
11293 
11294 			Assert.IsNotNull  (r);
11295 		}
11296 
11297 		[Test]
GenericFieldInCreatedTypeIncompleteTypeTLE()11298 		public void GenericFieldInCreatedTypeIncompleteTypeTLE () {
11299 			/*
11300 			 * Regression test for #47867.
11301 			 * We construct the following, but only call CreateType on R.
11302 			 * Then we try to use R.sr which is expected throw a
11303 			 * TLE because S hasn't been created yet.
11304 			 *
11305 			 * public class S<T> {
11306 			 *   public T t;
11307 			 * }
11308 			 * public class R {
11309 			 *   public static S<R> sr;
11310 			 * }
11311 			 */
11312 			var aname = new AssemblyName ("example1");
11313 			var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11314 			var mb = ab.DefineDynamicModule (aname.Name);
11315 			var tbS = mb.DefineType ("S", TypeAttributes.Public);
11316 			tbS.DefineGenericParameters (new String [] { "T" });
11317 			var tbR = mb.DefineType ("R", TypeAttributes.Public);
11318 			tbR.DefineField ("sr", tbS.MakeGenericType(new Type[] { tbR }), FieldAttributes.Public | FieldAttributes.Static);
11319 
11320 			Type r = tbR.CreateType ();
11321 
11322 			Assert.IsNotNull  (r);
11323 
11324 			// N.B.  tbS has not had CreateType called yet, so expect this to fail.
11325 			Assert.Throws<TypeLoadException> (delegate { var ft = r.GetField("sr").FieldType; });
11326 		}
11327 
11328 		[Test]
GetGenericTypeDefinitionAfterCreateReturnsBuilder()11329 		public void GetGenericTypeDefinitionAfterCreateReturnsBuilder () {
11330 			var aname = new AssemblyName ("genericDefnAfterCreate");
11331 			var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11332 			var mb = ab.DefineDynamicModule (aname.Name);
11333 			var buildX = mb.DefineType ("X", TypeAttributes.Public);
11334 			buildX.DefineGenericParameters ("T", "U");
11335 			var x = buildX.CreateType ();
11336 			var inst = x.MakeGenericType (typeof (string), typeof (int));
11337 			var defX = inst.GetGenericTypeDefinition ();
11338 
11339 			Assert.AreSame (buildX, defX);
11340 		}
11341 
11342 		[Test]
FieldsWithSameName()11343 		public void FieldsWithSameName () {
11344 			// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11345 			var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11346 
11347 			var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11348 			var mainMethodIl = mainMethod.GetILGenerator ();
11349 
11350 			var f1 = typeBuilder.DefineField ("x", typeof (byte), FieldAttributes.Private | FieldAttributes.Static);
11351 			var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11352 
11353 			mainMethodIl.Emit (OpCodes.Ldsflda, f1);
11354 			mainMethodIl.Emit (OpCodes.Ldsflda, f2);
11355 			mainMethodIl.Emit (OpCodes.Pop);
11356 			mainMethodIl.Emit (OpCodes.Pop);
11357 			mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11358 			mainMethodIl.Emit (OpCodes.Ret);
11359 
11360 			typeBuilder.CreateType ();
11361 			assembly.SetEntryPoint (mainMethod);
11362 
11363 			assembly.Save (ASSEMBLY_NAME + ".dll");
11364 		}
11365 		[Test]
FieldsWithSameNameAndType()11366 		public void FieldsWithSameNameAndType () {
11367 			// https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11368 			var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11369 
11370 			var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11371 			var mainMethodIl = mainMethod.GetILGenerator ();
11372 
11373 			var f1 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11374 			var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11375 
11376 			mainMethodIl.Emit (OpCodes.Ldsflda, f1);
11377 			mainMethodIl.Emit (OpCodes.Ldsflda, f2);
11378 			mainMethodIl.Emit (OpCodes.Pop);
11379 			mainMethodIl.Emit (OpCodes.Pop);
11380 			mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11381 			mainMethodIl.Emit (OpCodes.Ret);
11382 
11383 			typeBuilder.CreateType ();
11384 			assembly.SetEntryPoint (mainMethod);
11385 
11386 			assembly.Save (ASSEMBLY_NAME + ".dll");
11387 		}
11388 
11389 		[Test]
MethodsWithSameNameAndSig()11390 		public void MethodsWithSameNameAndSig () {
11391 			// https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11392 			var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11393 
11394 			var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11395 			var mainMethodIl = mainMethod.GetILGenerator ();
11396 
11397 			var m1 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
11398 			var m2 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
11399 			m1.GetILGenerator ().Emit (OpCodes.Ret);
11400 			m2.GetILGenerator ().Emit (OpCodes.Ret);
11401 
11402 			mainMethodIl.Emit (OpCodes.Call, m1);
11403 			mainMethodIl.Emit (OpCodes.Call, m2);
11404 			mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11405 			mainMethodIl.Emit (OpCodes.Ret);
11406 
11407 			typeBuilder.CreateType ();
11408 			assembly.SetEntryPoint (mainMethod);
11409 
11410 			assembly.Save (ASSEMBLY_NAME + ".dll");
11411 		}
11412 
11413 		[Test]
TwoAssembliesMidFlightTest()11414 		public void TwoAssembliesMidFlightTest () {
11415 			// Check that one AssemblyBuilder can refer to a TypeBuilder from another AssemblyBuilder.
11416 			// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58421
11417 			var name2 = "MonoTests.System.Reflection.Emit.TypeBuilderTest2";
11418 			var assemblyName2 = new AssemblyName (name2);
11419 			var assembly2 =
11420 				Thread.GetDomain ().DefineDynamicAssembly (
11421 					assemblyName2, AssemblyBuilderAccess.RunAndSave, tempDir);
11422 
11423 			var module2 = assembly2.DefineDynamicModule (name2, name2 + ".dll");
11424 
11425 			var tb = module.DefineType ("Foo", TypeAttributes.Public);
11426 			var tb2 = module2.DefineType ("Foo2", TypeAttributes.Public);
11427 
11428 			var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
11429 						       Type.EmptyTypes);
11430 
11431 			var ilg = cb.GetILGenerator ();
11432 
11433 			ilg.Emit (OpCodes.Ldtoken, tb2); // N.B. type from the other AssemblyBuilder
11434 			ilg.Emit (OpCodes.Pop);
11435 			ilg.Emit (OpCodes.Ret);
11436 
11437 			var t = tb.CreateType ();
11438 			tb2.CreateType ();
11439 
11440 			var ci = t.GetConstructor (Type.EmptyTypes);
11441 			var x = ci.Invoke (null);
11442 			assembly.Save (ASSEMBLY_NAME + ".dll");
11443 			assembly2.Save (name2 + ".dll");
11444 		}
11445 
11446 	}
11447 }
11448