2010-01-20 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / TypeBuilderTest.cs
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
28 #if NET_2_0
29 using System.Collections.Generic;
30 #endif
31
32 namespace MonoTests.System.Reflection.Emit
33 {
34         public interface EmptyInterface
35         {
36         }
37
38         public interface OneMethodInterface
39         {
40                 void foo ();
41         }
42
43         public class SimpleTestAttribute : Attribute
44         {
45         }
46         public class EmptyIfaceImpl : EmptyInterface
47         {
48         }
49
50 #if NET_2_0
51         public class Gen<T> {
52                 public static T field = default(T);
53         }
54 #endif
55
56         [TestFixture]
57         public class TypeBuilderTest
58         {
59                 private interface AnInterface
60                 {
61                 }
62
63                 public interface Foo
64                 {
65                 }
66
67                 public interface Bar : Foo
68                 {
69                 }
70
71                 public interface Baz : Bar
72                 {
73                 }
74
75                 public interface IMoveable
76                 {
77                 }
78
79                 public interface IThrowable : IMoveable
80                 {
81                 }
82
83                 public interface ILiquid
84                 {
85                 }
86
87                 public interface IWater : ILiquid
88                 {
89                 }
90
91                 public interface IAir
92                 {
93                 }
94
95                 public interface IDestroyable
96                 {
97                 }
98 #if NET_2_0
99
100                 public class Tuple <A,B> {
101                         A a;
102                         B b;
103                 }
104 #endif
105
106                 private AssemblyBuilder assembly;
107
108                 private ModuleBuilder module;
109
110                 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
111
112                 [SetUp]
113                 protected void SetUp ()
114                 {
115                         AssemblyName assemblyName = new AssemblyName ();
116                         assemblyName.Name = ASSEMBLY_NAME;
117
118                         assembly =
119                                 Thread.GetDomain ().DefineDynamicAssembly (
120                                         assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
121
122                         module = assembly.DefineDynamicModule ("module1");
123                 }
124
125                 static int typeIndexer = 0;
126
127                 // Return a unique type name
128                 private string genTypeName ()
129                 {
130                         return "t" + (typeIndexer++);
131                 }
132
133                 private string nullName ()
134                 {
135                         return String.Format ("{0}", (char) 0);
136                 }
137
138                 [Test]
139                 public void TestAssembly ()
140                 {
141                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
142                         Assert.AreEqual (assembly, tb.Assembly);
143                 }
144
145                 [Test]
146                 public void TestAssemblyQualifiedName ()
147                 {
148                         TypeBuilder tb = module.DefineType ("A.B.C.D", TypeAttributes.Public);
149                         Assert.AreEqual ("A.B.C.D, " + assembly.GetName ().FullName,
150                                 tb.AssemblyQualifiedName);
151                 }
152
153                 [Test]
154                 public void TestAttributes ()
155                 {
156                         TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
157                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
158                         Assert.AreEqual (attrs, tb.Attributes);
159                 }
160
161                 [Test]
162                 public void TestBaseTypeClass ()
163                 {
164                         TypeAttributes attrs = TypeAttributes.Public;
165                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
166                         Assert.AreEqual (typeof (object), tb.BaseType, "#1");
167
168                         TypeBuilder tb2 = module.DefineType (genTypeName (), attrs, tb);
169                         Assert.AreEqual (tb, tb2.BaseType, "#2");
170                 }
171
172                 [Test] // bug #71301
173                 public void TestBaseTypeInterface ()
174                 {
175                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
176                         Assert.IsNull (tb3.BaseType);
177                 }
178
179                 [Test]
180                 public void TestDeclaringType ()
181                 {
182                         TypeAttributes attrs = 0;
183                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
184                         Assert.IsNull (tb.DeclaringType, "#1");
185
186                         attrs = TypeAttributes.NestedPublic;
187                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName (), attrs);
188                         TypeBuilder tb3 = tb2.DefineNestedType (genTypeName (), attrs);
189                         Assert.AreEqual (tb3.DeclaringType.DeclaringType, tb, "#2");
190                 }
191
192                 [Test]
193                 public void TestFullName ()
194                 {
195                         string name = genTypeName ();
196                         TypeAttributes attrs = 0;
197                         TypeBuilder tb = module.DefineType (name, attrs);
198                         Assert.AreEqual (name, tb.FullName, "#1");
199
200                         string name2 = genTypeName ();
201                         attrs = TypeAttributes.NestedPublic;
202                         TypeBuilder tb2 = tb.DefineNestedType (name2, attrs);
203
204                         string name3 = genTypeName ();
205                         attrs = TypeAttributes.NestedPublic;
206                         TypeBuilder tb3 = tb2.DefineNestedType (name3, attrs);
207
208                         Assert.AreEqual (name + "+" + name2 + "+" + name3, tb3.FullName, "#2");
209                 }
210
211                 [Test]
212                 public void DefineCtorUsingDefineMethod ()
213                 {
214                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Class);
215                         MethodBuilder mb = tb.DefineMethod(
216                                 ".ctor", MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
217                                 null, null);
218                         ILGenerator ilgen = mb.GetILGenerator();
219                         ilgen.Emit(OpCodes.Ldarg_0);
220                         ilgen.Emit(OpCodes.Call,
221                                            typeof(object).GetConstructor(Type.EmptyTypes));
222                         ilgen.Emit(OpCodes.Ret);
223                         Type t = tb.CreateType();
224
225                         Assert.AreEqual (1, t.GetConstructors ().Length);
226                 }
227
228                 [Test]
229                 public void TestGUIDIncomplete ()
230                 {
231                         TypeBuilder tb = module.DefineType (genTypeName ());
232                         try {
233                                 Guid g = tb.GUID;
234                                 Assert.Fail ("#1");
235                         } catch (NotSupportedException ex) {
236                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
237                                 Assert.IsNull (ex.InnerException, "#3");
238                                 Assert.IsNotNull (ex.Message, "#4");
239                         }
240                 }
241
242                 [Test] // bug #71302
243                 [Category ("NotWorking")]
244                 public void TestGUIDComplete ()
245                 {
246                         TypeBuilder tb = module.DefineType (genTypeName ());
247                         tb.CreateType ();
248                         Assert.IsTrue (tb.GUID != Guid.Empty);
249                 }
250
251                 [Test]
252                 [Category ("NotWorking")]
253                 public void TestFixedGUIDComplete ()
254                 {
255                         TypeBuilder tb = module.DefineType (genTypeName ());
256
257                         Guid guid = Guid.NewGuid ();
258
259                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
260                                 new Type [] { typeof (string) });
261
262                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
263                                 new object [] { guid.ToString ("D") }, new FieldInfo [0], new object [0]);
264
265                         tb.SetCustomAttribute (caBuilder);
266                         tb.CreateType ();
267                         Assert.AreEqual (guid, tb.GUID);
268                 }
269
270                 [Test]
271                 public void TestHasElementType_Incomplete ()
272                 {
273                         // According to the MSDN docs, this member works, but in reality, it
274                         // returns a NotSupportedException
275                         TypeBuilder tb = module.DefineType (genTypeName ());
276 #if NET_2_0
277                         Assert.IsFalse (tb.HasElementType);
278 #else
279                         try {
280                                 bool b = tb.HasElementType;
281                                 Assert.Fail ("#1: " + b);
282                         } catch (NotSupportedException ex) {
283                                 // The invoked member is not supported in a
284                                 // dynamic module
285                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
286                                 Assert.IsNull (ex.InnerException, "#3");
287                                 Assert.IsNotNull (ex.Message, "#4");
288                         }
289 #endif
290                 }
291
292                 [Test]
293 #if ONLY_1_1
294                 [Category ("NotWorking")]
295 #endif
296                 public void TestHasElementType_Complete ()
297                 {
298                         // According to the MSDN docs, this member works, but in reality, it
299                         // returns a NotSupportedException
300                         TypeBuilder tb = module.DefineType (genTypeName ());
301                         tb.CreateType ();
302 #if NET_2_0
303                         Assert.IsFalse (tb.HasElementType);
304 #else
305                         try {
306                                 bool b = tb.HasElementType;
307                                 Assert.Fail ("#1: " + b);
308                         } catch (NotSupportedException ex) {
309                                 // The invoked member is not supported in a
310                                 // dynamic module
311                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
312                                 Assert.IsNull (ex.InnerException, "#3");
313                                 Assert.IsNotNull (ex.Message, "#4");
314                         }
315 #endif
316                 }
317
318                 [Test] // bug #324692
319                 public void CreateType_Enum_NoInstanceField ()
320                 {
321                         TypeBuilder tb = module.DefineType (genTypeName (),
322                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
323                                 typeof (Enum));
324
325                         try {
326                                 tb.CreateType ();
327                                 Assert.Fail ("#1: must throw TypeLoadException");
328                         } catch (TypeLoadException) {
329                         }
330
331 #if NET_2_0
332                         //Assert.IsTrue (tb.IsCreated (), "#2");
333 #endif
334                 }
335
336                 [Test] // bug #324692
337 #if ONLY_1_1
338                 [Category ("NotWorking")] // we do not throw IOE when repeatedly invoking CreateType
339 #endif
340                 public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
341                 {
342                         TypeBuilder tb = module.DefineType (genTypeName (),
343                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
344                                 typeof (Enum));
345
346                         try {
347                                 tb.CreateType ();
348                                 Assert.Fail ("#A1");
349                         } catch (TypeLoadException ex) {
350                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
351                                 Assert.IsNull (ex.InnerException, "#A3");
352                                 Assert.IsNotNull (ex.Message, "#A4");
353                         }
354
355 #if NET_2_0
356                         //Assert.IsTrue (tb.IsCreated (), "#B1");
357                         Assert.IsNull (tb.CreateType (), "#B2");
358                         //Assert.IsTrue (tb.IsCreated (), "#B3");
359 #else
360                         try {
361                                 tb.CreateType ();
362                                 Assert.Fail ("#B1");
363                         } catch (InvalidOperationException ex) {
364                                 // Unable to change after type has been created
365                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
366                                 Assert.IsNull (ex.InnerException, "#B3");
367                                 Assert.IsNotNull (ex.Message, "#B4");
368                         }
369 #endif
370                 }
371
372                 [Test]
373                 public void TestEnumWithEmptyInterfaceBuildsOk ()
374                 {
375                         TypeBuilder tb = module.DefineType (genTypeName (),
376                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
377                                 typeof (Enum));
378                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
379                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
380
381                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
382
383                         try {
384                                 tb.CreateType ();
385                         } catch (TypeLoadException) {
386                                 Assert.Fail ("#1: must build enum type ok");
387                         }
388
389 #if NET_2_0
390                         Assert.IsTrue (tb.IsCreated (), "#2");
391 #endif
392                 }
393
394                 [Test]
395                 [Category ("NotWorking")]
396                 public void TestEnumWithNonEmptyInterfaceBuildsFails ()
397                 {
398                         TypeBuilder tb = module.DefineType (genTypeName (),
399                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
400                                 typeof (Enum));
401                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
402                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
403
404                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
405
406                         try {
407                                 tb.CreateType ();
408                                 Assert.Fail ("#1: type doesn't have all interface methods");
409                         } catch (TypeLoadException) {
410                         }
411
412 #if NET_2_0
413                         Assert.IsTrue (tb.IsCreated (), "#2");
414 #endif
415                 }
416
417                 [Test]
418                 [Category ("NotWorking")]
419                 public void TestTypeDontImplementInterfaceMethodBuildsFails ()
420                 {
421                         TypeBuilder tb = module.DefineType (genTypeName (),
422                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
423                                 typeof (object));
424
425                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
426
427                         try {
428                                 tb.CreateType ();
429                                 Assert.Fail ("#1: type doesn't have all interface methods");
430                         } catch (TypeLoadException) {
431                         }
432
433 #if NET_2_0
434                         Assert.IsTrue (tb.IsCreated (), "#2");
435 #endif
436                 }
437
438                 [Test]
439                 public void TestEnumWithSequentialLayoutBuildsFails ()
440                 {
441                         TypeBuilder tb = module.DefineType (genTypeName (),
442                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
443                                 TypeAttributes.SequentialLayout, typeof (Enum));
444                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
445                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
446
447                         try {
448                                 tb.CreateType ();
449                                 Assert.Fail ("#1: type doesn't have all interface methods");
450                         } catch (TypeLoadException) {
451                         }
452
453 #if NET_2_0
454                         //Assert.IsTrue (tb.IsCreated (), "#2");
455 #endif
456                 }
457
458                 [Test]
459                 public void TestEnumWithExplicitLayoutBuildsFails ()
460                 {
461                         TypeBuilder tb = module.DefineType (genTypeName (),
462                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
463                                 TypeAttributes.ExplicitLayout, typeof (Enum));
464                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
465                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
466
467                         try {
468                                 tb.CreateType ();
469                                 Assert.Fail ("#1: type doesn't have all interface methods");
470                         } catch (TypeLoadException) {
471                         }
472
473 #if NET_2_0
474                         //Assert.IsTrue (tb.IsCreated (), "#2");
475 #endif
476                 }
477
478                 [Test]
479                 public void TestEnumWithMethodsBuildFails ()
480                 {
481                         TypeBuilder tb = module.DefineType ("FooEnum7",
482                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
483                                 typeof (Enum));
484                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
485                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
486
487                         MethodBuilder methodBuilder = tb.DefineMethod("mmm",
488                                 MethodAttributes.Public | MethodAttributes.Virtual,
489                                 null,
490                                 new Type[] { });
491
492                         methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
493                         try {
494                                 tb.CreateType ();
495                                 Assert.Fail ("#1: enum has method");
496                         } catch (TypeLoadException) {
497                         }
498
499 #if NET_2_0
500                         //Assert.IsTrue (tb.IsCreated (), "#2");
501 #endif
502                 }
503
504                 [Test]
505                 public void TestEnumWithBadTypeValueFieldBuildFails ()
506                 {
507                         Type[] badTypes = {
508                                 typeof (object),
509                                 typeof (string),
510                                 typeof (DateTime)
511                         };
512
513                         foreach (Type type in badTypes) {
514                                 TypeBuilder tb = module.DefineType (genTypeName (),
515                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
516                                         typeof (Enum));
517                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
518                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
519
520                                 try {
521                                         tb.CreateType ();
522                                         Assert.Fail ("#1: enum using bad type: " + type);
523                                 } catch (TypeLoadException) {
524                                 }
525
526 #if NET_2_0
527                                 //Assert.IsTrue (tb.IsCreated (), "#2");
528 #endif
529                         }
530                 }
531
532                 [Test]
533                 public void TestEnumWithGoodTypeValueFieldBuildOk ()
534                 {
535                         Type[] goodTypes = {
536                                 typeof (byte),typeof (sbyte),typeof (bool),
537                                 typeof (ushort),typeof (short),typeof (char),
538                                 typeof (uint),typeof (int),
539                                 typeof (ulong),typeof (long),
540                                 typeof (UIntPtr),typeof (IntPtr),
541                         };
542
543                         foreach (Type type in goodTypes) {
544                                 TypeBuilder tb = module.DefineType (genTypeName (),
545                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
546                                         typeof (Enum));
547                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
548                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
549
550                                 try {
551                                         tb.CreateType ();
552                                 } catch (TypeLoadException) {
553                                         Assert.Fail ("#1: enum using good type: " + type);
554                                 }
555                         }
556                 }
557
558                 [Test]
559                 public void TestEnumWithMultipleValueFieldsBuildFals ()
560                 {
561                         TypeBuilder tb = module.DefineType (genTypeName (),
562                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
563                                 typeof (Enum));
564                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
565                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
566                         tb.DefineField ("value2__", typeof (int), FieldAttributes.SpecialName |
567                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
568
569                         try {
570                                 tb.CreateType ();
571                                 Assert.Fail ("#1: invalid enum type");
572                         } catch (TypeLoadException) {
573                         }
574
575 #if NET_2_0
576                         //Assert.IsTrue (tb.IsCreated (), "#2");
577 #endif
578                 }
579
580                 [Test]
581                 [Category ("NotWorking")]
582                 public void TestEnumWithEmptyInterfaceCanBeCasted ()
583                 {
584                         TypeBuilder tb = module.DefineType (genTypeName (),
585                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
586                                 typeof (Enum));
587                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
588                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
589                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
590
591                         try {
592                                 tb.CreateType ();
593                         } catch (TypeLoadException) {
594                                 Assert.Fail ("#1: must build enum type ok");
595                         }
596
597                         try {
598                                 EmptyInterface obj = (EmptyInterface) Activator.CreateInstance (tb);
599                                 Assert.IsNotNull (obj, "#2");
600                         } catch (TypeLoadException) {
601                                 Assert.Fail ("#3: must cast enum to interface");
602                         }
603                 }
604
605                 [Test]
606                 public void TestEnumWithValueFieldBuildOk ()
607                 {
608                         TypeBuilder tb = module.DefineType (genTypeName (),
609                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
610                                 typeof (Enum));
611                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
612                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
613
614                         try {
615                                 tb.CreateType ();
616                         } catch (TypeLoadException) {
617                                 Assert.Fail ("#1: must build enum type ok");
618                         }
619                 }
620
621                 [Test]
622                 public void TestIsAbstract ()
623                 {
624                         TypeBuilder tb = module.DefineType (genTypeName ());
625                         Assert.IsFalse (tb.IsAbstract, "#1");
626
627                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Abstract);
628                         Assert.IsTrue (tb2.IsAbstract, "#2");
629                 }
630
631                 [Test]
632                 public void TestIsAnsiClass ()
633                 {
634                         TypeBuilder tb = module.DefineType (genTypeName ());
635                         Assert.IsTrue (tb.IsAnsiClass, "#1");
636
637                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
638                         Assert.IsFalse (tb2.IsAnsiClass, "#2");
639                 }
640
641                 [Test]
642                 public void TestIsArray ()
643                 {
644                         // How can a TypeBuilder be an array ?
645                         string name = genTypeName ();
646                         TypeBuilder tb = module.DefineType (name);
647                         Assert.IsFalse (tb.IsArray);
648                 }
649
650                 [Test]
651                 public void TestIsAutoClass ()
652                 {
653                         TypeBuilder tb = module.DefineType (genTypeName ());
654                         Assert.IsFalse (tb.IsAutoClass, "#1");
655
656                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.AutoClass);
657                         Assert.IsTrue (tb2.IsAutoClass, "#2");
658                 }
659
660                 [Test]
661                 public void TestIsAutoLayout ()
662                 {
663                         TypeBuilder tb = module.DefineType (genTypeName ());
664                         Assert.IsTrue (tb.IsAutoLayout, "#1");
665
666                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
667                         Assert.IsFalse (tb2.IsAutoLayout, "#2");
668                 }
669
670                 [Test]
671                 public void TestIsByRef ()
672                 {
673                         // How can a TypeBuilder be ByRef ?
674                         TypeBuilder tb = module.DefineType (genTypeName ());
675                         Assert.IsFalse (tb.IsByRef);
676                 }
677
678                 [Test]
679                 public void TestIsClass ()
680                 {
681                         TypeBuilder tb = module.DefineType (genTypeName ());
682                         Assert.IsTrue (tb.IsClass, "#1");
683
684                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
685                         Assert.IsFalse (tb2.IsClass, "#2");
686
687                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
688                         Assert.IsFalse (tb3.IsClass, "#3");
689
690                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
691                         Assert.IsFalse (tb4.IsClass, "#4");
692                 }
693
694                 [Test] // bug #71304
695                 public void TestIsCOMObject ()
696                 {
697                         TypeBuilder tb = module.DefineType (genTypeName ());
698                         Assert.IsFalse (tb.IsCOMObject, "#1");
699
700                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
701                         Assert.IsTrue (tb.IsCOMObject, "#2");
702                 }
703
704                 [Test]
705                 public void TestIsContextful ()
706                 {
707                         TypeBuilder tb = module.DefineType (genTypeName ());
708                         Assert.IsFalse (tb.IsContextful, "#1");
709
710                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
711                         Assert.IsTrue (tb2.IsContextful, "#2");
712                 }
713
714                 [Test]
715                 public void TestIsEnum ()
716                 {
717                         TypeBuilder tb = module.DefineType (genTypeName ());
718                         Assert.IsFalse (tb.IsEnum, "#1");
719
720                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ValueType));
721                         Assert.IsFalse (tb2.IsEnum, "#2");
722
723                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (Enum));
724                         Assert.IsTrue (tb3.IsEnum, "#3");
725                 }
726
727                 [Test]
728                 public void TestIsExplicitLayout ()
729                 {
730                         TypeBuilder tb = module.DefineType (genTypeName ());
731                         Assert.IsFalse (tb.IsExplicitLayout, "#1");
732
733                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
734                         Assert.IsTrue (tb2.IsExplicitLayout, "#2");
735                 }
736
737                 [Test]
738                 public void TestIsImport ()
739                 {
740                         TypeBuilder tb = module.DefineType (genTypeName ());
741                         Assert.IsFalse (tb.IsImport, "#1");
742
743                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
744                         Assert.IsTrue (tb.IsImport, "#2");
745                 }
746
747                 [Test]
748                 public void TestIsInterface ()
749                 {
750                         TypeBuilder tb = module.DefineType (genTypeName ());
751                         Assert.IsFalse (tb.IsInterface, "#1");
752
753                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
754                         Assert.IsTrue (tb2.IsInterface, "#2");
755
756                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
757                         Assert.IsFalse (tb3.IsInterface, "#3");
758                 }
759
760                 [Test]
761                 public void TestIsLayoutSequential ()
762                 {
763                         TypeBuilder tb = module.DefineType (genTypeName ());
764                         Assert.IsFalse (tb.IsLayoutSequential, "#1");
765
766                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SequentialLayout);
767                         Assert.IsTrue (tb2.IsLayoutSequential, "#2");
768                 }
769
770                 [Test]
771                 public void TestIsMarshalByRef ()
772                 {
773                         TypeBuilder tb = module.DefineType (genTypeName ());
774                         Assert.IsFalse (tb.IsMarshalByRef, "#1");
775
776                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (MarshalByRefObject));
777                         Assert.IsTrue (tb2.IsMarshalByRef, "#2");
778
779                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
780                         Assert.IsTrue (tb3.IsMarshalByRef, "#3");
781                 }
782
783                 // TODO: Visibility properties
784
785                 [Test]
786                 public void TestIsPointer ()
787                 {
788                         // How can this be true?
789                         TypeBuilder tb = module.DefineType (genTypeName ());
790                         Assert.IsFalse (tb.IsPointer);
791                 }
792
793                 [Test]
794                 public void TestIsPrimitive ()
795                 {
796                         TypeBuilder tb = module.DefineType ("int");
797                         Assert.IsFalse (tb.IsPrimitive);
798                 }
799
800                 [Test]
801                 public void IsSealed ()
802                 {
803                         TypeBuilder tb = module.DefineType (genTypeName ());
804                         Assert.IsFalse (tb.IsSealed, "#1");
805
806                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
807                         Assert.IsTrue (tb2.IsSealed, "#2");
808                 }
809
810                 static string CreateTempAssembly ()
811                 {
812                         FileStream f = null;
813                         string path;
814                         Random rnd;
815                         int num = 0;
816
817                         rnd = new Random ();
818                         do {
819                                 num = rnd.Next ();
820                                 num++;
821                                 path = Path.Combine (Path.GetTempPath (), "tmp" + num.ToString ("x") + ".dll");
822
823                                 try {
824                                         f = new FileStream (path, FileMode.CreateNew);
825                                 } catch { }
826                         } while (f == null);
827
828                         f.Close ();
829
830
831                         return "tmp" + num.ToString ("x") + ".dll";
832                 }
833
834                 [Test]
835                 public void IsSerializable ()
836                 {
837                         TypeBuilder tb = module.DefineType (genTypeName ());
838                         Assert.IsFalse (tb.IsSerializable, "#1");
839
840                         ConstructorInfo [] ctors = typeof (SerializableAttribute).GetConstructors (BindingFlags.Instance | BindingFlags.Public);
841                         Assert.IsTrue (ctors.Length > 0, "#2");
842
843                         tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
844                         Type createdType = tb.CreateType ();
845
846                         string an = CreateTempAssembly ();
847                         assembly.Save (an);
848                         Assert.IsTrue (createdType.IsSerializable, "#3");
849                         File.Delete (Path.Combine (Path.GetTempPath (), an));
850                 }
851
852                 [Test]
853                 public void TestIsSpecialName ()
854                 {
855                         TypeBuilder tb = module.DefineType (genTypeName ());
856                         Assert.IsFalse (tb.IsSpecialName, "#1");
857
858                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SpecialName);
859                         Assert.IsTrue (tb2.IsSpecialName, "#2");
860                 }
861
862                 [Test]
863                 public void TestIsUnicodeClass ()
864                 {
865                         TypeBuilder tb = module.DefineType (genTypeName ());
866                         Assert.IsFalse (tb.IsUnicodeClass, "#1");
867
868                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
869                         Assert.IsTrue (tb2.IsUnicodeClass, "#2");
870                 }
871
872                 [Test]
873                 public void TestIsValueType ()
874                 {
875                         TypeBuilder tb = module.DefineType (genTypeName ());
876                         Assert.IsFalse (tb.IsValueType, "#1");
877
878                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
879                         Assert.IsFalse (tb2.IsValueType, "#2");
880
881                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
882                         Assert.IsTrue (tb3.IsValueType, "#3");
883
884                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
885                         Assert.IsTrue (tb4.IsValueType, "#4");
886                 }
887
888                 [Test]
889                 public void TestMemberType ()
890                 {
891                         TypeBuilder tb = module.DefineType (genTypeName ());
892                         Assert.AreEqual (MemberTypes.TypeInfo, tb.MemberType);
893                 }
894
895                 [Test]
896                 public void TestModule ()
897                 {
898                         TypeBuilder tb = module.DefineType (genTypeName ());
899                         Assert.AreEqual (module, tb.Module);
900                 }
901
902                 [Test]
903                 public void TestName ()
904                 {
905                         TypeBuilder tb = module.DefineType ("A");
906                         Assert.AreEqual ("A", tb.Name, "#1");
907
908                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
909                         Assert.AreEqual ("E", tb2.Name, "#2");
910
911                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
912                         Assert.AreEqual ("A", tb3.Name, "#3");
913
914                         /* Is .E a valid name ?
915                         TypeBuilder tb4 = module.DefineType (".E");
916                         Assert.AreEqual ("E", tb4.Name);
917                         */
918                 }
919
920                 [Test]
921                 public void TestNamespace ()
922                 {
923                         TypeBuilder tb = module.DefineType ("A");
924                         Assert.AreEqual (string.Empty, tb.Namespace, "#1");
925
926                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
927                         Assert.AreEqual ("A.B.C.D", tb2.Namespace, "#2");
928
929                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
930                         Assert.AreEqual (string.Empty, tb3.Namespace, "#3");
931
932                         /* Is .E a valid name ?
933                         TypeBuilder tb4 = module.DefineType (".E");
934                         Assert.AreEqual ("E", tb4.Name);
935                         */
936                 }
937
938                 [Test]
939                 public void TestPackingSize ()
940                 {
941                         TypeBuilder tb = module.DefineType (genTypeName ());
942                         Assert.AreEqual (PackingSize.Unspecified, tb.PackingSize, "#1");
943
944                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (object),
945                                 PackingSize.Size16, 16);
946                         Assert.AreEqual (PackingSize.Size16, tb2.PackingSize, "#2");
947                 }
948
949                 [Test]
950                 public void TestReflectedType ()
951                 {
952                         // It is the same as DeclaringType, but why?
953                         TypeBuilder tb = module.DefineType (genTypeName ());
954                         Assert.IsNull (tb.ReflectedType, "#1");
955
956                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName ());
957                         Assert.AreEqual (tb, tb2.ReflectedType, "#2");
958                 }
959
960                 [Test]
961                 public void SetParent_Parent_Null ()
962                 {
963                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class,
964                                 typeof (Attribute));
965 #if NET_2_0
966                         tb.SetParent (null);
967                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
968 #else
969                         try {
970                                 tb.SetParent (null);
971                                 Assert.Fail ("#A1");
972                         } catch (ArgumentNullException ex) {
973                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
974                                 Assert.IsNull (ex.InnerException, "#A3");
975                                 Assert.IsNotNull (ex.Message, "#A4");
976                                 Assert.AreEqual ("parent", ex.ParamName, "#A5");
977                         }
978 #endif
979
980                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
981                                 TypeAttributes.Abstract);
982 #if NET_2_0
983                         tb.SetParent (null);
984                         Assert.IsNull (tb.BaseType, "#B1");
985 #else
986                         try {
987                                 tb.SetParent (null);
988                                 Assert.Fail ("#B1");
989                         } catch (ArgumentNullException ex) {
990                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
991                                 Assert.IsNull (ex.InnerException, "#B3");
992                                 Assert.IsNotNull (ex.Message, "#B4");
993                                 Assert.AreEqual ("parent", ex.ParamName, "#B5");
994                         }
995 #endif
996
997 #if NET_2_0
998                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
999                                 TypeAttributes.Abstract, typeof (ICloneable));
1000                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#C1");
1001                         tb.SetParent (null);
1002                         Assert.IsNull (tb.BaseType, "#C2");
1003
1004                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
1005                                 typeof (IDisposable));
1006                         try {
1007                                 tb.SetParent (null);
1008                                 Assert.Fail ("#D1");
1009                         } catch (InvalidOperationException ex) {
1010                                 // Interface must be declared abstract
1011                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1012                                 Assert.IsNull (ex.InnerException, "#D3");
1013                                 Assert.IsNotNull (ex.Message, "#D4");
1014                         }
1015 #endif
1016                 }
1017
1018                 [Test]
1019                 public void SetParent_Parent_Interface ()
1020                 {
1021                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class);
1022                         tb.SetParent (typeof (ICloneable));
1023                         Assert.AreEqual (typeof (ICloneable), tb.BaseType);
1024                 }
1025
1026                 [Test]
1027                 public void TestSetParentIncomplete ()
1028                 {
1029                         TypeBuilder tb = module.DefineType (genTypeName ());
1030                         tb.SetParent (typeof (Attribute));
1031                         Assert.AreEqual (typeof (Attribute), tb.BaseType, "#1");
1032
1033                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1034                                 TypeAttributes.Abstract);
1035                         tb.SetParent (typeof (IDisposable));
1036                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#2");
1037
1038                         tb = module.DefineType (genTypeName ());
1039                         tb.SetParent (typeof (IDisposable));
1040                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#3");
1041
1042 #if NET_2_0
1043                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1044                                 TypeAttributes.Abstract, typeof (IDisposable));
1045                         tb.SetParent (typeof (ICloneable));
1046                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#4");
1047
1048                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1049                                 TypeAttributes.Abstract, typeof (IDisposable));
1050                         tb.SetParent (typeof (ICloneable));
1051                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#5");
1052 #endif
1053                 }
1054
1055                 [Test]
1056                 public void TestSetParentComplete ()
1057                 {
1058                         TypeBuilder tb = module.DefineType (genTypeName ());
1059                         tb.CreateType ();
1060                         try {
1061                                 tb.SetParent (typeof (Attribute));
1062                                 Assert.Fail ("#1");
1063                         } catch (InvalidOperationException ex) {
1064                                 // Unable to change after type has been created
1065                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1066                                 Assert.IsNull (ex.InnerException, "#3");
1067                                 Assert.IsNotNull (ex.Message, "#4");
1068                         }
1069                 }
1070
1071                 [Test]
1072                 public void TestSize ()
1073                 {
1074                         {
1075                                 TypeBuilder tb = module.DefineType (genTypeName ());
1076                                 Assert.AreEqual (0, tb.Size, "#1");
1077                                 tb.CreateType ();
1078                                 Assert.AreEqual (0, tb.Size, "#2");
1079                         }
1080
1081                         {
1082                                 TypeBuilder tb = module.DefineType (genTypeName (), 0, typeof (object),
1083                                         PackingSize.Size16, 32);
1084                                 Assert.AreEqual (32, tb.Size, "#3");
1085                         }
1086                 }
1087
1088                 [Test]
1089                 public void TestTypeHandle ()
1090                 {
1091                         TypeBuilder tb = module.DefineType (genTypeName ());
1092                         try {
1093                                 RuntimeTypeHandle handle = tb.TypeHandle;
1094                                 Assert.Fail ("#1:" + handle);
1095                         } catch (NotSupportedException ex) {
1096                                 // The invoked member is not supported in a
1097                                 // dynamic module
1098                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1099                                 Assert.IsNull (ex.InnerException, "#3");
1100                                 Assert.IsNotNull (ex.Message, "#4");
1101                         }
1102                 }
1103
1104                 [Test]
1105                 public void TestTypeInitializerIncomplete ()
1106                 {
1107                         TypeBuilder tb = module.DefineType (genTypeName ());
1108                         try {
1109                                 ConstructorInfo cb = tb.TypeInitializer;
1110                                 Assert.Fail ("#1:" + (cb != null));
1111                         } catch (NotSupportedException ex) {
1112                                 // The invoked member is not supported in a
1113                                 // dynamic module
1114                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1115                                 Assert.IsNull (ex.InnerException, "#3");
1116                                 Assert.IsNotNull (ex.Message, "#4");
1117                         }
1118                 }
1119
1120                 [Test]
1121                 public void TestTypeInitializerComplete ()
1122                 {
1123                         TypeBuilder tb = module.DefineType (genTypeName ());
1124                         tb.CreateType ();
1125                         ConstructorInfo cb = tb.TypeInitializer;
1126                 }
1127
1128                 [Test]
1129                 public void TestTypeToken ()
1130                 {
1131                         TypeBuilder tb = module.DefineType (genTypeName ());
1132                         TypeToken token = tb.TypeToken;
1133                 }
1134
1135                 [Test]
1136                 public void UnderlyingSystemType ()
1137                 {
1138                         TypeBuilder tb;
1139                         Type emitted_type;
1140
1141                         tb = module.DefineType (genTypeName ());
1142                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#A1");
1143                         emitted_type = tb.CreateType ();
1144                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#A2");
1145
1146                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1147                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#B1");
1148                         emitted_type = tb.CreateType ();
1149                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#B2");
1150
1151                         tb = module.DefineType (genTypeName (), 0, typeof (ValueType));
1152                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#C1");
1153                         emitted_type = tb.CreateType ();
1154                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#C2");
1155
1156                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1157                         try {
1158                                 Type t = tb.UnderlyingSystemType;
1159                                 Assert.Fail ("#D1:" + t);
1160                         } catch (InvalidOperationException ex) {
1161                                 // Underlying type information on enumeration
1162                                 // is not specified
1163                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1164                                 Assert.IsNull (ex.InnerException, "#D3");
1165                                 Assert.IsNotNull (ex.Message, "#D4");
1166                         }
1167                         tb.DefineField ("val", typeof (int), FieldAttributes.Private);
1168                         Assert.AreEqual (typeof (int), tb.UnderlyingSystemType, "#D5");
1169                         emitted_type = tb.CreateType ();
1170                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#D6");
1171
1172                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1173                         tb.DefineField ("val", typeof (int), FieldAttributes.Static);
1174                         try {
1175                                 Type t = tb.UnderlyingSystemType;
1176                                 Assert.Fail ("#E1:" + t);
1177                         } catch (InvalidOperationException ex) {
1178                                 // Underlying type information on enumeration
1179                                 // is not specified
1180                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1181                                 Assert.IsNull (ex.InnerException, "#E3");
1182                                 Assert.IsNotNull (ex.Message, "#E4");
1183                         }
1184                         tb.DefineField ("foo", typeof (long), FieldAttributes.Private);
1185                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E5");
1186                         tb.DefineField ("bar", typeof (short), FieldAttributes.Private);
1187                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E6");
1188                         tb.DefineField ("boo", typeof (int), FieldAttributes.Static);
1189                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E7");
1190                 }
1191
1192                 [Test]
1193                 public void AddInterfaceImplementation_InterfaceType_Null ()
1194                 {
1195                         TypeBuilder tb = module.DefineType (genTypeName ());
1196                         try {
1197                                 tb.AddInterfaceImplementation (null);
1198                                 Assert.Fail ("#1");
1199                         } catch (ArgumentNullException ex) {
1200                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1201                                 Assert.IsNull (ex.InnerException, "#3");
1202                                 Assert.IsNotNull (ex.Message, "#4");
1203                                 Assert.AreEqual ("interfaceType", ex.ParamName, "#5");
1204                         }
1205                 }
1206
1207                 [Test]
1208                 public void TestAddInterfaceImplementation ()
1209                 {
1210                         TypeBuilder tb = module.DefineType (genTypeName ());
1211                         tb.AddInterfaceImplementation (typeof (AnInterface));
1212                         tb.AddInterfaceImplementation (typeof (AnInterface));
1213
1214                         Type t = tb.CreateType ();
1215                         Assert.AreEqual (1, tb.GetInterfaces ().Length, "#2");
1216
1217                         // Can not be called on a created type
1218                         try {
1219                                 tb.AddInterfaceImplementation (typeof (AnInterface));
1220                                 Assert.Fail ("#3");
1221                         } catch (InvalidOperationException) {
1222                         }
1223                 }
1224
1225                 [Test]
1226 #if ONLY_1_1
1227                 [Category ("NotWorking")] // we allow CreateType to be invoked multiple times
1228 #endif
1229                 public void TestCreateType_Created ()
1230                 {
1231                         TypeBuilder tb = module.DefineType (genTypeName ());
1232 #if NET_2_0
1233                         Assert.IsFalse (tb.IsCreated (), "#A1");
1234 #endif
1235                         Type emittedType1 = tb.CreateType ();
1236 #if NET_2_0
1237                         Assert.IsTrue (tb.IsCreated (), "#A2");
1238 #endif
1239                         Assert.IsNotNull (emittedType1, "#A3");
1240
1241 #if NET_2_0
1242                         Type emittedType2 = tb.CreateType ();
1243                         Assert.IsNotNull (emittedType2, "#B1");
1244                         Assert.IsTrue (tb.IsCreated (), "#B2");
1245                         Assert.AreSame (emittedType1, emittedType2, "#B3");
1246 #else
1247                         try {
1248                                 tb.CreateType ();
1249                                 Assert.Fail ("#B1");
1250                         } catch (InvalidOperationException ex) {
1251                                 // Unable to change after type has been created
1252                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1253                                 Assert.IsNull (ex.InnerException, "#B3");
1254                                 Assert.IsNotNull (ex.Message, "#B4");
1255                         }
1256 #endif
1257                 }
1258
1259                 [Test]
1260                 public void TestDefineConstructor ()
1261                 {
1262                         TypeBuilder tb = module.DefineType (genTypeName ());
1263
1264                         ConstructorBuilder cb = tb.DefineConstructor (0, 0, null);
1265                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1266                         tb.CreateType ();
1267
1268                         // Can not be called on a created type
1269                         try {
1270                                 tb.DefineConstructor (0, 0, null);
1271                                 Assert.Fail ("#1");
1272                         } catch (InvalidOperationException ex) {
1273                                 // Unable to change after type has been created
1274                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1275                                 Assert.IsNull (ex.InnerException, "#3");
1276                                 Assert.IsNotNull (ex.Message, "#4");
1277                         }
1278                 }
1279
1280                 [Test]
1281                 public void DefineDefaultConstructor ()
1282                 {
1283                         TypeBuilder tb = module.DefineType (genTypeName ());
1284                         tb.DefineDefaultConstructor (0);
1285                         tb.CreateType ();
1286
1287                         // Can not be called on a created type, altough the MSDN docs does not mention this
1288                         try {
1289                                 tb.DefineDefaultConstructor (0);
1290                                 Assert.Fail ("#1");
1291                         } catch (InvalidOperationException ex) {
1292                                 // Unable to change after type has been created
1293                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1294                                 Assert.IsNull (ex.InnerException, "#3");
1295                                 Assert.IsNotNull (ex.Message, "#4");
1296                         }
1297                 }
1298
1299                 [Test]
1300                 public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1301                 {
1302                         TypeBuilder tb;
1303                         
1304                         tb = module.DefineType (genTypeName ());
1305                         tb.DefineDefaultConstructor (MethodAttributes.Private);
1306                         Type parent_type = tb.CreateType ();
1307
1308                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1309                                 parent_type);
1310                         tb.DefineDefaultConstructor (MethodAttributes.Public);
1311                         Type emitted_type = tb.CreateType ();
1312                         try {
1313                                 Activator.CreateInstance (emitted_type);
1314                                 Assert.Fail ("#1");
1315                         } catch (TargetInvocationException ex) {
1316                                 Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1317                                 Assert.IsNotNull (ex.InnerException, "#3");
1318                                 Assert.IsNotNull (ex.Message, "#4");
1319
1320                                 MethodAccessException mae = ex.InnerException as MethodAccessException;
1321                                 Assert.IsNotNull (mae, "#5");
1322                                 Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1323                                 Assert.IsNull (mae.InnerException, "#7");
1324                                 Assert.IsNotNull (mae.Message, "#8");
1325                                 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1326                                 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1327                         }
1328                 }
1329
1330                 [Test]
1331                 public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1332                 {
1333                         TypeBuilder tb;
1334
1335                         tb = module.DefineType (genTypeName ());
1336                         ConstructorBuilder cb = tb.DefineConstructor (
1337                                 MethodAttributes.Public,
1338                                 CallingConventions.Standard,
1339                                 new Type [] { typeof (string) });
1340                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1341                         Type parent_type = tb.CreateType ();
1342
1343                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1344                                 parent_type);
1345                         try {
1346                                 tb.DefineDefaultConstructor (MethodAttributes.Public);
1347                                 Assert.Fail ("#1");
1348                         } catch (NotSupportedException ex) {
1349                                 // Parent does not have a default constructor.
1350                                 // The default constructor must be explicitly defined
1351                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1352                                 Assert.IsNull (ex.InnerException, "#3");
1353                                 Assert.IsNotNull (ex.Message, "#4");
1354                         }
1355                 }
1356
1357                 [Test]
1358                 public void DefineEvent_Name_NullChar ()
1359                 {
1360                         TypeBuilder tb = module.DefineType (genTypeName ());
1361
1362                         try {
1363                                 tb.DefineEvent ("\0test", EventAttributes.None,
1364                                         typeof (int));
1365                                 Assert.Fail ("#A1");
1366                         } catch (ArgumentException ex) {
1367                                 // Illegal name
1368                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1369                                 Assert.IsNull (ex.InnerException, "#A3");
1370                                 Assert.IsNotNull (ex.Message, "#A4");
1371                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1372                         }
1373
1374                         EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1375                                 typeof (int));
1376                         Assert.IsNotNull (eb, "#B1");
1377                 }
1378
1379                 [Test]
1380                 public void TestDefineEvent ()
1381                 {
1382                         TypeBuilder tb = module.DefineType (genTypeName ());
1383
1384                         // Test invalid arguments
1385                         try {
1386                                 tb.DefineEvent (null, 0, typeof (int));
1387                                 Assert.Fail ("#A1");
1388                         } catch (ArgumentNullException ex) {
1389                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1390                                 Assert.IsNull (ex.InnerException, "#A3");
1391                                 Assert.IsNotNull (ex.Message, "#A4");
1392                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1393                         }
1394
1395                         try {
1396                                 tb.DefineEvent ("FOO", 0, null);
1397                                 Assert.Fail ("#B1");
1398                         } catch (ArgumentNullException ex) {
1399                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1400                                 Assert.IsNull (ex.InnerException, "#B3");
1401                                 Assert.IsNotNull (ex.Message, "#B4");
1402                                 Assert.AreEqual ("type", ex.ParamName, "#B5");
1403                         }
1404
1405                         try {
1406                                 tb.DefineEvent (string.Empty, 0, typeof (int));
1407                                 Assert.Fail ("#C1");
1408                         } catch (ArgumentException ex) {
1409                                 // Empty name is not legal
1410                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1411                                 Assert.IsNull (ex.InnerException, "#C3");
1412                                 Assert.IsNotNull (ex.Message, "#C4");
1413                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1414                         }
1415
1416                         tb.CreateType ();
1417
1418                         // Can not be called on a created type
1419                         try {
1420                                 tb.DefineEvent ("BAR", 0, typeof (int));
1421                                 Assert.Fail ("#D1");
1422                         } catch (InvalidOperationException ex) {
1423                                 // Unable to change after type has been created
1424                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1425                                 Assert.IsNull (ex.InnerException, "#D3");
1426                                 Assert.IsNotNull (ex.Message, "#D4");
1427                         }
1428                 }
1429
1430                 [Test] // DefineField (String, Type, FieldAttributes)
1431                 public void DefineField1 ()
1432                 {
1433                         TypeBuilder tb = module.DefineType (genTypeName ());
1434
1435                         // Check invalid arguments
1436                         try {
1437                                 tb.DefineField (null, typeof (int), 0);
1438                                 Assert.Fail ("#A1");
1439                         } catch (ArgumentNullException ex) {
1440                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1441                                 Assert.IsNull (ex.InnerException, "#A3");
1442                                 Assert.IsNotNull (ex.Message, "#A4");
1443                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1444                         }
1445
1446                         try {
1447                                 tb.DefineField (string.Empty, typeof (int), 0);
1448                                 Assert.Fail ("#B1");
1449                         } catch (ArgumentException ex) {
1450                                 // Empty name is not legal
1451                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1452                                 Assert.IsNull (ex.InnerException, "#B3");
1453                                 Assert.IsNotNull (ex.Message, "#B4");
1454                                 Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1455                         }
1456
1457                         try {
1458                                 // Strangely, 'A<NULL>' is accepted...
1459                                 string name = String.Format ("{0}", (char) 0);
1460                                 tb.DefineField (name, typeof (int), 0);
1461                                 Assert.Fail ("#C1");
1462                         } catch (ArgumentException ex) {
1463                                 // Illegal name
1464                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1465                                 Assert.IsNull (ex.InnerException, "#C3");
1466                                 Assert.IsNotNull (ex.Message, "#C4");
1467                                 Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1468                         }
1469
1470                         try {
1471                                 tb.DefineField ("A", typeof (void), 0);
1472                                 Assert.Fail ("#D1");
1473                         } catch (ArgumentException ex) {
1474                                 // Bad field type in defining field
1475                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1476                                 Assert.IsNull (ex.InnerException, "#D3");
1477                                 Assert.IsNotNull (ex.Message, "#D4");
1478                                 Assert.IsNull (ex.ParamName, "#D5");
1479                         }
1480
1481                         tb.CreateType ();
1482
1483                         // Can not be called on a created type
1484                         try {
1485                                 tb.DefineField ("B", typeof (int), 0);
1486                                 Assert.Fail ("#E1");
1487                         } catch (InvalidOperationException ex) {
1488                                 // Unable to change after type has been created
1489                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1490                                 Assert.IsNull (ex.InnerException, "#E3");
1491                                 Assert.IsNotNull (ex.Message, "#E4");
1492                         }
1493                 }
1494
1495                 [Test] // DefineField (String, Type, FieldAttributes)
1496                 public void DefineField1_Name_NullChar ()
1497                 {
1498                         TypeBuilder tb = module.DefineType (genTypeName ());
1499
1500                         try {
1501                                 tb.DefineField ("\0test", typeof (int),
1502                                         FieldAttributes.Private);
1503                                 Assert.Fail ("#A1");
1504                         } catch (ArgumentException ex) {
1505                                 // Illegal name
1506                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1507                                 Assert.IsNull (ex.InnerException, "#A3");
1508                                 Assert.IsNotNull (ex.Message, "#A4");
1509                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1510                         }
1511
1512                         FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1513                                 FieldAttributes.Private);
1514                         Assert.IsNotNull (fb, "#B1");
1515                         Assert.AreEqual ("te\0st", fb.Name, "#B2");
1516                 }
1517
1518                 [Test] // DefineField (String, Type, FieldAttributes)
1519                 public void DefineField1_Type_Null ()
1520                 {
1521                         TypeBuilder tb = module.DefineType (genTypeName ());
1522
1523                         try {
1524                                 tb.DefineField ("test", (Type) null,
1525                                         FieldAttributes.Private);
1526                                 Assert.Fail ("#1");
1527                         } catch (ArgumentNullException ex) {
1528                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1529                                 Assert.IsNull (ex.InnerException, "#3");
1530                                 Assert.IsNotNull (ex.Message, "#4");
1531                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1532                         }
1533                 }
1534
1535 #if NET_2_0
1536                 [Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
1537                 public void DefineField2_Type_Null ()
1538                 {
1539                         TypeBuilder tb = module.DefineType (genTypeName ());
1540
1541                         try {
1542                                 tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1543                                         Type.EmptyTypes, FieldAttributes.Private);
1544                                 Assert.Fail ("#1");
1545                         } catch (ArgumentNullException ex) {
1546                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1547                                 Assert.IsNull (ex.InnerException, "#3");
1548                                 Assert.IsNotNull (ex.Message, "#4");
1549                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1550                         }
1551                 }
1552 #endif
1553
1554                 [Test]
1555                 public void TestDefineInitializedData ()
1556                 {
1557                         TypeBuilder tb = module.DefineType (genTypeName ());
1558
1559                         // Check invalid arguments
1560                         try {
1561                                 tb.DefineInitializedData (null, new byte [1], 0);
1562                                 Assert.Fail ("#A1");
1563                         } catch (ArgumentNullException ex) {
1564                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1565                                 Assert.IsNull (ex.InnerException, "#A3");
1566                                 Assert.IsNotNull (ex.Message, "#A4");
1567                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1568                         }
1569
1570                         try {
1571                                 tb.DefineInitializedData ("FOO", null, 0);
1572                                 Assert.Fail ("#B1");
1573                         } catch (ArgumentNullException ex) {
1574                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1575                                 Assert.IsNull (ex.InnerException, "#B3");
1576                                 Assert.IsNotNull (ex.Message, "#B4");
1577                                 Assert.AreEqual ("data", ex.ParamName, "#B5");
1578                         }
1579
1580                         try {
1581                                 tb.DefineInitializedData (string.Empty, new byte [1], 0);
1582                                 Assert.Fail ("#C1");
1583                         } catch (ArgumentException ex) {
1584                                 // Empty name is not legal
1585                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1586                                 Assert.IsNull (ex.InnerException, "#C3");
1587                                 Assert.IsNotNull (ex.Message, "#C4");
1588                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1589                         }
1590
1591                         // The size of the data is less than or equal to zero ???
1592                         try {
1593                                 tb.DefineInitializedData ("BAR", new byte [0], 0);
1594                                 Assert.Fail ("#D1");
1595                         } catch (ArgumentException ex) {
1596                                 // Data size must be > 0 and < 0x3f0000
1597                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1598                                 Assert.IsNull (ex.InnerException, "#D3");
1599                                 Assert.IsNotNull (ex.Message, "#D4");
1600                                 Assert.IsNull (ex.ParamName, "#D5");
1601                         }
1602
1603                         try {
1604                                 string name = String.Format ("{0}", (char) 0);
1605                                 tb.DefineInitializedData (name, new byte [1], 0);
1606                                 Assert.Fail ("#E1");
1607                         } catch (ArgumentException ex) {
1608                                 // Illegal name
1609                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1610                                 Assert.IsNull (ex.InnerException, "#E3");
1611                                 Assert.IsNotNull (ex.Message, "#E4");
1612                                 Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1613                         }
1614
1615                         tb.CreateType ();
1616
1617                         // Can not be called on a created type, altough the MSDN docs does not mention this
1618                         try {
1619                                 tb.DefineInitializedData ("BAR2", new byte [1], 0);
1620                                 Assert.Fail ("#F1");
1621                         } catch (InvalidOperationException ex) {
1622                                 // Unable to change after type has been created
1623                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1624                                 Assert.IsNull (ex.InnerException, "#F3");
1625                                 Assert.IsNotNull (ex.Message, "#F4");
1626                         }
1627                 }
1628
1629                 [Test]
1630                 public void DefineUninitializedDataInvalidArgs ()
1631                 {
1632                         TypeBuilder tb = module.DefineType (genTypeName ());
1633
1634                         try {
1635                                 tb.DefineUninitializedData (null, 1, 0);
1636                                 Assert.Fail ("#A1");
1637                         } catch (ArgumentNullException ex) {
1638                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1639                                 Assert.IsNull (ex.InnerException, "#A3");
1640                                 Assert.IsNotNull (ex.Message, "#A4");
1641                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1642                         }
1643
1644                         try {
1645                                 tb.DefineUninitializedData (string.Empty, 1, 0);
1646                                 Assert.Fail ("#B1");
1647                         } catch (ArgumentException ex) {
1648                                 // Empty name is not legal
1649                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1650                                 Assert.IsNull (ex.InnerException, "#B3");
1651                                 Assert.IsNotNull (ex.Message, "#B4");
1652                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1653                         }
1654
1655                         // The size of the data is less than or equal to zero ???
1656                         try {
1657                                 tb.DefineUninitializedData ("BAR", 0, 0);
1658                                 Assert.Fail ("#C1");
1659                         } catch (ArgumentException ex) {
1660                                 // Data size must be > 0 and < 0x3f0000
1661                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1662                                 Assert.IsNull (ex.InnerException, "#C3");
1663                                 Assert.IsNotNull (ex.Message, "#C4");
1664                                 Assert.IsNull (ex.ParamName, "#C5");
1665                         }
1666
1667                         try {
1668                                 string name = String.Format ("{0}", (char) 0);
1669                                 tb.DefineUninitializedData (name, 1, 0);
1670                                 Assert.Fail ("#D1");
1671                         } catch (ArgumentException ex) {
1672                                 // Illegal name
1673                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1674                                 Assert.IsNull (ex.InnerException, "#D3");
1675                                 Assert.IsNotNull (ex.Message, "#D4");
1676                                 Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1677                         }
1678                 }
1679
1680                 [Test]
1681                 public void DefineUninitializedDataAlreadyCreated ()
1682                 {
1683                         TypeBuilder tb = module.DefineType (genTypeName ());
1684                         tb.CreateType ();
1685                         try {
1686                                 tb.DefineUninitializedData ("BAR2", 1, 0);
1687                                 Assert.Fail ("#1");
1688                         } catch (InvalidOperationException ex) {
1689                                 // Unable to change after type has been created
1690                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1691                                 Assert.IsNull (ex.InnerException, "#3");
1692                                 Assert.IsNotNull (ex.Message, "#4");
1693                         }
1694                 }
1695
1696                 [Test]
1697                 public void DefineUninitializedData ()
1698                 {
1699                         TypeBuilder tb = module.DefineType (genTypeName ());
1700
1701                         tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1702
1703                         Type t = tb.CreateType ();
1704
1705                         object o = Activator.CreateInstance (t);
1706
1707                         FieldInfo fi = t.GetField ("foo");
1708
1709                         object fieldVal = fi.GetValue (o);
1710
1711                         IntPtr ptr = Marshal.AllocHGlobal (4);
1712                         Marshal.StructureToPtr (fieldVal, ptr, true);
1713                         Marshal.FreeHGlobal (ptr);
1714                 }
1715
1716                 [Test]
1717                 public void DefineMethod_Name_NullChar ()
1718                 {
1719                         TypeBuilder tb = module.DefineType (genTypeName ());
1720                         try {
1721                                 tb.DefineMethod ("\0test", MethodAttributes.Private,
1722                                         typeof (string), Type.EmptyTypes);
1723                                 Assert.Fail ("#A1");
1724                         } catch (ArgumentException ex) {
1725                                 // Illegal name
1726                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1727                                 Assert.IsNull (ex.InnerException, "#A3");
1728                                 Assert.IsNotNull (ex.Message, "#A4");
1729                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1730                         }
1731
1732                         MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1733                                 typeof (string), Type.EmptyTypes);
1734                         Assert.IsNotNull (mb, "#B1");
1735                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1736                 }
1737
1738                 [Test]
1739                 public void TestDefineMethod ()
1740                 {
1741                         TypeBuilder tb = module.DefineType (genTypeName ());
1742
1743                         // Check invalid arguments
1744                         try {
1745                                 tb.DefineMethod (null, 0, null, null);
1746                                 Assert.Fail ("#A1");
1747                         } catch (ArgumentNullException ex) {
1748                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1749                                 Assert.IsNull (ex.InnerException, "#A3");
1750                                 Assert.IsNotNull (ex.Message, "#A4");
1751                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1752                         }
1753
1754                         try {
1755                                 tb.DefineMethod (string.Empty, 0, null, null);
1756                                 Assert.Fail ("#B1");
1757                         } catch (ArgumentException ex) {
1758                                 // Empty name is not legal
1759                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1760                                 Assert.IsNull (ex.InnerException, "#B3");
1761                                 Assert.IsNotNull (ex.Message, "#B4");
1762                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1763                         }
1764
1765                         // Check non-virtual methods on an interface
1766                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1767                         try {
1768                                 tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1769                                 Assert.Fail ("#C1");
1770                         } catch (ArgumentException ex) {
1771                                 // Interface method must be abstract and virtual
1772                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1773                                 Assert.IsNull (ex.InnerException, "#C3");
1774                                 Assert.IsNotNull (ex.Message, "#C4");
1775                                 Assert.IsNull (ex.ParamName, "#C5");
1776                         }
1777
1778                         // Check static methods on an interface
1779                         tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1780                                                           typeof (void),
1781                                                           Type.EmptyTypes);
1782
1783                         tb.CreateType ();
1784                         // Can not be called on a created type
1785                         try {
1786                                 tb.DefineMethod ("bar", 0, null, null);
1787                                 Assert.Fail ("#D1");
1788                         } catch (InvalidOperationException ex) {
1789                                 // Unable to change after type has been created
1790                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1791                                 Assert.IsNull (ex.InnerException, "#D3");
1792                                 Assert.IsNotNull (ex.Message, "#D4");
1793                         }
1794                 }
1795
1796                 [Test] // bug #327484
1797                 [Category ("NotWorking")]
1798                 public void TestDefineMethod_Abstract ()
1799                 {
1800                         TypeBuilder tb = module.DefineType (genTypeName ());
1801                         tb.DefineMethod ("Run", MethodAttributes.Public |
1802                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1803                                 typeof (void), Type.EmptyTypes);
1804
1805                         try {
1806                                 tb.CreateType ();
1807                                 Assert.Fail ("#A1");
1808                         } catch (InvalidOperationException ex) {
1809                                 // Type must be declared abstract if any of its
1810                                 // methods are abstract
1811                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1812                                 Assert.IsNull (ex.InnerException, "#A3");
1813                                 Assert.IsNotNull (ex.Message, "#A4");
1814                         }
1815
1816                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1817                         tb.DefineMethod ("Run", MethodAttributes.Public |
1818                                 MethodAttributes.Abstract, typeof (void),
1819                                 Type.EmptyTypes);
1820
1821                         try {
1822                                 tb.CreateType ();
1823                                 Assert.Fail ("#B1");
1824                         } catch (TypeLoadException ex) {
1825                                 // Non-virtual abstract method
1826                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1827                                 Assert.IsNull (ex.InnerException, "#B3");
1828                                 Assert.IsNotNull (ex.Message, "#B4");
1829                         }
1830
1831                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1832                                 TypeAttributes.Public);
1833                         tb.DefineMethod ("Run", MethodAttributes.Public |
1834                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1835                                 typeof (void), Type.EmptyTypes);
1836                         Type emittedType = tb.CreateType ();
1837
1838                         MethodInfo mi1 = emittedType.GetMethod ("Run");
1839                         Assert.IsNotNull (mi1, "#C1");
1840                         Assert.IsTrue (mi1.IsAbstract, "#C2");
1841
1842                         MethodInfo mi2 = tb.GetMethod ("Run");
1843                         Assert.IsNotNull (mi2, "#D1");
1844                         Assert.IsTrue (mi2.IsAbstract, "#D2");
1845                 }
1846
1847                 // TODO: DefineMethodOverride
1848
1849                 [Test]
1850                 public void TestDefineNestedType ()
1851                 {
1852                         TypeBuilder tb = module.DefineType (genTypeName ());
1853
1854                         // Check invalid arguments
1855                         try {
1856                                 tb.DefineNestedType (null);
1857                                 Assert.Fail ("#A1");
1858                         } catch (ArgumentNullException ex) {
1859                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1860                                 Assert.IsNull (ex.InnerException, "#A3");
1861                                 Assert.IsNotNull (ex.Message, "#A4");
1862                                 Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1863                         }
1864
1865                         try {
1866                                 tb.DefineNestedType (string.Empty);
1867                                 Assert.Fail ("#B1");
1868                         } catch (ArgumentException ex) {
1869                                 // Empty name is not legal
1870                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1871                                 Assert.IsNull (ex.InnerException, "#B3");
1872                                 Assert.IsNotNull (ex.Message, "#B4");
1873                                 Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1874                         }
1875
1876                         try {
1877                                 tb.DefineNestedType (nullName ());
1878                                 Assert.Fail ("#C1");
1879                         } catch (ArgumentException ex) {
1880                                 // Illegal name
1881                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1882                                 Assert.IsNull (ex.InnerException, "#C3");
1883                                 Assert.IsNotNull (ex.Message, "#C4");
1884                                 Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1885                         }
1886
1887                         // If I fix the code so this works then mcs breaks -> how can mcs
1888                         // works under MS .NET in the first place ???
1889                         /*
1890                         try {
1891                                 tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1892                                 Fail ("Nested visibility must be specified.");
1893                         }
1894                         catch (ArgumentException) {
1895                         }
1896                         */
1897
1898                         try {
1899                                 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1900                                                                          new Type [1]);
1901                                 Assert.Fail ("#D1");
1902                         } catch (ArgumentNullException ex) {
1903                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1904                                 Assert.IsNull (ex.InnerException, "#D3");
1905                                 Assert.IsNotNull (ex.Message, "#D4");
1906                                 Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1907                         }
1908
1909                         // I think this should reject non-interfaces, but it does not
1910                         tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1911                                                                  new Type [1] { typeof (object) });
1912
1913                         // Normal invocation
1914                         tb.DefineNestedType ("Nest");
1915
1916                         tb.CreateType ();
1917
1918                         // According to the MSDN docs, this cannnot be called after the type
1919                         // is created, but it works.
1920                         tb.DefineNestedType ("Nest2");
1921
1922                         // According to the MSDN docs, a Sealed class can't contain nested 
1923                         // types, but this is not true
1924                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1925                         tb2.DefineNestedType ("AA");
1926
1927                         // According to the MSDN docs, interfaces can only contain interfaces,
1928                         // but this is not true
1929                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1930
1931                         tb3.DefineNestedType ("AA");
1932
1933                         // Check shorter versions
1934                         {
1935                                 TypeBuilder nested = tb.DefineNestedType ("N1");
1936
1937                                 Assert.AreEqual ("N1", nested.Name, "#E1");
1938                                 Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1939                                 Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1940                                 Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1941                         }
1942
1943                         // TODO:
1944                 }
1945
1946                 [Test]
1947                 public void DefinePInvokeMethod_Name_NullChar ()
1948                 {
1949                         TypeBuilder tb = module.DefineType (genTypeName ());
1950                         try {
1951                                 tb.DefinePInvokeMethod ("\0test", "B", "C",
1952                                         MethodAttributes.Private, CallingConventions.Standard,
1953                                         typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1954                                         CharSet.Unicode);
1955                                 Assert.Fail ("#A1");
1956                         } catch (ArgumentException ex) {
1957                                 // Illegal name
1958                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1959                                 Assert.IsNull (ex.InnerException, "#A3");
1960                                 Assert.IsNotNull (ex.Message, "#A4");
1961                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1962                         }
1963
1964                         MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1965                                 MethodAttributes.Private, CallingConventions.Standard,
1966                                 typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1967                                 CharSet.Unicode);
1968                         Assert.IsNotNull (mb, "#B1");
1969                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1970                 }
1971
1972                 [Test]
1973                 public void TestDefinePInvokeMethod ()
1974                 {
1975                         TypeBuilder tb = module.DefineType (genTypeName ());
1976
1977                         tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1978
1979                         // Try invalid parameters
1980                         try {
1981                                 tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1982                                 Assert.Fail ("#A1");
1983                         } catch (ArgumentNullException ex) {
1984                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1985                                 Assert.IsNull (ex.InnerException, "#A3");
1986                                 Assert.IsNotNull (ex.Message, "#A4");
1987                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1988                         }
1989                         // etc...
1990
1991                         // Try invalid attributes
1992                         try {
1993                                 tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1994                                 Assert.Fail ("#B1");
1995                         } catch (ArgumentException ex) {
1996                                 // PInvoke methods must be static and native and
1997                                 // cannot be abstract
1998                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1999                                 Assert.IsNull (ex.InnerException, "#B3");
2000                                 Assert.IsNotNull (ex.Message, "#B4");
2001                                 Assert.IsNull (ex.ParamName, "#B5");
2002                         }
2003
2004                         // Try an interface parent
2005                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
2006
2007                         try {
2008                                 tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
2009                                 Assert.Fail ("#C1");
2010                         } catch (ArgumentException ex) {
2011                                 // PInvoke methods cannot exist on interfaces
2012                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
2013                                 Assert.IsNull (ex.InnerException, "#B3");
2014                                 Assert.IsNotNull (ex.Message, "#B4");
2015                                 Assert.IsNull (ex.ParamName, "#B5");
2016                         }
2017                 }
2018
2019                 [Test]
2020                 public void DefineProperty_Name_NullChar ()
2021                 {
2022                         TypeBuilder tb = module.DefineType (genTypeName ());
2023
2024                         try {
2025                                 tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
2026                                 Assert.Fail ("#A1");
2027                         } catch (ArgumentException ex) {
2028                                 // Illegal name
2029                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
2030                                 Assert.IsNull (ex.InnerException, "#A3");
2031                                 Assert.IsNotNull (ex.Message, "#A4");
2032                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
2033                         }
2034
2035                         PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
2036                                 typeof (string), Type.EmptyTypes); 
2037                         Assert.IsNotNull (pb, "#B1");
2038                         Assert.AreEqual ("te\0st", pb.Name, "#B2");
2039                 }
2040
2041                 [Test]
2042                 public void DefineProperty_ParameterTypes_ItemNull ()
2043                 {
2044                         TypeBuilder tb = module.DefineType (genTypeName ());
2045
2046                         try {
2047                                 tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
2048                                 Assert.Fail ("#1");
2049                         } catch (ArgumentNullException ex) {
2050                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2051                                 Assert.IsNull (ex.InnerException, "#3");
2052                                 Assert.IsNotNull (ex.Message, "#4");
2053                         }
2054                 }
2055
2056                 [Test]
2057                 public void DefineProperty_ReturnType_Null ()
2058                 {
2059                         TypeBuilder tb = module.DefineType (genTypeName ());
2060                         tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
2061                 }
2062
2063 #if NET_2_0
2064                 [Test]
2065                 public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
2066                         TypeBuilder tb = module.DefineType (genTypeName ());
2067                         tb.DefineGenericParameters ("T");
2068                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2069
2070                         Type ginst = tb.MakeGenericType (typeof (int));
2071                         
2072                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2073                         try {
2074                                 TypeBuilder.GetMethod (ginst, mi);
2075                                 Assert.Fail ("#1");
2076                         } catch (ArgumentException ex) {
2077                                 Assert.AreEqual ("method", ex.ParamName, "#5");
2078                         }
2079                 }
2080
2081                 [Test]
2082                 public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2083                         TypeBuilder tb = module.DefineType (genTypeName ());
2084                         tb.DefineGenericParameters ("T");
2085                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2086                         ILGenerator ig = mb.GetILGenerator ();
2087                         ig.Emit (OpCodes.Ret);
2088                         
2089                         tb.CreateType ();
2090                         
2091                         MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2092                         Assert.IsNotNull (mi);
2093                 }
2094
2095                 [Test]
2096                 [Category ("NotDotNet")]
2097                 [Category ("NotWorking")]
2098                 public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2099                         AssemblyName assemblyName = new AssemblyName ();
2100                         assemblyName.Name = ASSEMBLY_NAME;
2101
2102                         assembly =
2103                                 Thread.GetDomain ().DefineDynamicAssembly (
2104                                         assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, Path.GetTempPath ());
2105
2106                         module = assembly.DefineDynamicModule ("module1");
2107                         
2108                         TypeBuilder tb = module.DefineType (genTypeName ());
2109                         tb.DefineGenericParameters ("T");
2110                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2111
2112                         Type ginst = tb.MakeGenericType (typeof (int));
2113                         
2114                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2115
2116                         try {
2117                                 TypeBuilder.GetMethod (ginst, mi);
2118                         } catch (ArgumentException ex) {
2119                                 Assert.Fail ("#1");
2120                         }
2121                 }
2122
2123
2124                 [Test]
2125                 // Test that changes made to the method builder after a call to GetMethod ()
2126                 // are visible
2127                 public void TestGetMethod ()
2128                 {
2129                         TypeBuilder tb = module.DefineType (genTypeName ());
2130                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2131
2132                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2133                         ILGenerator ig;
2134                         ig = cb.GetILGenerator ();
2135                         ig.Emit (OpCodes.Ret);
2136
2137                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2138
2139                         // Create a method builder but do not emit IL yet
2140                         MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2141
2142                         Type t = tb.MakeGenericType (typeof (int));
2143
2144                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2145
2146                         ig = mb.GetILGenerator ();
2147                         ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2148                         ig.Emit (OpCodes.Ret);
2149
2150                         // Finish the method
2151                         ig = mb1.GetILGenerator ();
2152                         ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2153                         ig.Emit (OpCodes.Ret);
2154
2155                         Type t2 = tb.CreateType ();
2156
2157                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2158                 }
2159
2160                 [Test]
2161                 public void TestGetConstructor ()
2162                 {
2163                         TypeBuilder tb = module.DefineType (genTypeName ());
2164                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2165
2166                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2167                         ILGenerator ig;
2168
2169                         Type t = tb.MakeGenericType (typeof (int));
2170
2171                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2172
2173                         ig = mb.GetILGenerator ();
2174
2175                         ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2176
2177                         ig.Emit (OpCodes.Newobj, ci);
2178                         ig.Emit (OpCodes.Ret);
2179
2180                         // Finish the ctorbuilder
2181                         ig = cb.GetILGenerator ();
2182                         ig.Emit (OpCodes.Ret);
2183
2184                         Type t2 = tb.CreateType ();
2185
2186                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2187                 }
2188
2189                 [Test]
2190                 [ExpectedException (typeof (ArgumentException))]
2191                 public void Static_GetConstructor_TypeNull ()
2192                 {
2193                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2194                         // null is non-generic (from exception message)
2195                         TypeBuilder.GetConstructor (null, ci);
2196                 }
2197
2198                 [Test]
2199                 [ExpectedException (typeof (ArgumentException))]
2200                 public void Static_GetConstructor_TypeGeneric ()
2201                 {
2202                         Type t = typeof (List<>).MakeGenericType (typeof (int));
2203                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2204                         // type is not 'TypeBuilder' (from exception message)
2205                         TypeBuilder.GetConstructor (t, ci);
2206                 }
2207
2208                 [Test]
2209                 public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
2210                 {
2211                         TypeBuilder tb = module.DefineType ("XXX");
2212                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2213                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2214                         try {
2215                                 TypeBuilder.GetConstructor (fooOfT, null);
2216                                 Assert.Fail ("Expected NullReferenceException");
2217                         }
2218                         catch (NullReferenceException) {
2219                         }
2220                 }
2221 #endif
2222
2223                 [Test] //#536243
2224                 public void CreateTypeThrowsForMethodsWithBadLabels ()
2225                 {
2226                         TypeBuilder tb = module.DefineType (genTypeName ());
2227
2228                         MethodBuilder mb = tb.DefineMethod("F", MethodAttributes.Public, typeof(string), null);
2229                         ILGenerator il_gen = mb.GetILGenerator ();
2230                         il_gen.DefineLabel ();
2231                         il_gen.Emit (OpCodes.Leave, new Label ());
2232                         try {
2233                                 tb.CreateType ();
2234                                 Assert.Fail ();
2235                         } catch (ArgumentException) {}
2236                 }
2237
2238                 [Test]
2239                 [Category ("NotWorking")]
2240                 public void TestIsDefinedIncomplete ()
2241                 {
2242                         TypeBuilder tb = module.DefineType (genTypeName ());
2243                         try {
2244                                 tb.IsDefined (typeof (int), true);
2245                                 Assert.Fail ("#1");
2246                         } catch (NotSupportedException ex) {
2247                                 // The invoked member is not supported in a
2248                                 // dynamic module
2249                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2250                                 Assert.IsNull (ex.InnerException, "#3");
2251                                 Assert.IsNotNull (ex.Message, "#4");
2252                         }
2253                 }
2254
2255                 [Test]
2256                 public void TestIsDefinedComplete ()
2257                 {
2258                         TypeBuilder tb = module.DefineType (genTypeName ());
2259
2260                         ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2261                                 new Type [] { typeof (string) });
2262
2263                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2264                                 new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2265
2266                         tb.SetCustomAttribute (caBuilder);
2267                         tb.CreateType ();
2268                         Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2269                 }
2270
2271                 [Test]
2272                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
2273                 public void IsDefined_AttributeType_Null ()
2274                 {
2275                         TypeBuilder tb = module.DefineType (genTypeName ());
2276                         tb.CreateType ();
2277
2278                         try {
2279                                 tb.IsDefined ((Type) null, false);
2280                                 Assert.Fail ("#1");
2281                         } catch (ArgumentNullException ex) {
2282                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2283                                 Assert.IsNull (ex.InnerException, "#3");
2284                                 Assert.IsNotNull (ex.Message, "#4");
2285                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2286                         }
2287                 }
2288
2289                 [Test] // GetConstructor (Type [])
2290                 public void GetConstructor1_Incomplete ()
2291                 {
2292                         TypeBuilder tb = module.DefineType (genTypeName ());
2293                         ConstructorBuilder cb = tb.DefineConstructor (
2294                                 MethodAttributes.Public,
2295                                 CallingConventions.Standard,
2296                                 Type.EmptyTypes);
2297                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2298
2299                         try {
2300                                 tb.GetConstructor (Type.EmptyTypes);
2301                                 Assert.Fail ("#1");
2302                         } catch (NotSupportedException ex) {
2303                                 // The invoked member is not supported in a
2304                                 // dynamic module
2305                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2306                                 Assert.IsNull (ex.InnerException, "#3");
2307                                 Assert.IsNotNull (ex.Message, "#4");
2308                         }
2309                 }
2310
2311                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2312                 public void GetConstructor2_Complete ()
2313                 {
2314                         BindingFlags flags;
2315                         ConstructorInfo ctor;
2316
2317                         TypeBuilder redType = module.DefineType (genTypeName (),
2318                                 TypeAttributes.Public);
2319                         CreateMembers (redType, "Red", true);
2320
2321                         TypeBuilder greenType = module.DefineType (genTypeName (),
2322                                 TypeAttributes.Public, redType);
2323                         CreateMembers (greenType, "Green", false);
2324                         ConstructorBuilder cb = greenType.DefineConstructor (
2325                                 MethodAttributes.Public,
2326                                 CallingConventions.Standard,
2327                                 Type.EmptyTypes);
2328                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2329
2330                         redType.CreateType ();
2331                         greenType.CreateType ();
2332
2333                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
2334
2335                         ctor = greenType.GetConstructor (flags, null,
2336                                 new Type [] { typeof (int), typeof (int) },
2337                                 new ParameterModifier [0]);
2338                         Assert.IsNull (ctor, "#A1");
2339
2340                         ctor = greenType.GetConstructor (flags, null,
2341                                 new Type [] { typeof (string) },
2342                                 new ParameterModifier [0]);
2343                         Assert.IsNull (ctor, "#A2");
2344
2345                         ctor = greenType.GetConstructor (flags, null,
2346                                 new Type [] { typeof (string), typeof (string) },
2347                                 new ParameterModifier [0]);
2348                         Assert.IsNull (ctor, "#A3");
2349
2350                         ctor = greenType.GetConstructor (flags, null,
2351                                 new Type [] { typeof (int) },
2352                                 new ParameterModifier [0]);
2353                         Assert.IsNull (ctor, "#A4");
2354
2355                         ctor = greenType.GetConstructor (flags, null,
2356                                 new Type [] { typeof (int), typeof (bool) },
2357                                 new ParameterModifier [0]);
2358                         Assert.IsNull (ctor, "#A5");
2359
2360                         ctor = greenType.GetConstructor (flags, null,
2361                                 new Type [] { typeof (string), typeof (int) },
2362                                 new ParameterModifier [0]);
2363                         Assert.IsNull (ctor, "#A6");
2364
2365                         ctor = greenType.GetConstructor (flags, null,
2366                                 Type.EmptyTypes,
2367                                 new ParameterModifier [0]);
2368                         Assert.IsNull (ctor, "#A7");
2369
2370                         ctor = redType.GetConstructor (flags, null,
2371                                 new Type [] { typeof (int), typeof (int) },
2372                                 new ParameterModifier [0]);
2373                         Assert.IsNotNull (ctor, "#A8a");
2374                         Assert.IsTrue (ctor.IsPrivate, "#A8b");
2375                         Assert.IsFalse (ctor.IsStatic, "#A8c");
2376                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2377                         Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2378
2379                         ctor = redType.GetConstructor (flags, null,
2380                                 new Type [] { typeof (string) },
2381                                 new ParameterModifier [0]);
2382                         Assert.IsNotNull (ctor, "#A9a");
2383                         Assert.IsTrue (ctor.IsFamily, "#A9b");
2384                         Assert.IsFalse (ctor.IsStatic, "#A9c");
2385                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2386                         Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2387
2388                         ctor = redType.GetConstructor (flags, null,
2389                                 new Type [] { typeof (string), typeof (string) },
2390                                 new ParameterModifier [0]);
2391                         Assert.IsNotNull (ctor, "#A10a");
2392                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2393                         Assert.IsFalse (ctor.IsStatic, "#A10c");
2394                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2395                         Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2396
2397                         ctor = redType.GetConstructor (flags, null,
2398                                 new Type [] { typeof (int) },
2399                                 new ParameterModifier [0]);
2400                         Assert.IsNotNull (ctor, "#A11a");
2401                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2402                         Assert.IsFalse (ctor.IsStatic, "#A11c");
2403                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2404                         Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2405
2406                         ctor = redType.GetConstructor (flags, null,
2407                                 new Type [] { typeof (int), typeof (bool) },
2408                                 new ParameterModifier [0]);
2409                         Assert.IsNull (ctor, "#A12");
2410
2411                         ctor = redType.GetConstructor (flags, null,
2412                                 new Type [] { typeof (string), typeof (int) },
2413                                 new ParameterModifier [0]);
2414                         Assert.IsNotNull (ctor, "#A13a");
2415                         Assert.IsTrue (ctor.IsAssembly, "#A13b");
2416                         Assert.IsFalse (ctor.IsStatic, "#A13c");
2417                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2418                         Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2419
2420                         ctor = redType.GetConstructor (flags, null,
2421                                 Type.EmptyTypes,
2422                                 new ParameterModifier [0]);
2423                         Assert.IsNull (ctor, "#A14");
2424
2425                         flags = BindingFlags.Instance | BindingFlags.Public;
2426
2427                         ctor = greenType.GetConstructor (flags, null,
2428                                 new Type [] { typeof (int), typeof (int) },
2429                                 new ParameterModifier [0]);
2430                         Assert.IsNull (ctor, "#B1");
2431
2432                         ctor = greenType.GetConstructor (flags, null,
2433                                 new Type [] { typeof (string) },
2434                                 new ParameterModifier [0]);
2435                         Assert.IsNull (ctor, "#B2");
2436
2437                         ctor = greenType.GetConstructor (flags, null,
2438                                 new Type [] { typeof (string), typeof (string) },
2439                                 new ParameterModifier [0]);
2440                         Assert.IsNull (ctor, "#B3");
2441
2442                         ctor = greenType.GetConstructor (flags, null,
2443                                 new Type [] { typeof (int) },
2444                                 new ParameterModifier [0]);
2445                         Assert.IsNull (ctor, "#B4");
2446
2447                         ctor = greenType.GetConstructor (flags, null,
2448                                 new Type [] { typeof (int), typeof (bool) },
2449                                 new ParameterModifier [0]);
2450                         Assert.IsNull (ctor, "#B5");
2451
2452                         ctor = greenType.GetConstructor (flags, null,
2453                                 new Type [] { typeof (string), typeof (int) },
2454                                 new ParameterModifier [0]);
2455                         Assert.IsNull (ctor, "#B6");
2456
2457                         ctor = greenType.GetConstructor (flags, null,
2458                                 Type.EmptyTypes,
2459                                 new ParameterModifier [0]);
2460                         Assert.IsNotNull (ctor, "#B7a");
2461                         Assert.IsTrue (ctor.IsPublic, "#B7b");
2462                         Assert.IsFalse (ctor.IsStatic, "#B7c");
2463                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2464                         Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2465
2466                         ctor = redType.GetConstructor (flags, null,
2467                                 new Type [] { typeof (int), typeof (int) },
2468                                 new ParameterModifier [0]);
2469                         Assert.IsNull (ctor, "#B8");
2470
2471                         ctor = redType.GetConstructor (flags, null,
2472                                 new Type [] { typeof (string) },
2473                                 new ParameterModifier [0]);
2474                         Assert.IsNull (ctor, "#B9");
2475
2476                         ctor = redType.GetConstructor (flags, null,
2477                                 new Type [] { typeof (string), typeof (string) },
2478                                 new ParameterModifier [0]);
2479                         Assert.IsNull (ctor, "#B10");
2480
2481                         ctor = redType.GetConstructor (flags, null,
2482                                 new Type [] { typeof (int) },
2483                                 new ParameterModifier [0]);
2484                         Assert.IsNull (ctor, "#B11");
2485
2486                         ctor = redType.GetConstructor (flags, null,
2487                                 new Type [] { typeof (int), typeof (bool) },
2488                                 new ParameterModifier [0]);
2489                         Assert.IsNotNull (ctor, "#B12a");
2490                         Assert.IsTrue (ctor.IsPublic, "#B12b");
2491                         Assert.IsFalse (ctor.IsStatic, "#B12c");
2492                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2493                         Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2494
2495                         ctor = redType.GetConstructor (flags, null,
2496                                 new Type [] { typeof (string), typeof (int) },
2497                                 new ParameterModifier [0]);
2498                         Assert.IsNull (ctor, "#B13");
2499
2500                         ctor = redType.GetConstructor (flags, null,
2501                                 Type.EmptyTypes,
2502                                 new ParameterModifier [0]);
2503                         Assert.IsNull (ctor, "#B14");
2504
2505                         flags = BindingFlags.Static | BindingFlags.Public;
2506
2507                         ctor = greenType.GetConstructor (flags, null,
2508                                 new Type [] { typeof (int), typeof (int) },
2509                                 new ParameterModifier [0]);
2510                         Assert.IsNull (ctor, "#C1");
2511
2512                         ctor = greenType.GetConstructor (flags, null,
2513                                 new Type [] { typeof (string) },
2514                                 new ParameterModifier [0]);
2515                         Assert.IsNull (ctor, "#C2");
2516
2517                         ctor = greenType.GetConstructor (flags, null,
2518                                 new Type [] { typeof (string), typeof (string) },
2519                                 new ParameterModifier [0]);
2520                         Assert.IsNull (ctor, "#C3");
2521
2522                         ctor = greenType.GetConstructor (flags, null,
2523                                 new Type [] { typeof (int) },
2524                                 new ParameterModifier [0]);
2525                         Assert.IsNull (ctor, "#C4");
2526
2527                         ctor = greenType.GetConstructor (flags, null,
2528                                 new Type [] { typeof (int), typeof (bool) },
2529                                 new ParameterModifier [0]);
2530                         Assert.IsNull (ctor, "#C5");
2531
2532                         ctor = greenType.GetConstructor (flags, null,
2533                                 new Type [] { typeof (string), typeof (int) },
2534                                 new ParameterModifier [0]);
2535                         Assert.IsNull (ctor, "#C6");
2536
2537                         ctor = greenType.GetConstructor (flags, null,
2538                                 Type.EmptyTypes,
2539                                 new ParameterModifier [0]);
2540                         Assert.IsNull (ctor, "#C7");
2541
2542                         ctor = redType.GetConstructor (flags, null,
2543                                 new Type [] { typeof (int), typeof (int) },
2544                                 new ParameterModifier [0]);
2545                         Assert.IsNull (ctor, "#C8");
2546
2547                         ctor = redType.GetConstructor (flags, null,
2548                                 new Type [] { typeof (string) },
2549                                 new ParameterModifier [0]);
2550                         Assert.IsNull (ctor, "#C9");
2551
2552                         ctor = redType.GetConstructor (flags, null,
2553                                 new Type [] { typeof (string), typeof (string) },
2554                                 new ParameterModifier [0]);
2555                         Assert.IsNull (ctor, "#C10");
2556
2557                         ctor = redType.GetConstructor (flags, null,
2558                                 new Type [] { typeof (int) },
2559                                 new ParameterModifier [0]);
2560                         Assert.IsNull (ctor, "#C11a");
2561
2562                         ctor = redType.GetConstructor (flags, null,
2563                                 new Type [] { typeof (int), typeof (bool) },
2564                                 new ParameterModifier [0]);
2565                         Assert.IsNull (ctor, "#C12");
2566
2567                         ctor = redType.GetConstructor (flags, null,
2568                                 new Type [] { typeof (string), typeof (int) },
2569                                 new ParameterModifier [0]);
2570                         Assert.IsNull (ctor, "#C13");
2571
2572                         ctor = redType.GetConstructor (flags, null,
2573                                 Type.EmptyTypes,
2574                                 new ParameterModifier [0]);
2575                         Assert.IsNull (ctor, "#C14");
2576
2577                         flags = BindingFlags.Static | BindingFlags.NonPublic;
2578
2579                         ctor = greenType.GetConstructor (flags, null,
2580                                 new Type [] { typeof (int), typeof (int) },
2581                                 new ParameterModifier [0]);
2582                         Assert.IsNull (ctor, "#D1");
2583
2584                         ctor = greenType.GetConstructor (flags, null,
2585                                 new Type [] { typeof (string) },
2586                                 new ParameterModifier [0]);
2587                         Assert.IsNull (ctor, "#D2");
2588
2589                         ctor = greenType.GetConstructor (flags, null,
2590                                 new Type [] { typeof (string), typeof (string) },
2591                                 new ParameterModifier [0]);
2592                         Assert.IsNull (ctor, "#D3");
2593
2594                         ctor = greenType.GetConstructor (flags, null,
2595                                 new Type [] { typeof (int) },
2596                                 new ParameterModifier [0]);
2597                         Assert.IsNull (ctor, "#D4");
2598
2599                         ctor = greenType.GetConstructor (flags, null,
2600                                 new Type [] { typeof (int), typeof (bool) },
2601                                 new ParameterModifier [0]);
2602                         Assert.IsNull (ctor, "#D5");
2603
2604                         ctor = greenType.GetConstructor (flags, null,
2605                                 new Type [] { typeof (string), typeof (int) },
2606                                 new ParameterModifier [0]);
2607                         Assert.IsNull (ctor, "#D6");
2608
2609                         ctor = greenType.GetConstructor (flags, null,
2610                                 Type.EmptyTypes,
2611                                 new ParameterModifier [0]);
2612                         Assert.IsNull (ctor, "#D7");
2613
2614                         ctor = redType.GetConstructor (flags, null,
2615                                 new Type [] { typeof (int), typeof (int) },
2616                                 new ParameterModifier [0]);
2617                         Assert.IsNull (ctor, "#D8");
2618
2619                         ctor = redType.GetConstructor (flags, null,
2620                                 new Type [] { typeof (string) },
2621                                 new ParameterModifier [0]);
2622                         Assert.IsNull (ctor, "#D9");
2623
2624                         ctor = redType.GetConstructor (flags, null,
2625                                 new Type [] { typeof (string), typeof (string) },
2626                                 new ParameterModifier [0]);
2627                         Assert.IsNull (ctor, "#D10");
2628
2629                         ctor = redType.GetConstructor (flags, null,
2630                                 new Type [] { typeof (int) },
2631                                 new ParameterModifier [0]);
2632                         Assert.IsNull (ctor, "#D11");
2633
2634                         ctor = redType.GetConstructor (flags, null,
2635                                 new Type [] { typeof (int), typeof (bool) },
2636                                 new ParameterModifier [0]);
2637                         Assert.IsNull (ctor, "#D12");
2638
2639                         ctor = redType.GetConstructor (flags, null,
2640                                 new Type [] { typeof (string), typeof (int) },
2641                                 new ParameterModifier [0]);
2642                         Assert.IsNull (ctor, "#D13");
2643
2644                         ctor = redType.GetConstructor (flags, null,
2645                                 Type.EmptyTypes,
2646                                 new ParameterModifier [0]);
2647                         Assert.IsNotNull (ctor, "#D14a");
2648                         Assert.IsTrue (ctor.IsPrivate, "#D14b");
2649                         Assert.IsTrue (ctor.IsStatic, "#B14c");
2650                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2651                         Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2652
2653                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2654                                 BindingFlags.FlattenHierarchy;
2655
2656                         ctor = greenType.GetConstructor (flags, null,
2657                                 new Type [] { typeof (int), typeof (int) },
2658                                 new ParameterModifier [0]);
2659                         Assert.IsNull (ctor, "#E1");
2660
2661                         ctor = greenType.GetConstructor (flags, null,
2662                                 new Type [] { typeof (string) },
2663                                 new ParameterModifier [0]);
2664                         Assert.IsNull (ctor, "#E2");
2665
2666                         ctor = greenType.GetConstructor (flags, null,
2667                                 new Type [] { typeof (string), typeof (string) },
2668                                 new ParameterModifier [0]);
2669                         Assert.IsNull (ctor, "#E3");
2670
2671                         ctor = greenType.GetConstructor (flags, null,
2672                                 new Type [] { typeof (int) },
2673                                 new ParameterModifier [0]);
2674                         Assert.IsNull (ctor, "#E4");
2675
2676                         ctor = greenType.GetConstructor (flags, null,
2677                                 new Type [] { typeof (int), typeof (bool) },
2678                                 new ParameterModifier [0]);
2679                         Assert.IsNull (ctor, "#E5");
2680
2681                         ctor = greenType.GetConstructor (flags, null,
2682                                 new Type [] { typeof (string), typeof (int) },
2683                                 new ParameterModifier [0]);
2684                         Assert.IsNull (ctor, "#E6");
2685
2686                         ctor = greenType.GetConstructor (flags, null,
2687                                 Type.EmptyTypes,
2688                                 new ParameterModifier [0]);
2689                         Assert.IsNull (ctor, "#E7");
2690
2691                         ctor = redType.GetConstructor (flags, null,
2692                                 new Type [] { typeof (int), typeof (int) },
2693                                 new ParameterModifier [0]);
2694                         Assert.IsNotNull (ctor, "#E8a");
2695                         Assert.IsTrue (ctor.IsPrivate, "#E8b");
2696                         Assert.IsFalse (ctor.IsStatic, "#E8c");
2697                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2698                         Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2699
2700                         ctor = redType.GetConstructor (flags, null,
2701                                 new Type [] { typeof (string) },
2702                                 new ParameterModifier [0]);
2703                         Assert.IsNotNull (ctor, "#E9a");
2704                         Assert.IsTrue (ctor.IsFamily, "#E9b");
2705                         Assert.IsFalse (ctor.IsStatic, "#E9c");
2706                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2707                         Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2708
2709                         ctor = redType.GetConstructor (flags, null,
2710                                 new Type [] { typeof (string), typeof (string) },
2711                                 new ParameterModifier [0]);
2712                         Assert.IsNotNull (ctor, "#E10a");
2713                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2714                         Assert.IsFalse (ctor.IsStatic, "#E10c");
2715                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2716                         Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2717
2718                         ctor = redType.GetConstructor (flags, null,
2719                                 new Type [] { typeof (int) },
2720                                 new ParameterModifier [0]);
2721                         Assert.IsNotNull (ctor, "#E11a");
2722                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2723                         Assert.IsFalse (ctor.IsStatic, "#E11c");
2724                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2725                         Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2726
2727                         ctor = redType.GetConstructor (flags, null,
2728                                 new Type [] { typeof (int), typeof (bool) },
2729                                 new ParameterModifier [0]);
2730                         Assert.IsNull (ctor, "#E12");
2731
2732                         ctor = redType.GetConstructor (flags, null,
2733                                 new Type [] { typeof (string), typeof (int) },
2734                                 new ParameterModifier [0]);
2735                         Assert.IsNotNull (ctor, "#E13a");
2736                         Assert.IsTrue (ctor.IsAssembly, "#E13b");
2737                         Assert.IsFalse (ctor.IsStatic, "#E13c");
2738                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2739                         Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2740
2741                         ctor = redType.GetConstructor (flags, null,
2742                                 Type.EmptyTypes,
2743                                 new ParameterModifier [0]);
2744                         Assert.IsNull (ctor, "#E14");
2745
2746                         flags = BindingFlags.Instance | BindingFlags.Public |
2747                                 BindingFlags.FlattenHierarchy;
2748
2749                         ctor = greenType.GetConstructor (flags, null,
2750                                 new Type [] { typeof (int), typeof (int) },
2751                                 new ParameterModifier [0]);
2752                         Assert.IsNull (ctor, "#F1");
2753
2754                         ctor = greenType.GetConstructor (flags, null,
2755                                 new Type [] { typeof (string) },
2756                                 new ParameterModifier [0]);
2757                         Assert.IsNull (ctor, "#F2");
2758
2759                         ctor = greenType.GetConstructor (flags, null,
2760                                 new Type [] { typeof (string), typeof (string) },
2761                                 new ParameterModifier [0]);
2762                         Assert.IsNull (ctor, "#F3");
2763
2764                         ctor = greenType.GetConstructor (flags, null,
2765                                 new Type [] { typeof (int) },
2766                                 new ParameterModifier [0]);
2767                         Assert.IsNull (ctor, "#F4");
2768
2769                         ctor = greenType.GetConstructor (flags, null,
2770                                 new Type [] { typeof (int), typeof (bool) },
2771                                 new ParameterModifier [0]);
2772                         Assert.IsNull (ctor, "#F5");
2773
2774                         ctor = greenType.GetConstructor (flags, null,
2775                                 new Type [] { typeof (string), typeof (int) },
2776                                 new ParameterModifier [0]);
2777                         Assert.IsNull (ctor, "#F6");
2778
2779                         ctor = greenType.GetConstructor (flags, null,
2780                                 Type.EmptyTypes,
2781                                 new ParameterModifier [0]);
2782                         Assert.IsNotNull (ctor, "#F7a");
2783                         Assert.IsTrue (ctor.IsPublic, "#F7b");
2784                         Assert.IsFalse (ctor.IsStatic, "#F7c");
2785                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2786                         Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2787
2788                         ctor = redType.GetConstructor (flags, null,
2789                                 new Type [] { typeof (int), typeof (int) },
2790                                 new ParameterModifier [0]);
2791                         Assert.IsNull (ctor, "#F8");
2792
2793                         ctor = redType.GetConstructor (flags, null,
2794                                 new Type [] { typeof (string) },
2795                                 new ParameterModifier [0]);
2796                         Assert.IsNull (ctor, "#F9");
2797
2798                         ctor = redType.GetConstructor (flags, null,
2799                                 new Type [] { typeof (string), typeof (string) },
2800                                 new ParameterModifier [0]);
2801                         Assert.IsNull (ctor, "#F10");
2802
2803                         ctor = redType.GetConstructor (flags, null,
2804                                 new Type [] { typeof (int) },
2805                                 new ParameterModifier [0]);
2806                         Assert.IsNull (ctor, "#F11");
2807
2808                         ctor = redType.GetConstructor (flags, null,
2809                                 new Type [] { typeof (int), typeof (bool) },
2810                                 new ParameterModifier [0]);
2811                         Assert.IsNotNull (ctor, "#F12a");
2812                         Assert.IsTrue (ctor.IsPublic, "#F12b");
2813                         Assert.IsFalse (ctor.IsStatic, "#F12c");
2814                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2815                         Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2816
2817                         ctor = redType.GetConstructor (flags, null,
2818                                 new Type [] { typeof (string), typeof (int) },
2819                                 new ParameterModifier [0]);
2820                         Assert.IsNull (ctor, "#F13");
2821
2822                         ctor = redType.GetConstructor (flags, null,
2823                                 Type.EmptyTypes,
2824                                 new ParameterModifier [0]);
2825                         Assert.IsNull (ctor, "#F14");
2826
2827                         flags = BindingFlags.Static | BindingFlags.Public |
2828                                 BindingFlags.FlattenHierarchy;
2829
2830                         ctor = greenType.GetConstructor (flags, null,
2831                                 new Type [] { typeof (int), typeof (int) },
2832                                 new ParameterModifier [0]);
2833                         Assert.IsNull (ctor, "#G1");
2834
2835                         ctor = greenType.GetConstructor (flags, null,
2836                                 new Type [] { typeof (string) },
2837                                 new ParameterModifier [0]);
2838                         Assert.IsNull (ctor, "#G2");
2839
2840                         ctor = greenType.GetConstructor (flags, null,
2841                                 new Type [] { typeof (string), typeof (string) },
2842                                 new ParameterModifier [0]);
2843                         Assert.IsNull (ctor, "#G3");
2844
2845                         ctor = greenType.GetConstructor (flags, null,
2846                                 new Type [] { typeof (int) },
2847                                 new ParameterModifier [0]);
2848                         Assert.IsNull (ctor, "#G4");
2849
2850                         ctor = greenType.GetConstructor (flags, null,
2851                                 new Type [] { typeof (int), typeof (bool) },
2852                                 new ParameterModifier [0]);
2853                         Assert.IsNull (ctor, "#G5");
2854
2855                         ctor = greenType.GetConstructor (flags, null,
2856                                 new Type [] { typeof (string), typeof (int) },
2857                                 new ParameterModifier [0]);
2858                         Assert.IsNull (ctor, "#G6");
2859
2860                         ctor = greenType.GetConstructor (flags, null,
2861                                 Type.EmptyTypes,
2862                                 new ParameterModifier [0]);
2863                         Assert.IsNull (ctor, "#G7");
2864
2865                         ctor = redType.GetConstructor (flags, null,
2866                                 new Type [] { typeof (int), typeof (int) },
2867                                 new ParameterModifier [0]);
2868                         Assert.IsNull (ctor, "#G8");
2869
2870                         ctor = redType.GetConstructor (flags, null,
2871                                 new Type [] { typeof (string) },
2872                                 new ParameterModifier [0]);
2873                         Assert.IsNull (ctor, "#G9");
2874
2875                         ctor = redType.GetConstructor (flags, null,
2876                                 new Type [] { typeof (string), typeof (string) },
2877                                 new ParameterModifier [0]);
2878                         Assert.IsNull (ctor, "#G10");
2879
2880                         ctor = redType.GetConstructor (flags, null,
2881                                 new Type [] { typeof (int) },
2882                                 new ParameterModifier [0]);
2883                         Assert.IsNull (ctor, "#G11");
2884
2885                         ctor = redType.GetConstructor (flags, null,
2886                                 new Type [] { typeof (int), typeof (bool) },
2887                                 new ParameterModifier [0]);
2888                         Assert.IsNull (ctor, "#G12");
2889
2890                         ctor = redType.GetConstructor (flags, null,
2891                                 new Type [] { typeof (string), typeof (int) },
2892                                 new ParameterModifier [0]);
2893                         Assert.IsNull (ctor, "#G13");
2894
2895                         ctor = redType.GetConstructor (flags, null,
2896                                 Type.EmptyTypes,
2897                                 new ParameterModifier [0]);
2898                         Assert.IsNull (ctor, "#G14");
2899
2900                         flags = BindingFlags.Static | BindingFlags.NonPublic |
2901                                 BindingFlags.FlattenHierarchy;
2902
2903                         ctor = greenType.GetConstructor (flags, null,
2904                                 new Type [] { typeof (int), typeof (int) },
2905                                 new ParameterModifier [0]);
2906                         Assert.IsNull (ctor, "#H1");
2907
2908                         ctor = greenType.GetConstructor (flags, null,
2909                                 new Type [] { typeof (string) },
2910                                 new ParameterModifier [0]);
2911                         Assert.IsNull (ctor, "#H2");
2912
2913                         ctor = greenType.GetConstructor (flags, null,
2914                                 new Type [] { typeof (string), typeof (string) },
2915                                 new ParameterModifier [0]);
2916                         Assert.IsNull (ctor, "#H3");
2917
2918                         ctor = greenType.GetConstructor (flags, null,
2919                                 new Type [] { typeof (int) },
2920                                 new ParameterModifier [0]);
2921                         Assert.IsNull (ctor, "#H4");
2922
2923                         ctor = greenType.GetConstructor (flags, null,
2924                                 new Type [] { typeof (int), typeof (bool) },
2925                                 new ParameterModifier [0]);
2926                         Assert.IsNull (ctor, "#H5");
2927
2928                         ctor = greenType.GetConstructor (flags, null,
2929                                 new Type [] { typeof (string), typeof (int) },
2930                                 new ParameterModifier [0]);
2931                         Assert.IsNull (ctor, "#H6");
2932
2933                         ctor = greenType.GetConstructor (flags, null,
2934                                 Type.EmptyTypes,
2935                                 new ParameterModifier [0]);
2936                         Assert.IsNull (ctor, "#H7");
2937
2938                         ctor = redType.GetConstructor (flags, null,
2939                                 new Type [] { typeof (int), typeof (int) },
2940                                 new ParameterModifier [0]);
2941                         Assert.IsNull (ctor, "#H8");
2942
2943                         ctor = redType.GetConstructor (flags, null,
2944                                 new Type [] { typeof (string) },
2945                                 new ParameterModifier [0]);
2946                         Assert.IsNull (ctor, "#H9");
2947
2948                         ctor = redType.GetConstructor (flags, null,
2949                                 new Type [] { typeof (string), typeof (string) },
2950                                 new ParameterModifier [0]);
2951                         Assert.IsNull (ctor, "#H10");
2952
2953                         ctor = redType.GetConstructor (flags, null,
2954                                 new Type [] { typeof (int) },
2955                                 new ParameterModifier [0]);
2956                         Assert.IsNull (ctor, "#H11");
2957
2958                         ctor = redType.GetConstructor (flags, null,
2959                                 new Type [] { typeof (int), typeof (bool) },
2960                                 new ParameterModifier [0]);
2961                         Assert.IsNull (ctor, "#H12");
2962
2963                         ctor = redType.GetConstructor (flags, null,
2964                                 new Type [] { typeof (string), typeof (int) },
2965                                 new ParameterModifier [0]);
2966                         Assert.IsNull (ctor, "#H13");
2967
2968                         ctor = redType.GetConstructor (flags, null,
2969                                 Type.EmptyTypes,
2970                                 new ParameterModifier [0]);
2971                         Assert.IsNotNull (ctor, "#H14");
2972                         Assert.IsTrue (ctor.IsPrivate, "#H14b");
2973                         Assert.IsTrue (ctor.IsStatic, "#H14c");
2974                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2975                         Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2976
2977                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2978                                 BindingFlags.DeclaredOnly;
2979
2980                         ctor = greenType.GetConstructor (flags, null,
2981                                 new Type [] { typeof (int), typeof (int) },
2982                                 new ParameterModifier [0]);
2983                         Assert.IsNull (ctor, "#I1");
2984
2985                         ctor = greenType.GetConstructor (flags, null,
2986                                 new Type [] { typeof (string) },
2987                                 new ParameterModifier [0]);
2988                         Assert.IsNull (ctor, "#I2");
2989
2990                         ctor = greenType.GetConstructor (flags, null,
2991                                 new Type [] { typeof (string), typeof (string) },
2992                                 new ParameterModifier [0]);
2993                         Assert.IsNull (ctor, "#I3");
2994
2995                         ctor = greenType.GetConstructor (flags, null,
2996                                 new Type [] { typeof (int) },
2997                                 new ParameterModifier [0]);
2998                         Assert.IsNull (ctor, "#I4");
2999
3000                         ctor = greenType.GetConstructor (flags, null,
3001                                 new Type [] { typeof (int), typeof (bool) },
3002                                 new ParameterModifier [0]);
3003                         Assert.IsNull (ctor, "#I5");
3004
3005                         ctor = greenType.GetConstructor (flags, null,
3006                                 new Type [] { typeof (string), typeof (int) },
3007                                 new ParameterModifier [0]);
3008                         Assert.IsNull (ctor, "#I6");
3009
3010                         ctor = greenType.GetConstructor (flags, null,
3011                                 Type.EmptyTypes,
3012                                 new ParameterModifier [0]);
3013                         Assert.IsNull (ctor, "#I7");
3014
3015                         ctor = redType.GetConstructor (flags, null,
3016                                 new Type [] { typeof (int), typeof (int) },
3017                                 new ParameterModifier [0]);
3018                         Assert.IsNotNull (ctor, "#I8a");
3019                         Assert.IsTrue (ctor.IsPrivate, "#I8b");
3020                         Assert.IsFalse (ctor.IsStatic, "#I8c");
3021                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
3022                         Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
3023
3024                         ctor = redType.GetConstructor (flags, null,
3025                                 new Type [] { typeof (string) },
3026                                 new ParameterModifier [0]);
3027                         Assert.IsNotNull (ctor, "#I9a");
3028                         Assert.IsTrue (ctor.IsFamily, "#I9b");
3029                         Assert.IsFalse (ctor.IsStatic, "#I9c");
3030                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
3031                         Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
3032
3033                         ctor = redType.GetConstructor (flags, null,
3034                                 new Type [] { typeof (string), typeof (string) },
3035                                 new ParameterModifier [0]);
3036                         Assert.IsNotNull (ctor, "#I10a");
3037                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
3038                         Assert.IsFalse (ctor.IsStatic, "#I10c");
3039                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
3040                         Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
3041
3042                         ctor = redType.GetConstructor (flags, null,
3043                                 new Type [] { typeof (int) },
3044                                 new ParameterModifier [0]);
3045                         Assert.IsNotNull (ctor, "#I11a");
3046                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
3047                         Assert.IsFalse (ctor.IsStatic, "#I11c");
3048                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
3049                         Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
3050
3051                         ctor = redType.GetConstructor (flags, null,
3052                                 new Type [] { typeof (int), typeof (bool) },
3053                                 new ParameterModifier [0]);
3054                         Assert.IsNull (ctor, "#I12");
3055
3056                         ctor = redType.GetConstructor (flags, null,
3057                                 new Type [] { typeof (string), typeof (int) },
3058                                 new ParameterModifier [0]);
3059                         Assert.IsNotNull (ctor, "#I13a");
3060                         Assert.IsTrue (ctor.IsAssembly, "#I13b");
3061                         Assert.IsFalse (ctor.IsStatic, "#I13c");
3062                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
3063                         Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
3064
3065                         ctor = redType.GetConstructor (flags, null,
3066                                 Type.EmptyTypes,
3067                                 new ParameterModifier [0]);
3068                         Assert.IsNull (ctor, "#I14");
3069
3070                         flags = BindingFlags.Instance | BindingFlags.Public |
3071                                 BindingFlags.DeclaredOnly;
3072
3073                         ctor = greenType.GetConstructor (flags, null,
3074                                 new Type [] { typeof (int), typeof (int) },
3075                                 new ParameterModifier [0]);
3076                         Assert.IsNull (ctor, "#J1");
3077
3078                         ctor = greenType.GetConstructor (flags, null,
3079                                 new Type [] { typeof (string) },
3080                                 new ParameterModifier [0]);
3081                         Assert.IsNull (ctor, "#J2");
3082
3083                         ctor = greenType.GetConstructor (flags, null,
3084                                 new Type [] { typeof (string), typeof (string) },
3085                                 new ParameterModifier [0]);
3086                         Assert.IsNull (ctor, "#J3");
3087
3088                         ctor = greenType.GetConstructor (flags, null,
3089                                 new Type [] { typeof (int) },
3090                                 new ParameterModifier [0]);
3091                         Assert.IsNull (ctor, "#J4");
3092
3093                         ctor = greenType.GetConstructor (flags, null,
3094                                 new Type [] { typeof (int), typeof (bool) },
3095                                 new ParameterModifier [0]);
3096                         Assert.IsNull (ctor, "#J5");
3097
3098                         ctor = greenType.GetConstructor (flags, null,
3099                                 new Type [] { typeof (string), typeof (int) },
3100                                 new ParameterModifier [0]);
3101                         Assert.IsNull (ctor, "#J6");
3102
3103                         ctor = greenType.GetConstructor (flags, null,
3104                                 Type.EmptyTypes,
3105                                 new ParameterModifier [0]);
3106                         Assert.IsNotNull (ctor, "#J7a");
3107                         Assert.IsTrue (ctor.IsPublic, "#J7b");
3108                         Assert.IsFalse (ctor.IsStatic, "#J7c");
3109                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3110                         Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3111
3112                         ctor = redType.GetConstructor (flags, null,
3113                                 new Type [] { typeof (int), typeof (int) },
3114                                 new ParameterModifier [0]);
3115                         Assert.IsNull (ctor, "#J8");
3116
3117                         ctor = redType.GetConstructor (flags, null,
3118                                 new Type [] { typeof (string) },
3119                                 new ParameterModifier [0]);
3120                         Assert.IsNull (ctor, "#J9");
3121
3122                         ctor = redType.GetConstructor (flags, null,
3123                                 new Type [] { typeof (string), typeof (string) },
3124                                 new ParameterModifier [0]);
3125                         Assert.IsNull (ctor, "#J10");
3126
3127                         ctor = redType.GetConstructor (flags, null,
3128                                 new Type [] { typeof (int) },
3129                                 new ParameterModifier [0]);
3130                         Assert.IsNull (ctor, "#J11");
3131
3132                         ctor = redType.GetConstructor (flags, null,
3133                                 new Type [] { typeof (int), typeof (bool) },
3134                                 new ParameterModifier [0]);
3135                         Assert.IsNotNull (ctor, "#J12a");
3136                         Assert.IsTrue (ctor.IsPublic, "#J12b");
3137                         Assert.IsFalse (ctor.IsStatic, "#J12c");
3138                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3139                         Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3140
3141                         ctor = redType.GetConstructor (flags, null,
3142                                 new Type [] { typeof (string), typeof (int) },
3143                                 new ParameterModifier [0]);
3144                         Assert.IsNull (ctor, "#J13");
3145
3146                         ctor = redType.GetConstructor (flags, null,
3147                                 Type.EmptyTypes,
3148                                 new ParameterModifier [0]);
3149                         Assert.IsNull (ctor, "#J14");
3150
3151                         flags = BindingFlags.Static | BindingFlags.Public |
3152                                 BindingFlags.DeclaredOnly;
3153
3154                         ctor = greenType.GetConstructor (flags, null,
3155                                 new Type [] { typeof (int), typeof (int) },
3156                                 new ParameterModifier [0]);
3157                         Assert.IsNull (ctor, "#K1");
3158
3159                         ctor = greenType.GetConstructor (flags, null,
3160                                 new Type [] { typeof (string) },
3161                                 new ParameterModifier [0]);
3162                         Assert.IsNull (ctor, "#K2");
3163
3164                         ctor = greenType.GetConstructor (flags, null,
3165                                 new Type [] { typeof (string), typeof (string) },
3166                                 new ParameterModifier [0]);
3167                         Assert.IsNull (ctor, "#K3");
3168
3169                         ctor = greenType.GetConstructor (flags, null,
3170                                 new Type [] { typeof (int) },
3171                                 new ParameterModifier [0]);
3172                         Assert.IsNull (ctor, "#K4");
3173
3174                         ctor = greenType.GetConstructor (flags, null,
3175                                 new Type [] { typeof (int), typeof (bool) },
3176                                 new ParameterModifier [0]);
3177                         Assert.IsNull (ctor, "#K5");
3178
3179                         ctor = greenType.GetConstructor (flags, null,
3180                                 new Type [] { typeof (string), typeof (int) },
3181                                 new ParameterModifier [0]);
3182                         Assert.IsNull (ctor, "#K6");
3183
3184                         ctor = greenType.GetConstructor (flags, null,
3185                                 Type.EmptyTypes,
3186                                 new ParameterModifier [0]);
3187                         Assert.IsNull (ctor, "#K7");
3188
3189                         ctor = redType.GetConstructor (flags, null,
3190                                 new Type [] { typeof (int), typeof (int) },
3191                                 new ParameterModifier [0]);
3192                         Assert.IsNull (ctor, "#K8");
3193
3194                         ctor = redType.GetConstructor (flags, null,
3195                                 new Type [] { typeof (string) },
3196                                 new ParameterModifier [0]);
3197                         Assert.IsNull (ctor, "#K9");
3198
3199                         ctor = redType.GetConstructor (flags, null,
3200                                 new Type [] { typeof (string), typeof (string) },
3201                                 new ParameterModifier [0]);
3202                         Assert.IsNull (ctor, "#K10");
3203
3204                         ctor = redType.GetConstructor (flags, null,
3205                                 new Type [] { typeof (int) },
3206                                 new ParameterModifier [0]);
3207                         Assert.IsNull (ctor, "#K11");
3208
3209                         ctor = redType.GetConstructor (flags, null,
3210                                 new Type [] { typeof (int), typeof (bool) },
3211                                 new ParameterModifier [0]);
3212                         Assert.IsNull (ctor, "#K12");
3213
3214                         ctor = redType.GetConstructor (flags, null,
3215                                 new Type [] { typeof (string), typeof (int) },
3216                                 new ParameterModifier [0]);
3217                         Assert.IsNull (ctor, "#K13");
3218
3219                         ctor = redType.GetConstructor (flags, null,
3220                                 Type.EmptyTypes,
3221                                 new ParameterModifier [0]);
3222                         Assert.IsNull (ctor, "#K14");
3223
3224                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3225                                 BindingFlags.DeclaredOnly;
3226
3227                         ctor = greenType.GetConstructor (flags, null,
3228                                 new Type [] { typeof (int), typeof (int) },
3229                                 new ParameterModifier [0]);
3230                         Assert.IsNull (ctor, "#L1");
3231
3232                         ctor = greenType.GetConstructor (flags, null,
3233                                 new Type [] { typeof (string) },
3234                                 new ParameterModifier [0]);
3235                         Assert.IsNull (ctor, "#L2");
3236
3237                         ctor = greenType.GetConstructor (flags, null,
3238                                 new Type [] { typeof (string), typeof (string) },
3239                                 new ParameterModifier [0]);
3240                         Assert.IsNull (ctor, "#L3");
3241
3242                         ctor = greenType.GetConstructor (flags, null,
3243                                 new Type [] { typeof (int) },
3244                                 new ParameterModifier [0]);
3245                         Assert.IsNull (ctor, "#L4");
3246
3247                         ctor = greenType.GetConstructor (flags, null,
3248                                 new Type [] { typeof (int), typeof (bool) },
3249                                 new ParameterModifier [0]);
3250                         Assert.IsNull (ctor, "#L5");
3251
3252                         ctor = greenType.GetConstructor (flags, null,
3253                                 new Type [] { typeof (string), typeof (int) },
3254                                 new ParameterModifier [0]);
3255                         Assert.IsNull (ctor, "#L6");
3256
3257                         ctor = greenType.GetConstructor (flags, null,
3258                                 Type.EmptyTypes,
3259                                 new ParameterModifier [0]);
3260                         Assert.IsNull (ctor, "#L7");
3261
3262                         ctor = redType.GetConstructor (flags, null,
3263                                 new Type [] { typeof (int), typeof (int) },
3264                                 new ParameterModifier [0]);
3265                         Assert.IsNull (ctor, "#L8");
3266
3267                         ctor = redType.GetConstructor (flags, null,
3268                                 new Type [] { typeof (string) },
3269                                 new ParameterModifier [0]);
3270                         Assert.IsNull (ctor, "#L9");
3271
3272                         ctor = redType.GetConstructor (flags, null,
3273                                 new Type [] { typeof (string), typeof (string) },
3274                                 new ParameterModifier [0]);
3275                         Assert.IsNull (ctor, "#L10");
3276
3277                         ctor = redType.GetConstructor (flags, null,
3278                                 new Type [] { typeof (int) },
3279                                 new ParameterModifier [0]);
3280                         Assert.IsNull (ctor, "#L11");
3281
3282                         ctor = redType.GetConstructor (flags, null,
3283                                 new Type [] { typeof (int), typeof (bool) },
3284                                 new ParameterModifier [0]);
3285                         Assert.IsNull (ctor, "#L12");
3286
3287                         ctor = redType.GetConstructor (flags, null,
3288                                 new Type [] { typeof (string), typeof (int) },
3289                                 new ParameterModifier [0]);
3290                         Assert.IsNull (ctor, "#L13");
3291
3292                         ctor = redType.GetConstructor (flags, null,
3293                                 Type.EmptyTypes,
3294                                 new ParameterModifier [0]);
3295                         Assert.IsNotNull (ctor, "#L14a");
3296                         Assert.IsTrue (ctor.IsPrivate, "#L14b");
3297                         Assert.IsTrue (ctor.IsStatic, "#L14c");
3298                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3299                         Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3300
3301                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3302                                 BindingFlags.Public;
3303
3304                         ctor = greenType.GetConstructor (flags, null,
3305                                 new Type [] { typeof (int), typeof (int) },
3306                                 new ParameterModifier [0]);
3307                         Assert.IsNull (ctor, "#M1");
3308
3309                         ctor = greenType.GetConstructor (flags, null,
3310                                 new Type [] { typeof (string) },
3311                                 new ParameterModifier [0]);
3312                         Assert.IsNull (ctor, "#M2");
3313
3314                         ctor = greenType.GetConstructor (flags, null,
3315                                 new Type [] { typeof (string), typeof (string) },
3316                                 new ParameterModifier [0]);
3317                         Assert.IsNull (ctor, "#M3");
3318
3319                         ctor = greenType.GetConstructor (flags, null,
3320                                 new Type [] { typeof (int) },
3321                                 new ParameterModifier [0]);
3322                         Assert.IsNull (ctor, "#M4");
3323
3324                         ctor = greenType.GetConstructor (flags, null,
3325                                 new Type [] { typeof (int), typeof (bool) },
3326                                 new ParameterModifier [0]);
3327                         Assert.IsNull (ctor, "#M5");
3328
3329                         ctor = greenType.GetConstructor (flags, null,
3330                                 new Type [] { typeof (string), typeof (int) },
3331                                 new ParameterModifier [0]);
3332                         Assert.IsNull (ctor, "#M6");
3333
3334                         ctor = greenType.GetConstructor (flags, null,
3335                                 Type.EmptyTypes,
3336                                 new ParameterModifier [0]);
3337                         Assert.IsNotNull (ctor, "#M7a");
3338                         Assert.IsTrue (ctor.IsPublic, "#M7b");
3339                         Assert.IsFalse (ctor.IsStatic, "#M7c");
3340                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3341                         Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3342
3343                         ctor = redType.GetConstructor (flags, null,
3344                                 new Type [] { typeof (int), typeof (int) },
3345                                 new ParameterModifier [0]);
3346                         Assert.IsNotNull (ctor, "#M8a");
3347                         Assert.IsTrue (ctor.IsPrivate, "#M8b");
3348                         Assert.IsFalse (ctor.IsStatic, "#M8c");
3349                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3350                         Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3351
3352                         ctor = redType.GetConstructor (flags, null,
3353                                 new Type [] { typeof (string) },
3354                                 new ParameterModifier [0]);
3355                         Assert.IsNotNull (ctor, "#M9a");
3356                         Assert.IsTrue (ctor.IsFamily, "#M9b");
3357                         Assert.IsFalse (ctor.IsStatic, "#M9c");
3358                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3359                         Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3360
3361                         ctor = redType.GetConstructor (flags, null,
3362                                 new Type [] { typeof (string), typeof (string) },
3363                                 new ParameterModifier [0]);
3364                         Assert.IsNotNull (ctor, "#M10a");
3365                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3366                         Assert.IsFalse (ctor.IsStatic, "#M10c");
3367                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3368                         Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3369
3370                         ctor = redType.GetConstructor (flags, null,
3371                                 new Type [] { typeof (int) },
3372                                 new ParameterModifier [0]);
3373                         Assert.IsNotNull (ctor, "#M11a");
3374                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3375                         Assert.IsFalse (ctor.IsStatic, "#M11c");
3376                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3377                         Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3378
3379                         ctor = redType.GetConstructor (flags, null,
3380                                 new Type [] { typeof (int), typeof (bool) },
3381                                 new ParameterModifier [0]);
3382                         Assert.IsNotNull (ctor, "#M12a");
3383                         Assert.IsTrue (ctor.IsPublic, "#M12b");
3384                         Assert.IsFalse (ctor.IsStatic, "#M12c");
3385                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3386                         Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3387
3388                         ctor = redType.GetConstructor (flags, null,
3389                                 new Type [] { typeof (string), typeof (int) },
3390                                 new ParameterModifier [0]);
3391                         Assert.IsNotNull (ctor, "#M13a");
3392                         Assert.IsTrue (ctor.IsAssembly, "#M13b");
3393                         Assert.IsFalse (ctor.IsStatic, "#M13c");
3394                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3395                         Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3396
3397                         ctor = redType.GetConstructor (flags, null,
3398                                 Type.EmptyTypes,
3399                                 new ParameterModifier [0]);
3400                         Assert.IsNull (ctor, "#M14");
3401
3402                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3403                                 BindingFlags.Public;
3404
3405                         ctor = greenType.GetConstructor (flags, null,
3406                                 new Type [] { typeof (int), typeof (int) },
3407                                 new ParameterModifier [0]);
3408                         Assert.IsNull (ctor, "#N1");
3409
3410                         ctor = greenType.GetConstructor (flags, null,
3411                                 new Type [] { typeof (string) },
3412                                 new ParameterModifier [0]);
3413                         Assert.IsNull (ctor, "#N2");
3414
3415                         ctor = greenType.GetConstructor (flags, null,
3416                                 new Type [] { typeof (string), typeof (string) },
3417                                 new ParameterModifier [0]);
3418                         Assert.IsNull (ctor, "#N3");
3419
3420                         ctor = greenType.GetConstructor (flags, null,
3421                                 new Type [] { typeof (int) },
3422                                 new ParameterModifier [0]);
3423                         Assert.IsNull (ctor, "#N4");
3424
3425                         ctor = greenType.GetConstructor (flags, null,
3426                                 new Type [] { typeof (int), typeof (bool) },
3427                                 new ParameterModifier [0]);
3428                         Assert.IsNull (ctor, "#N5");
3429
3430                         ctor = greenType.GetConstructor (flags, null,
3431                                 new Type [] { typeof (string), typeof (int) },
3432                                 new ParameterModifier [0]);
3433                         Assert.IsNull (ctor, "#N6");
3434
3435                         ctor = greenType.GetConstructor (flags, null,
3436                                 Type.EmptyTypes,
3437                                 new ParameterModifier [0]);
3438                         Assert.IsNull (ctor, "#N7");
3439
3440                         ctor = redType.GetConstructor (flags, null,
3441                                 new Type [] { typeof (int), typeof (int) },
3442                                 new ParameterModifier [0]);
3443                         Assert.IsNull (ctor, "#N8");
3444
3445                         ctor = redType.GetConstructor (flags, null,
3446                                 new Type [] { typeof (string) },
3447                                 new ParameterModifier [0]);
3448                         Assert.IsNull (ctor, "#N9");
3449
3450                         ctor = redType.GetConstructor (flags, null,
3451                                 new Type [] { typeof (string), typeof (string) },
3452                                 new ParameterModifier [0]);
3453                         Assert.IsNull (ctor, "#N10");
3454
3455                         ctor = redType.GetConstructor (flags, null,
3456                                 new Type [] { typeof (int) },
3457                                 new ParameterModifier [0]);
3458                         Assert.IsNull (ctor, "#N11");
3459
3460                         ctor = redType.GetConstructor (flags, null,
3461                                 new Type [] { typeof (int), typeof (bool) },
3462                                 new ParameterModifier [0]);
3463                         Assert.IsNull (ctor, "#N12");
3464
3465                         ctor = redType.GetConstructor (flags, null,
3466                                 new Type [] { typeof (string), typeof (int) },
3467                                 new ParameterModifier [0]);
3468                         Assert.IsNull (ctor, "#N13");
3469
3470                         ctor = redType.GetConstructor (flags, null,
3471                                 Type.EmptyTypes,
3472                                 new ParameterModifier [0]);
3473                         Assert.IsNotNull (ctor, "#N14a");
3474                         Assert.IsTrue (ctor.IsPrivate, "#N14b");
3475                         Assert.IsTrue (ctor.IsStatic, "#N14c");
3476                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3477                         Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3478                 }
3479
3480                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
3481                 public void GetConstructor2_Incomplete ()
3482                 {
3483                         TypeBuilder tb = module.DefineType (genTypeName ());
3484                         ConstructorBuilder cb = tb.DefineConstructor (
3485                                 MethodAttributes.Public,
3486                                 CallingConventions.Standard,
3487                                 Type.EmptyTypes);
3488                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3489
3490                         try {
3491                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3492                                         null, Type.EmptyTypes, new ParameterModifier [0]);
3493                                 Assert.Fail ("#1");
3494                         } catch (NotSupportedException ex) {
3495                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3496                                 Assert.IsNull (ex.InnerException, "#3");
3497                                 Assert.IsNotNull (ex.Message, "#4");
3498                         }
3499                 }
3500
3501                 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
3502                 public void GetConstructor3_Incomplete ()
3503                 {
3504                         TypeBuilder tb = module.DefineType (genTypeName ());
3505                         ConstructorBuilder cb = tb.DefineConstructor (
3506                                 MethodAttributes.Public,
3507                                 CallingConventions.Standard,
3508                                 Type.EmptyTypes);
3509                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3510
3511                         try {
3512                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3513                                         null, CallingConventions.Standard, Type.EmptyTypes,
3514                                         new ParameterModifier [0]);
3515                                 Assert.Fail ("#1");
3516                         } catch (NotSupportedException ex) {
3517                                 // The invoked member is not supported in a
3518                                 // dynamic module
3519                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3520                                 Assert.IsNull (ex.InnerException, "#3");
3521                                 Assert.IsNotNull (ex.Message, "#4");
3522                         }
3523                 }
3524
3525                 [Test] // GetConstructors ()
3526                 [Category ("NotWorking")] // mcs depends on this
3527                 public void GetConstructors1_Incomplete ()
3528                 {
3529                         TypeBuilder tb = module.DefineType (genTypeName ());
3530                         ConstructorBuilder cb = tb.DefineConstructor (
3531                                 MethodAttributes.Public,
3532                                 CallingConventions.Standard,
3533                                 Type.EmptyTypes);
3534                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3535
3536                         try {
3537                                 tb.GetConstructors ();
3538                                 Assert.Fail ("#1");
3539                         } catch (NotSupportedException ex) {
3540                                 // The invoked member is not supported in a
3541                                 // dynamic module
3542                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3543                                 Assert.IsNull (ex.InnerException, "#3");
3544                                 Assert.IsNotNull (ex.Message, "#4");
3545                         }
3546                 }
3547
3548                 [Test] // GetConstructors (BindingFlags)
3549                 public void GetConstructors2_Complete ()
3550                 {
3551                         BindingFlags flags;
3552                         ConstructorInfo [] ctors;
3553
3554                         TypeBuilder redType = module.DefineType (genTypeName (),
3555                                 TypeAttributes.Public);
3556                         CreateMembers (redType, "Red", true);
3557
3558                         TypeBuilder greenType = module.DefineType (genTypeName (),
3559                                 TypeAttributes.Public, redType);
3560                         CreateMembers (greenType, "Green", false);
3561                         ConstructorBuilder cb = greenType.DefineConstructor (
3562                                 MethodAttributes.Public,
3563                                 CallingConventions.Standard,
3564                                 Type.EmptyTypes);
3565                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3566
3567                         redType.CreateType ();
3568                         greenType.CreateType ();
3569
3570                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3571
3572                         ctors = greenType.GetConstructors (flags);
3573                         Assert.AreEqual (0, ctors.Length, "#A1");
3574
3575                         ctors = redType.GetConstructors (flags);
3576                         Assert.AreEqual (5, ctors.Length, "#A2");
3577                         Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3578                         Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3579                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3580                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3581                         Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3582                         Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3583                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3584                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3585                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3586                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3587                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3588                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3589                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3590                         Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3591                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3592                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3593                         Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3594                         Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3595                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3596                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3597
3598                         flags = BindingFlags.Instance | BindingFlags.Public;
3599
3600                         ctors = greenType.GetConstructors (flags);
3601                         Assert.AreEqual (1, ctors.Length, "#B1");
3602                         Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3603                         Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3604                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3605                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3606
3607                         ctors = redType.GetConstructors (flags);
3608                         Assert.AreEqual (1, ctors.Length, "#B3");
3609                         Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3610                         Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3611                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3612                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3613
3614                         flags = BindingFlags.Static | BindingFlags.Public;
3615
3616                         ctors = greenType.GetConstructors (flags);
3617                         Assert.AreEqual (0, ctors.Length, "#C1");
3618
3619                         ctors = redType.GetConstructors (flags);
3620                         Assert.AreEqual (0, ctors.Length, "#C2");
3621
3622                         flags = BindingFlags.Static | BindingFlags.NonPublic;
3623
3624                         ctors = greenType.GetConstructors (flags);
3625                         Assert.AreEqual (0, ctors.Length, "#D1");
3626
3627                         ctors = redType.GetConstructors (flags);
3628                         Assert.AreEqual (1, ctors.Length, "#D2");
3629                         Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3630                         Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3631                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3632                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3633
3634                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3635                                 BindingFlags.FlattenHierarchy;
3636
3637                         ctors = greenType.GetConstructors (flags);
3638                         Assert.AreEqual (0, ctors.Length, "#E1");
3639
3640                         ctors = redType.GetConstructors (flags);
3641                         Assert.AreEqual (5, ctors.Length, "#E2");
3642                         Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3643                         Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3644                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3645                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3646                         Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3647                         Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3648                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3649                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3650                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3651                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3652                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3653                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3654                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3655                         Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3656                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3657                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3658                         Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3659                         Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3660                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3661                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3662
3663                         flags = BindingFlags.Instance | BindingFlags.Public |
3664                                 BindingFlags.FlattenHierarchy;
3665
3666                         ctors = greenType.GetConstructors (flags);
3667                         Assert.AreEqual (1, ctors.Length, "#F1");
3668                         Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3669                         Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3670                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3671                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3672
3673                         ctors = redType.GetConstructors (flags);
3674                         Assert.AreEqual (1, ctors.Length, "#F3");
3675                         Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3676                         Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3677                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3678                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3679
3680                         flags = BindingFlags.Static | BindingFlags.Public |
3681                                 BindingFlags.FlattenHierarchy;
3682
3683                         ctors = greenType.GetConstructors (flags);
3684                         Assert.AreEqual (0, ctors.Length, "#G1");
3685
3686                         ctors = redType.GetConstructors (flags);
3687                         Assert.AreEqual (0, ctors.Length, "#G2");
3688
3689                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3690                                 BindingFlags.FlattenHierarchy;
3691
3692                         ctors = greenType.GetConstructors (flags);
3693                         Assert.AreEqual (0, ctors.Length, "#H1");
3694
3695                         ctors = redType.GetConstructors (flags);
3696                         Assert.AreEqual (1, ctors.Length, "#H2");
3697                         Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3698                         Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3699                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3700                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3701
3702                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3703                                 BindingFlags.DeclaredOnly;
3704
3705                         ctors = greenType.GetConstructors (flags);
3706                         Assert.AreEqual (0, ctors.Length, "#I1");
3707
3708                         ctors = redType.GetConstructors (flags);
3709                         Assert.AreEqual (5, ctors.Length, "#I2");
3710                         Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3711                         Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3712                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3713                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3714                         Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3715                         Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3716                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3717                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3718                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3719                         Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3720                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3721                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3722                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3723                         Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3724                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3725                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3726                         Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3727                         Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3728                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3729                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3730
3731                         flags = BindingFlags.Instance | BindingFlags.Public |
3732                                 BindingFlags.DeclaredOnly;
3733
3734                         ctors = greenType.GetConstructors (flags);
3735                         Assert.AreEqual (1, ctors.Length, "#J1");
3736                         Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3737                         Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3738                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3739                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3740
3741                         ctors = redType.GetConstructors (flags);
3742                         Assert.AreEqual (1, ctors.Length, "#J3");
3743                         Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3744                         Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3745                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3746                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3747
3748                         flags = BindingFlags.Static | BindingFlags.Public |
3749                                 BindingFlags.DeclaredOnly;
3750
3751                         ctors = greenType.GetConstructors (flags);
3752                         Assert.AreEqual (0, ctors.Length, "#K1");
3753
3754                         ctors = redType.GetConstructors (flags);
3755                         Assert.AreEqual (0, ctors.Length, "#K2");
3756
3757                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3758                                 BindingFlags.DeclaredOnly;
3759
3760                         ctors = greenType.GetConstructors (flags);
3761                         Assert.AreEqual (0, ctors.Length, "#L1");
3762
3763                         ctors = redType.GetConstructors (flags);
3764                         Assert.AreEqual (1, ctors.Length, "#L2");
3765                         Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3766                         Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3767                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3768                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3769
3770                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3771                                 BindingFlags.Public;
3772
3773                         ctors = greenType.GetConstructors (flags);
3774                         Assert.AreEqual (1, ctors.Length, "#M1");
3775                         Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3776                         Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3777                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3778                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3779
3780                         ctors = redType.GetConstructors (flags);
3781                         Assert.AreEqual (6, ctors.Length, "#M3");
3782                         Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3783                         Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3784                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3785                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3786                         Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3787                         Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3788                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3789                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3790                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3791                         Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3792                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3793                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3794                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3795                         Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3796                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3797                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3798                         Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3799                         Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3800                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3801                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3802                         Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3803                         Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3804                         Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3805                         Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3806
3807                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3808                                 BindingFlags.Public;
3809
3810                         ctors = greenType.GetConstructors (flags);
3811                         Assert.AreEqual (0, ctors.Length, "#N1");
3812
3813                         ctors = redType.GetConstructors (flags);
3814                         Assert.AreEqual (1, ctors.Length, "#N2");
3815                         Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3816                         Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3817                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3818                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3819                 }
3820
3821                 [Test] // GetConstructors (BindingFlags)
3822                 [Category ("NotWorking")] // mcs depends on this
3823                 public void GetConstructors2_Incomplete ()
3824                 {
3825                         TypeBuilder tb = module.DefineType (genTypeName ());
3826                         ConstructorBuilder cb = tb.DefineConstructor (
3827                                 MethodAttributes.Public,
3828                                 CallingConventions.Standard,
3829                                 Type.EmptyTypes);
3830                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3831
3832                         try {
3833                                 tb.GetConstructors (BindingFlags.Public |
3834                                         BindingFlags.Instance);
3835                                 Assert.Fail ("#1");
3836                         } catch (NotSupportedException ex) {
3837                                 // The invoked member is not supported in a
3838                                 // dynamic module
3839                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3840                                 Assert.IsNull (ex.InnerException, "#3");
3841                                 Assert.IsNotNull (ex.Message, "#4");
3842                         }
3843                 }
3844
3845                 [Test]
3846                 public void TestGetCustomAttributesIncomplete ()
3847                 {
3848                         TypeBuilder tb = module.DefineType (genTypeName ());
3849                         try {
3850                                 tb.GetCustomAttributes (false);
3851                                 Assert.Fail ("#1");
3852                         } catch (NotSupportedException ex) {
3853                                 // The invoked member is not supported in a
3854                                 // dynamic module
3855                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3856                                 Assert.IsNull (ex.InnerException, "#3");
3857                                 Assert.IsNotNull (ex.Message, "#4");
3858                         }
3859                 }
3860
3861                 [Test]
3862                 public void TestGetCustomAttributesComplete ()
3863                 {
3864                         TypeBuilder tb = module.DefineType (genTypeName ());
3865
3866                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3867                                 new Type [] { typeof (string) });
3868
3869                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3870                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3871
3872                         tb.SetCustomAttribute (caBuilder);
3873                         tb.CreateType ();
3874
3875                         Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3876                 }
3877
3878                 [Test]
3879                 public void TestGetCustomAttributesOfTypeIncomplete ()
3880                 {
3881                         TypeBuilder tb = module.DefineType (genTypeName ());
3882                         try {
3883                                 tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3884                                 Assert.Fail ("#1");
3885                         } catch (NotSupportedException ex) {
3886                                 // The invoked member is not supported in a
3887                                 // dynamic module
3888                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3889                                 Assert.IsNull (ex.InnerException, "#3");
3890                                 Assert.IsNotNull (ex.Message, "#4");
3891                         }
3892                 }
3893
3894                 [Test]
3895                 public void TestGetCustomAttributesOfTypeComplete ()
3896                 {
3897                         TypeBuilder tb = module.DefineType (genTypeName ());
3898
3899                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3900                                 new Type [] { typeof (string) });
3901
3902                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3903                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3904
3905                         tb.SetCustomAttribute (caBuilder);
3906                         tb.CreateType ();
3907
3908                         Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3909                         Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3910                 }
3911
3912                 [Test]
3913                 public void TestGetCustomAttributesOfNullTypeComplete ()
3914                 {
3915                         TypeBuilder tb = module.DefineType (genTypeName ());
3916                         tb.CreateType ();
3917                         try {
3918                                 tb.GetCustomAttributes (null, false);
3919                                 Assert.Fail ("#1");
3920                         } catch (ArgumentNullException ex) {
3921                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3922                                 Assert.IsNull (ex.InnerException, "#3");
3923                                 Assert.IsNotNull (ex.Message, "#4");
3924                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3925                         }
3926                 }
3927
3928                 [Test]
3929                 [Ignore ("mcs depends on this")]
3930                 public void TestGetEventsIncomplete ()
3931                 {
3932                         TypeBuilder tb = module.DefineType (genTypeName ());
3933                         try {
3934                                 tb.GetEvents ();
3935                                 Assert.Fail ("#1");
3936                         } catch (NotSupportedException ex) {
3937                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3938                                 Assert.IsNull (ex.InnerException, "#3");
3939                                 Assert.IsNotNull (ex.Message, "#4");
3940                                 throw;
3941                         }
3942                 }
3943
3944                 [Test]
3945                 public void TestGetEventsComplete ()
3946                 {
3947                         TypeBuilder tb = module.DefineType (genTypeName ());
3948
3949                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3950                                 typeof (void), new Type [] { typeof (Object) });
3951                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3952
3953                         // create public event
3954                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3955                                 typeof (ResolveEventHandler));
3956                         eventbuilder.SetRaiseMethod (onclickMethod);
3957
3958                         Type emittedType = tb.CreateType ();
3959
3960                         Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3961                         Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3962                 }
3963
3964
3965                 [Test]
3966                 [Ignore ("mcs depends on this")]
3967                 public void TestGetEventsFlagsIncomplete ()
3968                 {
3969                         TypeBuilder tb = module.DefineType (genTypeName ());
3970                         try {
3971                                 tb.GetEvents (BindingFlags.Public);
3972                                 Assert.Fail ("#1");
3973                         } catch (NotSupportedException ex) {
3974                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3975                                 Assert.IsNull (ex.InnerException, "#3");
3976                                 Assert.IsNotNull (ex.Message, "#4");
3977                                 throw;
3978                         }
3979                 }
3980
3981                 [Test]
3982                 public void TestGetEventsFlagsComplete ()
3983                 {
3984                         TypeBuilder tb = module.DefineType (genTypeName ());
3985
3986                         MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3987                                 typeof (void), new Type [] { typeof (Object) });
3988                         onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3989
3990                         // create public event
3991                         EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3992                                 typeof (ResolveEventHandler));
3993                         changeEvent.SetRaiseMethod (onchangeMethod);
3994
3995                         // create non-public event
3996                         EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3997                                 typeof (ResolveEventHandler));
3998
3999                         Type emittedType = tb.CreateType ();
4000
4001                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
4002                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4003                         Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
4004                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
4005                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
4006                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
4007                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4008                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
4009                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
4010                 }
4011
4012                 [Test]
4013                 public void TestGetEventsFlagsComplete_Inheritance ()
4014                 {
4015                         EventInfo [] events;
4016                         BindingFlags flags;
4017
4018                         TypeBuilder blueType = module.DefineType (genTypeName (),
4019                                 TypeAttributes.Public);
4020                         CreateMembers (blueType, "Blue", false);
4021
4022                         TypeBuilder redType = module.DefineType (genTypeName (),
4023                                 TypeAttributes.Public, blueType);
4024                         CreateMembers (redType, "Red", false);
4025
4026                         TypeBuilder greenType = module.DefineType (genTypeName (),
4027                                 TypeAttributes.Public, redType);
4028                         CreateMembers (greenType, "Green", false);
4029
4030                         blueType.CreateType ();
4031                         redType.CreateType ();
4032                         greenType.CreateType ();
4033
4034                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4035                         events = greenType.GetEvents (flags);
4036
4037                         Assert.AreEqual (13, events.Length, "#A1");
4038                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
4039                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
4040                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
4041                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
4042                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
4043                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
4044                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
4045                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
4046                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
4047                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
4048                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
4049                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
4050                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
4051
4052                         flags = BindingFlags.Instance | BindingFlags.Public;
4053                         events = greenType.GetEvents (flags);
4054
4055                         Assert.AreEqual (3, events.Length, "#B1");
4056                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
4057                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
4058                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
4059
4060                         flags = BindingFlags.Static | BindingFlags.Public;
4061                         events = greenType.GetEvents (flags);
4062
4063                         Assert.AreEqual (1, events.Length, "#C1");
4064                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
4065
4066                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4067                         events = greenType.GetEvents (flags);
4068
4069                         Assert.AreEqual (5, events.Length, "#D1");
4070                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
4071                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
4072                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
4073                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4074                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4075
4076                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4077                                 BindingFlags.FlattenHierarchy;
4078                         events = greenType.GetEvents (flags);
4079
4080                         Assert.AreEqual (13, events.Length, "#E1");
4081                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4082                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4083                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4084                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4085                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4086                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4087                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4088                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4089                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4090                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4091                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4092                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4093                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4094
4095                         flags = BindingFlags.Instance | BindingFlags.Public |
4096                                 BindingFlags.FlattenHierarchy;
4097                         events = greenType.GetEvents (flags);
4098
4099                         Assert.AreEqual (3, events.Length, "#F1");
4100                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4101                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4102                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4103
4104                         flags = BindingFlags.Static | BindingFlags.Public |
4105                                 BindingFlags.FlattenHierarchy;
4106                         events = greenType.GetEvents (flags);
4107
4108                         Assert.AreEqual (3, events.Length, "#G1");
4109                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4110                         Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4111                         Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4112
4113                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4114                                 BindingFlags.FlattenHierarchy;
4115                         events = greenType.GetEvents (flags);
4116
4117                         Assert.AreEqual (13, events.Length, "#H1");
4118                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4119                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4120                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4121                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4122                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4123                         Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4124                         Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4125                         Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4126                         Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4127                         Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4128                         Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4129                         Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4130                         Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4131
4132                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4133                                 BindingFlags.DeclaredOnly;
4134                         events = greenType.GetEvents (flags);
4135
4136                         Assert.AreEqual (5, events.Length, "#I1");
4137                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4138                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4139                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4140                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4141                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4142
4143                         flags = BindingFlags.Instance | BindingFlags.Public |
4144                                 BindingFlags.DeclaredOnly;
4145                         events = greenType.GetEvents (flags);
4146
4147                         Assert.AreEqual (1, events.Length, "#J1");
4148                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4149
4150                         flags = BindingFlags.Static | BindingFlags.Public |
4151                                 BindingFlags.DeclaredOnly;
4152                         events = greenType.GetEvents (flags);
4153
4154                         Assert.AreEqual (1, events.Length, "#K1");
4155                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4156
4157                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4158                                 BindingFlags.DeclaredOnly;
4159                         events = greenType.GetEvents (flags);
4160
4161                         Assert.AreEqual (5, events.Length, "#L1");
4162                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4163                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4164                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4165                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4166                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4167
4168                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4169                                 BindingFlags.Public;
4170                         events = greenType.GetEvents (flags);
4171
4172                         Assert.AreEqual (16, events.Length, "#M1");
4173                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4174                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4175                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4176                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4177                         Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4178                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4179                         Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4180                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4181                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4182                         Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4183                         Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4184                         Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4185                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4186                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4187                         Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4188                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4189
4190                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4191                                 BindingFlags.Public;
4192                         events = greenType.GetEvents (flags);
4193
4194                         Assert.AreEqual (6, events.Length, "#N1");
4195                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4196                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4197                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4198                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4199                         Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4200                         Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4201                 }
4202
4203                 [Test]
4204                 [Ignore ("mcs depends on this")]
4205                 public void TestGetEventIncomplete ()
4206                 {
4207                         TypeBuilder tb = module.DefineType (genTypeName ());
4208                         try {
4209                                 tb.GetEvent ("FOO");
4210                                 Assert.Fail ("#1");
4211                         } catch (NotSupportedException ex) {
4212                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4213                                 Assert.IsNull (ex.InnerException, "#3");
4214                                 Assert.IsNotNull (ex.Message, "#4");
4215                                 throw;
4216                         }
4217                 }
4218
4219                 [Test]
4220                 public void TestGetEventComplete ()
4221                 {
4222                         TypeBuilder tb = module.DefineType (genTypeName ());
4223
4224                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4225                                 typeof (void), new Type [] { typeof (Object) });
4226                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4227
4228                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4229                                 typeof (ResolveEventHandler));
4230                         eventbuilder.SetRaiseMethod (onclickMethod);
4231
4232                         Type emittedType = tb.CreateType ();
4233
4234                         Assert.IsNotNull (tb.GetEvent ("Change"));
4235                         Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4236                         Assert.IsNull (tb.GetEvent ("NotChange"));
4237                         Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4238                 }
4239
4240                 [Test]
4241                 [Ignore ("mcs depends on this")]
4242                 public void TestGetEventFlagsIncomplete ()
4243                 {
4244                         TypeBuilder tb = module.DefineType (genTypeName ());
4245                         try {
4246                                 tb.GetEvent ("FOO", BindingFlags.Public);
4247                                 Assert.Fail ("#1");
4248                         } catch (NotSupportedException ex) {
4249                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4250                                 Assert.IsNull (ex.InnerException, "#3");
4251                                 Assert.IsNotNull (ex.Message, "#4");
4252                                 throw;
4253                         }
4254                 }
4255
4256                 [Test]
4257                 public void TestGetEventFlagsComplete ()
4258                 {
4259                         TypeBuilder tb = module.DefineType (genTypeName ());
4260
4261                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4262                                 typeof (void), new Type [] { typeof (Object) });
4263                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4264
4265                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4266                                 typeof (ResolveEventHandler));
4267                         eventbuilder.SetRaiseMethod (onclickMethod);
4268
4269                         Type emittedType = tb.CreateType ();
4270
4271                         Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4272                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4273                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4274                         Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4275                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4276                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4277                 }
4278
4279                 [Test]
4280                 public void TestGetEventFlagsComplete_Inheritance ()
4281                 {
4282                         BindingFlags flags;
4283
4284                         TypeBuilder blueType = module.DefineType (genTypeName (),
4285                                 TypeAttributes.Public);
4286                         CreateMembers (blueType, "Blue", false);
4287
4288                         TypeBuilder redType = module.DefineType (genTypeName (),
4289                                 TypeAttributes.Public, blueType);
4290                         CreateMembers (redType, "Red", false);
4291
4292                         TypeBuilder greenType = module.DefineType (genTypeName (),
4293                                 TypeAttributes.Public, redType);
4294                         CreateMembers (greenType, "Green", false);
4295
4296                         blueType.CreateType ();
4297                         redType.CreateType ();
4298                         greenType.CreateType ();
4299
4300                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4301
4302                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4303                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4304                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4305                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4306                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4307                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4308                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4309                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4310                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4311                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4312                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4313                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4314                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4315                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4316                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4317                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4318                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4319                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4320                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4321                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4322                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4323                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4324                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4325                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4326                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4327                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4328                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4329                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4330                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4331                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4332                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4333                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4334                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4335                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4336                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4337                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4338
4339                         flags = BindingFlags.Instance | BindingFlags.Public;
4340
4341                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4342                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4343                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4344                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4345                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4346                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4347                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4348                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4349                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4350                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4351                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4352                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4353                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4354                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4355                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4356                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4357                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4358                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4359                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4360                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4361                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4362                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4363                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4364                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4365                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4366                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4367                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4368                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4369                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4370                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4371                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4372                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4373                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4374                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4375                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4376                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4377
4378                         flags = BindingFlags.Static | BindingFlags.Public;
4379
4380                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4381                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4382                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4383                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4384                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4385                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4386                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4387                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4388                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4389                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4390                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4391                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4392                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4393                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4394                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4395                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4396                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4397                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4398                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4399                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4400                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4401                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4402                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4403                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4404                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4405                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4406                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4407                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4408                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4409                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4410                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4411                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4412                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4413                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4414                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4415                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4416
4417                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4418
4419                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4420                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4421                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4422                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4423                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4424                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4425                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4426                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4427                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4428                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4429                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4430                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4431                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4432                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4433                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4434                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4435                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4436                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4437                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4438                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4439                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4440                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4441                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4442                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4443                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4444                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4445                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4446                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4447                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4448                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4449                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4450                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4451                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4452                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4453                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4454                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4455
4456                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4457                                 BindingFlags.FlattenHierarchy;
4458
4459                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4460                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4461                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4462                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4463                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4464                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4465                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4466                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4467                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4468                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4469                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4470                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4471                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4472                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4473                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4474                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4475                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4476                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4477                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4478                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4479                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4480                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4481                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4482                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4483                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4484                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4485                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4486                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4487                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4488                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4489                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4490                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4491                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4492                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4493                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4494                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4495
4496                         flags = BindingFlags.Instance | BindingFlags.Public |
4497                                 BindingFlags.FlattenHierarchy;
4498
4499                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4500                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4501                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4502                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4503                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4504                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4505                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4506                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4507                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4508                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4509                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4510                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4511                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4512                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4513                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4514                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4515                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4516                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4517                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4518                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4519                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4520                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4521                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4522                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4523                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4524                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4525                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4526                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4527                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4528                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4529                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4530                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4531                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4532                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4533                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4534                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4535
4536                         flags = BindingFlags.Static | BindingFlags.Public |
4537                                 BindingFlags.FlattenHierarchy;
4538
4539                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4540                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4541                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4542                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4543                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4544                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4545                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4546                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4547                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4548                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4549                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4550                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4551                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4552                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4553                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4554                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4555                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4556                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4557                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4558                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4559                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4560                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4561                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4562                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4563                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4564                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4565                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4566                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4567                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4568                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4569                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4570                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4571                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4572                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4573                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4574                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4575
4576                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4577                                 BindingFlags.FlattenHierarchy;
4578
4579                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4580                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4581                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4582                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4583                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4584                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4585                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4586                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4587                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4588                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4589                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4590                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4591                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4592                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4593                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4594                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4595                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4596                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4597                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4598                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4599                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4600                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4601                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4602                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4603                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4604                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4605                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4606                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4607                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4608                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4609                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4610                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4611                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4612                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4613                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4614                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4615
4616                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4617                                 BindingFlags.DeclaredOnly;
4618
4619                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4620                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4621                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4622                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4623                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4624                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4625                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4626                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4627                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4628                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4629                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4630                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4631                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4632                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4633                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4634                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4635                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4636                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4637                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4638                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4639                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4640                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4641                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4642                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4643                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4644                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4645                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4646                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4647                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4648                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4649                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4650                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4651                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4652                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4653                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4654                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4655
4656                         flags = BindingFlags.Instance | BindingFlags.Public |
4657                                 BindingFlags.DeclaredOnly;
4658
4659                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4660                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4661                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4662                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4663                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4664                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4665                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4666                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4667                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4668                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4669                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4670                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4671                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4672                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4673                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4674                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4675                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4676                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4677                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4678                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4679                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4680                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4681                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4682                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4683                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4684                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4685                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4686                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4687                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4688                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4689                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4690                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4691                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4692                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4693                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4694                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4695
4696                         flags = BindingFlags.Static | BindingFlags.Public |
4697                                 BindingFlags.DeclaredOnly;
4698
4699                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4700                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4701                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4702                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4703                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4704                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4705                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4706                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4707                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4708                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4709                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4710                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4711                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4712                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4713                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4714                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4715                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4716                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4717                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4718                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4719                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4720                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4721                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4722                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4723                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4724                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4725                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4726                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4727                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4728                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4729                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4730                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4731                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4732                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4733                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4734                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4735
4736                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4737                                 BindingFlags.DeclaredOnly;
4738
4739                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4740                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4741                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4742                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4743                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4744                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4745                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4746                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4747                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4748                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4749                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4750                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4751                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4752                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4753                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4754                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4755                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4756                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4757                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4758                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4759                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4760                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4761                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4762                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4763                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4764                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4765                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4766                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4767                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4768                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4769                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4770                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4771                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4772                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4773                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4774                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4775
4776                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4777                                 BindingFlags.Public;
4778
4779                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4780                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4781                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4782                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4783                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4784                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4785                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4786                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4787                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4788                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4789                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4790                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4791                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4792                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4793                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4794                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4795                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4796                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4797                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4798                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4799                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4800                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4801                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4802                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4803                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4804                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4805                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4806                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4807                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4808                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4809                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4810                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4811                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4812                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4813                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4814                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4815
4816                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4817                                 BindingFlags.Public;
4818
4819                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4820                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4821                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4822                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4823                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4824                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4825                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4826                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4827                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4828                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4829                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4830                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4831                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4832                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4833                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4834                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4835                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4836                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4837                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4838                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4839                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4840                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4841                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4842                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4843                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4844                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4845                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4846                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4847                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4848                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4849                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4850                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4851                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4852                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4853                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4854                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4855                 }
4856
4857                 [Test]
4858                 [Category ("NotWorking")] // mcs depends on this
4859                 public void TestGetFieldsIncomplete_MS ()
4860                 {
4861                         TypeBuilder tb = module.DefineType (genTypeName ());
4862                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4863                         try {
4864                                 tb.GetFields ();
4865                                 Assert.Fail ("#1");
4866                         } catch (NotSupportedException ex) {
4867                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4868                                 Assert.IsNull (ex.InnerException, "#3");
4869                                 Assert.IsNotNull (ex.Message, "#4");
4870                         }
4871                 }
4872
4873                 [Test]
4874                 [Category ("NotDotNet")] // mcs depends on this
4875                 public void TestGetFieldsIncomplete_Mono ()
4876                 {
4877                         TypeBuilder tb = module.DefineType (genTypeName ());
4878                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4879                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4880                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4881                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4882
4883                         FieldInfo [] fields = tb.GetFields ();
4884                         Assert.AreEqual (2, fields.Length, "#A1");
4885                         Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4886                         Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4887
4888 #if NET_2_0
4889                         tb = module.DefineType (genTypeName ());
4890                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4891                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4892                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4893                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4894                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4895                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4896
4897                         fields = tb.GetFields ();
4898                         Assert.AreEqual (4, fields.Length, "#B1");
4899                         Assert.AreEqual ("First", fields [0].Name, "#B2");
4900                         Assert.AreEqual ("Second", fields [1].Name, "#B3");
4901                         Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4902                         Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4903 #endif
4904                 }
4905
4906                 [Test]
4907                 public void TestGetFieldsComplete ()
4908                 {
4909                         TypeBuilder tb = module.DefineType (genTypeName ());
4910                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4911
4912                         Type emittedType = tb.CreateType ();
4913                         FieldInfo [] dynamicFields = tb.GetFields ();
4914                         FieldInfo [] emittedFields = emittedType.GetFields ();
4915
4916                         Assert.AreEqual (1, dynamicFields.Length, "#A1");
4917                         Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4918                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4919                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4920
4921                         // bug #81638
4922                         object value = Activator.CreateInstance (emittedType);
4923                         emittedFields [0].SetValue (value, 5);
4924                         Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4925                         Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4926                         dynamicFields [0].SetValue (value, 4);
4927                         Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4928                         Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4929                 }
4930
4931 #if NET_2_0
4932                 [Test] // bug #82625 / 325292
4933                 public void TestGetFieldsComplete_Generic ()
4934                 {
4935                         // FIXME: merge this with TestGetFieldsComplete when
4936                         // bug #82625 is fixed
4937
4938                         TypeBuilder tb;
4939                         Type emittedType;
4940                         FieldInfo [] dynamicFields;
4941                         FieldInfo [] emittedFields;
4942
4943                         tb = module.DefineType (genTypeName ());
4944                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4945                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4946                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4947                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4948                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4949                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4950
4951                         emittedType = tb.CreateType ();
4952                         dynamicFields = tb.GetFields ();
4953                         emittedFields = emittedType.GetFields ();
4954
4955                         Assert.AreEqual (4, dynamicFields.Length, "#C1");
4956                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4957                         Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4958                         Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4959                         Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4960                         Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4961                         Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4962                         Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4963                         Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4964
4965                         Assert.AreEqual (4, emittedFields.Length, "#D1");
4966                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4967                         Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4968                         Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4969                         Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4970                         Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4971                         Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4972                         Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4973                         Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4974                 }
4975 #endif
4976
4977                 [Test]
4978                 [Category ("NotWorking")] // mcs depends on this
4979                 public void TestGetFieldsFlagsIncomplete_MS ()
4980                 {
4981                         TypeBuilder tb = module.DefineType (genTypeName ());
4982                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4983                         try {
4984                                 tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4985                                 Assert.Fail ("#1");
4986                         } catch (NotSupportedException ex) {
4987                                 // The invoked member is not supported in a
4988                                 // dynamic module
4989                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4990                                 Assert.IsNull (ex.InnerException, "#3");
4991                                 Assert.IsNotNull (ex.Message, "#4");
4992                         }
4993                 }
4994
4995                 [Test]
4996                 [Category ("NotDotNet")] // mcs depends on this
4997                 public void TestGetFieldsFlagsIncomplete_Mono ()
4998                 {
4999                         FieldInfo [] fields;
5000
5001                         TypeBuilder tb = module.DefineType (genTypeName ());
5002                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
5003                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
5004                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
5005                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
5006
5007                         fields = tb.GetFields (BindingFlags.Public |
5008                                 BindingFlags.NonPublic | BindingFlags.Instance);
5009                         Assert.AreEqual (2, fields.Length, "#A1");
5010                         Assert.AreEqual ("name", fields [0].Name, "#A2");
5011                         Assert.AreEqual ("Sex", fields [1].Name, "#A3");
5012
5013                         fields = tb.GetFields (BindingFlags.Public |
5014                                 BindingFlags.Instance | BindingFlags.Static);
5015                         Assert.AreEqual (2, fields.Length, "#B1");
5016                         Assert.AreEqual ("Sex", fields [0].Name, "#B2");
5017                         Assert.AreEqual ("MALE", fields [1].Name, "#B3");
5018
5019                         fields = tb.GetFields (BindingFlags.Public |
5020                                 BindingFlags.NonPublic | BindingFlags.Instance |
5021                                 BindingFlags.Static);
5022                         Assert.AreEqual (4, fields.Length, "#C1");
5023                         Assert.AreEqual ("name", fields [0].Name, "#C2");
5024                         Assert.AreEqual ("Sex", fields [1].Name, "#C3");
5025                         Assert.AreEqual ("MALE", fields [2].Name, "#C4");
5026                         Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
5027                 }
5028
5029                 [Test]
5030                 public void TestGetFieldsFlagsComplete ()
5031                 {
5032                         TypeBuilder tb = module.DefineType (genTypeName ());
5033                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5034
5035                         Type emittedType = tb.CreateType ();
5036
5037                         Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
5038                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
5039                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
5040                         Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5041                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
5042                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5043                 }
5044
5045                 [Test]
5046                 public void TestGetFieldsFlagsComplete_Inheritance ()
5047                 {
5048                         FieldInfo [] fields;
5049                         BindingFlags flags;
5050
5051                         TypeBuilder blueType = module.DefineType (genTypeName (),
5052                                 TypeAttributes.Public);
5053                         CreateMembers (blueType, "Blue", false);
5054
5055                         TypeBuilder redType = module.DefineType (genTypeName (),
5056                                 TypeAttributes.Public, blueType);
5057                         CreateMembers (redType, "Red", false);
5058
5059                         TypeBuilder greenType = module.DefineType (genTypeName (),
5060                                 TypeAttributes.Public, redType);
5061                         CreateMembers (greenType, "Green", false);
5062
5063                         blueType.CreateType ();
5064                         redType.CreateType ();
5065                         greenType.CreateType ();
5066
5067                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5068                         fields = greenType.GetFields (flags);
5069
5070                         Assert.AreEqual (13, fields.Length, "#A1");
5071                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
5072                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
5073                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
5074                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
5075                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
5076                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
5077                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5078                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5079                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5080                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5081                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5082                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5083                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5084
5085                         flags = BindingFlags.Instance | BindingFlags.Public;
5086                         fields = greenType.GetFields (flags);
5087
5088                         Assert.AreEqual (3, fields.Length, "#B1");
5089                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5090                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5091                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5092
5093                         flags = BindingFlags.Static | BindingFlags.Public;
5094                         fields = greenType.GetFields (flags);
5095
5096                         Assert.AreEqual (1, fields.Length, "#C1");
5097                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5098
5099                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5100                         fields = greenType.GetFields (flags);
5101
5102                         Assert.AreEqual (5, fields.Length, "#D1");
5103                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5104                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5105                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5106                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5107                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5108
5109                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5110                                 BindingFlags.FlattenHierarchy;
5111                         fields = greenType.GetFields (flags);
5112
5113                         Assert.AreEqual (13, fields.Length, "#E1");
5114                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5115                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5116                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5117                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5118                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5119                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5120                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5121                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5122                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5123                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5124                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5125                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5126                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5127
5128                         flags = BindingFlags.Instance | BindingFlags.Public |
5129                                 BindingFlags.FlattenHierarchy;
5130                         fields = greenType.GetFields (flags);
5131
5132                         Assert.AreEqual (3, fields.Length, "#F1");
5133                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5134                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5135                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5136
5137                         flags = BindingFlags.Static | BindingFlags.Public |
5138                                 BindingFlags.FlattenHierarchy;
5139                         fields = greenType.GetFields (flags);
5140
5141                         Assert.AreEqual (3, fields.Length, "#G1");
5142                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5143                         Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5144                         Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5145
5146                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5147                                 BindingFlags.FlattenHierarchy;
5148                         fields = greenType.GetFields (flags);
5149
5150                         Assert.AreEqual (13, fields.Length, "#H1");
5151                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5152                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5153                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5154                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5155                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5156                         Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5157                         Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5158                         Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5159                         Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5160                         Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5161                         Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5162                         Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5163                         Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5164
5165                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5166                                 BindingFlags.DeclaredOnly;
5167                         fields = greenType.GetFields (flags);
5168
5169                         Assert.AreEqual (5, fields.Length, "#I1");
5170                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5171                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5172                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5173                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5174                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5175
5176                         flags = BindingFlags.Instance | BindingFlags.Public |
5177                                 BindingFlags.DeclaredOnly;
5178                         fields = greenType.GetFields (flags);
5179
5180                         Assert.AreEqual (1, fields.Length, "#J1");
5181                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5182
5183                         flags = BindingFlags.Static | BindingFlags.Public |
5184                                 BindingFlags.DeclaredOnly;
5185                         fields = greenType.GetFields (flags);
5186
5187                         Assert.AreEqual (1, fields.Length, "#K1");
5188                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5189
5190                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5191                                 BindingFlags.DeclaredOnly;
5192                         fields = greenType.GetFields (flags);
5193
5194                         Assert.AreEqual (5, fields.Length, "#L1");
5195                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5196                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5197                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5198                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5199                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5200
5201                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5202                                 BindingFlags.Public;
5203                         fields = greenType.GetFields (flags);
5204
5205                         Assert.AreEqual (16, fields.Length, "#M1");
5206                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5207                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5208                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5209                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5210                         Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5211                         Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5212                         Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5213                         Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5214                         Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5215                         Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5216                         Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5217                         Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5218                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5219                         Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5220                         Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5221                         Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5222
5223                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5224                                 BindingFlags.Public;
5225                         fields = greenType.GetFields (flags);
5226
5227                         Assert.AreEqual (6, fields.Length, "#N1");
5228                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5229                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5230                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5231                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5232                         Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5233                         Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5234                 }
5235
5236                 [Test]
5237                 [Category ("NotWorking")] // mcs depends on this
5238                 public void TestGetFieldIncomplete_MS ()
5239                 {
5240                         TypeBuilder tb = module.DefineType (genTypeName ());
5241                         tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5242                         try {
5243                                 tb.GetField ("test");
5244                                 Assert.Fail ("#1");
5245                         } catch (NotSupportedException ex) {
5246                                 // The invoked member is not supported in a
5247                                 // dynamic module
5248                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5249                                 Assert.IsNull (ex.InnerException, "#3");
5250                                 Assert.IsNotNull (ex.Message, "#4");
5251                         }
5252                 }
5253
5254                 [Test]
5255                 [Category ("NotDotNet")] // mcs depends on this
5256                 public void TestGetFieldIncomplete_Mono ()
5257                 {
5258                         TypeBuilder tb = module.DefineType (genTypeName ());
5259                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5260                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5261
5262                         FieldInfo field = tb.GetField ("TestField");
5263                         Assert.IsNotNull (field, "#A1");
5264                         Assert.AreEqual ("TestField", field.Name, "#A2");
5265                         Assert.IsTrue (field is FieldBuilder, "#A3");
5266
5267                         Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5268                         Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5269                 }
5270
5271                 [Test]
5272                 public void TestGetFieldComplete ()
5273                 {
5274                         TypeBuilder tb = module.DefineType (genTypeName ());
5275                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5276
5277                         Type emittedType = tb.CreateType ();
5278
5279                         FieldInfo dynamicField = tb.GetField ("TestField");
5280                         FieldInfo emittedField = emittedType.GetField ("TestField");
5281                         Assert.IsNotNull (dynamicField, "#A1");
5282                         Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5283                         Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5284                         Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5285                         Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5286
5287                         // bug #81638
5288                         object value = Activator.CreateInstance (emittedType);
5289                         emittedField.SetValue (value, 5);
5290                         Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5291                         Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5292                         dynamicField.SetValue (value, 4);
5293                         Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5294                         Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5295                 }
5296
5297                 [Test] // bug #81640
5298                 public void TestGetFieldComplete_Type ()
5299                 {
5300                         TypeBuilder tb = module.DefineType (genTypeName ());
5301                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5302                         Type emittedType = tb.CreateType ();
5303                         FieldInfo dynamicField = tb.GetField ("TestField");
5304                         Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5305
5306                         object value = Activator.CreateInstance (emittedType);
5307                         Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5308                 }
5309
5310                 [Test]
5311                 [Category ("NotWorking")] // mcs depends on this
5312                 public void TestGetFieldFlagsIncomplete_MS ()
5313                 {
5314                         TypeBuilder tb = module.DefineType (genTypeName ());
5315                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5316                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5317                         try {
5318                                 tb.GetField ("test", BindingFlags.Public);
5319                                 Assert.Fail ("#1");
5320                         } catch (NotSupportedException ex) {
5321                                 // The invoked member is not supported in a
5322                                 // dynamic module
5323                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5324                                 Assert.IsNull (ex.InnerException, "#3");
5325                                 Assert.IsNotNull (ex.Message, "#4");
5326                         }
5327                 }
5328
5329                 [Test]
5330                 [Category ("NotDotNet")] // mcs depends on this
5331                 public void TestGetFieldFlagsIncomplete_Mono ()
5332                 {
5333                         TypeBuilder tb = module.DefineType (genTypeName ());
5334                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5335                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5336
5337                         FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5338                                 | BindingFlags.Instance);
5339                         Assert.IsNotNull (field, "#A1");
5340                         Assert.AreEqual ("TestField", field.Name, "#A2");
5341                         Assert.IsTrue (field is FieldBuilder, "#A3");
5342
5343                         field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5344                                 BindingFlags.Instance);
5345                         Assert.IsNotNull (field, "#B1");
5346                         Assert.AreEqual ("OtherField", field.Name, "#B2");
5347                         Assert.IsTrue (field is FieldBuilder, "#B3");
5348
5349                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5350                                 BindingFlags.Instance), "#C1");
5351                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5352                                 BindingFlags.Static), "#C2");
5353                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5354                                 BindingFlags.Instance), "#C3");
5355                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5356                                 BindingFlags.Static), "#C4");
5357                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5358                                 BindingFlags.Instance), "#C5");
5359                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5360                                 BindingFlags.Instance), "#C6");
5361                 }
5362
5363                 [Test]
5364                 public void TestGetFieldFlagsComplete ()
5365                 {
5366                         TypeBuilder tb = module.DefineType (genTypeName ());
5367                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5368
5369                         Type emittedType = tb.CreateType ();
5370
5371                         Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5372                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5373                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5374                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5375                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5376                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5377                 }
5378
5379                 [Test]
5380                 public void TestGetFieldFlagsComplete_Inheritance ()
5381                 {
5382                         BindingFlags flags;
5383
5384                         TypeBuilder blueType = module.DefineType (genTypeName (),
5385                                 TypeAttributes.Public);
5386                         CreateMembers (blueType, "Blue", false);
5387
5388                         TypeBuilder redType = module.DefineType (genTypeName (),
5389                                 TypeAttributes.Public, blueType);
5390                         CreateMembers (redType, "Red", false);
5391
5392                         TypeBuilder greenType = module.DefineType (genTypeName (),
5393                                 TypeAttributes.Public, redType);
5394                         CreateMembers (greenType, "Green", false);
5395
5396                         blueType.CreateType ();
5397                         redType.CreateType ();
5398                         greenType.CreateType ();
5399
5400                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5401
5402                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5403                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5404                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5405                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5406                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5407                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5408                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5409                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5410                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5411                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5412                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5413                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5414                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5415                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5416                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5417                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5418                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5419                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5420                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5421                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5422                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5423                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5424                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5425                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5426                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5427                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5428                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5429                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5430                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5431                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5432                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5433                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5434                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5435                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5436                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5437                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5438
5439                         flags = BindingFlags.Instance | BindingFlags.Public;
5440
5441                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5442                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5443                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5444                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5445                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5446                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5447                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5448                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5449                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5450                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5451                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5452                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5453                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5454                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5455                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5456                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5457                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5458                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5459                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5460                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5461                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5462                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5463                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5464                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5465                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5466                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5467                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5468                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5469                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5470                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5471                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5472                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5473                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5474                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5475                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5476                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5477
5478                         flags = BindingFlags.Static | BindingFlags.Public;
5479
5480                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5481                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5482                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5483                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5484                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5485                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5486                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5487                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5488                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5489                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5490                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5491                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5492                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5493                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5494                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5495                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5496                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5497                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5498                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5499                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5500                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5501                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5502                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5503                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5504                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5505                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5506                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5507                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5508                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5509                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5510                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5511                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5512                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5513                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5514                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5515                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5516
5517                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5518
5519                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5520                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5521                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5522                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5523                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5524                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5525                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5526                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5527                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5528                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5529                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5530                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5531                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5532                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5533                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5534                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5535                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5536                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5537                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5538                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5539                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5540                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5541                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5542                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5543                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5544                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5545                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5546                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5547                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5548                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5549                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5550                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5551                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5552                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5553                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5554                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5555
5556                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5557                                 BindingFlags.FlattenHierarchy;
5558
5559                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5560                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5561                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5562                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5563                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5564                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5565                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5566                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5567                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5568                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5569                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5570                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5571                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5572                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5573                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5574                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5575                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5576                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5577                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5578                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5579                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5580                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5581                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5582                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5583                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5584                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5585                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5586                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5587                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5588                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5589                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5590                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5591                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5592                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5593                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5594                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5595
5596                         flags = BindingFlags.Instance | BindingFlags.Public |
5597                                 BindingFlags.FlattenHierarchy;
5598
5599                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5600                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5601                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5602                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5603                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5604                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5605                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5606                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5607                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5608                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5609                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5610                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5611                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5612                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5613                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5614                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5615                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5616                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5617                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5618                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5619                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5620                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5621                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5622                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5623                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5624                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5625                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5626                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5627                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5628                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5629                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5630                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5631                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5632                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5633                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5634                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5635
5636                         flags = BindingFlags.Static | BindingFlags.Public |
5637                                 BindingFlags.FlattenHierarchy;
5638
5639                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5640                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5641                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5642                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5643                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5644                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5645                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5646                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5647                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5648                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5649                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5650                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5651                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5652                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5653                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5654                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5655                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5656                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5657                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5658                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5659                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5660                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5661                         Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5662                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5663                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5664                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5665                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5666                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5667                         Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5668                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5669                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5670                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5671                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5672                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5673                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5674                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5675
5676                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5677                                 BindingFlags.FlattenHierarchy;
5678
5679                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5680                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5681                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5682                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5683                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5684                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5685                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5686                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5687                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5688                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5689                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5690                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5691                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5692                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5693                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5694                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5695                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5696                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5697                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5698                         Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5699                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5700                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5701                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5702                         Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5703                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5704                         Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5705                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5706                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5707                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5708                         Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5709                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5710                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5711                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5712                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5713                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5714                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5715
5716                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5717                                 BindingFlags.DeclaredOnly;
5718
5719                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5720                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5721                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5722                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5723                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5724                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5725                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5726                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5727                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5728                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5729                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5730                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5731                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5732                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5733                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5734                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5735                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5736                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5737                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5738                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5739                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5740                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5741                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5742                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5743                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5744                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5745                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5746                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5747                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5748                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5749                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5750                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5751                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5752                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5753                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5754                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5755
5756                         flags = BindingFlags.Instance | BindingFlags.Public |
5757                                 BindingFlags.DeclaredOnly;
5758
5759                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5760                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5761                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5762                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5763                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5764                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5765                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5766                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5767                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5768                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5769                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5770                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5771                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5772                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5773                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5774                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5775                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5776                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5777                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5778                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5779                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5780                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5781                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5782                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5783                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5784                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5785                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5786                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5787                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5788                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5789                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5790                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5791                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5792                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5793                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5794                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5795
5796                         flags = BindingFlags.Static | BindingFlags.Public |
5797                                 BindingFlags.DeclaredOnly;
5798
5799                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5800                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5801                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5802                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5803                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5804                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5805                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5806                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5807                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5808                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5809                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5810                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5811                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5812                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5813                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5814                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5815                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5816                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5817                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5818                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5819                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5820                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5821                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5822                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5823                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5824                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5825                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5826                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5827                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5828                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5829                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5830                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5831                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5832                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5833                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5834                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5835
5836                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5837                                 BindingFlags.DeclaredOnly;
5838
5839                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5840                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5841                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5842                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5843                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5844                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5845                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5846                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5847                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5848                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5849                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5850                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5851                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5852                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5853                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5854                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5855                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5856                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5857                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5858                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5859                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5860                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5861                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5862                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5863                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5864                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5865                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5866                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5867                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5868                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5869                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5870                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5871                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5872                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5873                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5874                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5875
5876                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5877                                 BindingFlags.Public;
5878
5879                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5880                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5881                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5882                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5883                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5884                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5885                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5886                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5887                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5888                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5889                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5890                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5891                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5892                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5893                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5894                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5895                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5896                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5897                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5898                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5899                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5900                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5901                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5902                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5903                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5904                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5905                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5906                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5907                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5908                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5909                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5910                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5911                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5912                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5913                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5914                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5915
5916                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5917                                 BindingFlags.Public;
5918
5919                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5920                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5921                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5922                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5923                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5924                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5925                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5926                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5927                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5928                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5929                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5930                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5931                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5932                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5933                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5934                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5935                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5936                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5937                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5938                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5939                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5940                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5941                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5942                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5943                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5944                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5945                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5946                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5947                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5948                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5949                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5950                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5951                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5952                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5953                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5954                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5955                 }
5956
5957                 [Test]
5958                 [Category ("NotDotNet")] // mcs depends on this
5959                 public void TestGetPropertiesIncomplete_Mono ()
5960                 {
5961                         TypeBuilder tb = module.DefineType (genTypeName ());
5962                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5963                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5964                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5965
5966                         PropertyInfo [] properties = tb.GetProperties ();
5967                         Assert.AreEqual (2, properties.Length, "#1");
5968                         Assert.AreEqual ("Name", properties [0].Name, "#2");
5969                         Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5970                 }
5971
5972                 [Test]
5973                 [Category ("NotWorking")] // mcs depends on this
5974                 public void TestGetPropertiesIncomplete_MS ()
5975                 {
5976                         TypeBuilder tb = module.DefineType (genTypeName ());
5977                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5978                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5979                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5980
5981                         try {
5982                                 tb.GetProperties ();
5983                                 Assert.Fail ("#1");
5984                         } catch (NotSupportedException ex) {
5985                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5986                                 Assert.IsNull (ex.InnerException, "#3");
5987                                 Assert.IsNotNull (ex.Message, "#4");
5988                         }
5989                 }
5990
5991                 [Test]
5992                 public void TestGetPropertiesComplete ()
5993                 {
5994                         TypeBuilder tb = module.DefineType (genTypeName ());
5995                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5996
5997                         Type emittedType = tb.CreateType ();
5998
5999                         Assert.AreEqual (1, tb.GetProperties ().Length);
6000                         Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
6001                 }
6002
6003                 [Test]
6004                 [Category ("NotDotNet")] // mcs depends on this
6005                 public void TestGetPropertiesFlagsIncomplete_Mono ()
6006                 {
6007                         PropertyInfo [] properties;
6008
6009                         TypeBuilder tb = module.DefineType (genTypeName ());
6010                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
6011                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
6012                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
6013
6014                         properties = tb.GetProperties (BindingFlags.Public | 
6015                                 BindingFlags.NonPublic | BindingFlags.Instance);
6016                         Assert.AreEqual (3, properties.Length, "#A1");
6017                         Assert.AreEqual ("Name", properties [0].Name, "#A2");
6018                         Assert.AreEqual ("Income", properties [1].Name, "#A3");
6019                         Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
6020
6021                         properties = tb.GetProperties (BindingFlags.Public |
6022                                 BindingFlags.Instance);
6023                         Assert.AreEqual (2, properties.Length, "#B1");
6024                         Assert.AreEqual ("Name", properties [0].Name, "#B2");
6025                         Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
6026
6027                         properties = tb.GetProperties (BindingFlags.NonPublic |
6028                                 BindingFlags.Instance);
6029                         Assert.AreEqual (1, properties.Length, "#C1");
6030                         Assert.AreEqual ("Income", properties [0].Name, "#C2");
6031                 }
6032
6033                 [Test]
6034                 [Category ("NotWorking")] // mcs depends on this
6035                 public void TestGetPropertiesFlagsIncomplete_MS ()
6036                 {
6037                         TypeBuilder tb = module.DefineType (genTypeName ());
6038                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
6039                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
6040                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
6041
6042                         try {
6043                                 tb.GetProperties (BindingFlags.Public);
6044                                 Assert.Fail ("#1");
6045                         } catch (NotSupportedException ex) {
6046                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6047                                 Assert.IsNull (ex.InnerException, "#3");
6048                                 Assert.IsNotNull (ex.Message, "#4");
6049                         }
6050                 }
6051
6052                 [Test]
6053                 public void TestGetPropertiesFlagsComplete ()
6054                 {
6055                         TypeBuilder tb = module.DefineType (genTypeName ());
6056                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6057
6058                         Type emittedType = tb.CreateType ();
6059
6060                         Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6061                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
6062                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6063                         Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6064                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
6065                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6066                 }
6067
6068                 [Test]
6069                 public void TestGetPropertiesFlagsComplete_Inheritance ()
6070                 {
6071                         PropertyInfo [] props;
6072                         BindingFlags flags;
6073
6074                         TypeBuilder blueType = module.DefineType (genTypeName (),
6075                                 TypeAttributes.Public);
6076                         CreateMembers (blueType, "Blue", false);
6077
6078                         TypeBuilder redType = module.DefineType (genTypeName (),
6079                                 TypeAttributes.Public, blueType);
6080                         CreateMembers (redType, "Red", false);
6081
6082                         TypeBuilder greenType = module.DefineType (genTypeName (),
6083                                 TypeAttributes.Public, redType);
6084                         CreateMembers (greenType, "Green", false);
6085
6086                         blueType.CreateType ();
6087                         redType.CreateType ();
6088                         greenType.CreateType ();
6089
6090                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6091                         props = greenType.GetProperties (flags);
6092
6093 #if NET_2_0
6094                         Assert.AreEqual (13, props.Length, "#A1");
6095 #else
6096                         Assert.AreEqual (11, props.Length, "#A1");
6097 #endif
6098                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6099                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6100                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6101                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6102                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6103                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6104                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6105                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6106 #if NET_2_0
6107                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6108                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6109                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6110                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6111                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6112 #else
6113                         Assert.AreEqual ("FamilyInstanceBlue", props [8].Name, "#A10");
6114                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [9].Name, "#A11");
6115                         Assert.AreEqual ("FamORAssemInstanceBlue", props [10].Name, "#A12");
6116 #endif
6117
6118                         flags = BindingFlags.Instance | BindingFlags.Public;
6119                         props = greenType.GetProperties (flags);
6120
6121                         Assert.AreEqual (3, props.Length, "#B1");
6122                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6123                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6124                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6125
6126                         flags = BindingFlags.Static | BindingFlags.Public;
6127                         props = greenType.GetProperties (flags);
6128
6129                         Assert.AreEqual (1, props.Length, "#C1");
6130                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6131
6132                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6133                         props = greenType.GetProperties (flags);
6134
6135                         Assert.AreEqual (5, props.Length, "#D1");
6136                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6137                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6138                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6139                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6140                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6141
6142                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6143                                 BindingFlags.FlattenHierarchy;
6144                         props = greenType.GetProperties (flags);
6145
6146 #if NET_2_0
6147                         Assert.AreEqual (13, props.Length, "#E1");
6148 #else
6149                         Assert.AreEqual (11, props.Length, "#E1");
6150 #endif
6151                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6152                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6153                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6154                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6155                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6156                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6157                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6158                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6159 #if NET_2_0
6160                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6161                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6162                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6163                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6164                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6165 #else
6166                         Assert.AreEqual ("FamilyInstanceBlue", props [8].Name, "#E10");
6167                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [9].Name, "#E11");
6168                         Assert.AreEqual ("FamORAssemInstanceBlue", props [10].Name, "#E12");
6169 #endif
6170
6171                         flags = BindingFlags.Instance | BindingFlags.Public |
6172                                 BindingFlags.FlattenHierarchy;
6173                         props = greenType.GetProperties (flags);
6174
6175                         Assert.AreEqual (3, props.Length, "#F1");
6176                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6177                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6178                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6179
6180                         flags = BindingFlags.Static | BindingFlags.Public |
6181                                 BindingFlags.FlattenHierarchy;
6182                         props = greenType.GetProperties (flags);
6183
6184                         Assert.AreEqual (3, props.Length, "#G1");
6185                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6186                         Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6187                         Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6188
6189                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6190                                 BindingFlags.FlattenHierarchy;
6191                         props = greenType.GetProperties (flags);
6192
6193 #if NET_2_0
6194                         Assert.AreEqual (13, props.Length, "#H1");
6195 #else
6196                         Assert.AreEqual (11, props.Length, "#H1");
6197 #endif
6198                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6199                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6200                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6201                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6202                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6203                         Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6204                         Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6205                         Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6206 #if NET_2_0
6207                         Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6208                         Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6209                         Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6210                         Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6211                         Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6212 #else
6213                         Assert.AreEqual ("FamilyStaticBlue", props [8].Name, "#H10");
6214                         Assert.AreEqual ("FamANDAssemStaticBlue", props [9].Name, "#H11");
6215                         Assert.AreEqual ("FamORAssemStaticBlue", props [10].Name, "#H12");
6216 #endif
6217
6218                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6219                                 BindingFlags.DeclaredOnly;
6220                         props = greenType.GetProperties (flags);
6221
6222                         Assert.AreEqual (5, props.Length, "#I1");
6223                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6224                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6225                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6226                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6227                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6228
6229                         flags = BindingFlags.Instance | BindingFlags.Public |
6230                                 BindingFlags.DeclaredOnly;
6231                         props = greenType.GetProperties (flags);
6232
6233                         Assert.AreEqual (1, props.Length, "#J1");
6234                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6235
6236                         flags = BindingFlags.Static | BindingFlags.Public |
6237                                 BindingFlags.DeclaredOnly;
6238                         props = greenType.GetProperties (flags);
6239
6240                         Assert.AreEqual (1, props.Length, "#K1");
6241                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6242
6243                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6244                                 BindingFlags.DeclaredOnly;
6245                         props = greenType.GetProperties (flags);
6246
6247                         Assert.AreEqual (5, props.Length, "#L1");
6248                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6249                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6250                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6251                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6252                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6253
6254                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6255                                 BindingFlags.Public;
6256                         props = greenType.GetProperties (flags);
6257
6258 #if NET_2_0
6259                         Assert.AreEqual (16, props.Length, "#M1");
6260 #else
6261                         Assert.AreEqual (14, props.Length, "#M1");
6262 #endif
6263                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6264                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6265                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6266                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6267                         Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6268                         Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6269                         Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6270                         Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6271                         Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6272                         Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6273 #if NET_2_0
6274                         Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6275                         Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6276                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6277                         Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6278                         Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6279                         Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6280 #else
6281                         Assert.AreEqual ("FamilyInstanceBlue", props [10].Name, "#M12");
6282                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [11].Name, "#M13");
6283                         Assert.AreEqual ("FamORAssemInstanceBlue", props [12].Name, "#M14");
6284                         Assert.AreEqual ("PublicInstanceBlue", props [13].Name, "#M15");
6285 #endif
6286
6287                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6288                                 BindingFlags.Public;
6289                         props = greenType.GetProperties (flags);
6290
6291                         Assert.AreEqual (6, props.Length, "#N1");
6292                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6293                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6294                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6295                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6296                         Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6297                         Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6298                 }
6299
6300                 [Test]
6301                 public void TestGetPropertyIncomplete ()
6302                 {
6303                         TypeBuilder tb = module.DefineType (genTypeName ());
6304                         try {
6305                                 tb.GetProperty ("test");
6306                                 Assert.Fail ("#1");
6307                         } catch (NotSupportedException ex) {
6308                                 // The invoked member is not supported in a
6309                                 // dynamic module
6310                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6311                                 Assert.IsNull (ex.InnerException, "#3");
6312                                 Assert.IsNotNull (ex.Message, "#4");
6313                         }
6314                 }
6315
6316                 [Test]
6317                 public void TestGetPropertyComplete ()
6318                 {
6319                         TypeBuilder tb = module.DefineType (genTypeName ());
6320                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6321
6322                         Type emittedType = tb.CreateType ();
6323
6324                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6325                         Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6326
6327                         try {
6328                                 tb.GetProperty ("CustomerName");
6329                                 Assert.Fail ("#1");
6330                         } catch (NotSupportedException ex) {
6331                                 // The invoked member is not supported in a
6332                                 // dynamic module
6333                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6334                                 Assert.IsNull (ex.InnerException, "#3");
6335                                 Assert.IsNotNull (ex.Message, "#4");
6336                         }
6337                 }
6338
6339                 [Test]
6340                 public void TestGetPropertyFlagsIncomplete ()
6341                 {
6342                         TypeBuilder tb = module.DefineType (genTypeName ());
6343                         try {
6344                                 tb.GetProperty ("test", BindingFlags.Public);
6345                                 Assert.Fail ("#1");
6346                         } catch (NotSupportedException ex) {
6347                                 // The invoked member is not supported in a
6348                                 // dynamic module
6349                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6350                                 Assert.IsNull (ex.InnerException, "#3");
6351                                 Assert.IsNotNull (ex.Message, "#4");
6352                         }
6353                 }
6354
6355                 [Test]
6356                 public void TestGetPropertyFlagsComplete ()
6357                 {
6358                         TypeBuilder tb = module.DefineType (genTypeName ());
6359                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6360
6361                         Type emittedType = tb.CreateType ();
6362
6363                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6364                                 BindingFlags.Public));
6365                         Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6366                                 BindingFlags.NonPublic));
6367
6368                         try {
6369                                 tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6370                                 Assert.Fail ("#1");
6371                         } catch (NotSupportedException ex) {
6372                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6373                                 Assert.IsNull (ex.InnerException, "#3");
6374                                 Assert.IsNotNull (ex.Message, "#4");
6375                         }
6376                 }
6377
6378                 [Test]
6379                 public void TestGetMethodFlagsComplete ()
6380                 {
6381                         BindingFlags flags;
6382
6383                         TypeBuilder blueType = module.DefineType (genTypeName (),
6384                                 TypeAttributes.Public);
6385                         CreateMembers (blueType, "Blue", false);
6386
6387                         TypeBuilder redType = module.DefineType (genTypeName (),
6388                                 TypeAttributes.Public, blueType);
6389                         CreateMembers (redType, "Red", false);
6390
6391                         TypeBuilder greenType = module.DefineType (genTypeName (),
6392                                 TypeAttributes.Public, redType);
6393                         CreateMembers (greenType, "Green", false);
6394
6395                         blueType.CreateType ();
6396                         redType.CreateType ();
6397                         greenType.CreateType ();
6398
6399                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6400
6401                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6402                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6403                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6404                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6405                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6406 #if NET_2_0
6407                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6408 #else
6409                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6410 #endif
6411                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6412                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6413                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6414                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6415                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6416 #if NET_2_0
6417                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6418 #else
6419                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6420 #endif
6421                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6422                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6423                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6424                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6425                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6426                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6427                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6428                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6429                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6430                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6431                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6432                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6433                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6434                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6435                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6436                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6437                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6438                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6439                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6440                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6441                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6442                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6443                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6444                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6445
6446                         flags = BindingFlags.Instance | BindingFlags.Public;
6447
6448                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6449                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6450                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6451                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6452                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6453                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6454                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6455                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6456                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6457                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6458                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6459                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6460                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6461                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6462                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6463                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6464                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6465                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6466                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6467                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6468                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6469                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6470                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6471                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6472                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6473                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6474                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6475                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6476                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6477                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6478                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6479                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6480                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6481                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6482                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6483                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6484
6485                         flags = BindingFlags.Static | BindingFlags.Public;
6486
6487                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6488                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6489                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6490                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6491                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6492                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6493                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6494                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6495                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6496                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6497                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6498                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6499                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6500                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6501                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6502                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6503                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6504                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6505                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6506                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6507                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6508                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6509                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6510                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6511                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6512                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6513                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6514                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6515                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6516                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6517                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6518                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6519                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6520                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6521                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6522                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6523
6524                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6525
6526                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6527                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6528                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6529                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6530                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6531                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6532                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6533                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6534                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6535                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6536                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6537                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6538                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6539                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6540                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6541                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6542                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6543                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6544                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6545                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6546                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6547                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6548                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6549                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6550                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6551                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6552                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6553                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6554                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6555                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6556                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6557                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6558                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6559                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6560                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6561                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6562
6563                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6564                                 BindingFlags.FlattenHierarchy;
6565
6566                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6567                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6568                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6569                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6570                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6571 #if NET_2_0
6572                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6573 #else
6574                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6575 #endif
6576                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6577                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6578                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6579                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6580                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6581 #if NET_2_0
6582                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6583 #else
6584                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6585 #endif
6586                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6587                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6588                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6589                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6590                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6591                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6592                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6593                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6594                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6595                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6596                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6597                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6598                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6599                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6600                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6601                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6602                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6603                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6604                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6605                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6606                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6607                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6608                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6609                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6610
6611                         flags = BindingFlags.Instance | BindingFlags.Public |
6612                                 BindingFlags.FlattenHierarchy;
6613
6614                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6615                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6616                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6617                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6618                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6619                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6620                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6621                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6622                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6623                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6624                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6625                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6626                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6627                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6628                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6629                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6630                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6631                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6632                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6633                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6634                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6635                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6636                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6637                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6638                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6639                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6640                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6641                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6642                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6643                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6644                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6645                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6646                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6647                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6648                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6649                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6650
6651                         flags = BindingFlags.Static | BindingFlags.Public |
6652                                 BindingFlags.FlattenHierarchy;
6653
6654                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6655                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6656                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6657                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6658                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6659                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6660                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6661                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6662                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6663                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6664                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6665                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6666                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6667                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6668                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6669                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6670                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6671                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6672                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6673                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6674                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6675                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6676                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6677                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6678                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6679                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6680                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6681                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6682                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6683                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6684                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6685                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6686                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6687                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6688                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6689                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6690
6691                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6692                                 BindingFlags.FlattenHierarchy;
6693
6694                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6695                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6696                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6697                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6698                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6699                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6700                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6701                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6702                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6703                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6704                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6705                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6706                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6707                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6708                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6709                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6710                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6711                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6712                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6713                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6714                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6715                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6716                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6717 #if NET_2_0
6718                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6719 #else
6720                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6721 #endif
6722                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6723                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6724                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6725                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6726                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6727 #if NET_2_0
6728                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6729 #else
6730                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6731 #endif
6732                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6733                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6734                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6735                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6736                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6737                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6738
6739                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6740                                 BindingFlags.DeclaredOnly;
6741
6742                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6743                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6744                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6745                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6746                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6747                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6748                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6749                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6750                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6751                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6752                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6753                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6754                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6755                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6756                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6757                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6758                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6759                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6760                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6761                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6762                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6763                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6764                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6765                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6766                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6767                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6768                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6769                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6770                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6771                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6772                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6773                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6774                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6775                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6776                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6777                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6778
6779                         flags = BindingFlags.Instance | BindingFlags.Public |
6780                                 BindingFlags.DeclaredOnly;
6781
6782                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6783                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6784                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6785                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6786                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6787                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6788                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6789                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6790                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6791                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6792                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6793                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6794                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6795                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6796                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6797                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6798                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6799                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6800                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6801                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6802                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6803                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6804                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6805                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6806                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6807                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6808                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6809                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6810                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6811                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6812                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6813                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6814                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6815                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6816                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6817                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6818
6819                         flags = BindingFlags.Static | BindingFlags.Public |
6820                                 BindingFlags.DeclaredOnly;
6821
6822                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6823                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6824                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6825                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6826                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6827                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6828                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6829                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6830                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6831                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6832                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6833                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6834                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6835                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6836                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6837                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6838                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6839                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6840                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6841                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6842                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6843                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6844                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6845                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6846                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6847                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6848                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6849                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6850                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6851                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6852                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6853                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6854                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6855                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6856                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6857                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6858
6859                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6860                                 BindingFlags.DeclaredOnly;
6861
6862                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6863                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6864                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6865                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6866                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6867                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6868                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6869                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6870                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6871                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6872                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6873                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6874                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6875                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6876                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6877                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6878                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6879                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6880                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6881                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6882                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6883                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6884                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6885                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6886                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6887                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6888                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6889                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6890                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6891                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6892                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6893                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6894                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6895                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6896                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6897                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6898
6899                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6900                                 BindingFlags.Public;
6901
6902                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6903                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6904                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6905                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6906                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6907 #if NET_2_0
6908                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6909 #else
6910                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6911 #endif
6912                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6913                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6914                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6915                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6916                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6917 #if NET_2_0
6918                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6919 #else
6920                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6921 #endif
6922                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6923                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6924                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6925                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6926                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6927                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6928                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6929                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6930                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6931                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6932                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6933                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6934                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6935                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6936                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6937                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6938                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6939                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6940                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6941                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6942                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6943                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6944                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6945                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6946
6947                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6948                                 BindingFlags.Public;
6949
6950                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6951                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6952                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6953                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6954                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6955                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6956                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6957                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6958                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6959                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6960                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6961                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6962                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6963                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6964                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6965                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6966                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6967                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6968                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6969                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6970                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6971                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6972                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6973                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6974                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6975                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6976                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6977                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6978                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6979                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6980                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6981                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6982                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6983                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6984                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6985                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6986                 }
6987
6988                 [Test]
6989                 [Category ("NotDotNet")] // mcs depends on this
6990                 public void TestGetMethodsIncomplete_Mono ()
6991                 {
6992                         MethodBuilder mb;
6993                         ILGenerator ilgen;
6994
6995                         TypeBuilder tb = module.DefineType (genTypeName (),
6996                                 TypeAttributes.Abstract);
6997                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6998                                 typeof (void), Type.EmptyTypes);
6999                         ilgen = mb.GetILGenerator ();
7000                         ilgen.Emit (OpCodes.Ret);
7001
7002                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7003                                 typeof (void), Type.EmptyTypes);
7004                         ilgen = mb.GetILGenerator ();
7005                         ilgen.Emit (OpCodes.Ret);
7006
7007                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7008                                 MethodAttributes.Static,
7009                                 typeof (void), Type.EmptyTypes);
7010                         ilgen = mb.GetILGenerator ();
7011                         ilgen.Emit (OpCodes.Ret);
7012
7013                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7014                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7015                                 typeof (void), Type.EmptyTypes);
7016
7017                         MethodInfo [] methods = tb.GetMethods ();
7018                         Assert.AreEqual (7, methods.Length, "#A");
7019
7020                         Assert.AreEqual ("Equals", methods [0].Name, "#B1");
7021                         Assert.IsFalse (methods [0].IsStatic, "#B2");
7022                         Assert.IsFalse (methods [0].IsAbstract, "#B3");
7023
7024                         Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
7025                         Assert.IsFalse (methods [1].IsStatic, "#C2");
7026                         Assert.IsFalse (methods [1].IsAbstract, "#C3");
7027
7028                         Assert.AreEqual ("GetType", methods [2].Name, "#D1");
7029                         Assert.IsFalse (methods [2].IsStatic, "#D2");
7030                         Assert.IsFalse (methods [2].IsAbstract, "#D3");
7031
7032                         Assert.AreEqual ("ToString", methods [3].Name, "#E1");
7033                         Assert.IsFalse (methods [3].IsStatic, "#E2");
7034                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
7035
7036                         Assert.AreEqual ("Hello", methods [4].Name, "#F1");
7037                         Assert.IsFalse (methods [4].IsStatic, "#F2");
7038                         Assert.IsFalse (methods [4].IsAbstract, "#F3");
7039
7040                         Assert.AreEqual ("Execute", methods [5].Name, "#G1");
7041                         Assert.IsTrue (methods [5].IsStatic, "#G2");
7042                         Assert.IsFalse (methods [5].IsAbstract, "#G3");
7043
7044                         Assert.AreEqual ("Init", methods [6].Name, "#H1");
7045                         Assert.IsFalse (methods [6].IsStatic, "#H2");
7046                         Assert.IsTrue (methods [6].IsAbstract, "#H3");
7047                 }
7048
7049                 [Test]
7050                 [Category ("NotWorking")] // mcs depends on this
7051                 public void TestGetMethodsIncomplete_MS ()
7052                 {
7053                         MethodBuilder mb;
7054                         ILGenerator ilgen;
7055
7056                         TypeBuilder tb = module.DefineType (genTypeName (),
7057                                 TypeAttributes.Abstract);
7058                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7059                                 typeof (void), Type.EmptyTypes);
7060                         ilgen = mb.GetILGenerator ();
7061                         ilgen.Emit (OpCodes.Ret);
7062
7063                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7064                                 typeof (void), Type.EmptyTypes);
7065                         ilgen = mb.GetILGenerator ();
7066                         ilgen.Emit (OpCodes.Ret);
7067
7068                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7069                                 MethodAttributes.Static,
7070                                 typeof (void), Type.EmptyTypes);
7071                         ilgen = mb.GetILGenerator ();
7072                         ilgen.Emit (OpCodes.Ret);
7073
7074                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7075                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7076                                 typeof (void), Type.EmptyTypes);
7077
7078                         try {
7079                                 tb.GetMethods ();
7080                                 Assert.Fail ("#1");
7081                         } catch (NotSupportedException ex) {
7082                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7083                                 Assert.IsNull (ex.InnerException, "#3");
7084                                 Assert.IsNotNull (ex.Message, "#4");
7085                         }
7086                 }
7087
7088                 [Test]
7089                 public void TestGetMethodsComplete ()
7090                 {
7091                         MethodBuilder mb;
7092                         ILGenerator ilgen;
7093                         MethodInfo mi;
7094
7095                         TypeBuilder tb = module.DefineType (genTypeName (),
7096                                 TypeAttributes.Abstract);
7097                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7098                                 typeof (string), Type.EmptyTypes);
7099                         ilgen = mb.GetILGenerator ();
7100                         ilgen.Emit (OpCodes.Ldstr, "Hi! ");
7101                         ilgen.Emit (OpCodes.Ldarg_1);
7102                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7103                                 new Type [] { typeof (string), typeof (string) });
7104                         ilgen.Emit (OpCodes.Call, infoMethod);
7105                         ilgen.Emit (OpCodes.Ret);
7106
7107                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7108                                 typeof (void), Type.EmptyTypes);
7109                         ilgen = mb.GetILGenerator ();
7110                         ilgen.Emit (OpCodes.Ret);
7111
7112                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7113                                 MethodAttributes.Static,
7114                                 typeof (void), Type.EmptyTypes);
7115                         ilgen = mb.GetILGenerator ();
7116                         ilgen.Emit (OpCodes.Ret);
7117
7118                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7119                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7120                                 typeof (void), Type.EmptyTypes);
7121
7122                         Type emittedType = tb.CreateType ();
7123
7124                         MethodInfo [] methods = emittedType.GetMethods ();
7125                         Assert.AreEqual (7, methods.Length, "#A1");
7126                         Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
7127
7128                         mi = GetMethodByName (methods, "Hello");
7129                         Assert.IsNotNull (mi, "#B1");
7130                         Assert.IsFalse (mi.IsStatic, "#B2");
7131                         Assert.IsFalse (mi.IsAbstract, "#B3");
7132
7133                         mi = GetMethodByName (methods, "Execute");
7134                         Assert.IsNotNull (mi, "#C1");
7135                         Assert.IsTrue (mi.IsStatic, "#C2");
7136                         Assert.IsFalse (mi.IsAbstract, "#C3");
7137
7138                         mi = GetMethodByName (methods, "Init");
7139                         Assert.IsNotNull (mi, "#D1");
7140                         Assert.IsFalse (mi.IsStatic, "#D2");
7141                         Assert.IsTrue (mi.IsAbstract, "#D3");
7142
7143                         mi = GetMethodByName (methods, "GetType");
7144                         Assert.IsNotNull (mi, "#E1");
7145                         Assert.IsFalse (methods [3].IsStatic, "#E2");
7146                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
7147
7148                         mi = GetMethodByName (methods, "ToString");
7149                         Assert.IsNotNull (mi, "#F1");
7150                         Assert.IsFalse (mi.IsStatic, "#F2");
7151                         Assert.IsFalse (mi.IsAbstract, "#F3");
7152
7153                         mi = GetMethodByName (methods, "Equals");
7154                         Assert.IsNotNull (mi, "#G1");
7155                         Assert.IsFalse (mi.IsStatic, "#G2");
7156                         Assert.IsFalse (mi.IsAbstract, "#G3");
7157
7158                         mi = GetMethodByName (methods, "GetHashCode");
7159                         Assert.IsNotNull (mi, "#H1");
7160                         Assert.IsFalse (mi.IsStatic, "#H2");
7161                         Assert.IsFalse (mi.IsAbstract, "#H3");
7162                 }
7163
7164                 [Test]
7165                 [Category ("NotDotNet")] // mcs depends on this
7166                 public void TestGetMethodsFlagsIncomplete_Inheritance ()
7167                 {
7168                         MethodInfo [] methods;
7169                         BindingFlags flags;
7170
7171                         TypeBuilder blueType = module.DefineType (genTypeName (),
7172                                 TypeAttributes.Public);
7173                         CreateMembers (blueType, "Blue", false);
7174
7175                         TypeBuilder redType = module.DefineType (genTypeName (),
7176                                 TypeAttributes.Public, blueType);
7177                         CreateMembers (redType, "Red", false);
7178
7179                         TypeBuilder greenType = module.DefineType (genTypeName (),
7180                                 TypeAttributes.Public, redType);
7181                         CreateMembers (greenType, "Green", false);
7182
7183                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7184                         methods = greenType.GetMethods (flags);
7185
7186                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7187                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7188                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7189                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7190                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7191 #if NET_2_0
7192                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7193 #else
7194                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7195 #endif
7196                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7197                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7198                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7199                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7200                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7201 #if NET_2_0
7202                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7203 #else
7204                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7205 #endif
7206                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7207                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7208                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7209                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7210                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7211                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7212                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7213                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7214                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7215                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7216                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7217                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7218                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7219                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7220                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7221                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7222                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7223                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7224                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7225                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7226                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7227                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7228                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7229                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7230
7231                         flags = BindingFlags.Instance | BindingFlags.Public;
7232                         methods = greenType.GetMethods (flags);
7233
7234                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7235                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7236                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7237                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7238                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7239                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7240                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7241                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7242                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7243                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7244                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7245                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7246                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7247                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7248                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7249                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7250                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7251                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7252                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7253                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7254                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7255                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7256                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7257                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7258                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7259                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7260                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7261                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7262                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7263                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7264                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7265                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7266                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7267                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7268                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7269                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7270
7271                         flags = BindingFlags.Static | BindingFlags.Public;
7272                         methods = greenType.GetMethods (flags);
7273
7274                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7275                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7276                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7277                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7278                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7279                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7280                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7281                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7282                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7283                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7284                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7285                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7286                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7287                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7288                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7289                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7290                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7291                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7292                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7293                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7294                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7295                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7296                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7297                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7298                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7299                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7300                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7301                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7302                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7303                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7304                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7305                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7306                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7307                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7308                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7309                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7310
7311                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7312                         methods = greenType.GetMethods (flags);
7313
7314                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7315                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7316                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7317                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7318                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7319                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7320                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7321                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7322                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7323                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7324                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7325                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7326                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7327                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7328                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7329                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7330                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7331                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7332                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7333                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7334                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7335                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7336                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7337                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7338                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7339                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7340                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7341                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7342                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7343                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7344                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7345                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7346                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7347                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7348                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7349                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7350
7351                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7352                                 BindingFlags.FlattenHierarchy;
7353                         methods = greenType.GetMethods (flags);
7354
7355                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7356                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7357                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7358                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7359                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7360 #if NET_2_0
7361                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7362 #else
7363                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7364 #endif
7365                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7366                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7367                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7368                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7369                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7370 #if NET_2_0
7371                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7372 #else
7373                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7374 #endif
7375                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7376                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7377                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7378                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7379                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7380                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7381                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7382                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7383                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7384                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7385                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7386                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7387                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7388                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7389                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7390                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7391                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7392                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7393                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7394                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7395                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7396                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7397                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7398                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7399
7400                         flags = BindingFlags.Instance | BindingFlags.Public |
7401                                 BindingFlags.FlattenHierarchy;
7402                         methods = greenType.GetMethods (flags);
7403
7404                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7405                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7406                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7407                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7408                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7409                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7410                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7411                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7412                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7413                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7414                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7415                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7416                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7417                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7418                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7419                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7420                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7421                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7422                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7423                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7424                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7425                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7426                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7427                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7428                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7429                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7430                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7431                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7432                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7433                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7434                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7435                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7436                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7437                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7438                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7439                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7440
7441                         flags = BindingFlags.Static | BindingFlags.Public |
7442                                 BindingFlags.FlattenHierarchy;
7443                         methods = greenType.GetMethods (flags);
7444
7445                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7446                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7447                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7448                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7449                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7450                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7451                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7452                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7453                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7454                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7455                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7456                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7457                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7458                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7459                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7460                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7461                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7462                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7463                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7464                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7465                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7466                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7467                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7468                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7469                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7470                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7471                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7472                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7473                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7474                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7475                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7476                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7477                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7478                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7479                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7480                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7481
7482                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7483                                 BindingFlags.FlattenHierarchy;
7484                         methods = greenType.GetMethods (flags);
7485
7486                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7487                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7488                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7489                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7490                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7491                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7492                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7493                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7494                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7495                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7496                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7497                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7498                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7499                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7500                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7501                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7502                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7503                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7504                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7505                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7506                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7507                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7508                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7509 #if NET_2_0
7510                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7511 #else
7512                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7513 #endif
7514                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7515                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7516                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7517                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7518                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7519 #if NET_2_0
7520                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7521 #else
7522                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7523 #endif
7524                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7525                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7526                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7527                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7528                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7529                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7530
7531                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7532                                 BindingFlags.DeclaredOnly;
7533                         methods = greenType.GetMethods (flags);
7534
7535                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7536                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7537                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7538                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7539                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7540                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7541                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7542                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7543                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7544                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7545                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7546                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7547                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7548                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7549                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7550                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7551                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7552                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7553                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7554                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7555                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7556                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7557                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7558                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7559                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7560                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7561                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7562                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7563                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7564                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7565                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7566                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7567                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7568                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7569                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7570                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7571
7572                         flags = BindingFlags.Instance | BindingFlags.Public |
7573                                 BindingFlags.DeclaredOnly;
7574                         methods = greenType.GetMethods (flags);
7575
7576                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7577                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7578                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7579                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7580                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7581                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7582                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7583                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7584                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7585                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7586                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7587                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7588                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7589                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7590                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7591                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7592                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7593                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7594                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7595                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7596                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7597                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7598                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7599                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7600                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7601                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7602                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7603                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7604                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7605                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7606                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7607                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7608                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7609                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7610                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7611                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7612
7613                         flags = BindingFlags.Static | BindingFlags.Public |
7614                                 BindingFlags.DeclaredOnly;
7615                         methods = greenType.GetMethods (flags);
7616
7617                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7618                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7619                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7620                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7621                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7622                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7623                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7624                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7625                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7626                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7627                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7628                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7629                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7630                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7631                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7632                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7633                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7634                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7635                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7636                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7637                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7638                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7639                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7640                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7641                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7642                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7643                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7644                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7645                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7646                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7647                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7648                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7649                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7650                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7651                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7652                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7653
7654                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7655                                 BindingFlags.DeclaredOnly;
7656                         methods = greenType.GetMethods (flags);
7657
7658                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7659                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7660                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7661                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7662                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7663                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7664                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7665                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7666                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7667                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7668                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7669                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7670                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7671                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7672                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7673                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7674                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7675                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7676                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7677                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7678                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7679                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7680                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7681                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7682                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7683                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7684                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7685                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7686                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7687                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7688                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7689                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7690                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7691                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7692                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7693                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7694
7695                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7696                                 BindingFlags.Public;
7697                         methods = greenType.GetMethods (flags);
7698
7699                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7700                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7701                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7702                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7703                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7704 #if NET_2_0
7705                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7706 #else
7707                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7708 #endif
7709                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7710                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7711                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7712                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7713                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7714 #if NET_2_0
7715                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7716 #else
7717                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7718 #endif
7719                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7720                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7721                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7722                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7723                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7724                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7725                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7726                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7727                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7728                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7729                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7730                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7731                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7732                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7733                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7734                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7735                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7736                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7737                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7738                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7739                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7740                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7741                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7742                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7743
7744                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7745                                 BindingFlags.Public;
7746                         methods = greenType.GetMethods (flags);
7747
7748                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7749                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7750                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7751                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7752                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7753                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7754                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7755                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7756                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7757                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7758                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7759                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7760                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7761                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7762                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7763                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7764                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7765                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7766                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7767                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7768                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7769                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7770                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7771                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7772                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7773                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7774                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7775                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7776                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7777                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7778                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7779                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7780                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7781                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7782                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7783                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7784                 }
7785
7786                 [Test]
7787                 [Category ("NotDotNet")] // mcs depends on this
7788                 public void TestGetMethodsFlagsIncomplete_Mono ()
7789                 {
7790                         MethodBuilder mb;
7791                         ILGenerator ilgen;
7792                         MethodInfo [] methods;
7793
7794                         TypeBuilder tb = module.DefineType (genTypeName (),
7795                                 TypeAttributes.Abstract);
7796                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7797                                 typeof (void), Type.EmptyTypes);
7798                         ilgen = mb.GetILGenerator ();
7799                         ilgen.Emit (OpCodes.Ret);
7800
7801                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7802                                 typeof (void), Type.EmptyTypes);
7803                         ilgen = mb.GetILGenerator ();
7804                         ilgen.Emit (OpCodes.Ret);
7805
7806                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7807                                 MethodAttributes.Static,
7808                                 typeof (void), Type.EmptyTypes);
7809                         ilgen = mb.GetILGenerator ();
7810                         ilgen.Emit (OpCodes.Ret);
7811
7812                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7813                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7814                                 typeof (void), Type.EmptyTypes);
7815
7816                         methods = tb.GetMethods (BindingFlags.Public |
7817                                 BindingFlags.Instance);
7818                         Assert.AreEqual (6, methods.Length, "#A1");
7819                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7820                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7821                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7822                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7823                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7824
7825                         methods = tb.GetMethods (BindingFlags.Public |
7826                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7827                         Assert.AreEqual (2, methods.Length, "#B1");
7828                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7829                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7830
7831                         methods = tb.GetMethods (BindingFlags.Public |
7832                                 BindingFlags.Instance | BindingFlags.Static);
7833                         Assert.AreEqual (7, methods.Length, "#C1");
7834                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7835                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7836                         Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7837                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7838                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7839                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7840
7841                         methods = tb.GetMethods (BindingFlags.NonPublic |
7842                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7843                         Assert.AreEqual (1, methods.Length, "#D1");
7844                         Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7845                 }
7846
7847
7848                 [Test]
7849                 [Category ("NotWorking")] // mcs depends on this
7850                 public void TestGetMethodsFlagsIncomplete_MS ()
7851                 {
7852                         MethodBuilder mb;
7853                         ILGenerator ilgen;
7854
7855                         TypeBuilder tb = module.DefineType (genTypeName (),
7856                                 TypeAttributes.Abstract);
7857                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7858                                 typeof (void), Type.EmptyTypes);
7859                         ilgen = mb.GetILGenerator ();
7860                         ilgen.Emit (OpCodes.Ret);
7861
7862                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7863                                 typeof (void), Type.EmptyTypes);
7864                         ilgen = mb.GetILGenerator ();
7865                         ilgen.Emit (OpCodes.Ret);
7866
7867                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7868                                 MethodAttributes.Static,
7869                                 typeof (void), Type.EmptyTypes);
7870                         ilgen = mb.GetILGenerator ();
7871                         ilgen.Emit (OpCodes.Ret);
7872
7873                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7874                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7875                                 typeof (void), Type.EmptyTypes);
7876
7877                         try {
7878                                 tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7879                                 Assert.Fail ("#1");
7880                         } catch (NotSupportedException ex) {
7881                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7882                                 Assert.IsNull (ex.InnerException, "#3");
7883                                 Assert.IsNotNull (ex.Message, "#4");
7884                         }
7885                 }
7886
7887                 [Test]
7888                 public void TestGetMethodsFlagsComplete ()
7889                 {
7890                         TypeBuilder tb = module.DefineType (genTypeName ());
7891                         MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7892                                 MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7893                         ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7894                         helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7895                         helloMethodIL.Emit (OpCodes.Ldarg_1);
7896                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7897                                 new Type [] { typeof (string), typeof (string) });
7898                         helloMethodIL.Emit (OpCodes.Call, infoMethod);
7899                         helloMethodIL.Emit (OpCodes.Ret);
7900
7901                         Type emittedType = tb.CreateType ();
7902
7903                         Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7904                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7905                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7906                         Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7907                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7908                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7909                 }
7910
7911                 [Test]
7912                 public void TestGetMethodsFlagsComplete_Inheritance ()
7913                 {
7914                         MethodInfo [] methods;
7915                         BindingFlags flags;
7916
7917                         TypeBuilder blueType = module.DefineType (genTypeName (),
7918                                 TypeAttributes.Public);
7919                         CreateMembers (blueType, "Blue", false);
7920
7921                         TypeBuilder redType = module.DefineType (genTypeName (),
7922                                 TypeAttributes.Public, blueType);
7923                         CreateMembers (redType, "Red", false);
7924
7925                         TypeBuilder greenType = module.DefineType (genTypeName (),
7926                                 TypeAttributes.Public, redType);
7927                         CreateMembers (greenType, "Green", false);
7928
7929                         blueType.CreateType ();
7930                         redType.CreateType ();
7931                         greenType.CreateType ();
7932
7933                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7934                         methods = greenType.GetMethods (flags);
7935
7936                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7937                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7938                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7939                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7940                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7941 #if NET_2_0
7942                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7943 #else
7944                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7945 #endif
7946                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7947                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7948                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7949                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7950                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7951 #if NET_2_0
7952                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7953 #else
7954                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7955 #endif
7956                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7957                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7958                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7959                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7960                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7961                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7962                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7963                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7964                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7965                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7966                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7967                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7968                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7969                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7970                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7971                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7972                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7973                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7974                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7975                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7976                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7977                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7978                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7979                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7980
7981                         flags = BindingFlags.Instance | BindingFlags.Public;
7982                         methods = greenType.GetMethods (flags);
7983
7984                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7985                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7986                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7987                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7988                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7989                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7990                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7991                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7992                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7993                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7994                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7995                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7996                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7997                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7998                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7999                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
8000                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
8001                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
8002                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
8003                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
8004                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
8005                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
8006                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
8007                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
8008                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
8009                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
8010                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
8011                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
8012                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
8013                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
8014                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
8015                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
8016                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
8017                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
8018                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
8019                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
8020
8021                         flags = BindingFlags.Static | BindingFlags.Public;
8022                         methods = greenType.GetMethods (flags);
8023
8024                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
8025                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
8026                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
8027                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
8028                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
8029                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
8030                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
8031                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
8032                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
8033                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
8034                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
8035                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
8036                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
8037                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
8038                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
8039                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
8040                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
8041                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
8042                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
8043                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
8044                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
8045                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
8046                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
8047                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
8048                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
8049                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
8050                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
8051                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
8052                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
8053                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
8054                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
8055                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
8056                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
8057                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
8058                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
8059                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
8060
8061                         flags = BindingFlags.Static | BindingFlags.NonPublic;
8062                         methods = greenType.GetMethods (flags);
8063
8064                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
8065                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
8066                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
8067                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
8068                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
8069                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
8070                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
8071                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
8072                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
8073                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
8074                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
8075                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
8076                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
8077                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
8078                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
8079                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
8080                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
8081                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
8082                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
8083                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
8084                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
8085                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
8086                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
8087                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
8088                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
8089                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
8090                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
8091                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
8092                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
8093                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
8094                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
8095                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
8096                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
8097                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
8098                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
8099                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
8100
8101                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8102                                 BindingFlags.FlattenHierarchy;
8103                         methods = greenType.GetMethods (flags);
8104
8105                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
8106                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
8107                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
8108                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
8109                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
8110 #if NET_2_0
8111                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
8112 #else
8113                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
8114 #endif
8115                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
8116                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
8117                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
8118                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
8119                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
8120 #if NET_2_0
8121                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
8122 #else
8123                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
8124 #endif
8125                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
8126                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
8127                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
8128                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
8129                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
8130                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
8131                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
8132                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
8133                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
8134                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
8135                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
8136                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
8137                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
8138                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
8139                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
8140                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
8141                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
8142                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
8143                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
8144                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
8145                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
8146                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
8147                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
8148                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
8149
8150                         flags = BindingFlags.Instance | BindingFlags.Public |
8151                                 BindingFlags.FlattenHierarchy;
8152                         methods = greenType.GetMethods (flags);
8153
8154                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
8155                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
8156                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
8157                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
8158                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
8159                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
8160                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
8161                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
8162                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
8163                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
8164                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
8165                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
8166                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
8167                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
8168                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
8169                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
8170                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
8171                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
8172                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
8173                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
8174                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
8175                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
8176                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
8177                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
8178                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
8179                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
8180                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
8181                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
8182                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
8183                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
8184                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
8185                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
8186                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
8187                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
8188                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
8189                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
8190
8191                         flags = BindingFlags.Static | BindingFlags.Public |
8192                                 BindingFlags.FlattenHierarchy;
8193                         methods = greenType.GetMethods (flags);
8194
8195                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
8196                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
8197                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
8198                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8199                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8200                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8201                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8202                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8203                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8204                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8205                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8206                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8207                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8208                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8209                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8210                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8211                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8212                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8213                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8214                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8215                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8216                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8217                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8218                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8219                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8220                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8221                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8222                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8223                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8224                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8225                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8226                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8227                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8228                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8229                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8230                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8231
8232                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8233                                 BindingFlags.FlattenHierarchy;
8234                         methods = greenType.GetMethods (flags);
8235
8236                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8237                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8238                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8239                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8240                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8241                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8242                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8243                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8244                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8245                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8246                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8247                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8248                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8249                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8250                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8251                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8252                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8253                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8254                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8255                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8256                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8257                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8258                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8259 #if NET_2_0
8260                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8261 #else
8262                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8263 #endif
8264                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8265                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8266                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8267                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8268                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8269 #if NET_2_0
8270                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8271 #else
8272                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8273 #endif
8274                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8275                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8276                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8277                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8278                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8279                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8280
8281                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8282                                 BindingFlags.DeclaredOnly;
8283                         methods = greenType.GetMethods (flags);
8284
8285                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8286                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8287                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8288                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8289                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8290                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8291                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8292                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8293                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8294                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8295                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8296                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8297                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8298                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8299                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8300                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8301                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8302                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8303                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8304                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8305                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8306                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8307                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8308                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8309                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8310                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8311                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8312                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8313                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8314                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8315                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8316                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8317                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8318                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8319                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8320                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8321
8322                         flags = BindingFlags.Instance | BindingFlags.Public |
8323                                 BindingFlags.DeclaredOnly;
8324                         methods = greenType.GetMethods (flags);
8325
8326                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8327                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8328                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8329                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8330                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8331                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8332                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8333                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8334                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8335                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8336                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8337                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8338                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8339                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8340                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8341                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8342                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8343                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8344                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8345                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8346                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8347                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8348                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8349                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8350                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8351                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8352                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8353                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8354                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8355                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8356                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8357                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8358                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8359                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8360                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8361                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8362
8363                         flags = BindingFlags.Static | BindingFlags.Public |
8364                                 BindingFlags.DeclaredOnly;
8365                         methods = greenType.GetMethods (flags);
8366
8367                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8368                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8369                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8370                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8371                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8372                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8373                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8374                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8375                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8376                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8377                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8378                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8379                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8380                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8381                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8382                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8383                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8384                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8385                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8386                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8387                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8388                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8389                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8390                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8391                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8392                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8393                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8394                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8395                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8396                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8397                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8398                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8399                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8400                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8401                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8402                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8403
8404                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8405                                 BindingFlags.DeclaredOnly;
8406                         methods = greenType.GetMethods (flags);
8407
8408                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8409                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8410                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8411                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8412                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8413                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8414                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8415                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8416                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8417                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8418                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8419                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8420                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8421                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8422                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8423                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8424                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8425                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8426                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8427                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8428                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8429                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8430                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8431                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8432                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8433                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8434                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8435                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8436                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8437                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8438                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8439                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8440                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8441                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8442                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8443                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8444
8445                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8446                                 BindingFlags.Public;
8447                         methods = greenType.GetMethods (flags);
8448
8449                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8450                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8451                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8452                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8453                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8454 #if NET_2_0
8455                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8456 #else
8457                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8458 #endif
8459                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8460                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8461                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8462                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8463                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8464 #if NET_2_0
8465                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8466 #else
8467                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8468 #endif
8469                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8470                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8471                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8472                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8473                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8474                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8475                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8476                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8477                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8478                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8479                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8480                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8481                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8482                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8483                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8484                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8485                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8486                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8487                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8488                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8489                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8490                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8491                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8492                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8493
8494                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8495                                 BindingFlags.Public;
8496                         methods = greenType.GetMethods (flags);
8497
8498                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8499                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8500                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8501                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8502                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8503                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8504                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8505                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8506                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8507                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8508                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8509                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8510                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8511                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8512                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8513                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8514                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8515                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8516                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8517                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8518                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8519                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8520                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8521                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8522                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8523                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8524                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8525                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8526                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8527                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8528                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8529                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8530                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8531                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8532                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8533                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8534                 }
8535
8536                 [Test]
8537                 public void TestGetMemberIncomplete ()
8538                 {
8539                         TypeBuilder tb = module.DefineType (genTypeName ());
8540                         try {
8541                                 tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8542                                 Assert.Fail ("#1");
8543                         } catch (NotSupportedException ex) {
8544                                 // The invoked member is not supported in a
8545                                 // dynamic module
8546                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8547                                 Assert.IsNull (ex.InnerException, "#3");
8548                                 Assert.IsNotNull (ex.Message, "#4");
8549                         }
8550                 }
8551
8552                 [Test]
8553                 public void TestGetMemberComplete ()
8554                 {
8555                         TypeBuilder tb = module.DefineType (genTypeName ());
8556                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8557
8558                         Type emittedType = tb.CreateType ();
8559
8560                         Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8561                         Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8562                 }
8563
8564                 [Test]
8565                 public void TestGetMembersIncomplete ()
8566                 {
8567                         TypeBuilder tb = module.DefineType (genTypeName ());
8568                         try {
8569                                 tb.GetMembers ();
8570                                 Assert.Fail ("#1");
8571                         } catch (NotSupportedException ex) {
8572                                 // The invoked member is not supported in a
8573                                 // dynamic module
8574                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8575                                 Assert.IsNull (ex.InnerException, "#3");
8576                                 Assert.IsNotNull (ex.Message, "#4");
8577                         }
8578                 }
8579
8580                 [Test]
8581                 public void TestGetMembersComplete ()
8582                 {
8583                         TypeBuilder tb = module.DefineType (genTypeName ());
8584                         Type emittedType = tb.CreateType ();
8585
8586                         Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8587                 }
8588
8589                 [Test]
8590                 public void TestGetMembersFlagsIncomplete ()
8591                 {
8592                         TypeBuilder tb = module.DefineType (genTypeName ());
8593                         try {
8594                                 tb.GetMembers (BindingFlags.Public);
8595                                 Assert.Fail ("#1");
8596                         } catch (NotSupportedException ex) {
8597                                 // The invoked member is not supported in a
8598                                 // dynamic module
8599                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8600                                 Assert.IsNull (ex.InnerException, "#3");
8601                                 Assert.IsNotNull (ex.Message, "#4");
8602                         }
8603                 }
8604
8605                 [Test]
8606                 public void TestGetMembersFlagsComplete ()
8607                 {
8608                         TypeBuilder tb = module.DefineType (genTypeName ());
8609                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8610
8611                         Type emittedType = tb.CreateType ();
8612
8613                         Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8614                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8615                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8616                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8617                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8618                 }
8619
8620                 [Test]
8621                 public void TestGetInterfaceIncomplete ()
8622                 {
8623                         TypeBuilder tb = module.DefineType (genTypeName ());
8624                         try {
8625                                 tb.GetInterface ("FOO", true);
8626                                 Assert.Fail ("#1");
8627                         } catch (NotSupportedException ex) {
8628                                 // The invoked member is not supported in a
8629                                 // dynamic module
8630                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8631                                 Assert.IsNull (ex.InnerException, "#3");
8632                                 Assert.IsNotNull (ex.Message, "#4");
8633                         }
8634                 }
8635
8636                 [Test]
8637                 public void TestGetInterfaces ()
8638                 {
8639                         TypeBuilder tb = module.DefineType (genTypeName ());
8640                         Type [] interfaces = tb.GetInterfaces ();
8641                         Assert.AreEqual (0, interfaces.Length);
8642
8643                         TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8644                         Type emittedInterface = tbInterface.CreateType ();
8645
8646                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8647                         interfaces = tb.GetInterfaces ();
8648                         Assert.AreEqual (1, interfaces.Length);
8649                 }
8650
8651                 [Test]
8652                 public void TestAddDeclarativeSecurityAlreadyCreated ()
8653                 {
8654                         TypeBuilder tb = module.DefineType (genTypeName ());
8655                         tb.CreateType ();
8656
8657                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8658                         try {
8659                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8660                                 Assert.Fail ("#1");
8661                         } catch (InvalidOperationException ex) {
8662                                 // Unable to change after type has been created
8663                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8664                                 Assert.IsNull (ex.InnerException, "#3");
8665                                 Assert.IsNotNull (ex.Message, "#4");
8666                         }
8667                 }
8668
8669                 [Test]
8670                 public void TestAddDeclarativeSecurityNullPermissionSet ()
8671                 {
8672                         TypeBuilder tb = module.DefineType (genTypeName ());
8673                         try {
8674                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8675                                 Assert.Fail ("#1");
8676                         } catch (ArgumentNullException ex) {
8677                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8678                                 Assert.IsNull (ex.InnerException, "#3");
8679                                 Assert.IsNotNull (ex.Message, "#4");
8680                                 Assert.AreEqual ("pset", ex.ParamName, "#5");
8681                         }
8682
8683                 }
8684
8685                 [Test]
8686                 public void TestAddDeclarativeSecurityInvalidAction ()
8687                 {
8688                         TypeBuilder tb = module.DefineType (genTypeName ());
8689
8690                         SecurityAction [] actions = new SecurityAction [] { 
8691                         SecurityAction.RequestMinimum,
8692                         SecurityAction.RequestOptional,
8693                         SecurityAction.RequestRefuse };
8694                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8695
8696                         foreach (SecurityAction action in actions) {
8697                                 try {
8698                                         tb.AddDeclarativeSecurity (action, set);
8699                                         Assert.Fail ();
8700                                 } catch (ArgumentOutOfRangeException) {
8701                                 }
8702                         }
8703                 }
8704
8705                 [Test]
8706                 public void TestAddDeclarativeSecurityDuplicateAction ()
8707                 {
8708                         TypeBuilder tb = module.DefineType (genTypeName ());
8709
8710                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8711                         tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8712                         try {
8713                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8714                                 Assert.Fail ("#1");
8715                         } catch (InvalidOperationException ex) {
8716                                 // Multiple permission sets specified with the
8717                                 // same SecurityAction
8718                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8719                                 Assert.IsNull (ex.InnerException, "#3");
8720                                 Assert.IsNotNull (ex.Message, "#4");
8721                         }
8722                 }
8723
8724                 [Test]
8725                 public void TestEnums ()
8726                 {
8727                         TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8728                         TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8729                                                                                                                  typeof (Enum));
8730                         enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8731                         // add value__ field, see DefineEnum method of ModuleBuilder
8732                         enumToCreate.DefineField ("value__", typeof (Int32),
8733                                 FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8734
8735                         // add enum entries
8736                         FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8737                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8738                         fb.SetConstant ((Int32) 0);
8739
8740                         fb = enumToCreate.DefineField ("B", enumToCreate,
8741                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8742                         fb.SetConstant ((Int32) 1);
8743
8744                         fb = enumToCreate.DefineField ("C", enumToCreate,
8745                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8746                         fb.SetConstant ((Int32) 2);
8747
8748                         Type enumType = enumToCreate.CreateType ();
8749
8750                         object enumVal = Enum.ToObject (enumType, (Int32) 3);
8751
8752                         Assert.AreEqual ("B, C", enumVal.ToString ());
8753                         Assert.AreEqual (3, (Int32) enumVal);
8754                 }
8755
8756                 [Test]
8757                 public void DefineEnum ()
8758                 {
8759                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8760                                                                                                                  TypeAttributes.Public);
8761                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8762                                                                                                                  TypeAttributes.Public, typeof (int));
8763                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8764                         enumBuilder.CreateType ();
8765                         typeBuilder.CreateType ();
8766                 }
8767
8768                 [Test]
8769                 [Category ("NotWorking")]
8770                 public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8771                 {
8772                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8773                                                                                                                  TypeAttributes.Public);
8774                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8775                                                                                                                  TypeAttributes.Public, typeof (int));
8776                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8777                         try {
8778                                 typeBuilder.CreateType ();
8779                                 Assert.Fail ("#1");
8780                         } catch (TypeLoadException) {
8781                                 // Could not load type '...' from assembly
8782                                 // 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8783                         }
8784 #if NET_2_0
8785                         Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8786                         Assert.IsNull (typeBuilder.CreateType (), "#3");
8787 #else
8788                         try {
8789                                 typeBuilder.CreateType ();
8790                         } catch (InvalidOperationException ex) {
8791                                 // Unable to change after type has been created
8792                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
8793                                 Assert.IsNull (ex.InnerException, "#B3");
8794                                 Assert.IsNotNull (ex.Message, "#B4");
8795                         }
8796 #endif
8797                 }
8798
8799                 [Test]
8800                 public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8801                 {
8802                         TypeBuilder tb = module.DefineType (genTypeName ());
8803                         ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8804                                 GetConstructor (Type.EmptyTypes);
8805                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8806                                 attrCtor, new object [0]);
8807                         Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8808                         tb.SetCustomAttribute (caBuilder);
8809                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8810                         Type emittedType = tb.CreateType ();
8811                         Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8812                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8813                         object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8814                         Assert.AreEqual (1, emittedAttrs.Length, "#5");
8815                 }
8816
8817                 private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8818                 {
8819                         // define the field holding the property value
8820                         FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8821                                 typeof (string), FieldAttributes.Private);
8822
8823                         PropertyBuilder propertyBuilder = tb.DefineProperty (
8824                                 propertyName, PropertyAttributes.HasDefault, typeof (string),
8825                                 new Type [] { typeof (string) });
8826
8827                         // First, we'll define the behavior of the "get" property for CustomerName as a method.
8828                         MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8829                                                                         methodAttribs,
8830                                                                         typeof (string),
8831                                                                         new Type [] { });
8832
8833                         ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8834
8835                         getIL.Emit (OpCodes.Ldarg_0);
8836                         getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8837                         getIL.Emit (OpCodes.Ret);
8838
8839                         // Now, we'll define the behavior of the "set" property for CustomerName.
8840                         MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8841                                                                         methodAttribs,
8842                                                                         null,
8843                                                                         new Type [] { typeof (string) });
8844
8845                         ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8846
8847                         setIL.Emit (OpCodes.Ldarg_0);
8848                         setIL.Emit (OpCodes.Ldarg_1);
8849                         setIL.Emit (OpCodes.Stfld, fieldBuilder);
8850                         setIL.Emit (OpCodes.Ret);
8851
8852                         // Last, we must map the two methods created above to our PropertyBuilder to 
8853                         // their corresponding behaviors, "get" and "set" respectively. 
8854                         propertyBuilder.SetGetMethod (getMethodBuilder);
8855                         propertyBuilder.SetSetMethod (setMethodBuilder);
8856                         return propertyBuilder;
8857                 }
8858
8859                 static int handler_called = 0;
8860
8861                 [Test]
8862                 public void TestTypeResolve ()
8863                 {
8864                         string typeName = genTypeName ();
8865
8866                         ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8867                         AppDomain.CurrentDomain.TypeResolve += handler;
8868                         handler_called = 0;
8869                         Type t = Type.GetType (typeName);
8870                         Assert.AreEqual (typeName, t.Name);
8871                         Assert.AreEqual (1, handler_called);
8872                         AppDomain.CurrentDomain.TypeResolve -= handler;
8873                 }
8874
8875                 Assembly TypeResolve (object sender, ResolveEventArgs args)
8876                 {
8877                         TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8878                         tb.CreateType ();
8879                         handler_called++;
8880                         return tb.Assembly;
8881                 }
8882
8883                 [Test]
8884                 public void IsAssignableFrom_Created ()
8885                 {
8886                         TypeBuilder tb = module.DefineType (genTypeName (),
8887                                 TypeAttributes.Public, typeof (MemoryStream),
8888                                 new Type [] { typeof (IThrowable), typeof (Bar) });
8889                         tb.AddInterfaceImplementation (typeof (IDestroyable));
8890                         Type emitted_type = tb.CreateType ();
8891
8892                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8893                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8894                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8895                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8896                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8897                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8898                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8899                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8900                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8901                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8902                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8903                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8904                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8905                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8906                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8907                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8908                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8909                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8910
8911                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8912                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8913                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8914                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8915                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8916                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8917                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8918                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8919                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8920                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8921
8922                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8923                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8924                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8925                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8926                         Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8927
8928                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8929                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8930                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8931                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8932                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8933                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8934                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8935                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8936                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8937                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8938                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8939                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8940                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8941                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8942                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8943                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8944                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8945                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8946
8947                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8948                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8949                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8950                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8951                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8952                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8953                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8954                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8955                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8956                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8957
8958                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8959                                 tb.FullName + "[]")), "#F1");
8960                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8961                                 tb.FullName + "[]")), "#F2");
8962                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8963                                 tb.FullName + "[]")), "#F3");
8964
8965                         TypeBuilder tb2 = module.DefineType (genTypeName (),
8966                                 TypeAttributes.Public, tb,
8967                                 new Type [] { typeof (IAir) });
8968                         Type emitted_type2 = tb2.CreateType ();
8969
8970                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8971                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8972                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8973                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8974                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8975                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8976                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8977                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8978                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8979                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8980                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8981                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8982                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8983                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8984                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8985                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8986                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8987                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8988
8989                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8990                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8991                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8992                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8993                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8994                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8995                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8996                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8997                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8998                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8999
9000                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
9001                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
9002                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
9003                         Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
9004                         Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
9005                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
9006                         Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
9007                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
9008                         Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
9009                         Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
9010                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
9011                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
9012                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
9013                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
9014
9015                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
9016                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
9017                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
9018                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
9019                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
9020                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
9021                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
9022                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
9023                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
9024                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
9025                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
9026                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
9027                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
9028                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
9029                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
9030                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
9031                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
9032                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
9033
9034                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
9035                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9036                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
9037                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
9038                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
9039                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
9040                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
9041                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
9042                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
9043                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
9044
9045                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9046                                 tb2.FullName + "[]")), "#L1");
9047                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9048                                 tb2.FullName + "[]")), "#L2");
9049                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9050                                 tb2.FullName + "[]")), "#L3");
9051
9052                         TypeBuilder tb3 = module.DefineType (genTypeName (),
9053                                 TypeAttributes.Public, tb2,
9054                                 new Type [] { typeof (IWater) });
9055                         Type emitted_type3 = tb3.CreateType ();
9056
9057                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
9058                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
9059                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
9060                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
9061                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
9062                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
9063                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
9064                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
9065                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
9066                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
9067                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
9068                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
9069                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
9070                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
9071                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
9072                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
9073                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
9074                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
9075
9076                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
9077                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
9078                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
9079                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
9080                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
9081                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
9082                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
9083                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
9084                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
9085                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
9086
9087                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
9088                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
9089                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
9090                         Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
9091                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
9092                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
9093                         Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
9094                         Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
9095                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
9096                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
9097                         Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
9098                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
9099                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
9100                         Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
9101                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
9102                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
9103                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
9104                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
9105                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
9106                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
9107                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
9108                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
9109
9110                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
9111                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
9112                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
9113                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
9114                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
9115                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
9116                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
9117                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
9118                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
9119                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
9120                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
9121                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
9122                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
9123                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
9124                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
9125                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
9126                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
9127                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
9128
9129                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
9130                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
9131                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
9132                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
9133                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
9134                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
9135                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
9136                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
9137                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
9138                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
9139
9140                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9141                                 tb3.FullName + "[]")), "#R1");
9142                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9143                                 tb3.FullName + "[]")), "#R2");
9144                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9145                                 tb3.FullName + "[]")), "#R3");
9146
9147 #if NET_2_0
9148                         TypeBuilder tb4 = module.DefineType (genTypeName (),
9149                                 TypeAttributes.Public, null,
9150                                 new Type [] { typeof (IWater) });
9151                         tb4.DefineGenericParameters ("T");
9152
9153                         Type inst = tb4.MakeGenericType (typeof (int));
9154                         Type emitted_type4 = tb4.CreateType ();
9155                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
9156                         // This returns True if CreateType () is called _before_ MakeGenericType...
9157                         //Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
9158 #endif
9159                 }
9160
9161                 [Test]
9162                 public void IsAssignableFrom_NotCreated ()
9163                 {
9164                         TypeBuilder tb = module.DefineType (genTypeName (),
9165                                 TypeAttributes.Public, typeof (MemoryStream),
9166                                 new Type [] {
9167                                         typeof (IThrowable), typeof (Bar),
9168                                         typeof (IComparable)
9169                                         });
9170
9171                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9172                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9173                         //Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
9174                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
9175                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
9176                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
9177                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
9178                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
9179                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
9180                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
9181                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
9182                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
9183
9184                         //Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
9185                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
9186                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
9187                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
9188                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
9189                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
9190
9191                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
9192                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
9193                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
9194                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
9195                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
9196                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
9197                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
9198                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
9199                         Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
9200                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
9201
9202                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
9203                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
9204
9205                         TypeBuilder tb2 = module.DefineType (genTypeName (),
9206                                 TypeAttributes.Public, tb,
9207                                 new Type [] { typeof (IAir) });
9208
9209                         Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
9210                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
9211                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
9212                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
9213                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
9214                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
9215                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
9216                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
9217                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
9218                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
9219                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
9220                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
9221
9222                         Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb2), "#F1");
9223                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
9224                         Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb2), "#F3");
9225                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
9226                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
9227                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9228
9229                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9230                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9231                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9232                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9233                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9234                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9235                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9236                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9237                         Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9238                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9239
9240                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9241                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9242                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9243
9244                         TypeBuilder tb3 = module.DefineType (genTypeName (),
9245                                 TypeAttributes.Public, tb2,
9246                                 new Type [] { typeof (IWater) });
9247
9248                         Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9249                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9250                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9251                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9252                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9253                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9254                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9255                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9256                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9257                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9258                         //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9259                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9260
9261                         Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9262                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9263                         Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9264                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9265                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9266                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9267
9268                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9269                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9270                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9271                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9272                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9273                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9274                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9275                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9276                         Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9277                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9278
9279                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9280                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9281                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9282                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9283                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9284                 }
9285
9286                 [Test]
9287                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9288                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9289                 {
9290                         TypeBuilder tb = module.DefineType (genTypeName (),
9291                                 TypeAttributes.Public, typeof (FormatException),
9292                                 new Type [] { typeof (IThrowable) });
9293                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9294
9295                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9296                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9297
9298                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9299                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9300                 }
9301
9302                 [Test]
9303                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9304                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9305                 {
9306                         TypeBuilder tb = module.DefineType (genTypeName (),
9307                                 TypeAttributes.Public, typeof (FormatException),
9308                                 new Type [] { typeof (IThrowable) });
9309                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9310
9311                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9312                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9313
9314                         Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9315                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9316                 }
9317
9318
9319                 [Test]
9320                 [Category ("NotDotNet")]
9321                 public void IsAssignableFrom_NotCreated_Array ()
9322                 {
9323                         TypeBuilder tb = module.DefineType (genTypeName (),
9324                                 TypeAttributes.Public, typeof (FormatException),
9325                                 new Type [] {
9326                                         typeof (IThrowable), typeof (Bar),
9327                                         typeof (IComparable)
9328                                         });
9329
9330                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9331                                 tb.FullName + "[]")), "#1");
9332                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9333                                 tb.FullName + "[]")), "#2");
9334                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9335                                 tb.FullName + "[]")), "#3");
9336                 }
9337
9338                 [Test]
9339                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9340                 public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9341                 {
9342                         TypeBuilder tb = module.DefineType (genTypeName (),
9343                                 TypeAttributes.Public, typeof (FormatException),
9344                                 new Type [] {
9345                                         typeof (IThrowable), typeof (Bar),
9346                                         typeof (IComparable)
9347                                         });
9348
9349                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9350                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9351                 }
9352
9353                 [Test]
9354                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9355                 public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9356                 {
9357                         TypeBuilder tb = module.DefineType (genTypeName (),
9358                                 TypeAttributes.Public, typeof (FormatException),
9359                                 new Type [] {
9360                                         typeof (IThrowable), typeof (Bar),
9361                                         typeof (IComparable)
9362                                         });
9363
9364                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9365                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9366                 }
9367
9368                 [Test]
9369                 public void CreateType_EmptyMethodBody ()
9370                 {
9371                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9372
9373                         tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9374                         try {
9375                                 tb.CreateType ();
9376                                 Assert.Fail ("#1");
9377                         } catch (InvalidOperationException ex) {
9378                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9379                                 Assert.IsNull (ex.InnerException, "#3");
9380                                 Assert.IsNotNull (ex.Message, "#4");
9381                         }
9382                 }
9383
9384                 [Test]
9385                 public void CreateType_EmptyCtorBody ()
9386                 {
9387                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9388
9389                         tb.DefineConstructor (0, CallingConventions.Standard, null);
9390                         try {
9391                                 tb.CreateType ();
9392                                 Assert.Fail ("#1");
9393                         } catch (InvalidOperationException ex) {
9394                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9395                                 Assert.IsNull (ex.InnerException, "#3");
9396                                 Assert.IsNotNull (ex.Message, "#4");
9397                         }
9398                 }
9399
9400                 [Test]
9401 #if ONLY_1_1
9402                 [Category ("NotDotNet")] // Parent type was not extensible by the given type
9403 #endif
9404                 [Category ("NotWorking")]
9405                 public void CreateType_Interface_ParentInvalid ()
9406                 {
9407                         TypeBuilder tb;
9408
9409                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9410                                 typeof (Exception));
9411                         Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9412                         try {
9413                                 tb.CreateType ();
9414                                 Assert.Fail ("#A2");
9415                         } catch (TypeLoadException ex) {
9416                                 // Could not load interface 't5' from assembly '...'
9417                                 // because it must extend from Object
9418                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9419                                 Assert.IsNull (ex.InnerException, "#A4");
9420                                 Assert.IsNotNull (ex.Message, "#A5");
9421                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9422                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9423                         }
9424
9425                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9426                                 typeof (object));
9427                         Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9428                         try {
9429                                 tb.CreateType ();
9430                                 Assert.Fail ("#B2");
9431                         } catch (TypeLoadException ex) {
9432                                 // Failure has occurred while loading a type
9433                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9434                                 Assert.IsNull (ex.InnerException, "#B4");
9435                                 Assert.IsNotNull (ex.Message, "#B5");
9436                         }
9437
9438                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9439                                 typeof (EmptyInterface));
9440                         Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9441                         try {
9442                                 tb.CreateType ();
9443                                 Assert.Fail ("#C2");
9444                         } catch (TypeLoadException ex) {
9445                                 // Could not load interface 't5' from assembly '...'
9446                                 // because the parent type is an interface
9447                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9448                                 Assert.IsNull (ex.InnerException, "#C4");
9449                                 Assert.IsNotNull (ex.Message, "#C5");
9450                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9451                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9452                         }
9453                 }
9454
9455                 [Test]
9456                 public void CreateType_Parent_DefaultCtorMissing ()
9457                 {
9458                         TypeBuilder tb;
9459
9460                         tb = module.DefineType (genTypeName ());
9461                         ConstructorBuilder cb = tb.DefineConstructor (
9462                                 MethodAttributes.Public,
9463                                 CallingConventions.Standard,
9464                                 new Type [] { typeof (string) });
9465                         cb.GetILGenerator ().Emit (OpCodes.Ret);
9466                         Type parent_type = tb.CreateType ();
9467
9468                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9469                                 parent_type);
9470                         try {
9471                                 tb.CreateType ();
9472                                 Assert.Fail ("#1");
9473                         } catch (NotSupportedException ex) {
9474                                 // Parent does not have a default constructor.
9475                                 // The default constructor must be explicitly defined
9476                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9477                                 Assert.IsNull (ex.InnerException, "#3");
9478                                 Assert.IsNotNull (ex.Message, "#4");
9479                         }
9480                 }
9481
9482                 [Test]
9483                 public void CreateType_Parent_Null ()
9484                 {
9485                         TypeBuilder tb;
9486                         Type emitted_type;
9487                         
9488                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9489                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9490                         emitted_type = tb.CreateType ();
9491                         Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9492
9493                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9494                         Assert.IsNull (tb.BaseType, "#B1");
9495                         emitted_type = tb.CreateType ();
9496                         Assert.IsNull (emitted_type.BaseType, "#B2");
9497                 }
9498
9499 #if NET_2_0
9500                 [Test]
9501                 [Category ("NotWorking")]
9502                 public void DefineGenericParameters_AlreadyDefined ()
9503                 {
9504                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9505                         tb.DefineGenericParameters ("K");
9506                         try {
9507                                 tb.DefineGenericParameters ("V");
9508                                 Assert.Fail ("#1");
9509                         } catch (InvalidOperationException ex) {
9510                                 // Operation is not valid due to the current
9511                                 // state of the object
9512                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9513                                 Assert.IsNull (ex.InnerException, "#3");
9514                                 Assert.IsNotNull (ex.Message, "#4");
9515                         }
9516                 }
9517
9518                 [Test]
9519                 public void DefineGenericParameters_Names_Empty ()
9520                 {
9521                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9522
9523                         try {
9524                                 tb.DefineGenericParameters (new string [0]);
9525                                 Assert.Fail ("#1");
9526                         } catch (ArgumentException ex) {
9527                                 // Value does not fall within the expected range
9528                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9529                                 Assert.IsNull (ex.InnerException, "#3");
9530                                 Assert.IsNotNull (ex.Message, "#4");
9531                                 Assert.IsNull (ex.ParamName, "#5");
9532                         }
9533                 }
9534
9535                 [Test]
9536                 public void DefineGenericParameters_Names_Null ()
9537                 {
9538                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9539
9540                         try {
9541                                 tb.DefineGenericParameters ((string []) null);
9542                                 Assert.Fail ("#A1");
9543                         } catch (ArgumentNullException ex) {
9544                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9545                                 Assert.IsNull (ex.InnerException, "#A3");
9546                                 Assert.IsNotNull (ex.Message, "#A4");
9547                                 Assert.AreEqual ("names", ex.ParamName, "#A5");
9548                         }
9549
9550                         try {
9551                                 tb.DefineGenericParameters ("K", null, "V");
9552                                 Assert.Fail ("#B1");
9553                         } catch (ArgumentNullException ex) {
9554                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9555                                 Assert.IsNull (ex.InnerException, "#B3");
9556                                 Assert.IsNotNull (ex.Message, "#B4");
9557                                 Assert.AreEqual ("names", ex.ParamName, "#B5");
9558                         }
9559                 }
9560
9561                 [Test]
9562                 public void GenericType ()
9563                 {
9564                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9565                         tb.DefineGenericParameters ("T");
9566
9567                         Assert.IsTrue (tb.IsGenericType, "#A1");
9568                         Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9569                         Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9570                         Assert.IsFalse (tb.IsGenericParameter, "#A4");
9571
9572                         Type[] args = tb.GetGenericArguments ();
9573                         Assert.IsFalse (args [0].IsGenericType, "#B1");
9574                         Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9575                         Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9576                         Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9577                 }
9578
9579                 [Test]
9580                 public void MakeGenericType ()
9581                 {
9582                         TypeBuilder tb;
9583                         Type generic_type;
9584                 
9585                         tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9586                         tb.DefineGenericParameters ("T");
9587
9588                         generic_type = tb.MakeGenericType (typeof (int));
9589                         Assert.IsTrue (generic_type.IsGenericType, "#A1");
9590                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9591                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9592                         Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9593
9594                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9595                         Assert.IsTrue (generic_type.IsGenericType, "#B1");
9596                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9597                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9598                         Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9599
9600                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9601                                 | TypeAttributes.Abstract | TypeAttributes.Public);
9602                         tb.DefineGenericParameters ("T");
9603
9604                         generic_type = tb.MakeGenericType (typeof (int));
9605                         Assert.IsTrue (generic_type.IsGenericType, "#C1");
9606                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9607                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9608                         Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9609
9610                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9611                         Assert.IsTrue (generic_type.IsGenericType, "#D1");
9612                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9613                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9614                         Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9615                 }
9616
9617                 [Test]
9618                 public void MakeGenericType_NoGenericTypeDefinition ()
9619                 {
9620                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9621                         try {
9622                                 tb.MakeGenericType (typeof (int));
9623                                 Assert.Fail ("#1");
9624                         } catch (InvalidOperationException ex) {
9625                                 // Operation is not valid due to the current
9626                                 // state of the object
9627                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9628                                 Assert.IsNull (ex.InnerException, "#3");
9629                                 Assert.IsNotNull (ex.Message, "#4");
9630                         }
9631                 }
9632
9633                 [Test]
9634                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9635                 public void MakeGenericType_TypeArguments_Null_Mono ()
9636                 {
9637                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9638                         tb.DefineGenericParameters ("K", "V");
9639
9640                         try {
9641                                 tb.MakeGenericType ((Type []) null);
9642                                 Assert.Fail ("#A1");
9643                         } catch (ArgumentNullException ex) {
9644                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9645                                 Assert.IsNull (ex.InnerException, "#A3");
9646                                 Assert.IsNotNull (ex.Message, "#A4");
9647                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9648                         }
9649
9650                         try {
9651                                 tb.MakeGenericType (typeof (string), (Type) null);
9652                                 Assert.Fail ("#B1");
9653                         } catch (ArgumentNullException ex) {
9654                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9655                                 Assert.IsNull (ex.InnerException, "#B3");
9656                                 Assert.IsNotNull (ex.Message, "#B4");
9657                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9658                         }
9659                 }
9660
9661                 [Test]
9662                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9663                 public void MakeGenericType_TypeArguments_Null_MS ()
9664                 {
9665                         Type generic_type;
9666                         Type [] type_args;
9667
9668                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9669                         tb.DefineGenericParameters ("K", "V");
9670
9671                         generic_type = tb.MakeGenericType ((Type []) null);
9672                         Assert.IsNotNull (generic_type, "#A1");
9673                         Assert.IsTrue (generic_type.IsGenericType, "#A2");
9674                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9675                         type_args = generic_type.GetGenericArguments ();
9676                         Assert.IsNull (type_args, "#A4");
9677
9678                         generic_type  = tb.MakeGenericType (typeof (string), (Type) null);
9679                         Assert.IsNotNull (generic_type, "#B1");
9680                         Assert.IsTrue (generic_type.IsGenericType, "#B2");
9681                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9682                         type_args = generic_type.GetGenericArguments ();
9683                         Assert.IsNotNull (type_args, "#B4");
9684                         Assert.AreEqual (2, type_args.Length, "#B5");
9685                         Assert.AreEqual (typeof (string), type_args [0], "#B6");
9686                         Assert.IsNull (type_args [1], "#B7");
9687                 }
9688
9689                 [Test]
9690                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9691                 public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9692                 {
9693                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9694                         tb.DefineGenericParameters ("K", "V");
9695                         try {
9696                                 tb.MakeGenericType (typeof (int));
9697                                 Assert.Fail ("#1");
9698                         } catch (ArgumentException ex) {
9699                                 // The type or method has 2 generic prarameter(s)
9700                                 // but 1 generic argument(s) were provided. A
9701                                 // generic argument must be provided for each
9702                                 // generic parameter
9703                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9704                                 Assert.IsNull (ex.InnerException, "#3");
9705                                 Assert.IsNotNull (ex.Message, "#4");
9706                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9707                         }
9708                 }
9709
9710                 [Test]
9711                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9712                 public void MakeGenericType_TypeArguments_Mismatch_MS ()
9713                 {
9714                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9715                         tb.DefineGenericParameters ("K", "V");
9716                         
9717                         Type generic_type = tb.MakeGenericType (typeof (int));
9718                         Assert.IsTrue (generic_type.IsGenericType, "#1");
9719                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9720                         Type [] type_args = generic_type.GetGenericArguments ();
9721                         Assert.IsNotNull (type_args, "#3");
9722                         Assert.AreEqual (1, type_args.Length, "#4");
9723                         Assert.AreEqual (typeof (int), type_args [0], "#5");
9724                 }
9725
9726                 [Test]
9727                 public void MakeArrayType_Complete ()
9728                 {
9729                         // reference type
9730                         TypeBuilder tb = module.DefineType (genTypeName (),
9731                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9732                                 typeof (ContextBoundObject));
9733                         Type emittedType = tb.CreateType ();
9734                         Type arrayType = tb.MakeArrayType ();
9735                         Assert.IsTrue (arrayType.IsArray, "#A1");
9736                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9737                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9738                         Assert.IsFalse (tb.HasElementType, "#A4");
9739                         Assert.IsTrue (tb.IsCreated (), "#A5");
9740
9741                         // value type
9742                         tb = module.DefineType (genTypeName (),
9743                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9744                                 typeof (ValueType));
9745                         emittedType = tb.CreateType ();
9746                         arrayType = tb.MakeArrayType ();
9747                         Assert.IsTrue (arrayType.IsArray, "#B1");
9748                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9749                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9750                         Assert.IsFalse (tb.HasElementType, "#B4");
9751                         Assert.IsTrue (tb.IsCreated (), "#B5");
9752
9753                         tb = module.DefineType (genTypeName (),
9754                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9755                                 typeof (Enum));
9756                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9757                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
9758                         emittedType = tb.CreateType ();
9759                         arrayType = tb.MakeArrayType ();
9760                         Assert.IsTrue (arrayType.IsArray, "#C1");
9761                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9762                         Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9763                         Assert.IsFalse (tb.HasElementType, "#C4");
9764                         Assert.IsTrue (tb.IsCreated (), "#C5");
9765                 }
9766
9767                 [Test] // bug #82015
9768                 public void MakeArrayType_Incomplete ()
9769                 {
9770                         // reference type
9771                         TypeBuilder tb = module.DefineType (genTypeName (),
9772                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9773                                 typeof (ContextBoundObject));
9774                         Type arrayType = tb.MakeArrayType ();
9775                         Assert.IsTrue (arrayType.IsArray, "#A1");
9776                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9777                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9778                         Assert.IsFalse (tb.HasElementType, "#A4");
9779                         Assert.IsFalse (tb.IsCreated (), "#A5");
9780
9781                         // value type
9782                         tb = module.DefineType (genTypeName (),
9783                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9784                                 typeof (ValueType));
9785                         arrayType = tb.MakeArrayType ();
9786                         Assert.IsTrue (arrayType.IsArray, "#B1");
9787                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9788                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9789                         Assert.IsFalse (tb.HasElementType, "#B4");
9790                         Assert.IsFalse (tb.IsCreated (), "#B5");
9791
9792                         // enum
9793                         tb = module.DefineType (genTypeName (),
9794                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9795                                 typeof (Enum));
9796                         arrayType = tb.MakeArrayType ();
9797                         Assert.IsTrue (arrayType.IsArray, "#C1");
9798                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9799                         Assert.IsFalse (tb.HasElementType, "#C3");
9800                         Assert.IsFalse (tb.IsCreated (), "#C4");
9801                 }
9802
9803                 [Test]
9804                 public void GetCustomAttributes_InflatedType ()
9805                 {
9806                         TypeBuilder tb = module.DefineType (genTypeName ());
9807                         tb.DefineGenericParameters (new string[] { "FOO" });
9808
9809                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9810                                 new Type [] { typeof (string) });
9811
9812                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9813                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9814
9815                         tb.SetCustomAttribute (caBuilder);
9816                         Type t = tb.CreateType ();
9817
9818                         Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9819
9820                         Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9821                 }
9822
9823                 [Test]
9824                 public void GetField ()
9825                 {
9826                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9827                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9828
9829                         ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9830
9831                         FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9832
9833                         Type t = tb.MakeGenericType (typeof (int));
9834
9835                         // Chect that calling MakeArrayType () does not initialize the class
9836                         // (bug #351172)
9837                         t.MakeArrayType ();
9838
9839                         // Check that the instantiation of a type builder contains live data
9840                         TypeBuilder.GetField (t, fb1);
9841                         FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9842                         FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9843
9844                         MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9845                         ILGenerator ilgen = mb.GetILGenerator ();
9846                         ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9847                         ilgen.Emit (OpCodes.Dup);
9848                         ilgen.Emit (OpCodes.Ldc_I4, 42);
9849                         ilgen.Emit (OpCodes.Stfld, fi2);
9850                         ilgen.Emit (OpCodes.Ldfld, fi2);
9851                         ilgen.Emit (OpCodes.Ret);
9852
9853                         // Check GetField on a type instantiated with type parameters
9854                         Type t3 = tb.MakeGenericType (typeParams [0]);
9855                         FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9856                         FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9857
9858                         MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9859                         ILGenerator ilgen3 = mb3.GetILGenerator ();
9860                         ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9861                         ilgen3.Emit (OpCodes.Ldfld, fi3);
9862                         ilgen3.Emit (OpCodes.Ret);
9863
9864                         Type created = tb.CreateType ();
9865
9866                         Type inst = created.MakeGenericType (typeof (object));
9867
9868                         Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9869
9870                         Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9871                 }
9872                 
9873                 [Test] //bug #354047
9874                 public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9875                 {
9876                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9877                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9878                         Type t = tb.CreateType ();
9879
9880                         Type inst = tb.MakeGenericType (typeParams [0]);
9881                         Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9882                 }
9883
9884                 [Test] //bug #354047
9885                 public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9886                 {
9887                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9888                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9889                         Type t = tb.CreateType ();
9890
9891                         Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9892                         Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9893                 }
9894
9895                 [Test] //bug #354047
9896                 public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9897                 {
9898                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9899                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9900                         Type t = tb.CreateType ();
9901
9902                         Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9903                 }
9904
9905                 [Test] //bug #399047
9906                 public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9907                                 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9908
9909                                 module = assembly.DefineDynamicModule ("Instance.exe");
9910   
9911                 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9912                 Type T = G.DefineGenericParameters ("T") [0];
9913                                 ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9914                 Type GObj = G.MakeGenericType (new Type [] { T });
9915
9916                 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9917
9918                 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9919
9920                 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9921                 Type TATest = Test.DefineGenericParameters ("TA") [0];
9922                 {
9923                         Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9924
9925                         ILGenerator il = Test.GetILGenerator ();
9926
9927                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9928                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9929                         il.Emit (OpCodes.Pop);
9930
9931                         il.Emit (OpCodes.Ret);
9932                 }
9933
9934                                 MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9935                                 {
9936                                         ILGenerator il = main.GetILGenerator ();
9937                                         il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9938                                         il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9939                                         il.Emit (OpCodes.Ret);
9940                                 }
9941
9942                                 assembly.SetEntryPoint (main);
9943                 G.CreateType ();
9944                 P.CreateType ();
9945
9946                 assembly.Save ("Instance.exe");
9947                                 Thread.GetDomain ().ExecuteAssembly(Path.GetTempPath () + Path.DirectorySeparatorChar + "Instance.exe");
9948                 }
9949
9950                 [Test]
9951                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9952                 {
9953                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9954                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9955                         tb.CreateType ();
9956
9957                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9958                         module = assembly.DefineDynamicModule ("Instance.exe");
9959
9960                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9961                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9962                         ILGenerator il = mb.GetILGenerator ();
9963
9964                         il.Emit (OpCodes.Ldc_I4_1);
9965                         il.Emit (OpCodes.Newarr, typeof (int));
9966                         il.Emit (OpCodes.Dup);
9967                         il.Emit (OpCodes.Ldtoken, fb);
9968                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9969                         il.Emit (OpCodes.Ret);
9970
9971                         Type t = tb2.CreateType ();
9972                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9973                         //Console.WriteLine (res[0]);
9974                 }
9975 #endif
9976
9977                 public interface IDelegateFactory
9978                 {
9979                         Delegate Create (Delegate del);
9980                 }
9981
9982                 [Test]
9983                 public void CreateType_Ctor_NoBody ()
9984                 {
9985                         TypeBuilder tb = module.DefineType (genTypeName ());
9986                         tb.DefineConstructor (MethodAttributes.Public,
9987                                 CallingConventions.Standard,
9988                                 new Type [] { typeof (string) });
9989                         try {
9990                                 tb.CreateType ();
9991                                 Assert.Fail ("#1");
9992                         } catch (InvalidOperationException ex) {
9993                                 // Method '.ctor' does not have a method body
9994                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9995                                 Assert.IsNull (ex.InnerException, "#3");
9996                                 Assert.IsNotNull (ex.Message, "#4");
9997                                 Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9998                         }
9999                 }
10000
10001                 [Test] //bug #361689
10002                 public void CreateTypeFailsWithInvalidMethodOverride ()
10003                 {
10004                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
10005
10006                         MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
10007                         ILGenerator gen = mc.GetILGenerator ();
10008                         gen.Emit (OpCodes.Ldarg_0);
10009                         gen.Emit (OpCodes.Ret);
10010                         tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
10011                         try {
10012                                 tb.CreateType ();
10013                                 Assert.Fail ("#1 create type did not throw TypeLoadException");
10014                         } catch (TypeLoadException) {
10015                         
10016                         }
10017                 }
10018
10019                 [Test] //bug #349194
10020                 public void IsAssignableToWorksWithInterfacesOnParent ()
10021                 {
10022             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
10023                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
10024
10025                         Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb));
10026                         Type t = tb.CreateType ();
10027                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
10028                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
10029                         
10030                         
10031                         Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb2));
10032                         Type t2 = tb2.CreateType ();
10033                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
10034                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
10035                 }
10036
10037 #if NET_2_0
10038
10039                 [Test] //bug #430508
10040                 public void MakeGenericTypeRespectBaseType ()
10041                 {
10042             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
10043                         EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
10044
10045                         MethodBuilder mb = tb.DefineMethod ("Test",
10046                                                                                                 MethodAttributes.Public,
10047                                                                                                 typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
10048                                                                                                 new Type [0]);
10049                         ILGenerator il = mb.GetILGenerator();
10050                         il.Emit (OpCodes.Ldnull);
10051                         il.Emit (OpCodes.Ret);
10052         
10053                         Type e = eb.CreateType ();
10054                         Type c = tb.CreateType ();
10055                 
10056                         Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
10057                 }
10058
10059                 [Test]
10060                 public void GetCustomAttrOnFieldOfInflatedType ()
10061                 {
10062                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
10063                         tb.DefineGenericParameters ("T");
10064
10065                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10066                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
10067                                 new object [0]);
10068
10069                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
10070                         field.SetCustomAttribute (caBuilder);
10071
10072                         Type t = tb.CreateType ();
10073
10074                         FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10075                         object[] cattrs = fi.GetCustomAttributes (false);
10076                         Assert.AreEqual (1, cattrs.Length);
10077
10078                         fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10079                         cattrs = fi.GetCustomAttributes (false);
10080                         Assert.AreEqual (1, cattrs.Length);
10081                 }
10082
10083                 [Test]
10084                 public void GetCustomAttrOnPropertyOfInflatedType ()
10085                 {
10086                         TypeBuilder tb = module.DefineType (genTypeName ());
10087                         tb.DefineGenericParameters ("T");
10088
10089                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10090                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
10091                                 new object [0]);
10092
10093                         PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
10094                         property.SetCustomAttribute (caBuilder);
10095
10096                         Type t = tb.CreateType ();
10097
10098                         PropertyInfo pi = t.GetProperties ()[0];
10099                         object[] cattrs = pi.GetCustomAttributes (false);
10100                         Assert.AreEqual (1, cattrs.Length);
10101
10102                         pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
10103                         cattrs = pi.GetCustomAttributes (false);
10104                         Assert.AreEqual (1, cattrs.Length);
10105                 }
10106
10107                 [Test]
10108                 public void GetCustomAttrOnEventOfInflatedType ()
10109                 {
10110                         TypeBuilder tb = module.DefineType (genTypeName ());
10111                         tb.DefineGenericParameters ("T");
10112
10113                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10114                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
10115                                 new object [0]);
10116
10117                         EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
10118                         evt.SetCustomAttribute (caBuilder);
10119
10120                         Type t = tb.CreateType ();
10121
10122                         EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10123                         object[] cattrs = ei.GetCustomAttributes (false);
10124                         Assert.AreEqual (1, cattrs.Length);
10125
10126                         ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10127                         cattrs = ei.GetCustomAttributes (false);
10128                         Assert.AreEqual (1, cattrs.Length);
10129                 }
10130
10131                 public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
10132                 {
10133                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
10134                         tb.DefineGenericParameters ("T");
10135  
10136                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10137                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
10138                                 new object [0]);
10139
10140                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
10141                         field.SetCustomAttribute (caBuilder);
10142
10143
10144                         tb.MakeGenericType (typeof (int)).GetMethods ();
10145                         tb.MakeGenericType (typeof (double)).GetMethods ();
10146                         
10147                         Type t = tb.CreateType ();
10148                         
10149                         t.MakeGenericType (typeof (int)).GetMethods ();
10150                         t.MakeGenericType (typeof (double)).GetMethods ();
10151                 }
10152
10153                 [Test]
10154                 public void TestGenericFieldAccess () // bug #467415
10155                 {
10156                         AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
10157                         AppDomain domain = AppDomain.CurrentDomain;
10158                         AssemblyBuilder demoAssembly =
10159                                 domain.DefineDynamicAssembly(asmName,
10160                                                 AssemblyBuilderAccess.RunAndSave);
10161
10162                         // Define the module that contains the code. For an
10163                         // assembly with one module, the module name is the
10164                         // assembly name plus a file extension.
10165                         ModuleBuilder demoModule =
10166                                 demoAssembly.DefineDynamicModule(asmName.Name,
10167                                                 asmName.Name+".dll");
10168
10169                         TypeBuilder demoType =
10170                                 demoModule.DefineType("DemoType", TypeAttributes.Public);
10171
10172                         MethodBuilder factory =
10173                                 demoType.DefineMethod("Factory",
10174                                                 MethodAttributes.Public | MethodAttributes.Static);
10175
10176                         string[] typeParameterNames = {"T"};
10177                         GenericTypeParameterBuilder[] typeParameters =
10178                                 factory.DefineGenericParameters(typeParameterNames);
10179
10180                         GenericTypeParameterBuilder T = typeParameters[0];
10181
10182                         Type[] parms = {};
10183                         factory.SetParameters(parms);
10184
10185                         factory.SetReturnType(T);
10186
10187                         ILGenerator ilgen = factory.GetILGenerator();
10188
10189                         Type G = typeof(Gen<>);
10190                         Type GT = G.MakeGenericType (T);
10191                         FieldInfo GF = G.GetField("field");
10192                         FieldInfo GTF = TypeBuilder.GetField(GT, GF);
10193
10194                         ilgen.Emit(OpCodes.Ldsfld, GTF);
10195                         ilgen.Emit(OpCodes.Ret);
10196
10197                         // Complete the type.
10198                         Type dt = demoType.CreateType();
10199                         // Save the assembly, so it can be examined with Ildasm.exe.
10200                         //demoAssembly.Save(asmName.Name+".dll");
10201
10202                         MethodInfo m = dt.GetMethod("Factory");
10203                         MethodInfo bound = m.MakeGenericMethod(typeof(int));
10204
10205                         // Display a string representing the bound method.
10206                         //Console.WriteLine(bound);
10207
10208                         object[] parameters = {};
10209                         int result = (int)(bound.Invoke(null, parameters));
10210
10211                         Assert.AreEqual (0, result, "#1");
10212                 }
10213 #endif
10214
10215                 static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
10216                 {
10217                         foreach (MethodInfo mi in methods)
10218                                 if (mi.Name == name)
10219                                         return mi;
10220                         return null;
10221                 }
10222
10223                 void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
10224                 {
10225                         ConstructorBuilder cb;
10226                         MethodBuilder mb;
10227                         PropertyBuilder pb;
10228                         EventBuilder eb;
10229                         ILGenerator ilgen;
10230
10231                         if (defineCtors) {
10232                                 //
10233                                 // instance constructors
10234                                 //
10235                                 cb = tb.DefineConstructor (MethodAttributes.Private,
10236                                         CallingConventions.Standard,
10237                                         new Type [] { typeof (int), typeof (int) });
10238                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10239
10240                                 cb = tb.DefineConstructor (MethodAttributes.Family,
10241                                         CallingConventions.Standard,
10242                                         new Type [] { typeof (string) });
10243                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10244
10245                                 cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10246                                         CallingConventions.Standard,
10247                                         new Type [] { typeof (string), typeof (string) });
10248                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10249
10250                                 cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10251                                         CallingConventions.Standard,
10252                                         new Type [] { typeof (int) });
10253                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10254
10255                                 cb = tb.DefineConstructor (MethodAttributes.Public,
10256                                         CallingConventions.Standard,
10257                                         new Type [] { typeof (int), typeof (bool) });
10258                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10259
10260                                 cb = tb.DefineConstructor (MethodAttributes.Assembly,
10261                                         CallingConventions.Standard,
10262                                         new Type [] { typeof (string), typeof (int) });
10263                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10264
10265                                 //
10266                                 // static constructors
10267                                 //
10268
10269                                 cb = tb.DefineConstructor (MethodAttributes.Private |
10270                                         MethodAttributes.Static,
10271                                         CallingConventions.Standard,
10272                                         Type.EmptyTypes);
10273                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10274                         }
10275
10276                         //
10277                         // instance methods
10278                         //
10279
10280                         mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10281                                 MethodAttributes.Private, typeof (void),
10282                                 Type.EmptyTypes);
10283                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10284
10285                         mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10286                                 MethodAttributes.Family, typeof (void),
10287                                 Type.EmptyTypes);
10288                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10289
10290                         mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10291                                 MethodAttributes.FamANDAssem, typeof (void),
10292                                 Type.EmptyTypes);
10293                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10294
10295                         mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10296                                 MethodAttributes.FamORAssem, typeof (void),
10297                                 Type.EmptyTypes);
10298                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10299
10300                         mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10301                                 MethodAttributes.Public, typeof (void),
10302                                 Type.EmptyTypes);
10303                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10304
10305                         mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10306                                 MethodAttributes.Assembly, typeof (void),
10307                                 Type.EmptyTypes);
10308                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10309
10310                         //
10311                         // static methods
10312                         //
10313
10314                         mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10315                                 MethodAttributes.Private | MethodAttributes.Static,
10316                                 typeof (void), Type.EmptyTypes);
10317                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10318
10319                         mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10320                                 MethodAttributes.Family | MethodAttributes.Static,
10321                                 typeof (void), Type.EmptyTypes);
10322                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10323
10324                         mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10325                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10326                                 typeof (void), Type.EmptyTypes);
10327                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10328
10329                         mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10330                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10331                                 typeof (void), Type.EmptyTypes);
10332                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10333
10334                         mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10335                                 MethodAttributes.Public | MethodAttributes.Static,
10336                                 typeof (void), Type.EmptyTypes);
10337                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10338
10339                         mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10340                                 MethodAttributes.Assembly | MethodAttributes.Static,
10341                                 typeof (void), Type.EmptyTypes);
10342                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10343
10344                         //
10345                         // instance fields
10346                         //
10347
10348                         tb.DefineField ("privateInstance" + suffix,
10349                                 typeof (string), FieldAttributes.Private);
10350                         tb.DefineField ("familyInstance" + suffix,
10351                                 typeof (string), FieldAttributes.Family);
10352                         tb.DefineField ("famANDAssemInstance" + suffix,
10353                                 typeof (string), FieldAttributes.FamANDAssem);
10354                         tb.DefineField ("famORAssemInstance" + suffix,
10355                                 typeof (string), FieldAttributes.FamORAssem);
10356                         tb.DefineField ("publicInstance" + suffix,
10357                                 typeof (string), FieldAttributes.Public);
10358                         tb.DefineField ("assemblyInstance" + suffix,
10359                                 typeof (string), FieldAttributes.Assembly);
10360
10361                         //
10362                         // static fields
10363                         //
10364
10365                         tb.DefineField ("privateStatic" + suffix,
10366                                 typeof (string), FieldAttributes.Private |
10367                                 FieldAttributes.Static);
10368                         tb.DefineField ("familyStatic" + suffix,
10369                                 typeof (string), FieldAttributes.Family |
10370                                 FieldAttributes.Static);
10371                         tb.DefineField ("famANDAssemStatic" + suffix,
10372                                 typeof (string), FieldAttributes.FamANDAssem |
10373                                 FieldAttributes.Static);
10374                         tb.DefineField ("famORAssemStatic" + suffix,
10375                                 typeof (string), FieldAttributes.FamORAssem |
10376                                 FieldAttributes.Static);
10377                         tb.DefineField ("publicStatic" + suffix,
10378                                 typeof (string), FieldAttributes.Public |
10379                                 FieldAttributes.Static);
10380                         tb.DefineField ("assemblyStatic" + suffix,
10381                                 typeof (string), FieldAttributes.Assembly |
10382                                 FieldAttributes.Static);
10383
10384                         //
10385                         // instance properties
10386                         //
10387
10388                         pb = tb.DefineProperty ("PrivateInstance" + suffix,
10389                                 PropertyAttributes.None, typeof (string),
10390                                 Type.EmptyTypes);
10391                         mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10392                                 MethodAttributes.Private, typeof (string),
10393                                 Type.EmptyTypes);
10394                         ilgen = mb.GetILGenerator ();
10395                         ilgen.Emit (OpCodes.Ldnull);
10396                         ilgen.Emit (OpCodes.Ret);
10397                         pb.SetGetMethod (mb);
10398
10399                         pb = tb.DefineProperty ("FamilyInstance" + suffix,
10400                                 PropertyAttributes.None, typeof (string),
10401                                 Type.EmptyTypes);
10402                         mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10403                                 MethodAttributes.Family, typeof (string),
10404                                 Type.EmptyTypes);
10405                         ilgen = mb.GetILGenerator ();
10406                         ilgen.Emit (OpCodes.Ldnull);
10407                         ilgen.Emit (OpCodes.Ret);
10408                         pb.SetGetMethod (mb);
10409
10410                         pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10411                                 PropertyAttributes.None, typeof (string),
10412                                 Type.EmptyTypes);
10413                         mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10414                                 MethodAttributes.FamANDAssem, typeof (string),
10415                                 Type.EmptyTypes);
10416                         ilgen = mb.GetILGenerator ();
10417                         ilgen.Emit (OpCodes.Ldnull);
10418                         ilgen.Emit (OpCodes.Ret);
10419                         pb.SetGetMethod (mb);
10420
10421                         pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10422                                 PropertyAttributes.None, typeof (string),
10423                                 Type.EmptyTypes);
10424                         mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10425                                 MethodAttributes.FamORAssem, typeof (string),
10426                                 Type.EmptyTypes);
10427                         ilgen = mb.GetILGenerator ();
10428                         ilgen.Emit (OpCodes.Ldnull);
10429                         ilgen.Emit (OpCodes.Ret);
10430                         pb.SetGetMethod (mb);
10431
10432                         pb = tb.DefineProperty ("PublicInstance" + suffix,
10433                                 PropertyAttributes.None, typeof (string),
10434                                 Type.EmptyTypes);
10435                         mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10436                                 MethodAttributes.Public, typeof (string),
10437                                 Type.EmptyTypes);
10438                         ilgen = mb.GetILGenerator ();
10439                         ilgen.Emit (OpCodes.Ldnull);
10440                         ilgen.Emit (OpCodes.Ret);
10441                         pb.SetGetMethod (mb);
10442
10443                         pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10444                                 PropertyAttributes.None, typeof (string),
10445                                 Type.EmptyTypes);
10446                         mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10447                                 MethodAttributes.Assembly, typeof (string),
10448                                 Type.EmptyTypes);
10449                         ilgen = mb.GetILGenerator ();
10450                         ilgen.Emit (OpCodes.Ldnull);
10451                         ilgen.Emit (OpCodes.Ret);
10452                         pb.SetGetMethod (mb);
10453
10454                         //
10455                         // static properties
10456                         //
10457
10458                         pb = tb.DefineProperty ("PrivateStatic" + suffix,
10459                                 PropertyAttributes.None, typeof (string),
10460                                 Type.EmptyTypes);
10461                         mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10462                                 MethodAttributes.Private | MethodAttributes.Static,
10463                                 typeof (string), Type.EmptyTypes);
10464                         ilgen = mb.GetILGenerator ();
10465                         ilgen.Emit (OpCodes.Ldnull);
10466                         ilgen.Emit (OpCodes.Ret);
10467                         pb.SetGetMethod (mb);
10468
10469                         pb = tb.DefineProperty ("FamilyStatic" + suffix,
10470                                 PropertyAttributes.None, typeof (string),
10471                                 Type.EmptyTypes);
10472                         mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10473                                 MethodAttributes.Family | MethodAttributes.Static,
10474                                 typeof (string), Type.EmptyTypes);
10475                         ilgen = mb.GetILGenerator ();
10476                         ilgen.Emit (OpCodes.Ldnull);
10477                         ilgen.Emit (OpCodes.Ret);
10478                         pb.SetGetMethod (mb);
10479
10480                         pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10481                                 PropertyAttributes.None, typeof (string),
10482                                 Type.EmptyTypes);
10483                         mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10484                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10485                                 typeof (string), Type.EmptyTypes);
10486                         ilgen = mb.GetILGenerator ();
10487                         ilgen.Emit (OpCodes.Ldnull);
10488                         ilgen.Emit (OpCodes.Ret);
10489                         pb.SetGetMethod (mb);
10490
10491                         pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10492                                 PropertyAttributes.None, typeof (string),
10493                                 Type.EmptyTypes);
10494                         mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10495                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10496                                 typeof (string), Type.EmptyTypes);
10497                         ilgen = mb.GetILGenerator ();
10498                         ilgen.Emit (OpCodes.Ldnull);
10499                         ilgen.Emit (OpCodes.Ret);
10500                         pb.SetGetMethod (mb);
10501
10502                         pb = tb.DefineProperty ("PublicStatic" + suffix,
10503                                 PropertyAttributes.None, typeof (string),
10504                                 Type.EmptyTypes);
10505                         mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10506                                 MethodAttributes.Public | MethodAttributes.Static,
10507                                 typeof (string), Type.EmptyTypes);
10508                         ilgen = mb.GetILGenerator ();
10509                         ilgen.Emit (OpCodes.Ldnull);
10510                         ilgen.Emit (OpCodes.Ret);
10511                         pb.SetGetMethod (mb);
10512
10513                         pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10514                                 PropertyAttributes.None, typeof (string),
10515                                 Type.EmptyTypes);
10516                         mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10517                                 MethodAttributes.Assembly | MethodAttributes.Static,
10518                                 typeof (string), Type.EmptyTypes);
10519                         ilgen = mb.GetILGenerator ();
10520                         ilgen.Emit (OpCodes.Ldnull);
10521                         ilgen.Emit (OpCodes.Ret);
10522                         pb.SetGetMethod (mb);
10523
10524                         //
10525                         // instance events
10526                         //
10527
10528                         eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10529                                 EventAttributes.None, typeof (EventHandler));
10530                         mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10531                                 MethodAttributes.Private, typeof (void),
10532                                 Type.EmptyTypes);
10533                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10534                         eb.SetAddOnMethod (mb);
10535
10536                         eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10537                                 EventAttributes.None, typeof (EventHandler));
10538                         mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10539                                 MethodAttributes.Family, typeof (void),
10540                                 Type.EmptyTypes);
10541                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10542                         eb.SetAddOnMethod (mb);
10543
10544                         eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10545                                 EventAttributes.None, typeof (EventHandler));
10546                         mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10547                                 MethodAttributes.FamANDAssem, typeof (void),
10548                                 Type.EmptyTypes);
10549                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10550                         eb.SetAddOnMethod (mb);
10551
10552                         eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10553                                 EventAttributes.None, typeof (EventHandler));
10554                         mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10555                                 MethodAttributes.FamORAssem, typeof (void),
10556                                 Type.EmptyTypes);
10557                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10558                         eb.SetAddOnMethod (mb);
10559
10560                         eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10561                                 EventAttributes.None, typeof (EventHandler));
10562                         mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10563                                 MethodAttributes.Public, typeof (void),
10564                                 Type.EmptyTypes);
10565                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10566                         eb.SetAddOnMethod (mb);
10567
10568                         eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10569                                 EventAttributes.None, typeof (EventHandler));
10570                         mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10571                                 MethodAttributes.Family, typeof (void),
10572                                 Type.EmptyTypes);
10573                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10574                         eb.SetAddOnMethod (mb);
10575
10576                         //
10577                         // static events
10578                         //
10579
10580                         eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10581                                 EventAttributes.None, typeof (EventHandler));
10582                         mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10583                                 MethodAttributes.Private | MethodAttributes.Static,
10584                                 typeof (void), Type.EmptyTypes);
10585                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10586                         eb.SetAddOnMethod (mb);
10587
10588                         eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10589                                 EventAttributes.None, typeof (EventHandler));
10590                         mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10591                                 MethodAttributes.Family | MethodAttributes.Static,
10592                                 typeof (void), Type.EmptyTypes);
10593                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10594                         eb.SetAddOnMethod (mb);
10595
10596                         eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10597                                 EventAttributes.None, typeof (EventHandler));
10598                         mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10599                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10600                                 typeof (void), Type.EmptyTypes);
10601                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10602                         eb.SetAddOnMethod (mb);
10603
10604                         eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10605                                 EventAttributes.None, typeof (EventHandler));
10606                         mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10607                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10608                                 typeof (void), Type.EmptyTypes);
10609                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10610                         eb.SetAddOnMethod (mb);
10611
10612                         eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10613                                 EventAttributes.None, typeof (EventHandler));
10614                         mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10615                                 MethodAttributes.Public | MethodAttributes.Static,
10616                                 typeof (void), Type.EmptyTypes);
10617                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10618                         eb.SetAddOnMethod (mb);
10619
10620                         eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10621                                 EventAttributes.None, typeof (EventHandler));
10622                         mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10623                                 MethodAttributes.Family | MethodAttributes.Static,
10624                                 typeof (void), Type.EmptyTypes);
10625                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10626                         eb.SetAddOnMethod (mb);
10627                 }
10628
10629 #if NET_2_0
10630                 static TypeBuilder Resolve1_Tb;
10631                 static bool Resolve1_Called;
10632
10633                 public class Lookup<T>
10634                 {
10635                         public static Type t = typeof(T);
10636                 }
10637
10638                 Assembly Resolve1 (object sender, ResolveEventArgs args) {
10639                         Resolve1_Called = true;
10640                         Resolve1_Tb.CreateType ();
10641                         return Resolve1_Tb.Assembly;
10642                 }
10643
10644                 [Test]
10645                 public void TypeResolveGenericInstances () {
10646                         // Test that TypeResolve is called for generic instances (#483852)
10647                         TypeBuilder tb1 = null;
10648
10649                         AppDomain.CurrentDomain.TypeResolve += Resolve1;
10650
10651                         tb1 = module.DefineType("Foo");
10652                         Resolve1_Tb = tb1;
10653                         FieldInfo field = TypeBuilder.GetField(typeof(Lookup<>).MakeGenericType(tb1), typeof(Lookup<>).GetField("t"));
10654                         TypeBuilder tb2 = module.DefineType("Bar");
10655                         ConstructorBuilder cb = tb2.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
10656                         ILGenerator ilgen = cb.GetILGenerator();
10657                         ilgen.Emit(OpCodes.Ldsfld, field);
10658                         ilgen.Emit(OpCodes.Pop);
10659                         ilgen.Emit(OpCodes.Ret);
10660                         Activator.CreateInstance(tb2.CreateType());
10661
10662                         Assert.IsTrue (Resolve1_Called);
10663                 }
10664 #endif
10665
10666                 [Test]
10667                 public void CreateConcreteTypeWithAbstractMethod ()
10668                 {
10669                         TypeBuilder tb = module.DefineType (genTypeName ());
10670                         tb.DefineMethod("method", MethodAttributes.Abstract | MethodAttributes.Public, typeof (void), Type.EmptyTypes);
10671                         try {
10672                                 tb.CreateType ();
10673                                 Assert.Fail ("#1");
10674                         } catch (InvalidOperationException) {}
10675                 }
10676
10677                 [Test]
10678                 public void ConcreteTypeDontLeakGenericParamFromItSelf ()
10679                 {
10680             var tb = module.DefineType (genTypeName ());
10681                         var gps = tb.DefineGenericParameters ("T");
10682             var mb = tb.DefineMethod ("m", MethodAttributes.Public | MethodAttributes.Static);
10683             mb.SetParameters (gps);
10684             mb.GetILGenerator ().Emit (OpCodes.Ret);
10685
10686             var ti = tb.CreateType ();
10687             var mi = ti.GetMethod ("m");
10688                         var arg0 = mi.GetParameters () [0].ParameterType;
10689
10690                         Assert.AreNotSame (arg0, gps [0], "#1");
10691                 }
10692
10693                 [Test]
10694                 public void ConcreteTypeDontLeakGenericParamFromMethods ()
10695                 {
10696             var tb = module.DefineType (genTypeName ());
10697             var mb = tb.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Static);
10698             var gps = mb.DefineGenericParameters ("T");
10699             mb.SetParameters (gps);
10700             mb.GetILGenerator ().Emit (OpCodes.Ret);
10701
10702             var ti = tb.CreateType ();
10703             var mi = ti.GetMethod ("m");
10704                         var arg0 = mi.GetParameters () [0].ParameterType;
10705
10706                         Assert.AreNotSame (arg0, gps [0], "#1");
10707                 }
10708 #if NET_2_0
10709                 [Test]
10710                 public void DeclaringMethodReturnsNull ()
10711                 {
10712                         TypeBuilder tb = module.DefineType (genTypeName ());
10713                         Assert.IsNull (tb.DeclaringMethod, null, "#1");
10714                 }
10715
10716                 [Test]
10717                 public void GenericParameterPositionReturns0 ()
10718                 {
10719                         TypeBuilder tb = module.DefineType (genTypeName ());
10720                         Assert.AreEqual (0, tb.GenericParameterPosition, "#1");
10721                 }
10722
10723                 [Test]
10724                 public void GetGenericTypeDefinitionBehavior ()
10725                 {
10726                         TypeBuilder tb = module.DefineType (genTypeName ());
10727                         try {
10728                                 tb.GetGenericTypeDefinition ();
10729                                 Assert.Fail ("#1");
10730                         } catch (InvalidOperationException) {}
10731
10732                         tb.DefineGenericParameters ("T");
10733                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#2");
10734
10735                         tb.CreateType ();
10736                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#3");
10737                 }
10738
10739                 [Test]
10740                 public void GetElementTypeNotSupported ()
10741                 {
10742                         TypeBuilder tb = module.DefineType (genTypeName ());
10743                         try {
10744                                 tb.GetElementType ();
10745                                 Assert.Fail ("#1");
10746                         } catch (NotSupportedException) {}
10747                 }
10748
10749                 [Test]
10750                 public void GenericParameterAttributesReturnsNone ()
10751                 {
10752                         TypeBuilder tb = module.DefineType (genTypeName ());
10753                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#1");
10754
10755                         tb.DefineGenericParameters ("T");
10756                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#2");
10757
10758                         tb.CreateType ();
10759                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#3");
10760                 }
10761
10762                 [Test]
10763                 public void GetGenericArgumentsReturnsNullForNonGenericTypeBuilder ()
10764                 {
10765                         TypeBuilder tb = module.DefineType (genTypeName ());
10766                         Assert.IsNull (tb.GetGenericArguments (), "#1");
10767                 }
10768
10769                 public interface IFaceA {}
10770                 public interface IFaceB : IFaceA {}
10771                 [Test]
10772                 public void GetInterfacesAfterCreate ()
10773                 {
10774                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type[] { typeof (IFaceB) });
10775
10776                         Type[] ifaces = tb.GetInterfaces ();
10777                         Assert.AreEqual (1, ifaces.Length, "#1");
10778                         Assert.AreEqual (typeof (IFaceB), ifaces [0], "#2");
10779
10780                         tb.CreateType ();
10781                         ifaces = tb.GetInterfaces ();
10782                         Assert.AreEqual (2, ifaces.Length, "#3");
10783                         Assert.AreEqual (typeof (IFaceB), ifaces [0], "#4");
10784                         Assert.AreEqual (typeof (IFaceA), ifaces [1], "#5");
10785                 }
10786
10787                 public interface MB_Iface
10788                 {
10789                     int Test ();
10790                 }
10791
10792                 public class MB_Impl : MB_Iface
10793                 {
10794                     public virtual int Test () { return 1; }
10795                 }
10796                 [Test]
10797                 public void MethodOverrideBodyMustBelongToTypeBuilder ()
10798                 {
10799                         TypeBuilder tb = module.DefineType (genTypeName ());
10800                         MethodInfo md = typeof (MB_Iface).GetMethod("Test");
10801             MethodInfo md2 = typeof (MB_Impl).GetMethod("Test");
10802                         try {
10803                 tb.DefineMethodOverride (md, md2);
10804                 Assert.Fail ("#1");
10805                         } catch (ArgumentException) {}
10806                 }
10807
10808                 [Test]
10809                 public void GetConstructorsThrowWhenIncomplete ()
10810                 {
10811                         TypeBuilder tb = module.DefineType (genTypeName ());
10812                         try {
10813                                 tb.GetConstructors (BindingFlags.Instance);
10814                                 Assert.Fail ("#1");
10815                         } catch (NotSupportedException) { }
10816
10817                         tb.CreateType ();
10818                         Assert.IsNotNull (tb.GetConstructors (BindingFlags.Instance), "#2");
10819                 }
10820
10821                 [Test]
10822                 public void GetEventsThrowWhenIncomplete ()
10823                 {
10824                         TypeBuilder tb = module.DefineType (genTypeName ());
10825                         try {
10826                                 tb.GetEvents (BindingFlags.Instance);
10827                                 Assert.Fail ("#1");
10828                         } catch (NotSupportedException) { }
10829
10830                         tb.CreateType ();
10831                         Assert.IsNotNull (tb.GetEvents (BindingFlags.Instance), "#2");
10832                 }
10833
10834                 [Test]
10835                 public void GetNestedTypeCreatedAfterTypeIsCreated ()
10836                 {
10837                         TypeBuilder tb = module.DefineType (genTypeName ());
10838                         TypeBuilder nested = tb.DefineNestedType ("Bar", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10839                         tb.CreateType ();
10840                         Assert.IsNull (tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#1");
10841                         Type res = nested.CreateType ();
10842                         Assert.AreEqual (res, tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#2");
10843
10844                         TypeBuilder nested2 = tb.DefineNestedType ("Bar2", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10845                         Assert.IsNull (tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#3");
10846                         res = nested2.CreateType ();
10847                         Assert.AreEqual (res, tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#4");
10848                 }
10849
10850
10851                 [Test]
10852                 public void IsDefinedThrowWhenIncomplete ()
10853                 {
10854                         TypeBuilder tb = module.DefineType (genTypeName ());
10855                         try {
10856                                 tb.IsDefined (typeof (string), true);
10857                                 Assert.Fail ("#1");
10858                         } catch (NotSupportedException) { }
10859
10860                         tb.CreateType ();
10861                         Assert.IsNotNull (tb.IsDefined (typeof (string), true), "#2");
10862                 }
10863 #endif
10864 #if NET_2_0
10865 #if !WINDOWS
10866                 /* 
10867                  * Tests for passing user types to Ref.Emit. Currently these only test
10868                  * whenever the runtime code can handle them without crashing, since we
10869                  * don't support user types yet.
10870                  * These tests are disabled for windows since the MS runtime trips on them.
10871                  */
10872                 [Test]
10873                 public void UserTypes () {
10874                         TypeDelegator t = new TypeDelegator (typeof (int));
10875
10876                         try {
10877                                 /* Parent */
10878                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10879                         } catch {
10880                         }
10881
10882                         try {
10883                                 /* Interfaces */
10884                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10885                                 tb.CreateType ();
10886                         } catch {
10887                         }
10888
10889                         try {
10890                                 /* Fields */
10891                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10892                                 tb.DefineField ("Foo", t, FieldAttributes.Public);
10893                                 tb.CreateType ();
10894                         } catch {
10895                         }
10896
10897                         try {
10898                                 /* Custom modifiers on fields */
10899                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10900                                 tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10901                                 tb.CreateType ();
10902                         } catch {
10903                         }
10904
10905 #if !WINDOWS
10906                         try {
10907                                 /* This is mono only */
10908                                 UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10909                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10910                                 FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10911                                 fb.SetMarshal (m);
10912                                 tb.CreateType ();
10913                         } catch {
10914                         }
10915 #endif
10916
10917                         try {
10918                                 /* Properties */
10919                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10920                                 tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10921                                 tb.CreateType ();
10922                         } catch {
10923                         }
10924
10925                         try {
10926                                 /* Custom modifiers on properties */
10927                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10928                                 // FIXME: These seems to be ignored
10929                                 tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10930                                 tb.CreateType ();
10931                         } catch {
10932                         }
10933
10934                         try {
10935                                 /* Method return types */
10936                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10937                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10938                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10939                                 tb.CreateType ();
10940                         } catch {
10941                         }
10942
10943                         try {
10944                                 /* Custom modifiers on method return types */
10945                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10946                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10947                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10948                                 tb.CreateType ();
10949                         } catch {
10950                         }
10951
10952                         try {
10953                                 /* Method parameters */
10954                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10955                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10956                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10957                                 tb.CreateType ();
10958                         } catch {
10959                         }
10960
10961                         try {
10962                                 /* Custom modifiers on method parameters */
10963                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10964                                 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 }});
10965                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10966                                 tb.CreateType ();
10967                         } catch {
10968                         }
10969
10970                         try {
10971                                 /* Ctor parameters */
10972                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10973                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10974                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10975                                 tb.CreateType ();
10976                         } catch {
10977                         }
10978                         
10979                         try {
10980                                 /* Custom modifiers on ctor parameters */
10981                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10982                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10983                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10984                                 tb.CreateType ();
10985                         } catch {
10986                         }
10987
10988                         try {
10989                                 /* SignatureHelper arguments */
10990                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10991                                 sighelper.AddArgument (t, false);
10992                                 byte[] arr = sighelper.GetSignature ();
10993                         } catch {
10994                         }
10995
10996                         try {
10997                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10998                                 sighelper.AddArgument (t, false);
10999                                 byte[] arr = sighelper.GetSignature ();
11000                         } catch {
11001                         }
11002
11003                         try {
11004                                 /* Custom modifiers on SignatureHelper arguments */
11005                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
11006                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
11007                                 byte[] arr = sighelper.GetSignature ();
11008                         } catch {
11009                         }
11010
11011                         try {
11012                                 /* Custom modifiers on SignatureHelper arguments */
11013                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
11014                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
11015                                 byte[] arr = sighelper.GetSignature ();
11016                         } catch {
11017                         }
11018
11019                         /* Arguments to ILGenerator methods */
11020                         try {
11021                                 /* Emit () */
11022                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
11023                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
11024                                 ILGenerator ig = mb.GetILGenerator ();
11025                                 ig.Emit (OpCodes.Ldnull);
11026                                 ig.Emit (OpCodes.Castclass, t);
11027                                 ig.Emit (OpCodes.Pop);
11028                                 ig.Emit (OpCodes.Ret);
11029                                 tb.CreateType ();
11030                         } catch {
11031                         }
11032
11033                         try {
11034                                 /* DeclareLocal () */
11035                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
11036                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
11037                                 ILGenerator ig = mb.GetILGenerator ();
11038                                 ig.DeclareLocal (t);
11039                                 ig.Emit (OpCodes.Ret);
11040                                 tb.CreateType ();
11041                         } catch {
11042                         }
11043
11044                         try {
11045                                 /* BeginExceptionCatchBlock () */
11046                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
11047                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
11048                                 ILGenerator ig = mb.GetILGenerator ();
11049                                 ig.BeginExceptionBlock ();
11050                                 ig.BeginCatchBlock (t);
11051                                 ig.Emit (OpCodes.Ret);
11052                                 tb.CreateType ();
11053                         } catch {
11054                         }
11055
11056                         try {
11057                                 /* EmitCalli () */
11058                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
11059                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
11060                                 ILGenerator ig = mb.GetILGenerator ();
11061                                 ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
11062                                 ig.Emit (OpCodes.Ret);
11063                                 tb.CreateType ();
11064                         } catch {
11065                         }
11066                 }
11067 #endif
11068 #endif
11069         }
11070 }