[runtime] Remove handler block trampoline code
[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 using System.Collections.Generic;
28
29 namespace MonoTests.System.Reflection.Emit
30 {
31         public interface EmptyInterface
32         {
33         }
34
35         public interface OneMethodInterface
36         {
37                 void foo ();
38         }
39
40         public class SimpleTestAttribute : Attribute
41         {
42         }
43         public class EmptyIfaceImpl : EmptyInterface
44         {
45         }
46
47         public class Gen<T> {
48                 public static T field = default(T);
49         }
50
51         [TestFixture]
52         public class TypeBuilderTest
53         {
54                 public interface AnInterface
55                 {
56                 }
57
58                 public interface Foo
59                 {
60                 }
61
62                 public interface Bar : Foo
63                 {
64                 }
65
66                 public interface Baz : Bar
67                 {
68                 }
69
70                 public interface IMoveable
71                 {
72                 }
73
74                 public interface IThrowable : IMoveable
75                 {
76                 }
77
78                 public interface ILiquid
79                 {
80                 }
81
82                 public interface IWater : ILiquid
83                 {
84                 }
85
86                 public interface IAir
87                 {
88                 }
89
90                 public interface IDestroyable
91                 {
92                 }
93
94                 public class Tuple <A,B> {
95                         public A a;
96                         public B b;
97                 }
98
99                 private AssemblyBuilder assembly;
100
101                 private ModuleBuilder module;
102
103                 string tempDir = Path.Combine (Path.GetTempPath (), typeof (TypeBuilderTest).FullName);
104
105                 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
106
107                 [SetUp]
108                 protected void SetUp ()
109                 {
110                         Random AutoRand = new Random ();
111                         string basePath = tempDir;
112                         while (Directory.Exists (tempDir))
113                                 tempDir = Path.Combine (basePath, AutoRand.Next ().ToString ());
114                         Directory.CreateDirectory (tempDir);
115
116                         AssemblyName assemblyName = new AssemblyName ();
117                         assemblyName.Name = ASSEMBLY_NAME;
118
119                         assembly =
120                                 Thread.GetDomain ().DefineDynamicAssembly (
121                                         assemblyName, AssemblyBuilderAccess.RunAndSave, tempDir);
122
123                         module = assembly.DefineDynamicModule (ASSEMBLY_NAME, ASSEMBLY_NAME + ".dll");
124                 }
125
126                 [TearDown]
127                 protected void TearDown ()
128                 {
129                         try {
130                                 Directory.Delete (tempDir, true);
131                         } catch (DirectoryNotFoundException) {
132                         } catch (IOException) {
133                                 // Can happen on Windows if assemblies from this dir are still used
134                         }
135                 }
136
137
138                 static int typeIndexer = 0;
139
140                 // Return a unique type name
141                 private string genTypeName ()
142                 {
143                         return "t" + (typeIndexer++);
144                 }
145
146                 private string nullName ()
147                 {
148                         return String.Format ("{0}", (char) 0);
149                 }
150
151                 [Test]
152                 public void TestAssembly ()
153                 {
154                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
155                         Assert.AreEqual (assembly, tb.Assembly);
156                 }
157
158                 [Test]
159                 public void TestAssemblyQualifiedName ()
160                 {
161                         TypeBuilder tb = module.DefineType ("A.B.C.D", TypeAttributes.Public);
162                         Assert.AreEqual ("A.B.C.D, " + assembly.GetName ().FullName,
163                                 tb.AssemblyQualifiedName);
164                 }
165
166                 [Test]
167                 public void TestAttributes ()
168                 {
169                         TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
170                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
171                         Assert.AreEqual (attrs, tb.Attributes);
172                 }
173
174                 [Test]
175                 public void TestBaseTypeClass ()
176                 {
177                         TypeAttributes attrs = TypeAttributes.Public;
178                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
179                         Assert.AreEqual (typeof (object), tb.BaseType, "#1");
180
181                         TypeBuilder tb2 = module.DefineType (genTypeName (), attrs, tb);
182                         Assert.AreEqual (tb, tb2.BaseType, "#2");
183                 }
184
185                 [Test] // bug #71301
186                 public void TestBaseTypeInterface ()
187                 {
188                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
189                         Assert.IsNull (tb3.BaseType);
190                 }
191
192                 [Test]
193                 public void TestDeclaringType ()
194                 {
195                         TypeAttributes attrs = 0;
196                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
197                         Assert.IsNull (tb.DeclaringType, "#1");
198
199                         attrs = TypeAttributes.NestedPublic;
200                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName (), attrs);
201                         TypeBuilder tb3 = tb2.DefineNestedType (genTypeName (), attrs);
202                         Assert.AreEqual (tb3.DeclaringType.DeclaringType, tb, "#2");
203                 }
204
205                 [Test]
206                 public void TestFullName ()
207                 {
208                         string name = genTypeName ();
209                         TypeAttributes attrs = 0;
210                         TypeBuilder tb = module.DefineType (name, attrs);
211                         Assert.AreEqual (name, tb.FullName, "#1");
212
213                         string name2 = genTypeName ();
214                         attrs = TypeAttributes.NestedPublic;
215                         TypeBuilder tb2 = tb.DefineNestedType (name2, attrs);
216
217                         string name3 = genTypeName ();
218                         attrs = TypeAttributes.NestedPublic;
219                         TypeBuilder tb3 = tb2.DefineNestedType (name3, attrs);
220
221                         Assert.AreEqual (name + "+" + name2 + "+" + name3, tb3.FullName, "#2");
222                 }
223
224                 [Test]
225                 public void DefineCtorUsingDefineMethod ()
226                 {
227                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Class);
228                         MethodBuilder mb = tb.DefineMethod(
229                                 ".ctor", MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
230                                 null, null);
231                         ILGenerator ilgen = mb.GetILGenerator();
232                         ilgen.Emit(OpCodes.Ldarg_0);
233                         ilgen.Emit(OpCodes.Call,
234                                            typeof(object).GetConstructor(Type.EmptyTypes));
235                         ilgen.Emit(OpCodes.Ret);
236                         Type t = tb.CreateType();
237
238                         Assert.AreEqual (1, t.GetConstructors ().Length);
239                 }
240
241                 [Test]
242                 public void TestGUIDIncomplete ()
243                 {
244                         TypeBuilder tb = module.DefineType (genTypeName ());
245                         try {
246                                 Guid g = tb.GUID;
247                                 Assert.Fail ("#1");
248                         } catch (NotSupportedException ex) {
249                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
250                                 Assert.IsNull (ex.InnerException, "#3");
251                                 Assert.IsNotNull (ex.Message, "#4");
252                         }
253                 }
254
255                 [Test] // bug #71302
256                 [Category ("NotWorking")]
257                 public void TestGUIDComplete ()
258                 {
259                         TypeBuilder tb = module.DefineType (genTypeName ());
260                         tb.CreateType ();
261                         Assert.IsTrue (tb.GUID != Guid.Empty);
262                 }
263
264                 [Test]
265                 [Category ("NotWorking")]
266                 public void TestFixedGUIDComplete ()
267                 {
268                         TypeBuilder tb = module.DefineType (genTypeName ());
269
270                         Guid guid = Guid.NewGuid ();
271
272                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
273                                 new Type [] { typeof (string) });
274
275                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
276                                 new object [] { guid.ToString ("D") }, new FieldInfo [0], new object [0]);
277
278                         tb.SetCustomAttribute (caBuilder);
279                         tb.CreateType ();
280                         Assert.AreEqual (guid, tb.GUID);
281                 }
282
283                 [Test]
284                 public void TestHasElementType_Incomplete ()
285                 {
286                         // According to the MSDN docs, this member works, but in reality, it
287                         // returns a NotSupportedException
288                         TypeBuilder tb = module.DefineType (genTypeName ());
289                         Assert.IsFalse (tb.HasElementType);
290                 }
291
292                 [Test]
293                 public void TestHasElementType_Complete ()
294                 {
295                         // According to the MSDN docs, this member works, but in reality, it
296                         // returns a NotSupportedException
297                         TypeBuilder tb = module.DefineType (genTypeName ());
298                         tb.CreateType ();
299                         Assert.IsFalse (tb.HasElementType);
300                 }
301
302                 [Test] // bug #324692
303                 public void CreateType_Enum_NoInstanceField ()
304                 {
305                         TypeBuilder tb = module.DefineType (genTypeName (),
306                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
307                                 typeof (Enum));
308
309                         try {
310                                 tb.CreateType ();
311                                 Assert.Fail ("#1: must throw TypeLoadException");
312                         } catch (TypeLoadException) {
313                         }
314
315                         Assert.IsTrue (tb.IsCreated (), "#2");
316                 }
317
318                 [Test] // bug #324692
319                 public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
320                 {
321                         TypeBuilder tb = module.DefineType (genTypeName (),
322                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
323                                 typeof (Enum));
324
325                         try {
326                                 tb.CreateType ();
327                                 Assert.Fail ("#A1");
328                         } catch (TypeLoadException ex) {
329                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
330                                 Assert.IsNull (ex.InnerException, "#A3");
331                                 Assert.IsNotNull (ex.Message, "#A4");
332                         }
333
334                         Assert.IsTrue (tb.IsCreated (), "#B1");
335                         Assert.IsNull (tb.CreateType (), "#B2");
336                         Assert.IsTrue (tb.IsCreated (), "#B3");
337                 }
338
339                 [Test]
340                 public void TestEnumWithEmptyInterfaceBuildsOk ()
341                 {
342                         TypeBuilder tb = module.DefineType (genTypeName (),
343                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
344                                 typeof (Enum));
345                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
346                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
347
348                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
349
350                         try {
351                                 tb.CreateType ();
352                         } catch (TypeLoadException) {
353                                 Assert.Fail ("#1: must build enum type ok");
354                         }
355
356                         Assert.IsTrue (tb.IsCreated (), "#2");
357                 }
358
359                 [Test]
360                 [Category ("NotWorking")]
361                 public void TestEnumWithNonEmptyInterfaceBuildsFails ()
362                 {
363                         TypeBuilder tb = module.DefineType (genTypeName (),
364                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
365                                 typeof (Enum));
366                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
367                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
368
369                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
370
371                         try {
372                                 tb.CreateType ();
373                                 Assert.Fail ("#1: type doesn't have all interface methods");
374                         } catch (TypeLoadException) {
375                         }
376
377                         Assert.IsTrue (tb.IsCreated (), "#2");
378                 }
379
380                 [Test]
381                 [Category ("NotWorking")]
382                 public void TestTypeDontImplementInterfaceMethodBuildsFails ()
383                 {
384                         TypeBuilder tb = module.DefineType (genTypeName (),
385                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
386                                 typeof (object));
387
388                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
389
390                         try {
391                                 tb.CreateType ();
392                                 Assert.Fail ("#1: type doesn't have all interface methods");
393                         } catch (TypeLoadException) {
394                         }
395
396                         Assert.IsTrue (tb.IsCreated (), "#2");
397                 }
398
399                 [Test]
400                 public void TestEnumWithSequentialLayoutBuildsFails ()
401                 {
402                         TypeBuilder tb = module.DefineType (genTypeName (),
403                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
404                                 TypeAttributes.SequentialLayout, typeof (Enum));
405                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
406                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
407
408                         try {
409                                 tb.CreateType ();
410                                 Assert.Fail ("#1: type doesn't have all interface methods");
411                         } catch (TypeLoadException) {
412                         }
413
414                         Assert.IsTrue (tb.IsCreated (), "#2");
415                 }
416
417                 [Test]
418                 public void TestEnumWithExplicitLayoutBuildsFails ()
419                 {
420                         TypeBuilder tb = module.DefineType (genTypeName (),
421                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
422                                 TypeAttributes.ExplicitLayout, typeof (Enum));
423                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
424                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
425
426                         try {
427                                 tb.CreateType ();
428                                 Assert.Fail ("#1: type doesn't have all interface methods");
429                         } catch (TypeLoadException) {
430                         }
431
432                         Assert.IsTrue (tb.IsCreated (), "#2");
433                 }
434
435                 [Test]
436                 public void TestEnumWithMethodsBuildFails ()
437                 {
438                         TypeBuilder tb = module.DefineType ("FooEnum7",
439                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
440                                 typeof (Enum));
441                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
442                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
443
444                         MethodBuilder methodBuilder = tb.DefineMethod("mmm",
445                                 MethodAttributes.Public | MethodAttributes.Virtual,
446                                 null,
447                                 new Type[] { });
448
449                         methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
450                         try {
451                                 tb.CreateType ();
452                                 Assert.Fail ("#1: enum has method");
453                         } catch (TypeLoadException) {
454                         }
455
456                         Assert.IsTrue (tb.IsCreated (), "#2");
457                 }
458
459                 [Test]
460                 public void TestEnumWithBadTypeValueFieldBuildFails ()
461                 {
462                         Type[] badTypes = {
463                                 typeof (object),
464                                 typeof (string),
465                                 typeof (DateTime)
466                         };
467
468                         foreach (Type type in badTypes) {
469                                 TypeBuilder tb = module.DefineType (genTypeName (),
470                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
471                                         typeof (Enum));
472                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
473                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
474
475                                 try {
476                                         tb.CreateType ();
477                                         Assert.Fail ("#1: enum using bad type: " + type);
478                                 } catch (TypeLoadException) {
479                                 }
480
481                                 Assert.IsTrue (tb.IsCreated (), "#2");
482                         }
483                 }
484
485                 [Test]
486                 public void TestEnumWithGoodTypeValueFieldBuildOk ()
487                 {
488                         Type[] goodTypes = {
489                                 typeof (byte),typeof (sbyte),typeof (bool),
490                                 typeof (ushort),typeof (short),typeof (char),
491                                 typeof (uint),typeof (int),
492                                 typeof (ulong),typeof (long),
493                                 typeof (UIntPtr),typeof (IntPtr),
494                         };
495
496                         foreach (Type type in goodTypes) {
497                                 TypeBuilder tb = module.DefineType (genTypeName (),
498                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
499                                         typeof (Enum));
500                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
501                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
502
503                                 try {
504                                         tb.CreateType ();
505                                 } catch (TypeLoadException) {
506                                         Assert.Fail ("#1: enum using good type: " + type);
507                                 }
508                         }
509                 }
510
511                 [Test]
512                 public void TestEnumWithMultipleValueFieldsBuildFals ()
513                 {
514                         TypeBuilder tb = module.DefineType (genTypeName (),
515                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
516                                 typeof (Enum));
517                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
518                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
519                         tb.DefineField ("value2__", typeof (int), FieldAttributes.SpecialName |
520                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
521
522                         try {
523                                 tb.CreateType ();
524                                 Assert.Fail ("#1: invalid enum type");
525                         } catch (TypeLoadException) {
526                         }
527
528                         Assert.IsTrue (tb.IsCreated (), "#2");
529                 }
530
531                 [Test]
532                 [Category ("NotWorking")]
533                 public void TestEnumWithEmptyInterfaceCanBeCasted ()
534                 {
535                         TypeBuilder tb = module.DefineType (genTypeName (),
536                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
537                                 typeof (Enum));
538                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
539                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
540                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
541
542                         try {
543                                 tb.CreateType ();
544                         } catch (TypeLoadException) {
545                                 Assert.Fail ("#1: must build enum type ok");
546                         }
547
548                         try {
549                                 EmptyInterface obj = (EmptyInterface) Activator.CreateInstance (tb);
550                                 Assert.IsNotNull (obj, "#2");
551                         } catch (TypeLoadException) {
552                                 Assert.Fail ("#3: must cast enum to interface");
553                         }
554                 }
555
556                 [Test]
557                 public void TestEnumWithValueFieldBuildOk ()
558                 {
559                         TypeBuilder tb = module.DefineType (genTypeName (),
560                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
561                                 typeof (Enum));
562                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
563                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
564
565                         try {
566                                 tb.CreateType ();
567                         } catch (TypeLoadException) {
568                                 Assert.Fail ("#1: must build enum type ok");
569                         }
570                 }
571
572                 [Test]
573                 public void TestIsAbstract ()
574                 {
575                         TypeBuilder tb = module.DefineType (genTypeName ());
576                         Assert.IsFalse (tb.IsAbstract, "#1");
577
578                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Abstract);
579                         Assert.IsTrue (tb2.IsAbstract, "#2");
580                 }
581
582                 [Test]
583                 public void TestIsAnsiClass ()
584                 {
585                         TypeBuilder tb = module.DefineType (genTypeName ());
586                         Assert.IsTrue (tb.IsAnsiClass, "#1");
587
588                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
589                         Assert.IsFalse (tb2.IsAnsiClass, "#2");
590                 }
591
592                 [Test]
593                 public void TestIsArray ()
594                 {
595                         // How can a TypeBuilder be an array ?
596                         string name = genTypeName ();
597                         TypeBuilder tb = module.DefineType (name);
598                         Assert.IsFalse (tb.IsArray);
599                 }
600
601                 [Test]
602                 public void TestIsAutoClass ()
603                 {
604                         TypeBuilder tb = module.DefineType (genTypeName ());
605                         Assert.IsFalse (tb.IsAutoClass, "#1");
606
607                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.AutoClass);
608                         Assert.IsTrue (tb2.IsAutoClass, "#2");
609                 }
610
611                 [Test]
612                 public void TestIsAutoLayout ()
613                 {
614                         TypeBuilder tb = module.DefineType (genTypeName ());
615                         Assert.IsTrue (tb.IsAutoLayout, "#1");
616
617                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
618                         Assert.IsFalse (tb2.IsAutoLayout, "#2");
619                 }
620
621                 [Test]
622                 public void TestIsByRef ()
623                 {
624                         // How can a TypeBuilder be ByRef ?
625                         TypeBuilder tb = module.DefineType (genTypeName ());
626                         Assert.IsFalse (tb.IsByRef);
627                 }
628
629                 [Test]
630                 public void TestIsClass ()
631                 {
632                         TypeBuilder tb = module.DefineType (genTypeName ());
633                         Assert.IsTrue (tb.IsClass, "#1");
634
635                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
636                         Assert.IsFalse (tb2.IsClass, "#2");
637
638                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
639                         Assert.IsFalse (tb3.IsClass, "#3");
640
641                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
642                         Assert.IsFalse (tb4.IsClass, "#4");
643                 }
644
645                 [Test] // bug #71304
646                 public void TestIsCOMObject ()
647                 {
648                         TypeBuilder tb = module.DefineType (genTypeName ());
649                         Assert.IsFalse (tb.IsCOMObject, "#1");
650
651                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
652                         Assert.IsTrue (tb.IsCOMObject, "#2");
653                 }
654
655                 [Test]
656                 public void TestIsContextful ()
657                 {
658                         TypeBuilder tb = module.DefineType (genTypeName ());
659                         Assert.IsFalse (tb.IsContextful, "#1");
660
661                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
662                         Assert.IsTrue (tb2.IsContextful, "#2");
663                 }
664
665                 [Test]
666                 public void TestIsEnum ()
667                 {
668                         TypeBuilder tb = module.DefineType (genTypeName ());
669                         Assert.IsFalse (tb.IsEnum, "#1");
670
671                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ValueType));
672                         Assert.IsFalse (tb2.IsEnum, "#2");
673
674                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (Enum));
675                         Assert.IsTrue (tb3.IsEnum, "#3");
676                 }
677
678                 [Test]
679                 public void TestIsExplicitLayout ()
680                 {
681                         TypeBuilder tb = module.DefineType (genTypeName ());
682                         Assert.IsFalse (tb.IsExplicitLayout, "#1");
683
684                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
685                         Assert.IsTrue (tb2.IsExplicitLayout, "#2");
686                 }
687
688                 [Test]
689                 public void TestIsImport ()
690                 {
691                         TypeBuilder tb = module.DefineType (genTypeName ());
692                         Assert.IsFalse (tb.IsImport, "#1");
693
694                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
695                         Assert.IsTrue (tb.IsImport, "#2");
696                 }
697
698                 [Test]
699                 public void TestIsInterface ()
700                 {
701                         TypeBuilder tb = module.DefineType (genTypeName ());
702                         Assert.IsFalse (tb.IsInterface, "#1");
703
704                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
705                         Assert.IsTrue (tb2.IsInterface, "#2");
706
707                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
708                         Assert.IsFalse (tb3.IsInterface, "#3");
709                 }
710
711                 [Test]
712                 public void TestIsLayoutSequential ()
713                 {
714                         TypeBuilder tb = module.DefineType (genTypeName ());
715                         Assert.IsFalse (tb.IsLayoutSequential, "#1");
716
717                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SequentialLayout);
718                         Assert.IsTrue (tb2.IsLayoutSequential, "#2");
719                 }
720
721                 [Test]
722                 public void TestIsMarshalByRef ()
723                 {
724                         TypeBuilder tb = module.DefineType (genTypeName ());
725                         Assert.IsFalse (tb.IsMarshalByRef, "#1");
726
727                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (MarshalByRefObject));
728                         Assert.IsTrue (tb2.IsMarshalByRef, "#2");
729
730                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
731                         Assert.IsTrue (tb3.IsMarshalByRef, "#3");
732                 }
733
734                 // TODO: Visibility properties
735
736                 [Test]
737                 public void TestIsPointer ()
738                 {
739                         // How can this be true?
740                         TypeBuilder tb = module.DefineType (genTypeName ());
741                         Assert.IsFalse (tb.IsPointer);
742                 }
743
744                 [Test]
745                 public void TestIsPrimitive ()
746                 {
747                         TypeBuilder tb = module.DefineType ("int");
748                         Assert.IsFalse (tb.IsPrimitive);
749                 }
750
751                 [Test]
752                 public void IsSealed ()
753                 {
754                         TypeBuilder tb = module.DefineType (genTypeName ());
755                         Assert.IsFalse (tb.IsSealed, "#1");
756
757                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
758                         Assert.IsTrue (tb2.IsSealed, "#2");
759                 }
760
761                 [Test]
762                 public void IsSerializable ()
763                 {
764                         TypeBuilder tb = module.DefineType (genTypeName ());
765                         Assert.IsFalse (tb.IsSerializable, "#1");
766
767                         ConstructorInfo [] ctors = typeof (SerializableAttribute).GetConstructors (BindingFlags.Instance | BindingFlags.Public);
768                         Assert.IsTrue (ctors.Length > 0, "#2");
769
770                         tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
771                         Type createdType = tb.CreateType ();
772
773                         string an = "IsSerializableTestAssembly.dll";
774                         assembly.Save (an);
775                         Assert.IsTrue (createdType.IsSerializable, "#3");
776                         File.Delete (Path.Combine (tempDir, an));
777                 }
778
779                 [Test]
780                 public void TestIsSpecialName ()
781                 {
782                         TypeBuilder tb = module.DefineType (genTypeName ());
783                         Assert.IsFalse (tb.IsSpecialName, "#1");
784
785                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SpecialName);
786                         Assert.IsTrue (tb2.IsSpecialName, "#2");
787                 }
788
789                 [Test]
790                 public void TestIsUnicodeClass ()
791                 {
792                         TypeBuilder tb = module.DefineType (genTypeName ());
793                         Assert.IsFalse (tb.IsUnicodeClass, "#1");
794
795                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
796                         Assert.IsTrue (tb2.IsUnicodeClass, "#2");
797                 }
798
799                 [Test]
800                 public void TestIsValueType ()
801                 {
802                         TypeBuilder tb = module.DefineType (genTypeName ());
803                         Assert.IsFalse (tb.IsValueType, "#1");
804
805                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
806                         Assert.IsFalse (tb2.IsValueType, "#2");
807
808                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
809                         Assert.IsTrue (tb3.IsValueType, "#3");
810
811                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
812                         Assert.IsTrue (tb4.IsValueType, "#4");
813                 }
814
815                 [Test]
816                 public void TestMemberType ()
817                 {
818                         TypeBuilder tb = module.DefineType (genTypeName ());
819                         Assert.AreEqual (MemberTypes.TypeInfo, tb.MemberType);
820                 }
821
822                 [Test]
823                 public void TestModule ()
824                 {
825                         TypeBuilder tb = module.DefineType (genTypeName ());
826                         Assert.AreEqual (module, tb.Module);
827                 }
828
829                 [Test]
830                 public void TestName ()
831                 {
832                         TypeBuilder tb = module.DefineType ("A");
833                         Assert.AreEqual ("A", tb.Name, "#1");
834
835                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
836                         Assert.AreEqual ("E", tb2.Name, "#2");
837
838                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
839                         Assert.AreEqual ("A", tb3.Name, "#3");
840
841                         /* Is .E a valid name ?
842                         TypeBuilder tb4 = module.DefineType (".E");
843                         Assert.AreEqual ("E", tb4.Name);
844                         */
845                 }
846
847                 [Test]
848                 public void TestNamespace ()
849                 {
850                         TypeBuilder tb = module.DefineType ("A");
851                         Assert.AreEqual (string.Empty, tb.Namespace, "#1");
852
853                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
854                         Assert.AreEqual ("A.B.C.D", tb2.Namespace, "#2");
855
856                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
857                         Assert.AreEqual (string.Empty, tb3.Namespace, "#3");
858
859                         /* Is .E a valid name ?
860                         TypeBuilder tb4 = module.DefineType (".E");
861                         Assert.AreEqual ("E", tb4.Name);
862                         */
863                 }
864
865                 [Test]
866                 public void TestPackingSize ()
867                 {
868                         TypeBuilder tb = module.DefineType (genTypeName ());
869                         Assert.AreEqual (PackingSize.Unspecified, tb.PackingSize, "#1");
870
871                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (object),
872                                 PackingSize.Size16, 16);
873                         Assert.AreEqual (PackingSize.Size16, tb2.PackingSize, "#2");
874                 }
875
876                 [Test]
877                 public void TestReflectedType ()
878                 {
879                         // It is the same as DeclaringType, but why?
880                         TypeBuilder tb = module.DefineType (genTypeName ());
881                         Assert.IsNull (tb.ReflectedType, "#1");
882
883                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName ());
884                         Assert.AreEqual (tb, tb2.ReflectedType, "#2");
885                 }
886
887                 [Test]
888                 public void SetParent_Parent_Null ()
889                 {
890                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class,
891                                 typeof (Attribute));
892                         tb.SetParent (null);
893                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
894
895                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
896                                 TypeAttributes.Abstract);
897                         tb.SetParent (null);
898                         Assert.IsNull (tb.BaseType, "#B1");
899
900                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
901                                 TypeAttributes.Abstract, typeof (ICloneable));
902                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#C1");
903                         tb.SetParent (null);
904                         Assert.IsNull (tb.BaseType, "#C2");
905
906                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
907                                 typeof (IDisposable));
908                         try {
909                                 tb.SetParent (null);
910                                 Assert.Fail ("#D1");
911                         } catch (InvalidOperationException ex) {
912                                 // Interface must be declared abstract
913                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
914                                 Assert.IsNull (ex.InnerException, "#D3");
915                                 Assert.IsNotNull (ex.Message, "#D4");
916                         }
917                 }
918
919                 [Test]
920                 public void SetParent_Parent_Interface ()
921                 {
922                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class);
923                         tb.SetParent (typeof (ICloneable));
924                         Assert.AreEqual (typeof (ICloneable), tb.BaseType);
925                 }
926
927                 [Test]
928                 public void TestSetParentIncomplete ()
929                 {
930                         TypeBuilder tb = module.DefineType (genTypeName ());
931                         tb.SetParent (typeof (Attribute));
932                         Assert.AreEqual (typeof (Attribute), tb.BaseType, "#1");
933
934                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
935                                 TypeAttributes.Abstract);
936                         tb.SetParent (typeof (IDisposable));
937                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#2");
938
939                         tb = module.DefineType (genTypeName ());
940                         tb.SetParent (typeof (IDisposable));
941                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#3");
942
943                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
944                                 TypeAttributes.Abstract, typeof (IDisposable));
945                         tb.SetParent (typeof (ICloneable));
946                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#4");
947
948                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
949                                 TypeAttributes.Abstract, typeof (IDisposable));
950                         tb.SetParent (typeof (ICloneable));
951                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#5");
952                 }
953
954                 [Test]
955                 public void TestSetParentComplete ()
956                 {
957                         TypeBuilder tb = module.DefineType (genTypeName ());
958                         tb.CreateType ();
959                         try {
960                                 tb.SetParent (typeof (Attribute));
961                                 Assert.Fail ("#1");
962                         } catch (InvalidOperationException ex) {
963                                 // Unable to change after type has been created
964                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
965                                 Assert.IsNull (ex.InnerException, "#3");
966                                 Assert.IsNotNull (ex.Message, "#4");
967                         }
968                 }
969
970                 [Test]
971                 public void TestSize ()
972                 {
973                         {
974                                 TypeBuilder tb = module.DefineType (genTypeName ());
975                                 Assert.AreEqual (0, tb.Size, "#1");
976                                 tb.CreateType ();
977                                 Assert.AreEqual (0, tb.Size, "#2");
978                         }
979
980                         {
981                                 TypeBuilder tb = module.DefineType (genTypeName (), 0, typeof (object),
982                                         PackingSize.Size16, 32);
983                                 Assert.AreEqual (32, tb.Size, "#3");
984                         }
985                 }
986
987                 [Test]
988                 public void TestTypeHandle ()
989                 {
990                         TypeBuilder tb = module.DefineType (genTypeName ());
991                         try {
992                                 RuntimeTypeHandle handle = tb.TypeHandle;
993                                 Assert.Fail ("#1:" + handle);
994                         } catch (NotSupportedException ex) {
995                                 // The invoked member is not supported in a
996                                 // dynamic module
997                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
998                                 Assert.IsNull (ex.InnerException, "#3");
999                                 Assert.IsNotNull (ex.Message, "#4");
1000                         }
1001                 }
1002
1003                 [Test]
1004                 public void TestTypeInitializerIncomplete ()
1005                 {
1006                         TypeBuilder tb = module.DefineType (genTypeName ());
1007                         try {
1008                                 ConstructorInfo cb = tb.TypeInitializer;
1009                                 Assert.Fail ("#1:" + (cb != null));
1010                         } catch (NotSupportedException ex) {
1011                                 // The invoked member is not supported in a
1012                                 // dynamic module
1013                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1014                                 Assert.IsNull (ex.InnerException, "#3");
1015                                 Assert.IsNotNull (ex.Message, "#4");
1016                         }
1017                 }
1018
1019                 [Test]
1020                 public void TestTypeInitializerComplete ()
1021                 {
1022                         TypeBuilder tb = module.DefineType (genTypeName ());
1023                         tb.CreateType ();
1024                         ConstructorInfo cb = tb.TypeInitializer;
1025                 }
1026
1027                 [Test]
1028                 public void TestTypeToken ()
1029                 {
1030                         TypeBuilder tb = module.DefineType (genTypeName ());
1031                         TypeToken token = tb.TypeToken;
1032                 }
1033
1034                 [Test]
1035                 public void UnderlyingSystemType ()
1036                 {
1037                         TypeBuilder tb;
1038                         Type emitted_type;
1039
1040                         tb = module.DefineType (genTypeName ());
1041                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#A1");
1042                         emitted_type = tb.CreateType ();
1043                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#A2");
1044
1045                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1046                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#B1");
1047                         emitted_type = tb.CreateType ();
1048                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#B2");
1049
1050                         tb = module.DefineType (genTypeName (), 0, typeof (ValueType));
1051                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#C1");
1052                         emitted_type = tb.CreateType ();
1053                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#C2");
1054
1055                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1056                         try {
1057                                 Type t = tb.UnderlyingSystemType;
1058                                 Assert.Fail ("#D1:" + t);
1059                         } catch (InvalidOperationException ex) {
1060                                 // Underlying type information on enumeration
1061                                 // is not specified
1062                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1063                                 Assert.IsNull (ex.InnerException, "#D3");
1064                                 Assert.IsNotNull (ex.Message, "#D4");
1065                         }
1066                         tb.DefineField ("val", typeof (int), FieldAttributes.Private);
1067                         Assert.AreEqual (typeof (int), tb.UnderlyingSystemType, "#D5");
1068                         emitted_type = tb.CreateType ();
1069                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#D6");
1070
1071                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1072                         tb.DefineField ("val", typeof (int), FieldAttributes.Static);
1073                         try {
1074                                 Type t = tb.UnderlyingSystemType;
1075                                 Assert.Fail ("#E1:" + t);
1076                         } catch (InvalidOperationException ex) {
1077                                 // Underlying type information on enumeration
1078                                 // is not specified
1079                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1080                                 Assert.IsNull (ex.InnerException, "#E3");
1081                                 Assert.IsNotNull (ex.Message, "#E4");
1082                         }
1083                         tb.DefineField ("foo", typeof (long), FieldAttributes.Private);
1084                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E5");
1085                         tb.DefineField ("bar", typeof (short), FieldAttributes.Private);
1086                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E6");
1087                         tb.DefineField ("boo", typeof (int), FieldAttributes.Static);
1088                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E7");
1089                 }
1090
1091                 [Test]
1092                 public void AddInterfaceImplementation_InterfaceType_Null ()
1093                 {
1094                         TypeBuilder tb = module.DefineType (genTypeName ());
1095                         try {
1096                                 tb.AddInterfaceImplementation (null);
1097                                 Assert.Fail ("#1");
1098                         } catch (ArgumentNullException ex) {
1099                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1100                                 Assert.IsNull (ex.InnerException, "#3");
1101                                 Assert.IsNotNull (ex.Message, "#4");
1102                                 Assert.AreEqual ("interfaceType", ex.ParamName, "#5");
1103                         }
1104                 }
1105
1106                 [Test]
1107                 public void TestAddInterfaceImplementation ()
1108                 {
1109                         TypeBuilder tb = module.DefineType (genTypeName ());
1110                         tb.AddInterfaceImplementation (typeof (AnInterface));
1111                         tb.AddInterfaceImplementation (typeof (AnInterface));
1112
1113                         Type t = tb.CreateType ();
1114                         Assert.AreEqual (1, tb.GetInterfaces ().Length, "#2");
1115
1116                         // Can not be called on a created type
1117                         try {
1118                                 tb.AddInterfaceImplementation (typeof (AnInterface));
1119                                 Assert.Fail ("#3");
1120                         } catch (InvalidOperationException) {
1121                         }
1122                 }
1123
1124                 [Test]
1125                 public void TestCreateType_Created ()
1126                 {
1127                         TypeBuilder tb = module.DefineType (genTypeName ());
1128                         Assert.IsFalse (tb.IsCreated (), "#A1");
1129
1130                         Type emittedType1 = tb.CreateType ();
1131                         Assert.IsTrue (tb.IsCreated (), "#A2");
1132                         Assert.IsNotNull (emittedType1, "#A3");
1133
1134                         Type emittedType2 = tb.CreateType ();
1135                         Assert.IsNotNull (emittedType2, "#B1");
1136                         Assert.IsTrue (tb.IsCreated (), "#B2");
1137                         Assert.AreSame (emittedType1, emittedType2, "#B3");
1138                 }
1139
1140                 [Test]
1141                 public void TestDefineConstructor ()
1142                 {
1143                         TypeBuilder tb = module.DefineType (genTypeName ());
1144
1145                         ConstructorBuilder cb = tb.DefineConstructor (0, 0, null);
1146                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1147                         tb.CreateType ();
1148
1149                         // Can not be called on a created type
1150                         try {
1151                                 tb.DefineConstructor (0, 0, null);
1152                                 Assert.Fail ("#1");
1153                         } catch (InvalidOperationException ex) {
1154                                 // Unable to change after type has been created
1155                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1156                                 Assert.IsNull (ex.InnerException, "#3");
1157                                 Assert.IsNotNull (ex.Message, "#4");
1158                         }
1159                 }
1160
1161                 [Test]
1162                 public void DefineDefaultConstructor ()
1163                 {
1164                         TypeBuilder tb = module.DefineType (genTypeName ());
1165                         tb.DefineDefaultConstructor (0);
1166                         tb.CreateType ();
1167
1168                         // Can not be called on a created type, altough the MSDN docs does not mention this
1169                         try {
1170                                 tb.DefineDefaultConstructor (0);
1171                                 Assert.Fail ("#1");
1172                         } catch (InvalidOperationException ex) {
1173                                 // Unable to change after type has been created
1174                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1175                                 Assert.IsNull (ex.InnerException, "#3");
1176                                 Assert.IsNotNull (ex.Message, "#4");
1177                         }
1178                 }
1179
1180                 [Test]
1181                 public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1182                 {
1183                         TypeBuilder tb;
1184                         
1185                         tb = module.DefineType (genTypeName ());
1186                         tb.DefineDefaultConstructor (MethodAttributes.Private);
1187                         Type parent_type = tb.CreateType ();
1188
1189                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1190                                 parent_type);
1191                         tb.DefineDefaultConstructor (MethodAttributes.Public);
1192                         Type emitted_type = tb.CreateType ();
1193                         try {
1194                                 Activator.CreateInstance (emitted_type);
1195                                 Assert.Fail ("#1");
1196
1197                                 /* MOBILE special case MethodAccessException on reflection invokes and don't wrap them. */
1198 #if MOBILE
1199                         } catch (MethodAccessException mae) {
1200                                 Assert.IsNull (mae.InnerException, "#2");
1201                                 Assert.IsNotNull (mae.Message, "#3");
1202                                 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#4:" + mae.Message);
1203                                 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#4:" + mae.Message);
1204                         }
1205 #else
1206                         } catch (TargetInvocationException ex) {
1207                                 Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1208                                 Assert.IsNotNull (ex.InnerException, "#3");
1209                                 Assert.IsNotNull (ex.Message, "#4");
1210
1211                                 MethodAccessException mae = ex.InnerException as MethodAccessException;
1212                                 Assert.IsNotNull (mae, "#5");
1213                                 Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1214                                 Assert.IsNull (mae.InnerException, "#7");
1215                                 Assert.IsNotNull (mae.Message, "#8");
1216                                 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1217                                 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1218                         }
1219 #endif
1220                 }
1221
1222                 [Test]
1223                 public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1224                 {
1225                         TypeBuilder tb;
1226
1227                         tb = module.DefineType (genTypeName ());
1228                         ConstructorBuilder cb = tb.DefineConstructor (
1229                                 MethodAttributes.Public,
1230                                 CallingConventions.Standard,
1231                                 new Type [] { typeof (string) });
1232                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1233                         Type parent_type = tb.CreateType ();
1234
1235                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1236                                 parent_type);
1237                         try {
1238                                 tb.DefineDefaultConstructor (MethodAttributes.Public);
1239                                 Assert.Fail ("#1");
1240                         } catch (NotSupportedException ex) {
1241                                 // Parent does not have a default constructor.
1242                                 // The default constructor must be explicitly defined
1243                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1244                                 Assert.IsNull (ex.InnerException, "#3");
1245                                 Assert.IsNotNull (ex.Message, "#4");
1246                         }
1247                 }
1248
1249                 [Test]
1250                 public void DefineEvent_Name_NullChar ()
1251                 {
1252                         TypeBuilder tb = module.DefineType (genTypeName ());
1253
1254                         try {
1255                                 tb.DefineEvent ("\0test", EventAttributes.None,
1256                                         typeof (int));
1257                                 Assert.Fail ("#A1");
1258                         } catch (ArgumentException ex) {
1259                                 // Illegal name
1260                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1261                                 Assert.IsNull (ex.InnerException, "#A3");
1262                                 Assert.IsNotNull (ex.Message, "#A4");
1263                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1264                         }
1265
1266                         EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1267                                 typeof (int));
1268                         Assert.IsNotNull (eb, "#B1");
1269                 }
1270
1271                 [Test]
1272                 public void TestDefineEvent ()
1273                 {
1274                         TypeBuilder tb = module.DefineType (genTypeName ());
1275
1276                         // Test invalid arguments
1277                         try {
1278                                 tb.DefineEvent (null, 0, typeof (int));
1279                                 Assert.Fail ("#A1");
1280                         } catch (ArgumentNullException ex) {
1281                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1282                                 Assert.IsNull (ex.InnerException, "#A3");
1283                                 Assert.IsNotNull (ex.Message, "#A4");
1284                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1285                         }
1286
1287                         try {
1288                                 tb.DefineEvent ("FOO", 0, null);
1289                                 Assert.Fail ("#B1");
1290                         } catch (ArgumentNullException ex) {
1291                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1292                                 Assert.IsNull (ex.InnerException, "#B3");
1293                                 Assert.IsNotNull (ex.Message, "#B4");
1294                                 Assert.AreEqual ("type", ex.ParamName, "#B5");
1295                         }
1296
1297                         try {
1298                                 tb.DefineEvent (string.Empty, 0, typeof (int));
1299                                 Assert.Fail ("#C1");
1300                         } catch (ArgumentException ex) {
1301                                 // Empty name is not legal
1302                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1303                                 Assert.IsNull (ex.InnerException, "#C3");
1304                                 Assert.IsNotNull (ex.Message, "#C4");
1305                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1306                         }
1307
1308                         tb.CreateType ();
1309
1310                         // Can not be called on a created type
1311                         try {
1312                                 tb.DefineEvent ("BAR", 0, typeof (int));
1313                                 Assert.Fail ("#D1");
1314                         } catch (InvalidOperationException ex) {
1315                                 // Unable to change after type has been created
1316                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1317                                 Assert.IsNull (ex.InnerException, "#D3");
1318                                 Assert.IsNotNull (ex.Message, "#D4");
1319                         }
1320                 }
1321
1322                 [Test] // DefineField (String, Type, FieldAttributes)
1323                 public void DefineField1 ()
1324                 {
1325                         TypeBuilder tb = module.DefineType (genTypeName ());
1326
1327                         // Check invalid arguments
1328                         try {
1329                                 tb.DefineField (null, typeof (int), 0);
1330                                 Assert.Fail ("#A1");
1331                         } catch (ArgumentNullException ex) {
1332                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1333                                 Assert.IsNull (ex.InnerException, "#A3");
1334                                 Assert.IsNotNull (ex.Message, "#A4");
1335                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1336                         }
1337
1338                         try {
1339                                 tb.DefineField (string.Empty, typeof (int), 0);
1340                                 Assert.Fail ("#B1");
1341                         } catch (ArgumentException ex) {
1342                                 // Empty name is not legal
1343                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1344                                 Assert.IsNull (ex.InnerException, "#B3");
1345                                 Assert.IsNotNull (ex.Message, "#B4");
1346                                 Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1347                         }
1348
1349                         try {
1350                                 // Strangely, 'A<NULL>' is accepted...
1351                                 string name = String.Format ("{0}", (char) 0);
1352                                 tb.DefineField (name, typeof (int), 0);
1353                                 Assert.Fail ("#C1");
1354                         } catch (ArgumentException ex) {
1355                                 // Illegal name
1356                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1357                                 Assert.IsNull (ex.InnerException, "#C3");
1358                                 Assert.IsNotNull (ex.Message, "#C4");
1359                                 Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1360                         }
1361
1362                         try {
1363                                 tb.DefineField ("A", typeof (void), 0);
1364                                 Assert.Fail ("#D1");
1365                         } catch (ArgumentException ex) {
1366                                 // Bad field type in defining field
1367                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1368                                 Assert.IsNull (ex.InnerException, "#D3");
1369                                 Assert.IsNotNull (ex.Message, "#D4");
1370                                 Assert.IsNull (ex.ParamName, "#D5");
1371                         }
1372
1373                         tb.CreateType ();
1374
1375                         // Can not be called on a created type
1376                         try {
1377                                 tb.DefineField ("B", typeof (int), 0);
1378                                 Assert.Fail ("#E1");
1379                         } catch (InvalidOperationException ex) {
1380                                 // Unable to change after type has been created
1381                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1382                                 Assert.IsNull (ex.InnerException, "#E3");
1383                                 Assert.IsNotNull (ex.Message, "#E4");
1384                         }
1385                 }
1386
1387                 [Test] // DefineField (String, Type, FieldAttributes)
1388                 public void DefineField1_Name_NullChar ()
1389                 {
1390                         TypeBuilder tb = module.DefineType (genTypeName ());
1391
1392                         try {
1393                                 tb.DefineField ("\0test", typeof (int),
1394                                         FieldAttributes.Private);
1395                                 Assert.Fail ("#A1");
1396                         } catch (ArgumentException ex) {
1397                                 // Illegal name
1398                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1399                                 Assert.IsNull (ex.InnerException, "#A3");
1400                                 Assert.IsNotNull (ex.Message, "#A4");
1401                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1402                         }
1403
1404                         FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1405                                 FieldAttributes.Private);
1406                         Assert.IsNotNull (fb, "#B1");
1407                         Assert.AreEqual ("te\0st", fb.Name, "#B2");
1408                 }
1409
1410                 [Test] // DefineField (String, Type, FieldAttributes)
1411                 public void DefineField1_Type_Null ()
1412                 {
1413                         TypeBuilder tb = module.DefineType (genTypeName ());
1414
1415                         try {
1416                                 tb.DefineField ("test", (Type) null,
1417                                         FieldAttributes.Private);
1418                                 Assert.Fail ("#1");
1419                         } catch (ArgumentNullException ex) {
1420                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1421                                 Assert.IsNull (ex.InnerException, "#3");
1422                                 Assert.IsNotNull (ex.Message, "#4");
1423                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1424                         }
1425                 }
1426
1427                 [Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
1428                 public void DefineField2_Type_Null ()
1429                 {
1430                         TypeBuilder tb = module.DefineType (genTypeName ());
1431
1432                         try {
1433                                 tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1434                                         Type.EmptyTypes, FieldAttributes.Private);
1435                                 Assert.Fail ("#1");
1436                         } catch (ArgumentNullException ex) {
1437                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1438                                 Assert.IsNull (ex.InnerException, "#3");
1439                                 Assert.IsNotNull (ex.Message, "#4");
1440                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1441                         }
1442                 }
1443
1444                 [Test]
1445                 public void TestDefineInitializedData ()
1446                 {
1447                         TypeBuilder tb = module.DefineType (genTypeName ());
1448
1449                         // Check invalid arguments
1450                         try {
1451                                 tb.DefineInitializedData (null, new byte [1], 0);
1452                                 Assert.Fail ("#A1");
1453                         } catch (ArgumentNullException ex) {
1454                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1455                                 Assert.IsNull (ex.InnerException, "#A3");
1456                                 Assert.IsNotNull (ex.Message, "#A4");
1457                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1458                         }
1459
1460                         try {
1461                                 tb.DefineInitializedData ("FOO", null, 0);
1462                                 Assert.Fail ("#B1");
1463                         } catch (ArgumentNullException ex) {
1464                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1465                                 Assert.IsNull (ex.InnerException, "#B3");
1466                                 Assert.IsNotNull (ex.Message, "#B4");
1467                                 Assert.AreEqual ("data", ex.ParamName, "#B5");
1468                         }
1469
1470                         try {
1471                                 tb.DefineInitializedData (string.Empty, new byte [1], 0);
1472                                 Assert.Fail ("#C1");
1473                         } catch (ArgumentException ex) {
1474                                 // Empty name is not legal
1475                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1476                                 Assert.IsNull (ex.InnerException, "#C3");
1477                                 Assert.IsNotNull (ex.Message, "#C4");
1478                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1479                         }
1480
1481                         // The size of the data is less than or equal to zero ???
1482                         try {
1483                                 tb.DefineInitializedData ("BAR", new byte [0], 0);
1484                                 Assert.Fail ("#D1");
1485                         } catch (ArgumentException ex) {
1486                                 // Data size must be > 0 and < 0x3f0000
1487                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1488                                 Assert.IsNull (ex.InnerException, "#D3");
1489                                 Assert.IsNotNull (ex.Message, "#D4");
1490                                 Assert.IsNull (ex.ParamName, "#D5");
1491                         }
1492
1493                         try {
1494                                 string name = String.Format ("{0}", (char) 0);
1495                                 tb.DefineInitializedData (name, new byte [1], 0);
1496                                 Assert.Fail ("#E1");
1497                         } catch (ArgumentException ex) {
1498                                 // Illegal name
1499                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1500                                 Assert.IsNull (ex.InnerException, "#E3");
1501                                 Assert.IsNotNull (ex.Message, "#E4");
1502                                 Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1503                         }
1504
1505                         tb.CreateType ();
1506
1507                         // Can not be called on a created type, altough the MSDN docs does not mention this
1508                         try {
1509                                 tb.DefineInitializedData ("BAR2", new byte [1], 0);
1510                                 Assert.Fail ("#F1");
1511                         } catch (InvalidOperationException ex) {
1512                                 // Unable to change after type has been created
1513                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1514                                 Assert.IsNull (ex.InnerException, "#F3");
1515                                 Assert.IsNotNull (ex.Message, "#F4");
1516                         }
1517                 }
1518
1519                 [Test]
1520                 public void DefineUninitializedDataInvalidArgs ()
1521                 {
1522                         TypeBuilder tb = module.DefineType (genTypeName ());
1523
1524                         try {
1525                                 tb.DefineUninitializedData (null, 1, 0);
1526                                 Assert.Fail ("#A1");
1527                         } catch (ArgumentNullException ex) {
1528                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1529                                 Assert.IsNull (ex.InnerException, "#A3");
1530                                 Assert.IsNotNull (ex.Message, "#A4");
1531                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1532                         }
1533
1534                         try {
1535                                 tb.DefineUninitializedData (string.Empty, 1, 0);
1536                                 Assert.Fail ("#B1");
1537                         } catch (ArgumentException ex) {
1538                                 // Empty name is not legal
1539                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1540                                 Assert.IsNull (ex.InnerException, "#B3");
1541                                 Assert.IsNotNull (ex.Message, "#B4");
1542                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1543                         }
1544
1545                         // The size of the data is less than or equal to zero ???
1546                         try {
1547                                 tb.DefineUninitializedData ("BAR", 0, 0);
1548                                 Assert.Fail ("#C1");
1549                         } catch (ArgumentException ex) {
1550                                 // Data size must be > 0 and < 0x3f0000
1551                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1552                                 Assert.IsNull (ex.InnerException, "#C3");
1553                                 Assert.IsNotNull (ex.Message, "#C4");
1554                                 Assert.IsNull (ex.ParamName, "#C5");
1555                         }
1556
1557                         try {
1558                                 string name = String.Format ("{0}", (char) 0);
1559                                 tb.DefineUninitializedData (name, 1, 0);
1560                                 Assert.Fail ("#D1");
1561                         } catch (ArgumentException ex) {
1562                                 // Illegal name
1563                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1564                                 Assert.IsNull (ex.InnerException, "#D3");
1565                                 Assert.IsNotNull (ex.Message, "#D4");
1566                                 Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1567                         }
1568                 }
1569
1570                 [Test]
1571                 public void DefineUninitializedDataAlreadyCreated ()
1572                 {
1573                         TypeBuilder tb = module.DefineType (genTypeName ());
1574                         tb.CreateType ();
1575                         try {
1576                                 tb.DefineUninitializedData ("BAR2", 1, 0);
1577                                 Assert.Fail ("#1");
1578                         } catch (InvalidOperationException ex) {
1579                                 // Unable to change after type has been created
1580                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1581                                 Assert.IsNull (ex.InnerException, "#3");
1582                                 Assert.IsNotNull (ex.Message, "#4");
1583                         }
1584                 }
1585
1586                 [Test]
1587                 public void DefineUninitializedData ()
1588                 {
1589                         TypeBuilder tb = module.DefineType (genTypeName ());
1590
1591                         tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1592
1593                         Type t = tb.CreateType ();
1594
1595                         object o = Activator.CreateInstance (t);
1596
1597                         FieldInfo fi = t.GetField ("foo");
1598
1599                         object fieldVal = fi.GetValue (o);
1600
1601                         IntPtr ptr = Marshal.AllocHGlobal (4);
1602                         Marshal.StructureToPtr (fieldVal, ptr, true);
1603                         Marshal.FreeHGlobal (ptr);
1604                 }
1605
1606                 [Test]
1607                 public void DefineMethod_Name_NullChar ()
1608                 {
1609                         TypeBuilder tb = module.DefineType (genTypeName ());
1610                         try {
1611                                 tb.DefineMethod ("\0test", MethodAttributes.Private,
1612                                         typeof (string), Type.EmptyTypes);
1613                                 Assert.Fail ("#A1");
1614                         } catch (ArgumentException ex) {
1615                                 // Illegal name
1616                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1617                                 Assert.IsNull (ex.InnerException, "#A3");
1618                                 Assert.IsNotNull (ex.Message, "#A4");
1619                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1620                         }
1621
1622                         MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1623                                 typeof (string), Type.EmptyTypes);
1624                         Assert.IsNotNull (mb, "#B1");
1625                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1626                 }
1627
1628                 [Test]
1629                 public void TestDefineMethod ()
1630                 {
1631                         TypeBuilder tb = module.DefineType (genTypeName ());
1632
1633                         // Check invalid arguments
1634                         try {
1635                                 tb.DefineMethod (null, 0, null, null);
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.DefineMethod (string.Empty, 0, null, null);
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                         // Check non-virtual methods on an interface
1656                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1657                         try {
1658                                 tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1659                                 Assert.Fail ("#C1");
1660                         } catch (ArgumentException ex) {
1661                                 // Interface method must be abstract and virtual
1662                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1663                                 Assert.IsNull (ex.InnerException, "#C3");
1664                                 Assert.IsNotNull (ex.Message, "#C4");
1665                                 Assert.IsNull (ex.ParamName, "#C5");
1666                         }
1667
1668                         // Check static methods on an interface
1669                         tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1670                                                           typeof (void),
1671                                                           Type.EmptyTypes);
1672
1673                         tb.CreateType ();
1674                         // Can not be called on a created type
1675                         try {
1676                                 tb.DefineMethod ("bar", 0, null, null);
1677                                 Assert.Fail ("#D1");
1678                         } catch (InvalidOperationException ex) {
1679                                 // Unable to change after type has been created
1680                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1681                                 Assert.IsNull (ex.InnerException, "#D3");
1682                                 Assert.IsNotNull (ex.Message, "#D4");
1683                         }
1684                 }
1685
1686                 [Test] // bug #327484
1687                 [Category ("NotWorking")]
1688                 public void TestDefineMethod_Abstract ()
1689                 {
1690                         TypeBuilder tb = module.DefineType (genTypeName ());
1691                         tb.DefineMethod ("Run", MethodAttributes.Public |
1692                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1693                                 typeof (void), Type.EmptyTypes);
1694
1695                         try {
1696                                 tb.CreateType ();
1697                                 Assert.Fail ("#A1");
1698                         } catch (InvalidOperationException ex) {
1699                                 // Type must be declared abstract if any of its
1700                                 // methods are abstract
1701                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1702                                 Assert.IsNull (ex.InnerException, "#A3");
1703                                 Assert.IsNotNull (ex.Message, "#A4");
1704                         }
1705
1706                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1707                         tb.DefineMethod ("Run", MethodAttributes.Public |
1708                                 MethodAttributes.Abstract, typeof (void),
1709                                 Type.EmptyTypes);
1710
1711                         try {
1712                                 tb.CreateType ();
1713                                 Assert.Fail ("#B1");
1714                         } catch (TypeLoadException ex) {
1715                                 // Non-virtual abstract method
1716                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1717                                 Assert.IsNull (ex.InnerException, "#B3");
1718                                 Assert.IsNotNull (ex.Message, "#B4");
1719                         }
1720
1721                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1722                                 TypeAttributes.Public);
1723                         tb.DefineMethod ("Run", MethodAttributes.Public |
1724                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1725                                 typeof (void), Type.EmptyTypes);
1726                         Type emittedType = tb.CreateType ();
1727
1728                         MethodInfo mi1 = emittedType.GetMethod ("Run");
1729                         Assert.IsNotNull (mi1, "#C1");
1730                         Assert.IsTrue (mi1.IsAbstract, "#C2");
1731
1732                         MethodInfo mi2 = tb.GetMethod ("Run");
1733                         Assert.IsNotNull (mi2, "#D1");
1734                         Assert.IsTrue (mi2.IsAbstract, "#D2");
1735                 }
1736
1737                 // TODO: DefineMethodOverride
1738
1739                 [Test]
1740                 public void TestDefineNestedType ()
1741                 {
1742                         TypeBuilder tb = module.DefineType (genTypeName ());
1743
1744                         // Check invalid arguments
1745                         try {
1746                                 tb.DefineNestedType (null);
1747                                 Assert.Fail ("#A1");
1748                         } catch (ArgumentNullException ex) {
1749                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1750                                 Assert.IsNull (ex.InnerException, "#A3");
1751                                 Assert.IsNotNull (ex.Message, "#A4");
1752                                 Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1753                         }
1754
1755                         try {
1756                                 tb.DefineNestedType (string.Empty);
1757                                 Assert.Fail ("#B1");
1758                         } catch (ArgumentException ex) {
1759                                 // Empty name is not legal
1760                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1761                                 Assert.IsNull (ex.InnerException, "#B3");
1762                                 Assert.IsNotNull (ex.Message, "#B4");
1763                                 Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1764                         }
1765
1766                         try {
1767                                 tb.DefineNestedType (nullName ());
1768                                 Assert.Fail ("#C1");
1769                         } catch (ArgumentException ex) {
1770                                 // Illegal name
1771                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1772                                 Assert.IsNull (ex.InnerException, "#C3");
1773                                 Assert.IsNotNull (ex.Message, "#C4");
1774                                 Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1775                         }
1776
1777                         // If I fix the code so this works then mcs breaks -> how can mcs
1778                         // works under MS .NET in the first place ???
1779                         /*
1780                         try {
1781                                 tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1782                                 Fail ("Nested visibility must be specified.");
1783                         }
1784                         catch (ArgumentException) {
1785                         }
1786                         */
1787
1788                         try {
1789                                 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1790                                                                          new Type [1]);
1791                                 Assert.Fail ("#D1");
1792                         } catch (ArgumentNullException ex) {
1793                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1794                                 Assert.IsNull (ex.InnerException, "#D3");
1795                                 Assert.IsNotNull (ex.Message, "#D4");
1796                                 Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1797                         }
1798
1799                         // I think this should reject non-interfaces, but it does not
1800                         tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1801                                                                  new Type [1] { typeof (object) });
1802
1803                         // Normal invocation
1804                         tb.DefineNestedType ("Nest");
1805
1806                         tb.CreateType ();
1807
1808                         // According to the MSDN docs, this cannnot be called after the type
1809                         // is created, but it works.
1810                         tb.DefineNestedType ("Nest2");
1811
1812                         // According to the MSDN docs, a Sealed class can't contain nested 
1813                         // types, but this is not true
1814                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1815                         tb2.DefineNestedType ("AA");
1816
1817                         // According to the MSDN docs, interfaces can only contain interfaces,
1818                         // but this is not true
1819                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1820
1821                         tb3.DefineNestedType ("AA");
1822
1823                         // Check shorter versions
1824                         {
1825                                 TypeBuilder nested = tb.DefineNestedType ("N1");
1826
1827                                 Assert.AreEqual ("N1", nested.Name, "#E1");
1828                                 Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1829                                 Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1830                                 Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1831                         }
1832
1833                         // TODO:
1834                 }
1835
1836                 [Test]
1837                 public void NestedTypeSave () {
1838                         var tb = module.DefineType (genTypeName ());
1839
1840                         var tbuilder = tb.DefineNestedType ("Test.CodeGen", TypeAttributes.Public | TypeAttributes.Class);
1841                         var entryp = tbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), null);
1842                         var ilg = entryp.GetILGenerator (128);
1843                         ilg.Emit (OpCodes.Ldtoken, tb);
1844                         ilg.Emit (OpCodes.Pop);
1845                         ilg.Emit (OpCodes.Ret);
1846
1847                         tbuilder.CreateType ();
1848                         tb.CreateType ();
1849
1850                         assembly.Save (ASSEMBLY_NAME + ".dll");
1851                 }
1852
1853                 [Test]
1854                 public void DefinePInvokeMethod_Name_NullChar ()
1855                 {
1856                         TypeBuilder tb = module.DefineType (genTypeName ());
1857                         try {
1858                                 tb.DefinePInvokeMethod ("\0test", "B", "C",
1859                                         MethodAttributes.Private, CallingConventions.Standard,
1860                                         typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1861                                         CharSet.Unicode);
1862                                 Assert.Fail ("#A1");
1863                         } catch (ArgumentException ex) {
1864                                 // Illegal name
1865                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1866                                 Assert.IsNull (ex.InnerException, "#A3");
1867                                 Assert.IsNotNull (ex.Message, "#A4");
1868                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1869                         }
1870
1871                         MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1872                                 MethodAttributes.Private, CallingConventions.Standard,
1873                                 typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1874                                 CharSet.Unicode);
1875                         Assert.IsNotNull (mb, "#B1");
1876                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1877                 }
1878
1879                 [Test]
1880                 public void TestDefinePInvokeMethod ()
1881                 {
1882                         TypeBuilder tb = module.DefineType (genTypeName ());
1883
1884                         tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1885
1886                         // Try invalid parameters
1887                         try {
1888                                 tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1889                                 Assert.Fail ("#A1");
1890                         } catch (ArgumentNullException ex) {
1891                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1892                                 Assert.IsNull (ex.InnerException, "#A3");
1893                                 Assert.IsNotNull (ex.Message, "#A4");
1894                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1895                         }
1896                         // etc...
1897
1898                         // Try invalid attributes
1899                         try {
1900                                 tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1901                                 Assert.Fail ("#B1");
1902                         } catch (ArgumentException ex) {
1903                                 // PInvoke methods must be static and native and
1904                                 // cannot be abstract
1905                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1906                                 Assert.IsNull (ex.InnerException, "#B3");
1907                                 Assert.IsNotNull (ex.Message, "#B4");
1908                                 Assert.IsNull (ex.ParamName, "#B5");
1909                         }
1910
1911                         // Try an interface parent
1912                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1913
1914                         try {
1915                                 tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1916                                 Assert.Fail ("#C1");
1917                         } catch (ArgumentException ex) {
1918                                 // PInvoke methods cannot exist on interfaces
1919                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1920                                 Assert.IsNull (ex.InnerException, "#B3");
1921                                 Assert.IsNotNull (ex.Message, "#B4");
1922                                 Assert.IsNull (ex.ParamName, "#B5");
1923                         }
1924                 }
1925
1926                 [Test]
1927                 public void DefineProperty_Name_NullChar ()
1928                 {
1929                         TypeBuilder tb = module.DefineType (genTypeName ());
1930
1931                         try {
1932                                 tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
1933                                 Assert.Fail ("#A1");
1934                         } catch (ArgumentException ex) {
1935                                 // Illegal name
1936                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1937                                 Assert.IsNull (ex.InnerException, "#A3");
1938                                 Assert.IsNotNull (ex.Message, "#A4");
1939                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1940                         }
1941
1942                         PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
1943                                 typeof (string), Type.EmptyTypes); 
1944                         Assert.IsNotNull (pb, "#B1");
1945                         Assert.AreEqual ("te\0st", pb.Name, "#B2");
1946                 }
1947
1948                 [Test]
1949                 public void DefineProperty_ParameterTypes_ItemNull ()
1950                 {
1951                         TypeBuilder tb = module.DefineType (genTypeName ());
1952
1953                         try {
1954                                 tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
1955                                 Assert.Fail ("#1");
1956                         } catch (ArgumentNullException ex) {
1957                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1958                                 Assert.IsNull (ex.InnerException, "#3");
1959                                 Assert.IsNotNull (ex.Message, "#4");
1960                         }
1961                 }
1962
1963                 [Test]
1964                 public void DefineProperty_ReturnType_Null ()
1965                 {
1966                         TypeBuilder tb = module.DefineType (genTypeName ());
1967                         tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
1968                 }
1969
1970                 [Test]
1971                 public void GetMethod_WorksWithTypeBuilderParameter () {
1972                         TypeBuilder tb = module.DefineType (genTypeName ());
1973                         var garg = tb.DefineGenericParameters ("T") [0];
1974                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
1975                 
1976                         var mi = TypeBuilder.GetMethod (tb, mb);
1977                         var decl = mi.DeclaringType;
1978
1979                         Assert.IsTrue (decl.IsGenericType, "#1");
1980                         Assert.IsFalse (decl.IsGenericTypeDefinition, "#2");
1981                         Assert.AreEqual (tb, decl.GetGenericTypeDefinition (), "#3");
1982                         Assert.AreEqual (garg, decl.GetGenericArguments () [0], "#4");
1983                 }
1984
1985                 [Test]
1986                 public void GetConstructor_FailWithTypeBuilderParameter () {
1987                         TypeBuilder tb = module.DefineType (genTypeName ());
1988                         var garg = tb.DefineGenericParameters ("T") [0];
1989                         var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
1990
1991                         try {
1992                                 TypeBuilder.GetConstructor (tb, cb);
1993                                 Assert.Fail ("#1");
1994                         } catch (ArgumentException ex) {
1995                                 Assert.AreEqual ("type", ex.ParamName, "#2");
1996                         }
1997                 }
1998
1999                 [Test]
2000                 public void GetField_FailWithTypeBuilderParameter () {
2001                         TypeBuilder tb = module.DefineType (genTypeName ());
2002                         var garg = tb.DefineGenericParameters ("T") [0];
2003                         var fb = tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
2004
2005                         try {
2006                                 TypeBuilder.GetField (tb, fb);
2007                                 Assert.Fail ("#1");
2008                         } catch (ArgumentException ex) {
2009                                 Assert.AreEqual ("type", ex.ParamName, "#2");
2010                         }
2011                 }
2012
2013                 [Test]
2014                 public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
2015                         TypeBuilder tb = module.DefineType (genTypeName ());
2016                         tb.DefineGenericParameters ("T");
2017                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2018
2019                         Type ginst = tb.MakeGenericType (typeof (int));
2020                         
2021                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2022                         try {
2023                                 TypeBuilder.GetMethod (ginst, mi);
2024                                 Assert.Fail ("#1");
2025                         } catch (ArgumentException ex) {
2026                                 Assert.AreEqual ("method", ex.ParamName, "#5");
2027                         }
2028                 }
2029
2030                 [Test]
2031                 public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2032                         TypeBuilder tb = module.DefineType (genTypeName ());
2033                         tb.DefineGenericParameters ("T");
2034                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2035                         ILGenerator ig = mb.GetILGenerator ();
2036                         ig.Emit (OpCodes.Ret);
2037                         
2038                         tb.CreateType ();
2039                         
2040                         MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2041                         Assert.IsNotNull (mi);
2042                 }
2043
2044                 [Test]
2045                 [Category ("NotDotNet")]
2046                 [Category ("NotWorking")]
2047                 public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2048                         AssemblyName assemblyName = new AssemblyName ();
2049                         assemblyName.Name = ASSEMBLY_NAME;
2050
2051                         assembly =
2052                                 Thread.GetDomain ().DefineDynamicAssembly (
2053                                         assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, tempDir);
2054
2055                         module = assembly.DefineDynamicModule ("module1");
2056                         
2057                         TypeBuilder tb = module.DefineType (genTypeName ());
2058                         tb.DefineGenericParameters ("T");
2059                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2060
2061                         Type ginst = tb.MakeGenericType (typeof (int));
2062                         
2063                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2064
2065                         try {
2066                                 TypeBuilder.GetMethod (ginst, mi);
2067                         } catch (ArgumentException ex) {
2068                                 Assert.Fail ("#1");
2069                         }
2070                 }
2071
2072
2073                 [Test]
2074                 // Test that changes made to the method builder after a call to GetMethod ()
2075                 // are visible
2076                 public void TestGetMethod ()
2077                 {
2078                         TypeBuilder tb = module.DefineType (genTypeName ());
2079                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2080
2081                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2082                         ILGenerator ig;
2083                         ig = cb.GetILGenerator ();
2084                         ig.Emit (OpCodes.Ret);
2085
2086                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2087
2088                         // Create a method builder but do not emit IL yet
2089                         MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2090
2091                         Type t = tb.MakeGenericType (typeof (int));
2092
2093                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2094
2095                         ig = mb.GetILGenerator ();
2096                         ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2097                         ig.Emit (OpCodes.Ret);
2098
2099                         // Finish the method
2100                         ig = mb1.GetILGenerator ();
2101                         ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2102                         ig.Emit (OpCodes.Ret);
2103
2104                         Type t2 = tb.CreateType ();
2105
2106                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2107                 }
2108
2109                 [Test]
2110                 public void TestGetConstructor ()
2111                 {
2112                         TypeBuilder tb = module.DefineType (genTypeName ());
2113                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2114
2115                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2116                         ILGenerator ig;
2117
2118                         Type t = tb.MakeGenericType (typeof (int));
2119
2120                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2121
2122                         ig = mb.GetILGenerator ();
2123
2124                         ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2125                         
2126                         ig.Emit (OpCodes.Newobj, ci);
2127                         ig.Emit (OpCodes.Ret);
2128
2129                         // Finish the ctorbuilder
2130                         ig = cb.GetILGenerator ();
2131                         ig.Emit(OpCodes.Ldarg_0);
2132                         ig.Emit(OpCodes.Call, tb.BaseType.GetConstructor(Type.EmptyTypes));             
2133                         ig.Emit (OpCodes.Ret);
2134
2135                         Type t2 = tb.CreateType ();
2136
2137                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2138                 }
2139
2140                 [Test]
2141                 [ExpectedException (typeof (ArgumentException))]
2142                 public void Static_GetConstructor_TypeNull ()
2143                 {
2144                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2145                         // null is non-generic (from exception message)
2146                         TypeBuilder.GetConstructor (null, ci);
2147                 }
2148
2149                 [Test]
2150                 [ExpectedException (typeof (ArgumentException))]
2151                 public void Static_GetConstructor_TypeGeneric ()
2152                 {
2153                         Type t = typeof (List<>).MakeGenericType (typeof (int));
2154                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2155                         // type is not 'TypeBuilder' (from exception message)
2156                         TypeBuilder.GetConstructor (t, ci);
2157                 }
2158
2159                 [Test]
2160                 public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
2161                 {
2162                         TypeBuilder tb = module.DefineType ("XXX");
2163                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2164                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2165                         try {
2166                                 TypeBuilder.GetConstructor (fooOfT, null);
2167                                 Assert.Fail ("Expected NullReferenceException");
2168                         }
2169                         catch (NullReferenceException) {
2170                         }
2171                 }
2172
2173                 [Test] //#536243
2174                 public void CreateTypeThrowsForMethodsWithBadLabels ()
2175                 {
2176                         TypeBuilder tb = module.DefineType (genTypeName ());
2177
2178                         MethodBuilder mb = tb.DefineMethod("F", MethodAttributes.Public, typeof(string), null);
2179                         ILGenerator il_gen = mb.GetILGenerator ();
2180                         il_gen.DefineLabel ();
2181                         il_gen.Emit (OpCodes.Leave, new Label ());
2182                         try {
2183                                 tb.CreateType ();
2184                                 Assert.Fail ();
2185                         } catch (ArgumentException) {}
2186                 }
2187
2188                 [Test]
2189                 [Category ("NotWorking")]
2190                 public void TestIsDefinedIncomplete ()
2191                 {
2192                         TypeBuilder tb = module.DefineType (genTypeName ());
2193                         try {
2194                                 tb.IsDefined (typeof (int), true);
2195                                 Assert.Fail ("#1");
2196                         } catch (NotSupportedException ex) {
2197                                 // The invoked member is not supported in a
2198                                 // dynamic module
2199                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2200                                 Assert.IsNull (ex.InnerException, "#3");
2201                                 Assert.IsNotNull (ex.Message, "#4");
2202                         }
2203                 }
2204
2205                 [Test]
2206                 public void TestIsDefinedComplete ()
2207                 {
2208                         TypeBuilder tb = module.DefineType (genTypeName ());
2209
2210                         ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2211                                 new Type [] { typeof (string) });
2212
2213                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2214                                 new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2215
2216                         tb.SetCustomAttribute (caBuilder);
2217                         tb.CreateType ();
2218                         Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2219                 }
2220
2221                 [Test]
2222                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
2223                 public void IsDefined_AttributeType_Null ()
2224                 {
2225                         TypeBuilder tb = module.DefineType (genTypeName ());
2226                         tb.CreateType ();
2227
2228                         try {
2229                                 tb.IsDefined ((Type) null, false);
2230                                 Assert.Fail ("#1");
2231                         } catch (ArgumentNullException ex) {
2232                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2233                                 Assert.IsNull (ex.InnerException, "#3");
2234                                 Assert.IsNotNull (ex.Message, "#4");
2235                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2236                         }
2237                 }
2238
2239                 [Test] // GetConstructor (Type [])
2240                 public void GetConstructor1_Incomplete ()
2241                 {
2242                         TypeBuilder tb = module.DefineType (genTypeName ());
2243                         ConstructorBuilder cb = tb.DefineConstructor (
2244                                 MethodAttributes.Public,
2245                                 CallingConventions.Standard,
2246                                 Type.EmptyTypes);
2247                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2248
2249                         try {
2250                                 tb.GetConstructor (Type.EmptyTypes);
2251                                 Assert.Fail ("#1");
2252                         } catch (NotSupportedException ex) {
2253                                 // The invoked member is not supported in a
2254                                 // dynamic module
2255                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2256                                 Assert.IsNull (ex.InnerException, "#3");
2257                                 Assert.IsNotNull (ex.Message, "#4");
2258                         }
2259                 }
2260
2261                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2262                 public void GetConstructor2_Complete ()
2263                 {
2264                         BindingFlags flags;
2265                         ConstructorInfo ctor;
2266
2267                         TypeBuilder redType = module.DefineType (genTypeName (),
2268                                 TypeAttributes.Public);
2269                         CreateMembers (redType, "Red", true);
2270
2271                         TypeBuilder greenType = module.DefineType (genTypeName (),
2272                                 TypeAttributes.Public, redType);
2273                         CreateMembers (greenType, "Green", false);
2274                         ConstructorBuilder cb = greenType.DefineConstructor (
2275                                 MethodAttributes.Public,
2276                                 CallingConventions.Standard,
2277                                 Type.EmptyTypes);
2278                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2279
2280                         redType.CreateType ();
2281                         greenType.CreateType ();
2282
2283                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
2284
2285                         ctor = greenType.GetConstructor (flags, null,
2286                                 new Type [] { typeof (int), typeof (int) },
2287                                 new ParameterModifier [0]);
2288                         Assert.IsNull (ctor, "#A1");
2289
2290                         ctor = greenType.GetConstructor (flags, null,
2291                                 new Type [] { typeof (string) },
2292                                 new ParameterModifier [0]);
2293                         Assert.IsNull (ctor, "#A2");
2294
2295                         ctor = greenType.GetConstructor (flags, null,
2296                                 new Type [] { typeof (string), typeof (string) },
2297                                 new ParameterModifier [0]);
2298                         Assert.IsNull (ctor, "#A3");
2299
2300                         ctor = greenType.GetConstructor (flags, null,
2301                                 new Type [] { typeof (int) },
2302                                 new ParameterModifier [0]);
2303                         Assert.IsNull (ctor, "#A4");
2304
2305                         ctor = greenType.GetConstructor (flags, null,
2306                                 new Type [] { typeof (int), typeof (bool) },
2307                                 new ParameterModifier [0]);
2308                         Assert.IsNull (ctor, "#A5");
2309
2310                         ctor = greenType.GetConstructor (flags, null,
2311                                 new Type [] { typeof (string), typeof (int) },
2312                                 new ParameterModifier [0]);
2313                         Assert.IsNull (ctor, "#A6");
2314
2315                         ctor = greenType.GetConstructor (flags, null,
2316                                 Type.EmptyTypes,
2317                                 new ParameterModifier [0]);
2318                         Assert.IsNull (ctor, "#A7");
2319
2320                         ctor = redType.GetConstructor (flags, null,
2321                                 new Type [] { typeof (int), typeof (int) },
2322                                 new ParameterModifier [0]);
2323                         Assert.IsNotNull (ctor, "#A8a");
2324                         Assert.IsTrue (ctor.IsPrivate, "#A8b");
2325                         Assert.IsFalse (ctor.IsStatic, "#A8c");
2326                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2327                         Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2328
2329                         ctor = redType.GetConstructor (flags, null,
2330                                 new Type [] { typeof (string) },
2331                                 new ParameterModifier [0]);
2332                         Assert.IsNotNull (ctor, "#A9a");
2333                         Assert.IsTrue (ctor.IsFamily, "#A9b");
2334                         Assert.IsFalse (ctor.IsStatic, "#A9c");
2335                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2336                         Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2337
2338                         ctor = redType.GetConstructor (flags, null,
2339                                 new Type [] { typeof (string), typeof (string) },
2340                                 new ParameterModifier [0]);
2341                         Assert.IsNotNull (ctor, "#A10a");
2342                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2343                         Assert.IsFalse (ctor.IsStatic, "#A10c");
2344                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2345                         Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2346
2347                         ctor = redType.GetConstructor (flags, null,
2348                                 new Type [] { typeof (int) },
2349                                 new ParameterModifier [0]);
2350                         Assert.IsNotNull (ctor, "#A11a");
2351                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2352                         Assert.IsFalse (ctor.IsStatic, "#A11c");
2353                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2354                         Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2355
2356                         ctor = redType.GetConstructor (flags, null,
2357                                 new Type [] { typeof (int), typeof (bool) },
2358                                 new ParameterModifier [0]);
2359                         Assert.IsNull (ctor, "#A12");
2360
2361                         ctor = redType.GetConstructor (flags, null,
2362                                 new Type [] { typeof (string), typeof (int) },
2363                                 new ParameterModifier [0]);
2364                         Assert.IsNotNull (ctor, "#A13a");
2365                         Assert.IsTrue (ctor.IsAssembly, "#A13b");
2366                         Assert.IsFalse (ctor.IsStatic, "#A13c");
2367                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2368                         Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2369
2370                         ctor = redType.GetConstructor (flags, null,
2371                                 Type.EmptyTypes,
2372                                 new ParameterModifier [0]);
2373                         Assert.IsNull (ctor, "#A14");
2374
2375                         flags = BindingFlags.Instance | BindingFlags.Public;
2376
2377                         ctor = greenType.GetConstructor (flags, null,
2378                                 new Type [] { typeof (int), typeof (int) },
2379                                 new ParameterModifier [0]);
2380                         Assert.IsNull (ctor, "#B1");
2381
2382                         ctor = greenType.GetConstructor (flags, null,
2383                                 new Type [] { typeof (string) },
2384                                 new ParameterModifier [0]);
2385                         Assert.IsNull (ctor, "#B2");
2386
2387                         ctor = greenType.GetConstructor (flags, null,
2388                                 new Type [] { typeof (string), typeof (string) },
2389                                 new ParameterModifier [0]);
2390                         Assert.IsNull (ctor, "#B3");
2391
2392                         ctor = greenType.GetConstructor (flags, null,
2393                                 new Type [] { typeof (int) },
2394                                 new ParameterModifier [0]);
2395                         Assert.IsNull (ctor, "#B4");
2396
2397                         ctor = greenType.GetConstructor (flags, null,
2398                                 new Type [] { typeof (int), typeof (bool) },
2399                                 new ParameterModifier [0]);
2400                         Assert.IsNull (ctor, "#B5");
2401
2402                         ctor = greenType.GetConstructor (flags, null,
2403                                 new Type [] { typeof (string), typeof (int) },
2404                                 new ParameterModifier [0]);
2405                         Assert.IsNull (ctor, "#B6");
2406
2407                         ctor = greenType.GetConstructor (flags, null,
2408                                 Type.EmptyTypes,
2409                                 new ParameterModifier [0]);
2410                         Assert.IsNotNull (ctor, "#B7a");
2411                         Assert.IsTrue (ctor.IsPublic, "#B7b");
2412                         Assert.IsFalse (ctor.IsStatic, "#B7c");
2413                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2414                         Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2415
2416                         ctor = redType.GetConstructor (flags, null,
2417                                 new Type [] { typeof (int), typeof (int) },
2418                                 new ParameterModifier [0]);
2419                         Assert.IsNull (ctor, "#B8");
2420
2421                         ctor = redType.GetConstructor (flags, null,
2422                                 new Type [] { typeof (string) },
2423                                 new ParameterModifier [0]);
2424                         Assert.IsNull (ctor, "#B9");
2425
2426                         ctor = redType.GetConstructor (flags, null,
2427                                 new Type [] { typeof (string), typeof (string) },
2428                                 new ParameterModifier [0]);
2429                         Assert.IsNull (ctor, "#B10");
2430
2431                         ctor = redType.GetConstructor (flags, null,
2432                                 new Type [] { typeof (int) },
2433                                 new ParameterModifier [0]);
2434                         Assert.IsNull (ctor, "#B11");
2435
2436                         ctor = redType.GetConstructor (flags, null,
2437                                 new Type [] { typeof (int), typeof (bool) },
2438                                 new ParameterModifier [0]);
2439                         Assert.IsNotNull (ctor, "#B12a");
2440                         Assert.IsTrue (ctor.IsPublic, "#B12b");
2441                         Assert.IsFalse (ctor.IsStatic, "#B12c");
2442                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2443                         Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2444
2445                         ctor = redType.GetConstructor (flags, null,
2446                                 new Type [] { typeof (string), typeof (int) },
2447                                 new ParameterModifier [0]);
2448                         Assert.IsNull (ctor, "#B13");
2449
2450                         ctor = redType.GetConstructor (flags, null,
2451                                 Type.EmptyTypes,
2452                                 new ParameterModifier [0]);
2453                         Assert.IsNull (ctor, "#B14");
2454
2455                         flags = BindingFlags.Static | BindingFlags.Public;
2456
2457                         ctor = greenType.GetConstructor (flags, null,
2458                                 new Type [] { typeof (int), typeof (int) },
2459                                 new ParameterModifier [0]);
2460                         Assert.IsNull (ctor, "#C1");
2461
2462                         ctor = greenType.GetConstructor (flags, null,
2463                                 new Type [] { typeof (string) },
2464                                 new ParameterModifier [0]);
2465                         Assert.IsNull (ctor, "#C2");
2466
2467                         ctor = greenType.GetConstructor (flags, null,
2468                                 new Type [] { typeof (string), typeof (string) },
2469                                 new ParameterModifier [0]);
2470                         Assert.IsNull (ctor, "#C3");
2471
2472                         ctor = greenType.GetConstructor (flags, null,
2473                                 new Type [] { typeof (int) },
2474                                 new ParameterModifier [0]);
2475                         Assert.IsNull (ctor, "#C4");
2476
2477                         ctor = greenType.GetConstructor (flags, null,
2478                                 new Type [] { typeof (int), typeof (bool) },
2479                                 new ParameterModifier [0]);
2480                         Assert.IsNull (ctor, "#C5");
2481
2482                         ctor = greenType.GetConstructor (flags, null,
2483                                 new Type [] { typeof (string), typeof (int) },
2484                                 new ParameterModifier [0]);
2485                         Assert.IsNull (ctor, "#C6");
2486
2487                         ctor = greenType.GetConstructor (flags, null,
2488                                 Type.EmptyTypes,
2489                                 new ParameterModifier [0]);
2490                         Assert.IsNull (ctor, "#C7");
2491
2492                         ctor = redType.GetConstructor (flags, null,
2493                                 new Type [] { typeof (int), typeof (int) },
2494                                 new ParameterModifier [0]);
2495                         Assert.IsNull (ctor, "#C8");
2496
2497                         ctor = redType.GetConstructor (flags, null,
2498                                 new Type [] { typeof (string) },
2499                                 new ParameterModifier [0]);
2500                         Assert.IsNull (ctor, "#C9");
2501
2502                         ctor = redType.GetConstructor (flags, null,
2503                                 new Type [] { typeof (string), typeof (string) },
2504                                 new ParameterModifier [0]);
2505                         Assert.IsNull (ctor, "#C10");
2506
2507                         ctor = redType.GetConstructor (flags, null,
2508                                 new Type [] { typeof (int) },
2509                                 new ParameterModifier [0]);
2510                         Assert.IsNull (ctor, "#C11a");
2511
2512                         ctor = redType.GetConstructor (flags, null,
2513                                 new Type [] { typeof (int), typeof (bool) },
2514                                 new ParameterModifier [0]);
2515                         Assert.IsNull (ctor, "#C12");
2516
2517                         ctor = redType.GetConstructor (flags, null,
2518                                 new Type [] { typeof (string), typeof (int) },
2519                                 new ParameterModifier [0]);
2520                         Assert.IsNull (ctor, "#C13");
2521
2522                         ctor = redType.GetConstructor (flags, null,
2523                                 Type.EmptyTypes,
2524                                 new ParameterModifier [0]);
2525                         Assert.IsNull (ctor, "#C14");
2526
2527                         flags = BindingFlags.Static | BindingFlags.NonPublic;
2528
2529                         ctor = greenType.GetConstructor (flags, null,
2530                                 new Type [] { typeof (int), typeof (int) },
2531                                 new ParameterModifier [0]);
2532                         Assert.IsNull (ctor, "#D1");
2533
2534                         ctor = greenType.GetConstructor (flags, null,
2535                                 new Type [] { typeof (string) },
2536                                 new ParameterModifier [0]);
2537                         Assert.IsNull (ctor, "#D2");
2538
2539                         ctor = greenType.GetConstructor (flags, null,
2540                                 new Type [] { typeof (string), typeof (string) },
2541                                 new ParameterModifier [0]);
2542                         Assert.IsNull (ctor, "#D3");
2543
2544                         ctor = greenType.GetConstructor (flags, null,
2545                                 new Type [] { typeof (int) },
2546                                 new ParameterModifier [0]);
2547                         Assert.IsNull (ctor, "#D4");
2548
2549                         ctor = greenType.GetConstructor (flags, null,
2550                                 new Type [] { typeof (int), typeof (bool) },
2551                                 new ParameterModifier [0]);
2552                         Assert.IsNull (ctor, "#D5");
2553
2554                         ctor = greenType.GetConstructor (flags, null,
2555                                 new Type [] { typeof (string), typeof (int) },
2556                                 new ParameterModifier [0]);
2557                         Assert.IsNull (ctor, "#D6");
2558
2559                         ctor = greenType.GetConstructor (flags, null,
2560                                 Type.EmptyTypes,
2561                                 new ParameterModifier [0]);
2562                         Assert.IsNull (ctor, "#D7");
2563
2564                         ctor = redType.GetConstructor (flags, null,
2565                                 new Type [] { typeof (int), typeof (int) },
2566                                 new ParameterModifier [0]);
2567                         Assert.IsNull (ctor, "#D8");
2568
2569                         ctor = redType.GetConstructor (flags, null,
2570                                 new Type [] { typeof (string) },
2571                                 new ParameterModifier [0]);
2572                         Assert.IsNull (ctor, "#D9");
2573
2574                         ctor = redType.GetConstructor (flags, null,
2575                                 new Type [] { typeof (string), typeof (string) },
2576                                 new ParameterModifier [0]);
2577                         Assert.IsNull (ctor, "#D10");
2578
2579                         ctor = redType.GetConstructor (flags, null,
2580                                 new Type [] { typeof (int) },
2581                                 new ParameterModifier [0]);
2582                         Assert.IsNull (ctor, "#D11");
2583
2584                         ctor = redType.GetConstructor (flags, null,
2585                                 new Type [] { typeof (int), typeof (bool) },
2586                                 new ParameterModifier [0]);
2587                         Assert.IsNull (ctor, "#D12");
2588
2589                         ctor = redType.GetConstructor (flags, null,
2590                                 new Type [] { typeof (string), typeof (int) },
2591                                 new ParameterModifier [0]);
2592                         Assert.IsNull (ctor, "#D13");
2593
2594                         ctor = redType.GetConstructor (flags, null,
2595                                 Type.EmptyTypes,
2596                                 new ParameterModifier [0]);
2597                         Assert.IsNotNull (ctor, "#D14a");
2598                         Assert.IsTrue (ctor.IsPrivate, "#D14b");
2599                         Assert.IsTrue (ctor.IsStatic, "#B14c");
2600                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2601                         Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2602
2603                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2604                                 BindingFlags.FlattenHierarchy;
2605
2606                         ctor = greenType.GetConstructor (flags, null,
2607                                 new Type [] { typeof (int), typeof (int) },
2608                                 new ParameterModifier [0]);
2609                         Assert.IsNull (ctor, "#E1");
2610
2611                         ctor = greenType.GetConstructor (flags, null,
2612                                 new Type [] { typeof (string) },
2613                                 new ParameterModifier [0]);
2614                         Assert.IsNull (ctor, "#E2");
2615
2616                         ctor = greenType.GetConstructor (flags, null,
2617                                 new Type [] { typeof (string), typeof (string) },
2618                                 new ParameterModifier [0]);
2619                         Assert.IsNull (ctor, "#E3");
2620
2621                         ctor = greenType.GetConstructor (flags, null,
2622                                 new Type [] { typeof (int) },
2623                                 new ParameterModifier [0]);
2624                         Assert.IsNull (ctor, "#E4");
2625
2626                         ctor = greenType.GetConstructor (flags, null,
2627                                 new Type [] { typeof (int), typeof (bool) },
2628                                 new ParameterModifier [0]);
2629                         Assert.IsNull (ctor, "#E5");
2630
2631                         ctor = greenType.GetConstructor (flags, null,
2632                                 new Type [] { typeof (string), typeof (int) },
2633                                 new ParameterModifier [0]);
2634                         Assert.IsNull (ctor, "#E6");
2635
2636                         ctor = greenType.GetConstructor (flags, null,
2637                                 Type.EmptyTypes,
2638                                 new ParameterModifier [0]);
2639                         Assert.IsNull (ctor, "#E7");
2640
2641                         ctor = redType.GetConstructor (flags, null,
2642                                 new Type [] { typeof (int), typeof (int) },
2643                                 new ParameterModifier [0]);
2644                         Assert.IsNotNull (ctor, "#E8a");
2645                         Assert.IsTrue (ctor.IsPrivate, "#E8b");
2646                         Assert.IsFalse (ctor.IsStatic, "#E8c");
2647                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2648                         Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2649
2650                         ctor = redType.GetConstructor (flags, null,
2651                                 new Type [] { typeof (string) },
2652                                 new ParameterModifier [0]);
2653                         Assert.IsNotNull (ctor, "#E9a");
2654                         Assert.IsTrue (ctor.IsFamily, "#E9b");
2655                         Assert.IsFalse (ctor.IsStatic, "#E9c");
2656                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2657                         Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2658
2659                         ctor = redType.GetConstructor (flags, null,
2660                                 new Type [] { typeof (string), typeof (string) },
2661                                 new ParameterModifier [0]);
2662                         Assert.IsNotNull (ctor, "#E10a");
2663                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2664                         Assert.IsFalse (ctor.IsStatic, "#E10c");
2665                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2666                         Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2667
2668                         ctor = redType.GetConstructor (flags, null,
2669                                 new Type [] { typeof (int) },
2670                                 new ParameterModifier [0]);
2671                         Assert.IsNotNull (ctor, "#E11a");
2672                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2673                         Assert.IsFalse (ctor.IsStatic, "#E11c");
2674                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2675                         Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2676
2677                         ctor = redType.GetConstructor (flags, null,
2678                                 new Type [] { typeof (int), typeof (bool) },
2679                                 new ParameterModifier [0]);
2680                         Assert.IsNull (ctor, "#E12");
2681
2682                         ctor = redType.GetConstructor (flags, null,
2683                                 new Type [] { typeof (string), typeof (int) },
2684                                 new ParameterModifier [0]);
2685                         Assert.IsNotNull (ctor, "#E13a");
2686                         Assert.IsTrue (ctor.IsAssembly, "#E13b");
2687                         Assert.IsFalse (ctor.IsStatic, "#E13c");
2688                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2689                         Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2690
2691                         ctor = redType.GetConstructor (flags, null,
2692                                 Type.EmptyTypes,
2693                                 new ParameterModifier [0]);
2694                         Assert.IsNull (ctor, "#E14");
2695
2696                         flags = BindingFlags.Instance | BindingFlags.Public |
2697                                 BindingFlags.FlattenHierarchy;
2698
2699                         ctor = greenType.GetConstructor (flags, null,
2700                                 new Type [] { typeof (int), typeof (int) },
2701                                 new ParameterModifier [0]);
2702                         Assert.IsNull (ctor, "#F1");
2703
2704                         ctor = greenType.GetConstructor (flags, null,
2705                                 new Type [] { typeof (string) },
2706                                 new ParameterModifier [0]);
2707                         Assert.IsNull (ctor, "#F2");
2708
2709                         ctor = greenType.GetConstructor (flags, null,
2710                                 new Type [] { typeof (string), typeof (string) },
2711                                 new ParameterModifier [0]);
2712                         Assert.IsNull (ctor, "#F3");
2713
2714                         ctor = greenType.GetConstructor (flags, null,
2715                                 new Type [] { typeof (int) },
2716                                 new ParameterModifier [0]);
2717                         Assert.IsNull (ctor, "#F4");
2718
2719                         ctor = greenType.GetConstructor (flags, null,
2720                                 new Type [] { typeof (int), typeof (bool) },
2721                                 new ParameterModifier [0]);
2722                         Assert.IsNull (ctor, "#F5");
2723
2724                         ctor = greenType.GetConstructor (flags, null,
2725                                 new Type [] { typeof (string), typeof (int) },
2726                                 new ParameterModifier [0]);
2727                         Assert.IsNull (ctor, "#F6");
2728
2729                         ctor = greenType.GetConstructor (flags, null,
2730                                 Type.EmptyTypes,
2731                                 new ParameterModifier [0]);
2732                         Assert.IsNotNull (ctor, "#F7a");
2733                         Assert.IsTrue (ctor.IsPublic, "#F7b");
2734                         Assert.IsFalse (ctor.IsStatic, "#F7c");
2735                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2736                         Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2737
2738                         ctor = redType.GetConstructor (flags, null,
2739                                 new Type [] { typeof (int), typeof (int) },
2740                                 new ParameterModifier [0]);
2741                         Assert.IsNull (ctor, "#F8");
2742
2743                         ctor = redType.GetConstructor (flags, null,
2744                                 new Type [] { typeof (string) },
2745                                 new ParameterModifier [0]);
2746                         Assert.IsNull (ctor, "#F9");
2747
2748                         ctor = redType.GetConstructor (flags, null,
2749                                 new Type [] { typeof (string), typeof (string) },
2750                                 new ParameterModifier [0]);
2751                         Assert.IsNull (ctor, "#F10");
2752
2753                         ctor = redType.GetConstructor (flags, null,
2754                                 new Type [] { typeof (int) },
2755                                 new ParameterModifier [0]);
2756                         Assert.IsNull (ctor, "#F11");
2757
2758                         ctor = redType.GetConstructor (flags, null,
2759                                 new Type [] { typeof (int), typeof (bool) },
2760                                 new ParameterModifier [0]);
2761                         Assert.IsNotNull (ctor, "#F12a");
2762                         Assert.IsTrue (ctor.IsPublic, "#F12b");
2763                         Assert.IsFalse (ctor.IsStatic, "#F12c");
2764                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2765                         Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2766
2767                         ctor = redType.GetConstructor (flags, null,
2768                                 new Type [] { typeof (string), typeof (int) },
2769                                 new ParameterModifier [0]);
2770                         Assert.IsNull (ctor, "#F13");
2771
2772                         ctor = redType.GetConstructor (flags, null,
2773                                 Type.EmptyTypes,
2774                                 new ParameterModifier [0]);
2775                         Assert.IsNull (ctor, "#F14");
2776
2777                         flags = BindingFlags.Static | BindingFlags.Public |
2778                                 BindingFlags.FlattenHierarchy;
2779
2780                         ctor = greenType.GetConstructor (flags, null,
2781                                 new Type [] { typeof (int), typeof (int) },
2782                                 new ParameterModifier [0]);
2783                         Assert.IsNull (ctor, "#G1");
2784
2785                         ctor = greenType.GetConstructor (flags, null,
2786                                 new Type [] { typeof (string) },
2787                                 new ParameterModifier [0]);
2788                         Assert.IsNull (ctor, "#G2");
2789
2790                         ctor = greenType.GetConstructor (flags, null,
2791                                 new Type [] { typeof (string), typeof (string) },
2792                                 new ParameterModifier [0]);
2793                         Assert.IsNull (ctor, "#G3");
2794
2795                         ctor = greenType.GetConstructor (flags, null,
2796                                 new Type [] { typeof (int) },
2797                                 new ParameterModifier [0]);
2798                         Assert.IsNull (ctor, "#G4");
2799
2800                         ctor = greenType.GetConstructor (flags, null,
2801                                 new Type [] { typeof (int), typeof (bool) },
2802                                 new ParameterModifier [0]);
2803                         Assert.IsNull (ctor, "#G5");
2804
2805                         ctor = greenType.GetConstructor (flags, null,
2806                                 new Type [] { typeof (string), typeof (int) },
2807                                 new ParameterModifier [0]);
2808                         Assert.IsNull (ctor, "#G6");
2809
2810                         ctor = greenType.GetConstructor (flags, null,
2811                                 Type.EmptyTypes,
2812                                 new ParameterModifier [0]);
2813                         Assert.IsNull (ctor, "#G7");
2814
2815                         ctor = redType.GetConstructor (flags, null,
2816                                 new Type [] { typeof (int), typeof (int) },
2817                                 new ParameterModifier [0]);
2818                         Assert.IsNull (ctor, "#G8");
2819
2820                         ctor = redType.GetConstructor (flags, null,
2821                                 new Type [] { typeof (string) },
2822                                 new ParameterModifier [0]);
2823                         Assert.IsNull (ctor, "#G9");
2824
2825                         ctor = redType.GetConstructor (flags, null,
2826                                 new Type [] { typeof (string), typeof (string) },
2827                                 new ParameterModifier [0]);
2828                         Assert.IsNull (ctor, "#G10");
2829
2830                         ctor = redType.GetConstructor (flags, null,
2831                                 new Type [] { typeof (int) },
2832                                 new ParameterModifier [0]);
2833                         Assert.IsNull (ctor, "#G11");
2834
2835                         ctor = redType.GetConstructor (flags, null,
2836                                 new Type [] { typeof (int), typeof (bool) },
2837                                 new ParameterModifier [0]);
2838                         Assert.IsNull (ctor, "#G12");
2839
2840                         ctor = redType.GetConstructor (flags, null,
2841                                 new Type [] { typeof (string), typeof (int) },
2842                                 new ParameterModifier [0]);
2843                         Assert.IsNull (ctor, "#G13");
2844
2845                         ctor = redType.GetConstructor (flags, null,
2846                                 Type.EmptyTypes,
2847                                 new ParameterModifier [0]);
2848                         Assert.IsNull (ctor, "#G14");
2849
2850                         flags = BindingFlags.Static | BindingFlags.NonPublic |
2851                                 BindingFlags.FlattenHierarchy;
2852
2853                         ctor = greenType.GetConstructor (flags, null,
2854                                 new Type [] { typeof (int), typeof (int) },
2855                                 new ParameterModifier [0]);
2856                         Assert.IsNull (ctor, "#H1");
2857
2858                         ctor = greenType.GetConstructor (flags, null,
2859                                 new Type [] { typeof (string) },
2860                                 new ParameterModifier [0]);
2861                         Assert.IsNull (ctor, "#H2");
2862
2863                         ctor = greenType.GetConstructor (flags, null,
2864                                 new Type [] { typeof (string), typeof (string) },
2865                                 new ParameterModifier [0]);
2866                         Assert.IsNull (ctor, "#H3");
2867
2868                         ctor = greenType.GetConstructor (flags, null,
2869                                 new Type [] { typeof (int) },
2870                                 new ParameterModifier [0]);
2871                         Assert.IsNull (ctor, "#H4");
2872
2873                         ctor = greenType.GetConstructor (flags, null,
2874                                 new Type [] { typeof (int), typeof (bool) },
2875                                 new ParameterModifier [0]);
2876                         Assert.IsNull (ctor, "#H5");
2877
2878                         ctor = greenType.GetConstructor (flags, null,
2879                                 new Type [] { typeof (string), typeof (int) },
2880                                 new ParameterModifier [0]);
2881                         Assert.IsNull (ctor, "#H6");
2882
2883                         ctor = greenType.GetConstructor (flags, null,
2884                                 Type.EmptyTypes,
2885                                 new ParameterModifier [0]);
2886                         Assert.IsNull (ctor, "#H7");
2887
2888                         ctor = redType.GetConstructor (flags, null,
2889                                 new Type [] { typeof (int), typeof (int) },
2890                                 new ParameterModifier [0]);
2891                         Assert.IsNull (ctor, "#H8");
2892
2893                         ctor = redType.GetConstructor (flags, null,
2894                                 new Type [] { typeof (string) },
2895                                 new ParameterModifier [0]);
2896                         Assert.IsNull (ctor, "#H9");
2897
2898                         ctor = redType.GetConstructor (flags, null,
2899                                 new Type [] { typeof (string), typeof (string) },
2900                                 new ParameterModifier [0]);
2901                         Assert.IsNull (ctor, "#H10");
2902
2903                         ctor = redType.GetConstructor (flags, null,
2904                                 new Type [] { typeof (int) },
2905                                 new ParameterModifier [0]);
2906                         Assert.IsNull (ctor, "#H11");
2907
2908                         ctor = redType.GetConstructor (flags, null,
2909                                 new Type [] { typeof (int), typeof (bool) },
2910                                 new ParameterModifier [0]);
2911                         Assert.IsNull (ctor, "#H12");
2912
2913                         ctor = redType.GetConstructor (flags, null,
2914                                 new Type [] { typeof (string), typeof (int) },
2915                                 new ParameterModifier [0]);
2916                         Assert.IsNull (ctor, "#H13");
2917
2918                         ctor = redType.GetConstructor (flags, null,
2919                                 Type.EmptyTypes,
2920                                 new ParameterModifier [0]);
2921                         Assert.IsNotNull (ctor, "#H14");
2922                         Assert.IsTrue (ctor.IsPrivate, "#H14b");
2923                         Assert.IsTrue (ctor.IsStatic, "#H14c");
2924                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2925                         Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2926
2927                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2928                                 BindingFlags.DeclaredOnly;
2929
2930                         ctor = greenType.GetConstructor (flags, null,
2931                                 new Type [] { typeof (int), typeof (int) },
2932                                 new ParameterModifier [0]);
2933                         Assert.IsNull (ctor, "#I1");
2934
2935                         ctor = greenType.GetConstructor (flags, null,
2936                                 new Type [] { typeof (string) },
2937                                 new ParameterModifier [0]);
2938                         Assert.IsNull (ctor, "#I2");
2939
2940                         ctor = greenType.GetConstructor (flags, null,
2941                                 new Type [] { typeof (string), typeof (string) },
2942                                 new ParameterModifier [0]);
2943                         Assert.IsNull (ctor, "#I3");
2944
2945                         ctor = greenType.GetConstructor (flags, null,
2946                                 new Type [] { typeof (int) },
2947                                 new ParameterModifier [0]);
2948                         Assert.IsNull (ctor, "#I4");
2949
2950                         ctor = greenType.GetConstructor (flags, null,
2951                                 new Type [] { typeof (int), typeof (bool) },
2952                                 new ParameterModifier [0]);
2953                         Assert.IsNull (ctor, "#I5");
2954
2955                         ctor = greenType.GetConstructor (flags, null,
2956                                 new Type [] { typeof (string), typeof (int) },
2957                                 new ParameterModifier [0]);
2958                         Assert.IsNull (ctor, "#I6");
2959
2960                         ctor = greenType.GetConstructor (flags, null,
2961                                 Type.EmptyTypes,
2962                                 new ParameterModifier [0]);
2963                         Assert.IsNull (ctor, "#I7");
2964
2965                         ctor = redType.GetConstructor (flags, null,
2966                                 new Type [] { typeof (int), typeof (int) },
2967                                 new ParameterModifier [0]);
2968                         Assert.IsNotNull (ctor, "#I8a");
2969                         Assert.IsTrue (ctor.IsPrivate, "#I8b");
2970                         Assert.IsFalse (ctor.IsStatic, "#I8c");
2971                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
2972                         Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
2973
2974                         ctor = redType.GetConstructor (flags, null,
2975                                 new Type [] { typeof (string) },
2976                                 new ParameterModifier [0]);
2977                         Assert.IsNotNull (ctor, "#I9a");
2978                         Assert.IsTrue (ctor.IsFamily, "#I9b");
2979                         Assert.IsFalse (ctor.IsStatic, "#I9c");
2980                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
2981                         Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
2982
2983                         ctor = redType.GetConstructor (flags, null,
2984                                 new Type [] { typeof (string), typeof (string) },
2985                                 new ParameterModifier [0]);
2986                         Assert.IsNotNull (ctor, "#I10a");
2987                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
2988                         Assert.IsFalse (ctor.IsStatic, "#I10c");
2989                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
2990                         Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
2991
2992                         ctor = redType.GetConstructor (flags, null,
2993                                 new Type [] { typeof (int) },
2994                                 new ParameterModifier [0]);
2995                         Assert.IsNotNull (ctor, "#I11a");
2996                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
2997                         Assert.IsFalse (ctor.IsStatic, "#I11c");
2998                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
2999                         Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
3000
3001                         ctor = redType.GetConstructor (flags, null,
3002                                 new Type [] { typeof (int), typeof (bool) },
3003                                 new ParameterModifier [0]);
3004                         Assert.IsNull (ctor, "#I12");
3005
3006                         ctor = redType.GetConstructor (flags, null,
3007                                 new Type [] { typeof (string), typeof (int) },
3008                                 new ParameterModifier [0]);
3009                         Assert.IsNotNull (ctor, "#I13a");
3010                         Assert.IsTrue (ctor.IsAssembly, "#I13b");
3011                         Assert.IsFalse (ctor.IsStatic, "#I13c");
3012                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
3013                         Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
3014
3015                         ctor = redType.GetConstructor (flags, null,
3016                                 Type.EmptyTypes,
3017                                 new ParameterModifier [0]);
3018                         Assert.IsNull (ctor, "#I14");
3019
3020                         flags = BindingFlags.Instance | BindingFlags.Public |
3021                                 BindingFlags.DeclaredOnly;
3022
3023                         ctor = greenType.GetConstructor (flags, null,
3024                                 new Type [] { typeof (int), typeof (int) },
3025                                 new ParameterModifier [0]);
3026                         Assert.IsNull (ctor, "#J1");
3027
3028                         ctor = greenType.GetConstructor (flags, null,
3029                                 new Type [] { typeof (string) },
3030                                 new ParameterModifier [0]);
3031                         Assert.IsNull (ctor, "#J2");
3032
3033                         ctor = greenType.GetConstructor (flags, null,
3034                                 new Type [] { typeof (string), typeof (string) },
3035                                 new ParameterModifier [0]);
3036                         Assert.IsNull (ctor, "#J3");
3037
3038                         ctor = greenType.GetConstructor (flags, null,
3039                                 new Type [] { typeof (int) },
3040                                 new ParameterModifier [0]);
3041                         Assert.IsNull (ctor, "#J4");
3042
3043                         ctor = greenType.GetConstructor (flags, null,
3044                                 new Type [] { typeof (int), typeof (bool) },
3045                                 new ParameterModifier [0]);
3046                         Assert.IsNull (ctor, "#J5");
3047
3048                         ctor = greenType.GetConstructor (flags, null,
3049                                 new Type [] { typeof (string), typeof (int) },
3050                                 new ParameterModifier [0]);
3051                         Assert.IsNull (ctor, "#J6");
3052
3053                         ctor = greenType.GetConstructor (flags, null,
3054                                 Type.EmptyTypes,
3055                                 new ParameterModifier [0]);
3056                         Assert.IsNotNull (ctor, "#J7a");
3057                         Assert.IsTrue (ctor.IsPublic, "#J7b");
3058                         Assert.IsFalse (ctor.IsStatic, "#J7c");
3059                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3060                         Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3061
3062                         ctor = redType.GetConstructor (flags, null,
3063                                 new Type [] { typeof (int), typeof (int) },
3064                                 new ParameterModifier [0]);
3065                         Assert.IsNull (ctor, "#J8");
3066
3067                         ctor = redType.GetConstructor (flags, null,
3068                                 new Type [] { typeof (string) },
3069                                 new ParameterModifier [0]);
3070                         Assert.IsNull (ctor, "#J9");
3071
3072                         ctor = redType.GetConstructor (flags, null,
3073                                 new Type [] { typeof (string), typeof (string) },
3074                                 new ParameterModifier [0]);
3075                         Assert.IsNull (ctor, "#J10");
3076
3077                         ctor = redType.GetConstructor (flags, null,
3078                                 new Type [] { typeof (int) },
3079                                 new ParameterModifier [0]);
3080                         Assert.IsNull (ctor, "#J11");
3081
3082                         ctor = redType.GetConstructor (flags, null,
3083                                 new Type [] { typeof (int), typeof (bool) },
3084                                 new ParameterModifier [0]);
3085                         Assert.IsNotNull (ctor, "#J12a");
3086                         Assert.IsTrue (ctor.IsPublic, "#J12b");
3087                         Assert.IsFalse (ctor.IsStatic, "#J12c");
3088                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3089                         Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3090
3091                         ctor = redType.GetConstructor (flags, null,
3092                                 new Type [] { typeof (string), typeof (int) },
3093                                 new ParameterModifier [0]);
3094                         Assert.IsNull (ctor, "#J13");
3095
3096                         ctor = redType.GetConstructor (flags, null,
3097                                 Type.EmptyTypes,
3098                                 new ParameterModifier [0]);
3099                         Assert.IsNull (ctor, "#J14");
3100
3101                         flags = BindingFlags.Static | BindingFlags.Public |
3102                                 BindingFlags.DeclaredOnly;
3103
3104                         ctor = greenType.GetConstructor (flags, null,
3105                                 new Type [] { typeof (int), typeof (int) },
3106                                 new ParameterModifier [0]);
3107                         Assert.IsNull (ctor, "#K1");
3108
3109                         ctor = greenType.GetConstructor (flags, null,
3110                                 new Type [] { typeof (string) },
3111                                 new ParameterModifier [0]);
3112                         Assert.IsNull (ctor, "#K2");
3113
3114                         ctor = greenType.GetConstructor (flags, null,
3115                                 new Type [] { typeof (string), typeof (string) },
3116                                 new ParameterModifier [0]);
3117                         Assert.IsNull (ctor, "#K3");
3118
3119                         ctor = greenType.GetConstructor (flags, null,
3120                                 new Type [] { typeof (int) },
3121                                 new ParameterModifier [0]);
3122                         Assert.IsNull (ctor, "#K4");
3123
3124                         ctor = greenType.GetConstructor (flags, null,
3125                                 new Type [] { typeof (int), typeof (bool) },
3126                                 new ParameterModifier [0]);
3127                         Assert.IsNull (ctor, "#K5");
3128
3129                         ctor = greenType.GetConstructor (flags, null,
3130                                 new Type [] { typeof (string), typeof (int) },
3131                                 new ParameterModifier [0]);
3132                         Assert.IsNull (ctor, "#K6");
3133
3134                         ctor = greenType.GetConstructor (flags, null,
3135                                 Type.EmptyTypes,
3136                                 new ParameterModifier [0]);
3137                         Assert.IsNull (ctor, "#K7");
3138
3139                         ctor = redType.GetConstructor (flags, null,
3140                                 new Type [] { typeof (int), typeof (int) },
3141                                 new ParameterModifier [0]);
3142                         Assert.IsNull (ctor, "#K8");
3143
3144                         ctor = redType.GetConstructor (flags, null,
3145                                 new Type [] { typeof (string) },
3146                                 new ParameterModifier [0]);
3147                         Assert.IsNull (ctor, "#K9");
3148
3149                         ctor = redType.GetConstructor (flags, null,
3150                                 new Type [] { typeof (string), typeof (string) },
3151                                 new ParameterModifier [0]);
3152                         Assert.IsNull (ctor, "#K10");
3153
3154                         ctor = redType.GetConstructor (flags, null,
3155                                 new Type [] { typeof (int) },
3156                                 new ParameterModifier [0]);
3157                         Assert.IsNull (ctor, "#K11");
3158
3159                         ctor = redType.GetConstructor (flags, null,
3160                                 new Type [] { typeof (int), typeof (bool) },
3161                                 new ParameterModifier [0]);
3162                         Assert.IsNull (ctor, "#K12");
3163
3164                         ctor = redType.GetConstructor (flags, null,
3165                                 new Type [] { typeof (string), typeof (int) },
3166                                 new ParameterModifier [0]);
3167                         Assert.IsNull (ctor, "#K13");
3168
3169                         ctor = redType.GetConstructor (flags, null,
3170                                 Type.EmptyTypes,
3171                                 new ParameterModifier [0]);
3172                         Assert.IsNull (ctor, "#K14");
3173
3174                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3175                                 BindingFlags.DeclaredOnly;
3176
3177                         ctor = greenType.GetConstructor (flags, null,
3178                                 new Type [] { typeof (int), typeof (int) },
3179                                 new ParameterModifier [0]);
3180                         Assert.IsNull (ctor, "#L1");
3181
3182                         ctor = greenType.GetConstructor (flags, null,
3183                                 new Type [] { typeof (string) },
3184                                 new ParameterModifier [0]);
3185                         Assert.IsNull (ctor, "#L2");
3186
3187                         ctor = greenType.GetConstructor (flags, null,
3188                                 new Type [] { typeof (string), typeof (string) },
3189                                 new ParameterModifier [0]);
3190                         Assert.IsNull (ctor, "#L3");
3191
3192                         ctor = greenType.GetConstructor (flags, null,
3193                                 new Type [] { typeof (int) },
3194                                 new ParameterModifier [0]);
3195                         Assert.IsNull (ctor, "#L4");
3196
3197                         ctor = greenType.GetConstructor (flags, null,
3198                                 new Type [] { typeof (int), typeof (bool) },
3199                                 new ParameterModifier [0]);
3200                         Assert.IsNull (ctor, "#L5");
3201
3202                         ctor = greenType.GetConstructor (flags, null,
3203                                 new Type [] { typeof (string), typeof (int) },
3204                                 new ParameterModifier [0]);
3205                         Assert.IsNull (ctor, "#L6");
3206
3207                         ctor = greenType.GetConstructor (flags, null,
3208                                 Type.EmptyTypes,
3209                                 new ParameterModifier [0]);
3210                         Assert.IsNull (ctor, "#L7");
3211
3212                         ctor = redType.GetConstructor (flags, null,
3213                                 new Type [] { typeof (int), typeof (int) },
3214                                 new ParameterModifier [0]);
3215                         Assert.IsNull (ctor, "#L8");
3216
3217                         ctor = redType.GetConstructor (flags, null,
3218                                 new Type [] { typeof (string) },
3219                                 new ParameterModifier [0]);
3220                         Assert.IsNull (ctor, "#L9");
3221
3222                         ctor = redType.GetConstructor (flags, null,
3223                                 new Type [] { typeof (string), typeof (string) },
3224                                 new ParameterModifier [0]);
3225                         Assert.IsNull (ctor, "#L10");
3226
3227                         ctor = redType.GetConstructor (flags, null,
3228                                 new Type [] { typeof (int) },
3229                                 new ParameterModifier [0]);
3230                         Assert.IsNull (ctor, "#L11");
3231
3232                         ctor = redType.GetConstructor (flags, null,
3233                                 new Type [] { typeof (int), typeof (bool) },
3234                                 new ParameterModifier [0]);
3235                         Assert.IsNull (ctor, "#L12");
3236
3237                         ctor = redType.GetConstructor (flags, null,
3238                                 new Type [] { typeof (string), typeof (int) },
3239                                 new ParameterModifier [0]);
3240                         Assert.IsNull (ctor, "#L13");
3241
3242                         ctor = redType.GetConstructor (flags, null,
3243                                 Type.EmptyTypes,
3244                                 new ParameterModifier [0]);
3245                         Assert.IsNotNull (ctor, "#L14a");
3246                         Assert.IsTrue (ctor.IsPrivate, "#L14b");
3247                         Assert.IsTrue (ctor.IsStatic, "#L14c");
3248                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3249                         Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3250
3251                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3252                                 BindingFlags.Public;
3253
3254                         ctor = greenType.GetConstructor (flags, null,
3255                                 new Type [] { typeof (int), typeof (int) },
3256                                 new ParameterModifier [0]);
3257                         Assert.IsNull (ctor, "#M1");
3258
3259                         ctor = greenType.GetConstructor (flags, null,
3260                                 new Type [] { typeof (string) },
3261                                 new ParameterModifier [0]);
3262                         Assert.IsNull (ctor, "#M2");
3263
3264                         ctor = greenType.GetConstructor (flags, null,
3265                                 new Type [] { typeof (string), typeof (string) },
3266                                 new ParameterModifier [0]);
3267                         Assert.IsNull (ctor, "#M3");
3268
3269                         ctor = greenType.GetConstructor (flags, null,
3270                                 new Type [] { typeof (int) },
3271                                 new ParameterModifier [0]);
3272                         Assert.IsNull (ctor, "#M4");
3273
3274                         ctor = greenType.GetConstructor (flags, null,
3275                                 new Type [] { typeof (int), typeof (bool) },
3276                                 new ParameterModifier [0]);
3277                         Assert.IsNull (ctor, "#M5");
3278
3279                         ctor = greenType.GetConstructor (flags, null,
3280                                 new Type [] { typeof (string), typeof (int) },
3281                                 new ParameterModifier [0]);
3282                         Assert.IsNull (ctor, "#M6");
3283
3284                         ctor = greenType.GetConstructor (flags, null,
3285                                 Type.EmptyTypes,
3286                                 new ParameterModifier [0]);
3287                         Assert.IsNotNull (ctor, "#M7a");
3288                         Assert.IsTrue (ctor.IsPublic, "#M7b");
3289                         Assert.IsFalse (ctor.IsStatic, "#M7c");
3290                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3291                         Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3292
3293                         ctor = redType.GetConstructor (flags, null,
3294                                 new Type [] { typeof (int), typeof (int) },
3295                                 new ParameterModifier [0]);
3296                         Assert.IsNotNull (ctor, "#M8a");
3297                         Assert.IsTrue (ctor.IsPrivate, "#M8b");
3298                         Assert.IsFalse (ctor.IsStatic, "#M8c");
3299                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3300                         Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3301
3302                         ctor = redType.GetConstructor (flags, null,
3303                                 new Type [] { typeof (string) },
3304                                 new ParameterModifier [0]);
3305                         Assert.IsNotNull (ctor, "#M9a");
3306                         Assert.IsTrue (ctor.IsFamily, "#M9b");
3307                         Assert.IsFalse (ctor.IsStatic, "#M9c");
3308                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3309                         Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3310
3311                         ctor = redType.GetConstructor (flags, null,
3312                                 new Type [] { typeof (string), typeof (string) },
3313                                 new ParameterModifier [0]);
3314                         Assert.IsNotNull (ctor, "#M10a");
3315                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3316                         Assert.IsFalse (ctor.IsStatic, "#M10c");
3317                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3318                         Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3319
3320                         ctor = redType.GetConstructor (flags, null,
3321                                 new Type [] { typeof (int) },
3322                                 new ParameterModifier [0]);
3323                         Assert.IsNotNull (ctor, "#M11a");
3324                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3325                         Assert.IsFalse (ctor.IsStatic, "#M11c");
3326                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3327                         Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3328
3329                         ctor = redType.GetConstructor (flags, null,
3330                                 new Type [] { typeof (int), typeof (bool) },
3331                                 new ParameterModifier [0]);
3332                         Assert.IsNotNull (ctor, "#M12a");
3333                         Assert.IsTrue (ctor.IsPublic, "#M12b");
3334                         Assert.IsFalse (ctor.IsStatic, "#M12c");
3335                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3336                         Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3337
3338                         ctor = redType.GetConstructor (flags, null,
3339                                 new Type [] { typeof (string), typeof (int) },
3340                                 new ParameterModifier [0]);
3341                         Assert.IsNotNull (ctor, "#M13a");
3342                         Assert.IsTrue (ctor.IsAssembly, "#M13b");
3343                         Assert.IsFalse (ctor.IsStatic, "#M13c");
3344                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3345                         Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3346
3347                         ctor = redType.GetConstructor (flags, null,
3348                                 Type.EmptyTypes,
3349                                 new ParameterModifier [0]);
3350                         Assert.IsNull (ctor, "#M14");
3351
3352                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3353                                 BindingFlags.Public;
3354
3355                         ctor = greenType.GetConstructor (flags, null,
3356                                 new Type [] { typeof (int), typeof (int) },
3357                                 new ParameterModifier [0]);
3358                         Assert.IsNull (ctor, "#N1");
3359
3360                         ctor = greenType.GetConstructor (flags, null,
3361                                 new Type [] { typeof (string) },
3362                                 new ParameterModifier [0]);
3363                         Assert.IsNull (ctor, "#N2");
3364
3365                         ctor = greenType.GetConstructor (flags, null,
3366                                 new Type [] { typeof (string), typeof (string) },
3367                                 new ParameterModifier [0]);
3368                         Assert.IsNull (ctor, "#N3");
3369
3370                         ctor = greenType.GetConstructor (flags, null,
3371                                 new Type [] { typeof (int) },
3372                                 new ParameterModifier [0]);
3373                         Assert.IsNull (ctor, "#N4");
3374
3375                         ctor = greenType.GetConstructor (flags, null,
3376                                 new Type [] { typeof (int), typeof (bool) },
3377                                 new ParameterModifier [0]);
3378                         Assert.IsNull (ctor, "#N5");
3379
3380                         ctor = greenType.GetConstructor (flags, null,
3381                                 new Type [] { typeof (string), typeof (int) },
3382                                 new ParameterModifier [0]);
3383                         Assert.IsNull (ctor, "#N6");
3384
3385                         ctor = greenType.GetConstructor (flags, null,
3386                                 Type.EmptyTypes,
3387                                 new ParameterModifier [0]);
3388                         Assert.IsNull (ctor, "#N7");
3389
3390                         ctor = redType.GetConstructor (flags, null,
3391                                 new Type [] { typeof (int), typeof (int) },
3392                                 new ParameterModifier [0]);
3393                         Assert.IsNull (ctor, "#N8");
3394
3395                         ctor = redType.GetConstructor (flags, null,
3396                                 new Type [] { typeof (string) },
3397                                 new ParameterModifier [0]);
3398                         Assert.IsNull (ctor, "#N9");
3399
3400                         ctor = redType.GetConstructor (flags, null,
3401                                 new Type [] { typeof (string), typeof (string) },
3402                                 new ParameterModifier [0]);
3403                         Assert.IsNull (ctor, "#N10");
3404
3405                         ctor = redType.GetConstructor (flags, null,
3406                                 new Type [] { typeof (int) },
3407                                 new ParameterModifier [0]);
3408                         Assert.IsNull (ctor, "#N11");
3409
3410                         ctor = redType.GetConstructor (flags, null,
3411                                 new Type [] { typeof (int), typeof (bool) },
3412                                 new ParameterModifier [0]);
3413                         Assert.IsNull (ctor, "#N12");
3414
3415                         ctor = redType.GetConstructor (flags, null,
3416                                 new Type [] { typeof (string), typeof (int) },
3417                                 new ParameterModifier [0]);
3418                         Assert.IsNull (ctor, "#N13");
3419
3420                         ctor = redType.GetConstructor (flags, null,
3421                                 Type.EmptyTypes,
3422                                 new ParameterModifier [0]);
3423                         Assert.IsNotNull (ctor, "#N14a");
3424                         Assert.IsTrue (ctor.IsPrivate, "#N14b");
3425                         Assert.IsTrue (ctor.IsStatic, "#N14c");
3426                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3427                         Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3428                 }
3429
3430                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
3431                 public void GetConstructor2_Incomplete ()
3432                 {
3433                         TypeBuilder tb = module.DefineType (genTypeName ());
3434                         ConstructorBuilder cb = tb.DefineConstructor (
3435                                 MethodAttributes.Public,
3436                                 CallingConventions.Standard,
3437                                 Type.EmptyTypes);
3438                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3439
3440                         try {
3441                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3442                                         null, Type.EmptyTypes, new ParameterModifier [0]);
3443                                 Assert.Fail ("#1");
3444                         } catch (NotSupportedException ex) {
3445                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3446                                 Assert.IsNull (ex.InnerException, "#3");
3447                                 Assert.IsNotNull (ex.Message, "#4");
3448                         }
3449                 }
3450
3451                 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
3452                 public void GetConstructor3_Incomplete ()
3453                 {
3454                         TypeBuilder tb = module.DefineType (genTypeName ());
3455                         ConstructorBuilder cb = tb.DefineConstructor (
3456                                 MethodAttributes.Public,
3457                                 CallingConventions.Standard,
3458                                 Type.EmptyTypes);
3459                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3460
3461                         try {
3462                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3463                                         null, CallingConventions.Standard, Type.EmptyTypes,
3464                                         new ParameterModifier [0]);
3465                                 Assert.Fail ("#1");
3466                         } catch (NotSupportedException ex) {
3467                                 // The invoked member is not supported in a
3468                                 // dynamic module
3469                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3470                                 Assert.IsNull (ex.InnerException, "#3");
3471                                 Assert.IsNotNull (ex.Message, "#4");
3472                         }
3473                 }
3474
3475                 [Test] // GetConstructors ()
3476                 [Category ("NotWorking")] // mcs depends on this
3477                 public void GetConstructors1_Incomplete ()
3478                 {
3479                         TypeBuilder tb = module.DefineType (genTypeName ());
3480                         ConstructorBuilder cb = tb.DefineConstructor (
3481                                 MethodAttributes.Public,
3482                                 CallingConventions.Standard,
3483                                 Type.EmptyTypes);
3484                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3485
3486                         try {
3487                                 tb.GetConstructors ();
3488                                 Assert.Fail ("#1");
3489                         } catch (NotSupportedException ex) {
3490                                 // The invoked member is not supported in a
3491                                 // dynamic module
3492                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3493                                 Assert.IsNull (ex.InnerException, "#3");
3494                                 Assert.IsNotNull (ex.Message, "#4");
3495                         }
3496                 }
3497
3498                 [Test] // GetConstructors (BindingFlags)
3499                 public void GetConstructors2_Complete ()
3500                 {
3501                         BindingFlags flags;
3502                         ConstructorInfo [] ctors;
3503
3504                         TypeBuilder redType = module.DefineType (genTypeName (),
3505                                 TypeAttributes.Public);
3506                         CreateMembers (redType, "Red", true);
3507
3508                         TypeBuilder greenType = module.DefineType (genTypeName (),
3509                                 TypeAttributes.Public, redType);
3510                         CreateMembers (greenType, "Green", false);
3511                         ConstructorBuilder cb = greenType.DefineConstructor (
3512                                 MethodAttributes.Public,
3513                                 CallingConventions.Standard,
3514                                 Type.EmptyTypes);
3515                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3516
3517                         redType.CreateType ();
3518                         greenType.CreateType ();
3519
3520                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3521
3522                         ctors = greenType.GetConstructors (flags);
3523                         Assert.AreEqual (0, ctors.Length, "#A1");
3524
3525                         ctors = redType.GetConstructors (flags);
3526                         Assert.AreEqual (5, ctors.Length, "#A2");
3527                         Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3528                         Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3529                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3530                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3531                         Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3532                         Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3533                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3534                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3535                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3536                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3537                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3538                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3539                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3540                         Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3541                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3542                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3543                         Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3544                         Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3545                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3546                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3547
3548                         flags = BindingFlags.Instance | BindingFlags.Public;
3549
3550                         ctors = greenType.GetConstructors (flags);
3551                         Assert.AreEqual (1, ctors.Length, "#B1");
3552                         Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3553                         Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3554                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3555                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3556
3557                         ctors = redType.GetConstructors (flags);
3558                         Assert.AreEqual (1, ctors.Length, "#B3");
3559                         Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3560                         Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3561                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3562                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3563
3564                         flags = BindingFlags.Static | BindingFlags.Public;
3565
3566                         ctors = greenType.GetConstructors (flags);
3567                         Assert.AreEqual (0, ctors.Length, "#C1");
3568
3569                         ctors = redType.GetConstructors (flags);
3570                         Assert.AreEqual (0, ctors.Length, "#C2");
3571
3572                         flags = BindingFlags.Static | BindingFlags.NonPublic;
3573
3574                         ctors = greenType.GetConstructors (flags);
3575                         Assert.AreEqual (0, ctors.Length, "#D1");
3576
3577                         ctors = redType.GetConstructors (flags);
3578                         Assert.AreEqual (1, ctors.Length, "#D2");
3579                         Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3580                         Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3581                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3582                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3583
3584                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3585                                 BindingFlags.FlattenHierarchy;
3586
3587                         ctors = greenType.GetConstructors (flags);
3588                         Assert.AreEqual (0, ctors.Length, "#E1");
3589
3590                         ctors = redType.GetConstructors (flags);
3591                         Assert.AreEqual (5, ctors.Length, "#E2");
3592                         Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3593                         Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3594                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3595                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3596                         Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3597                         Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3598                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3599                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3600                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3601                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3602                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3603                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3604                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3605                         Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3606                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3607                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3608                         Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3609                         Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3610                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3611                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3612
3613                         flags = BindingFlags.Instance | BindingFlags.Public |
3614                                 BindingFlags.FlattenHierarchy;
3615
3616                         ctors = greenType.GetConstructors (flags);
3617                         Assert.AreEqual (1, ctors.Length, "#F1");
3618                         Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3619                         Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3620                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3621                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3622
3623                         ctors = redType.GetConstructors (flags);
3624                         Assert.AreEqual (1, ctors.Length, "#F3");
3625                         Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3626                         Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3627                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3628                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3629
3630                         flags = BindingFlags.Static | BindingFlags.Public |
3631                                 BindingFlags.FlattenHierarchy;
3632
3633                         ctors = greenType.GetConstructors (flags);
3634                         Assert.AreEqual (0, ctors.Length, "#G1");
3635
3636                         ctors = redType.GetConstructors (flags);
3637                         Assert.AreEqual (0, ctors.Length, "#G2");
3638
3639                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3640                                 BindingFlags.FlattenHierarchy;
3641
3642                         ctors = greenType.GetConstructors (flags);
3643                         Assert.AreEqual (0, ctors.Length, "#H1");
3644
3645                         ctors = redType.GetConstructors (flags);
3646                         Assert.AreEqual (1, ctors.Length, "#H2");
3647                         Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3648                         Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3649                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3650                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3651
3652                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3653                                 BindingFlags.DeclaredOnly;
3654
3655                         ctors = greenType.GetConstructors (flags);
3656                         Assert.AreEqual (0, ctors.Length, "#I1");
3657
3658                         ctors = redType.GetConstructors (flags);
3659                         Assert.AreEqual (5, ctors.Length, "#I2");
3660                         Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3661                         Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3662                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3663                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3664                         Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3665                         Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3666                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3667                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3668                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3669                         Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3670                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3671                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3672                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3673                         Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3674                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3675                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3676                         Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3677                         Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3678                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3679                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3680
3681                         flags = BindingFlags.Instance | BindingFlags.Public |
3682                                 BindingFlags.DeclaredOnly;
3683
3684                         ctors = greenType.GetConstructors (flags);
3685                         Assert.AreEqual (1, ctors.Length, "#J1");
3686                         Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3687                         Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3688                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3689                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3690
3691                         ctors = redType.GetConstructors (flags);
3692                         Assert.AreEqual (1, ctors.Length, "#J3");
3693                         Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3694                         Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3695                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3696                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3697
3698                         flags = BindingFlags.Static | BindingFlags.Public |
3699                                 BindingFlags.DeclaredOnly;
3700
3701                         ctors = greenType.GetConstructors (flags);
3702                         Assert.AreEqual (0, ctors.Length, "#K1");
3703
3704                         ctors = redType.GetConstructors (flags);
3705                         Assert.AreEqual (0, ctors.Length, "#K2");
3706
3707                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3708                                 BindingFlags.DeclaredOnly;
3709
3710                         ctors = greenType.GetConstructors (flags);
3711                         Assert.AreEqual (0, ctors.Length, "#L1");
3712
3713                         ctors = redType.GetConstructors (flags);
3714                         Assert.AreEqual (1, ctors.Length, "#L2");
3715                         Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3716                         Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3717                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3718                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3719
3720                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3721                                 BindingFlags.Public;
3722
3723                         ctors = greenType.GetConstructors (flags);
3724                         Assert.AreEqual (1, ctors.Length, "#M1");
3725                         Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3726                         Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3727                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3728                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3729
3730                         ctors = redType.GetConstructors (flags);
3731                         Assert.AreEqual (6, ctors.Length, "#M3");
3732                         Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3733                         Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3734                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3735                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3736                         Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3737                         Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3738                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3739                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3740                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3741                         Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3742                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3743                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3744                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3745                         Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3746                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3747                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3748                         Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3749                         Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3750                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3751                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3752                         Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3753                         Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3754                         Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3755                         Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3756
3757                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3758                                 BindingFlags.Public;
3759
3760                         ctors = greenType.GetConstructors (flags);
3761                         Assert.AreEqual (0, ctors.Length, "#N1");
3762
3763                         ctors = redType.GetConstructors (flags);
3764                         Assert.AreEqual (1, ctors.Length, "#N2");
3765                         Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3766                         Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3767                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3768                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3769                 }
3770
3771                 [Test] // GetConstructors (BindingFlags)
3772                 [Category ("NotWorking")] // mcs depends on this
3773                 public void GetConstructors2_Incomplete ()
3774                 {
3775                         TypeBuilder tb = module.DefineType (genTypeName ());
3776                         ConstructorBuilder cb = tb.DefineConstructor (
3777                                 MethodAttributes.Public,
3778                                 CallingConventions.Standard,
3779                                 Type.EmptyTypes);
3780                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3781
3782                         try {
3783                                 tb.GetConstructors (BindingFlags.Public |
3784                                         BindingFlags.Instance);
3785                                 Assert.Fail ("#1");
3786                         } catch (NotSupportedException ex) {
3787                                 // The invoked member is not supported in a
3788                                 // dynamic module
3789                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3790                                 Assert.IsNull (ex.InnerException, "#3");
3791                                 Assert.IsNotNull (ex.Message, "#4");
3792                         }
3793                 }
3794
3795                 [Test]
3796                 public void TestGetCustomAttributesIncomplete ()
3797                 {
3798                         TypeBuilder tb = module.DefineType (genTypeName ());
3799                         try {
3800                                 tb.GetCustomAttributes (false);
3801                                 Assert.Fail ("#1");
3802                         } catch (NotSupportedException ex) {
3803                                 // The invoked member is not supported in a
3804                                 // dynamic module
3805                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3806                                 Assert.IsNull (ex.InnerException, "#3");
3807                                 Assert.IsNotNull (ex.Message, "#4");
3808                         }
3809                 }
3810
3811                 [Test]
3812                 public void TestGetCustomAttributesComplete ()
3813                 {
3814                         TypeBuilder tb = module.DefineType (genTypeName ());
3815
3816                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3817                                 new Type [] { typeof (string) });
3818
3819                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3820                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3821
3822                         tb.SetCustomAttribute (caBuilder);
3823                         tb.CreateType ();
3824
3825                         Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3826                 }
3827
3828                 [Test]
3829                 public void TestGetCustomAttributesOfTypeIncomplete ()
3830                 {
3831                         TypeBuilder tb = module.DefineType (genTypeName ());
3832                         try {
3833                                 tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3834                                 Assert.Fail ("#1");
3835                         } catch (NotSupportedException ex) {
3836                                 // The invoked member is not supported in a
3837                                 // dynamic module
3838                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3839                                 Assert.IsNull (ex.InnerException, "#3");
3840                                 Assert.IsNotNull (ex.Message, "#4");
3841                         }
3842                 }
3843
3844                 [Test]
3845                 public void TestGetCustomAttributesOfTypeComplete ()
3846                 {
3847                         TypeBuilder tb = module.DefineType (genTypeName ());
3848
3849                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3850                                 new Type [] { typeof (string) });
3851
3852                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3853                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3854
3855                         tb.SetCustomAttribute (caBuilder);
3856                         tb.CreateType ();
3857
3858                         Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3859                         Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3860                 }
3861
3862                 [Test]
3863                 public void TestGetCustomAttributesOfNullTypeComplete ()
3864                 {
3865                         TypeBuilder tb = module.DefineType (genTypeName ());
3866                         tb.CreateType ();
3867                         try {
3868                                 tb.GetCustomAttributes (null, false);
3869                                 Assert.Fail ("#1");
3870                         } catch (ArgumentNullException ex) {
3871                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3872                                 Assert.IsNull (ex.InnerException, "#3");
3873                                 Assert.IsNotNull (ex.Message, "#4");
3874                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3875                         }
3876                 }
3877
3878                 [Test]
3879                 [Ignore ("mcs depends on this")]
3880                 public void TestGetEventsIncomplete ()
3881                 {
3882                         TypeBuilder tb = module.DefineType (genTypeName ());
3883                         try {
3884                                 tb.GetEvents ();
3885                                 Assert.Fail ("#1");
3886                         } catch (NotSupportedException ex) {
3887                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3888                                 Assert.IsNull (ex.InnerException, "#3");
3889                                 Assert.IsNotNull (ex.Message, "#4");
3890                                 throw;
3891                         }
3892                 }
3893
3894                 [Test]
3895                 public void TestGetEventsComplete ()
3896                 {
3897                         TypeBuilder tb = module.DefineType (genTypeName ());
3898
3899                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3900                                 typeof (void), new Type [] { typeof (Object) });
3901                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3902
3903                         // create public event
3904                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3905                                 typeof (ResolveEventHandler));
3906                         eventbuilder.SetRaiseMethod (onclickMethod);
3907
3908                         Type emittedType = tb.CreateType ();
3909
3910                         Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3911                         Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3912                 }
3913
3914
3915                 [Test]
3916                 [Ignore ("mcs depends on this")]
3917                 public void TestGetEventsFlagsIncomplete ()
3918                 {
3919                         TypeBuilder tb = module.DefineType (genTypeName ());
3920                         try {
3921                                 tb.GetEvents (BindingFlags.Public);
3922                                 Assert.Fail ("#1");
3923                         } catch (NotSupportedException ex) {
3924                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3925                                 Assert.IsNull (ex.InnerException, "#3");
3926                                 Assert.IsNotNull (ex.Message, "#4");
3927                                 throw;
3928                         }
3929                 }
3930
3931                 [Test]
3932                 public void TestGetEventsFlagsComplete ()
3933                 {
3934                         TypeBuilder tb = module.DefineType (genTypeName ());
3935
3936                         MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3937                                 typeof (void), new Type [] { typeof (Object) });
3938                         onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3939
3940                         // create public event
3941                         EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3942                                 typeof (ResolveEventHandler));
3943                         changeEvent.SetRaiseMethod (onchangeMethod);
3944
3945                         // create non-public event
3946                         EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3947                                 typeof (ResolveEventHandler));
3948
3949                         Type emittedType = tb.CreateType ();
3950
3951                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3952                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3953                         Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3954                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
3955                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3956                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
3957                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3958                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
3959                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3960                 }
3961
3962                 [Test]
3963                 public void TestGetEventsFlagsComplete_Inheritance ()
3964                 {
3965                         EventInfo [] events;
3966                         BindingFlags flags;
3967
3968                         TypeBuilder blueType = module.DefineType (genTypeName (),
3969                                 TypeAttributes.Public);
3970                         CreateMembers (blueType, "Blue", false);
3971
3972                         TypeBuilder redType = module.DefineType (genTypeName (),
3973                                 TypeAttributes.Public, blueType);
3974                         CreateMembers (redType, "Red", false);
3975
3976                         TypeBuilder greenType = module.DefineType (genTypeName (),
3977                                 TypeAttributes.Public, redType);
3978                         CreateMembers (greenType, "Green", false);
3979
3980                         blueType.CreateType ();
3981                         redType.CreateType ();
3982                         greenType.CreateType ();
3983
3984                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3985                         events = greenType.GetEvents (flags);
3986
3987                         Assert.AreEqual (13, events.Length, "#A1");
3988                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
3989                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
3990                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
3991                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
3992                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
3993                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
3994                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
3995                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
3996                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
3997                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
3998                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
3999                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
4000                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
4001
4002                         flags = BindingFlags.Instance | BindingFlags.Public;
4003                         events = greenType.GetEvents (flags);
4004
4005                         Assert.AreEqual (3, events.Length, "#B1");
4006                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
4007                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
4008                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
4009
4010                         flags = BindingFlags.Static | BindingFlags.Public;
4011                         events = greenType.GetEvents (flags);
4012
4013                         Assert.AreEqual (1, events.Length, "#C1");
4014                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
4015
4016                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4017                         events = greenType.GetEvents (flags);
4018
4019                         Assert.AreEqual (5, events.Length, "#D1");
4020                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
4021                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
4022                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
4023                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4024                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4025
4026                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4027                                 BindingFlags.FlattenHierarchy;
4028                         events = greenType.GetEvents (flags);
4029
4030                         Assert.AreEqual (13, events.Length, "#E1");
4031                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4032                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4033                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4034                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4035                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4036                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4037                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4038                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4039                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4040                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4041                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4042                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4043                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4044
4045                         flags = BindingFlags.Instance | BindingFlags.Public |
4046                                 BindingFlags.FlattenHierarchy;
4047                         events = greenType.GetEvents (flags);
4048
4049                         Assert.AreEqual (3, events.Length, "#F1");
4050                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4051                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4052                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4053
4054                         flags = BindingFlags.Static | BindingFlags.Public |
4055                                 BindingFlags.FlattenHierarchy;
4056                         events = greenType.GetEvents (flags);
4057
4058                         Assert.AreEqual (3, events.Length, "#G1");
4059                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4060                         Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4061                         Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4062
4063                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4064                                 BindingFlags.FlattenHierarchy;
4065                         events = greenType.GetEvents (flags);
4066
4067                         Assert.AreEqual (13, events.Length, "#H1");
4068                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4069                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4070                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4071                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4072                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4073                         Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4074                         Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4075                         Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4076                         Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4077                         Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4078                         Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4079                         Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4080                         Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4081
4082                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4083                                 BindingFlags.DeclaredOnly;
4084                         events = greenType.GetEvents (flags);
4085
4086                         Assert.AreEqual (5, events.Length, "#I1");
4087                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4088                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4089                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4090                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4091                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4092
4093                         flags = BindingFlags.Instance | BindingFlags.Public |
4094                                 BindingFlags.DeclaredOnly;
4095                         events = greenType.GetEvents (flags);
4096
4097                         Assert.AreEqual (1, events.Length, "#J1");
4098                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4099
4100                         flags = BindingFlags.Static | BindingFlags.Public |
4101                                 BindingFlags.DeclaredOnly;
4102                         events = greenType.GetEvents (flags);
4103
4104                         Assert.AreEqual (1, events.Length, "#K1");
4105                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4106
4107                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4108                                 BindingFlags.DeclaredOnly;
4109                         events = greenType.GetEvents (flags);
4110
4111                         Assert.AreEqual (5, events.Length, "#L1");
4112                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4113                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4114                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4115                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4116                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4117
4118                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4119                                 BindingFlags.Public;
4120                         events = greenType.GetEvents (flags);
4121
4122                         Assert.AreEqual (16, events.Length, "#M1");
4123                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4124                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4125                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4126                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4127                         Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4128                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4129                         Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4130                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4131                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4132                         Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4133                         Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4134                         Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4135                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4136                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4137                         Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4138                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4139
4140                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4141                                 BindingFlags.Public;
4142                         events = greenType.GetEvents (flags);
4143
4144                         Assert.AreEqual (6, events.Length, "#N1");
4145                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4146                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4147                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4148                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4149                         Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4150                         Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4151                 }
4152
4153                 [Test]
4154                 [Ignore ("mcs depends on this")]
4155                 public void TestGetEventIncomplete ()
4156                 {
4157                         TypeBuilder tb = module.DefineType (genTypeName ());
4158                         try {
4159                                 tb.GetEvent ("FOO");
4160                                 Assert.Fail ("#1");
4161                         } catch (NotSupportedException ex) {
4162                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4163                                 Assert.IsNull (ex.InnerException, "#3");
4164                                 Assert.IsNotNull (ex.Message, "#4");
4165                                 throw;
4166                         }
4167                 }
4168
4169                 [Test]
4170                 public void TestGetEventComplete ()
4171                 {
4172                         TypeBuilder tb = module.DefineType (genTypeName ());
4173
4174                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4175                                 typeof (void), new Type [] { typeof (Object) });
4176                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4177
4178                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4179                                 typeof (ResolveEventHandler));
4180                         eventbuilder.SetRaiseMethod (onclickMethod);
4181
4182                         Type emittedType = tb.CreateType ();
4183
4184                         Assert.IsNotNull (tb.GetEvent ("Change"));
4185                         Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4186                         Assert.IsNull (tb.GetEvent ("NotChange"));
4187                         Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4188                 }
4189
4190                 [Test]
4191                 [Ignore ("mcs depends on this")]
4192                 public void TestGetEventFlagsIncomplete ()
4193                 {
4194                         TypeBuilder tb = module.DefineType (genTypeName ());
4195                         try {
4196                                 tb.GetEvent ("FOO", BindingFlags.Public);
4197                                 Assert.Fail ("#1");
4198                         } catch (NotSupportedException ex) {
4199                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4200                                 Assert.IsNull (ex.InnerException, "#3");
4201                                 Assert.IsNotNull (ex.Message, "#4");
4202                                 throw;
4203                         }
4204                 }
4205
4206                 [Test]
4207                 public void TestGetEventFlagsComplete ()
4208                 {
4209                         TypeBuilder tb = module.DefineType (genTypeName ());
4210
4211                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4212                                 typeof (void), new Type [] { typeof (Object) });
4213                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4214
4215                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4216                                 typeof (ResolveEventHandler));
4217                         eventbuilder.SetRaiseMethod (onclickMethod);
4218
4219                         Type emittedType = tb.CreateType ();
4220
4221                         Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4222                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4223                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4224                         Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4225                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4226                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4227                 }
4228
4229                 [Test]
4230                 public void TestGetEventFlagsComplete_Inheritance ()
4231                 {
4232                         BindingFlags flags;
4233
4234                         TypeBuilder blueType = module.DefineType (genTypeName (),
4235                                 TypeAttributes.Public);
4236                         CreateMembers (blueType, "Blue", false);
4237
4238                         TypeBuilder redType = module.DefineType (genTypeName (),
4239                                 TypeAttributes.Public, blueType);
4240                         CreateMembers (redType, "Red", false);
4241
4242                         TypeBuilder greenType = module.DefineType (genTypeName (),
4243                                 TypeAttributes.Public, redType);
4244                         CreateMembers (greenType, "Green", false);
4245
4246                         blueType.CreateType ();
4247                         redType.CreateType ();
4248                         greenType.CreateType ();
4249
4250                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4251
4252                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4253                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4254                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4255                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4256                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4257                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4258                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4259                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4260                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4261                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4262                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4263                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4264                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4265                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4266                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4267                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4268                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4269                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4270                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4271                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4272                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4273                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4274                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4275                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4276                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4277                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4278                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4279                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4280                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4281                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4282                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4283                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4284                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4285                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4286                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4287                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4288
4289                         flags = BindingFlags.Instance | BindingFlags.Public;
4290
4291                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4292                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4293                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4294                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4295                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4296                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4297                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4298                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4299                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4300                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4301                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4302                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4303                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4304                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4305                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4306                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4307                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4308                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4309                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4310                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4311                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4312                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4313                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4314                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4315                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4316                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4317                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4318                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4319                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4320                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4321                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4322                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4323                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4324                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4325                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4326                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4327
4328                         flags = BindingFlags.Static | BindingFlags.Public;
4329
4330                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4331                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4332                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4333                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4334                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4335                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4336                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4337                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4338                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4339                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4340                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4341                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4342                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4343                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4344                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4345                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4346                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4347                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4348                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4349                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4350                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4351                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4352                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4353                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4354                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4355                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4356                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4357                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4358                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4359                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4360                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4361                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4362                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4363                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4364                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4365                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4366
4367                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4368
4369                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4370                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4371                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4372                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4373                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4374                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4375                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4376                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4377                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4378                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4379                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4380                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4381                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4382                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4383                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4384                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4385                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4386                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4387                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4388                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4389                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4390                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4391                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4392                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4393                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4394                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4395                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4396                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4397                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4398                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4399                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4400                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4401                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4402                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4403                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4404                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4405
4406                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4407                                 BindingFlags.FlattenHierarchy;
4408
4409                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4410                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4411                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4412                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4413                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4414                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4415                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4416                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4417                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4418                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4419                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4420                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4421                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4422                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4423                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4424                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4425                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4426                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4427                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4428                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4429                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4430                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4431                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4432                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4433                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4434                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4435                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4436                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4437                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4438                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4439                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4440                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4441                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4442                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4443                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4444                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4445
4446                         flags = BindingFlags.Instance | BindingFlags.Public |
4447                                 BindingFlags.FlattenHierarchy;
4448
4449                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4450                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4451                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4452                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4453                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4454                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4455                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4456                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4457                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4458                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4459                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4460                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4461                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4462                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4463                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4464                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4465                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4466                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4467                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4468                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4469                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4470                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4471                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4472                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4473                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4474                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4475                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4476                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4477                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4478                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4479                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4480                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4481                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4482                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4483                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4484                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4485
4486                         flags = BindingFlags.Static | BindingFlags.Public |
4487                                 BindingFlags.FlattenHierarchy;
4488
4489                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4490                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4491                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4492                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4493                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4494                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4495                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4496                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4497                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4498                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4499                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4500                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4501                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4502                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4503                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4504                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4505                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4506                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4507                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4508                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4509                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4510                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4511                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4512                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4513                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4514                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4515                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4516                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4517                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4518                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4519                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4520                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4521                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4522                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4523                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4524                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4525
4526                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4527                                 BindingFlags.FlattenHierarchy;
4528
4529                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4530                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4531                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4532                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4533                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4534                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4535                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4536                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4537                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4538                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4539                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4540                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4541                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4542                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4543                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4544                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4545                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4546                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4547                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4548                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4549                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4550                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4551                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4552                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4553                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4554                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4555                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4556                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4557                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4558                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4559                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4560                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4561                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4562                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4563                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4564                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4565
4566                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4567                                 BindingFlags.DeclaredOnly;
4568
4569                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4570                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4571                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4572                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4573                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4574                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4575                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4576                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4577                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4578                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4579                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4580                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4581                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4582                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4583                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4584                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4585                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4586                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4587                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4588                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4589                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4590                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4591                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4592                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4593                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4594                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4595                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4596                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4597                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4598                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4599                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4600                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4601                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4602                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4603                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4604                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4605
4606                         flags = BindingFlags.Instance | BindingFlags.Public |
4607                                 BindingFlags.DeclaredOnly;
4608
4609                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4610                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4611                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4612                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4613                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4614                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4615                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4616                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4617                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4618                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4619                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4620                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4621                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4622                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4623                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4624                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4625                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4626                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4627                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4628                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4629                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4630                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4631                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4632                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4633                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4634                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4635                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4636                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4637                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4638                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4639                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4640                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4641                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4642                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4643                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4644                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4645
4646                         flags = BindingFlags.Static | BindingFlags.Public |
4647                                 BindingFlags.DeclaredOnly;
4648
4649                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4650                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4651                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4652                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4653                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4654                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4655                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4656                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4657                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4658                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4659                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4660                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4661                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4662                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4663                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4664                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4665                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4666                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4667                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4668                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4669                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4670                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4671                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4672                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4673                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4674                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4675                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4676                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4677                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4678                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4679                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4680                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4681                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4682                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4683                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4684                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4685
4686                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4687                                 BindingFlags.DeclaredOnly;
4688
4689                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4690                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4691                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4692                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4693                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4694                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4695                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4696                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4697                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4698                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4699                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4700                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4701                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4702                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4703                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4704                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4705                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4706                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4707                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4708                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4709                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4710                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4711                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4712                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4713                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4714                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4715                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4716                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4717                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4718                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4719                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4720                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4721                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4722                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4723                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4724                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4725
4726                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4727                                 BindingFlags.Public;
4728
4729                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4730                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4731                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4732                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4733                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4734                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4735                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4736                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4737                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4738                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4739                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4740                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4741                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4742                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4743                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4744                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4745                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4746                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4747                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4748                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4749                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4750                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4751                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4752                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4753                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4754                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4755                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4756                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4757                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4758                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4759                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4760                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4761                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4762                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4763                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4764                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4765
4766                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4767                                 BindingFlags.Public;
4768
4769                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4770                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4771                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4772                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4773                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4774                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4775                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4776                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4777                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4778                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4779                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4780                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4781                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4782                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4783                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4784                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4785                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4786                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4787                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4788                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4789                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4790                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4791                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4792                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4793                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4794                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4795                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4796                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4797                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4798                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4799                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4800                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4801                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4802                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4803                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4804                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4805                 }
4806
4807                 [Test]
4808                 [Category ("NotWorking")] // mcs depends on this
4809                 public void TestGetFieldsIncomplete_MS ()
4810                 {
4811                         TypeBuilder tb = module.DefineType (genTypeName ());
4812                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4813                         try {
4814                                 tb.GetFields ();
4815                                 Assert.Fail ("#1");
4816                         } catch (NotSupportedException ex) {
4817                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4818                                 Assert.IsNull (ex.InnerException, "#3");
4819                                 Assert.IsNotNull (ex.Message, "#4");
4820                         }
4821                 }
4822
4823                 [Test]
4824                 [Category ("NotDotNet")] // mcs depends on this
4825                 public void TestGetFieldsIncomplete_Mono ()
4826                 {
4827                         TypeBuilder tb = module.DefineType (genTypeName ());
4828                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4829                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4830                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4831                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4832
4833                         FieldInfo [] fields = tb.GetFields ();
4834                         Assert.AreEqual (2, fields.Length, "#A1");
4835                         Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4836                         Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4837
4838                         tb = module.DefineType (genTypeName ());
4839                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4840                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4841                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4842                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4843                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4844                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4845
4846                         fields = tb.GetFields ();
4847                         Assert.AreEqual (4, fields.Length, "#B1");
4848                         Assert.AreEqual ("First", fields [0].Name, "#B2");
4849                         Assert.AreEqual ("Second", fields [1].Name, "#B3");
4850                         Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4851                         Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4852                 }
4853
4854                 [Test]
4855                 public void TestGetFieldsComplete ()
4856                 {
4857                         TypeBuilder tb = module.DefineType (genTypeName ());
4858                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4859
4860                         Type emittedType = tb.CreateType ();
4861                         FieldInfo [] dynamicFields = tb.GetFields ();
4862                         FieldInfo [] emittedFields = emittedType.GetFields ();
4863
4864                         Assert.AreEqual (1, dynamicFields.Length, "#A1");
4865                         Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4866                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4867                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4868
4869                         // bug #81638
4870                         object value = Activator.CreateInstance (emittedType);
4871                         emittedFields [0].SetValue (value, 5);
4872                         Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4873                         Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4874                         dynamicFields [0].SetValue (value, 4);
4875                         Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4876                         Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4877                 }
4878
4879                 [Test] // bug #82625 / 325292
4880                 public void TestGetFieldsComplete_Generic ()
4881                 {
4882                         // FIXME: merge this with TestGetFieldsComplete when
4883                         // bug #82625 is fixed
4884
4885                         TypeBuilder tb;
4886                         Type emittedType;
4887                         FieldInfo [] dynamicFields;
4888                         FieldInfo [] emittedFields;
4889
4890                         tb = module.DefineType (genTypeName ());
4891                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4892                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4893                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4894                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4895                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4896                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4897
4898                         emittedType = tb.CreateType ();
4899                         dynamicFields = tb.GetFields ();
4900                         emittedFields = emittedType.GetFields ();
4901
4902                         Assert.AreEqual (4, dynamicFields.Length, "#C1");
4903                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4904                         Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4905                         Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4906                         Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4907                         Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4908                         Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4909                         Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4910                         Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4911
4912                         Assert.AreEqual (4, emittedFields.Length, "#D1");
4913                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4914                         Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4915                         Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4916                         Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4917                         Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4918                         Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4919                         Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4920                         Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4921                 }
4922
4923                 [Test]
4924                 [Category ("NotWorking")] // mcs depends on this
4925                 public void TestGetFieldsFlagsIncomplete_MS ()
4926                 {
4927                         TypeBuilder tb = module.DefineType (genTypeName ());
4928                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4929                         try {
4930                                 tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4931                                 Assert.Fail ("#1");
4932                         } catch (NotSupportedException ex) {
4933                                 // The invoked member is not supported in a
4934                                 // dynamic module
4935                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4936                                 Assert.IsNull (ex.InnerException, "#3");
4937                                 Assert.IsNotNull (ex.Message, "#4");
4938                         }
4939                 }
4940
4941                 [Test]
4942                 [Category ("NotDotNet")] // mcs depends on this
4943                 public void TestGetFieldsFlagsIncomplete_Mono ()
4944                 {
4945                         FieldInfo [] fields;
4946
4947                         TypeBuilder tb = module.DefineType (genTypeName ());
4948                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4949                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4950                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4951                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4952
4953                         fields = tb.GetFields (BindingFlags.Public |
4954                                 BindingFlags.NonPublic | BindingFlags.Instance);
4955                         Assert.AreEqual (2, fields.Length, "#A1");
4956                         Assert.AreEqual ("name", fields [0].Name, "#A2");
4957                         Assert.AreEqual ("Sex", fields [1].Name, "#A3");
4958
4959                         fields = tb.GetFields (BindingFlags.Public |
4960                                 BindingFlags.Instance | BindingFlags.Static);
4961                         Assert.AreEqual (2, fields.Length, "#B1");
4962                         Assert.AreEqual ("Sex", fields [0].Name, "#B2");
4963                         Assert.AreEqual ("MALE", fields [1].Name, "#B3");
4964
4965                         fields = tb.GetFields (BindingFlags.Public |
4966                                 BindingFlags.NonPublic | BindingFlags.Instance |
4967                                 BindingFlags.Static);
4968                         Assert.AreEqual (4, fields.Length, "#C1");
4969                         Assert.AreEqual ("name", fields [0].Name, "#C2");
4970                         Assert.AreEqual ("Sex", fields [1].Name, "#C3");
4971                         Assert.AreEqual ("MALE", fields [2].Name, "#C4");
4972                         Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
4973                 }
4974
4975                 [Test]
4976                 public void TestGetFieldsFlagsComplete ()
4977                 {
4978                         TypeBuilder tb = module.DefineType (genTypeName ());
4979                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4980
4981                         Type emittedType = tb.CreateType ();
4982
4983                         Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4984                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
4985                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4986                         Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4987                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
4988                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4989                 }
4990
4991                 [Test]
4992                 public void TestGetFieldsFlagsComplete_Inheritance ()
4993                 {
4994                         FieldInfo [] fields;
4995                         BindingFlags flags;
4996
4997                         TypeBuilder blueType = module.DefineType (genTypeName (),
4998                                 TypeAttributes.Public);
4999                         CreateMembers (blueType, "Blue", false);
5000
5001                         TypeBuilder redType = module.DefineType (genTypeName (),
5002                                 TypeAttributes.Public, blueType);
5003                         CreateMembers (redType, "Red", false);
5004
5005                         TypeBuilder greenType = module.DefineType (genTypeName (),
5006                                 TypeAttributes.Public, redType);
5007                         CreateMembers (greenType, "Green", false);
5008
5009                         blueType.CreateType ();
5010                         redType.CreateType ();
5011                         greenType.CreateType ();
5012
5013                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5014                         fields = greenType.GetFields (flags);
5015
5016                         Assert.AreEqual (13, fields.Length, "#A1");
5017                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
5018                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
5019                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
5020                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
5021                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
5022                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
5023                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5024                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5025                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5026                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5027                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5028                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5029                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5030
5031                         flags = BindingFlags.Instance | BindingFlags.Public;
5032                         fields = greenType.GetFields (flags);
5033
5034                         Assert.AreEqual (3, fields.Length, "#B1");
5035                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5036                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5037                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5038
5039                         flags = BindingFlags.Static | BindingFlags.Public;
5040                         fields = greenType.GetFields (flags);
5041
5042                         Assert.AreEqual (1, fields.Length, "#C1");
5043                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5044
5045                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5046                         fields = greenType.GetFields (flags);
5047
5048                         Assert.AreEqual (5, fields.Length, "#D1");
5049                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5050                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5051                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5052                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5053                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5054
5055                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5056                                 BindingFlags.FlattenHierarchy;
5057                         fields = greenType.GetFields (flags);
5058
5059                         Assert.AreEqual (13, fields.Length, "#E1");
5060                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5061                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5062                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5063                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5064                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5065                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5066                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5067                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5068                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5069                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5070                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5071                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5072                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5073
5074                         flags = BindingFlags.Instance | BindingFlags.Public |
5075                                 BindingFlags.FlattenHierarchy;
5076                         fields = greenType.GetFields (flags);
5077
5078                         Assert.AreEqual (3, fields.Length, "#F1");
5079                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5080                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5081                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5082
5083                         flags = BindingFlags.Static | BindingFlags.Public |
5084                                 BindingFlags.FlattenHierarchy;
5085                         fields = greenType.GetFields (flags);
5086
5087                         Assert.AreEqual (3, fields.Length, "#G1");
5088                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5089                         Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5090                         Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5091
5092                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5093                                 BindingFlags.FlattenHierarchy;
5094                         fields = greenType.GetFields (flags);
5095
5096                         Assert.AreEqual (13, fields.Length, "#H1");
5097                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5098                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5099                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5100                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5101                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5102                         Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5103                         Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5104                         Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5105                         Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5106                         Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5107                         Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5108                         Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5109                         Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5110
5111                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5112                                 BindingFlags.DeclaredOnly;
5113                         fields = greenType.GetFields (flags);
5114
5115                         Assert.AreEqual (5, fields.Length, "#I1");
5116                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5117                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5118                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5119                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5120                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5121
5122                         flags = BindingFlags.Instance | BindingFlags.Public |
5123                                 BindingFlags.DeclaredOnly;
5124                         fields = greenType.GetFields (flags);
5125
5126                         Assert.AreEqual (1, fields.Length, "#J1");
5127                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5128
5129                         flags = BindingFlags.Static | BindingFlags.Public |
5130                                 BindingFlags.DeclaredOnly;
5131                         fields = greenType.GetFields (flags);
5132
5133                         Assert.AreEqual (1, fields.Length, "#K1");
5134                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5135
5136                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5137                                 BindingFlags.DeclaredOnly;
5138                         fields = greenType.GetFields (flags);
5139
5140                         Assert.AreEqual (5, fields.Length, "#L1");
5141                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5142                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5143                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5144                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5145                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5146
5147                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5148                                 BindingFlags.Public;
5149                         fields = greenType.GetFields (flags);
5150
5151                         Assert.AreEqual (16, fields.Length, "#M1");
5152                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5153                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5154                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5155                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5156                         Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5157                         Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5158                         Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5159                         Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5160                         Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5161                         Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5162                         Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5163                         Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5164                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5165                         Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5166                         Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5167                         Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5168
5169                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5170                                 BindingFlags.Public;
5171                         fields = greenType.GetFields (flags);
5172
5173                         Assert.AreEqual (6, fields.Length, "#N1");
5174                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5175                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5176                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5177                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5178                         Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5179                         Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5180                 }
5181
5182                 [Test]
5183                 [Category ("NotWorking")] // mcs depends on this
5184                 public void TestGetFieldIncomplete_MS ()
5185                 {
5186                         TypeBuilder tb = module.DefineType (genTypeName ());
5187                         tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5188                         try {
5189                                 tb.GetField ("test");
5190                                 Assert.Fail ("#1");
5191                         } catch (NotSupportedException ex) {
5192                                 // The invoked member is not supported in a
5193                                 // dynamic module
5194                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5195                                 Assert.IsNull (ex.InnerException, "#3");
5196                                 Assert.IsNotNull (ex.Message, "#4");
5197                         }
5198                 }
5199
5200                 [Test]
5201                 [Category ("NotDotNet")] // mcs depends on this
5202                 public void TestGetFieldIncomplete_Mono ()
5203                 {
5204                         TypeBuilder tb = module.DefineType (genTypeName ());
5205                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5206                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5207
5208                         FieldInfo field = tb.GetField ("TestField");
5209                         Assert.IsNotNull (field, "#A1");
5210                         Assert.AreEqual ("TestField", field.Name, "#A2");
5211                         Assert.IsTrue (field is FieldBuilder, "#A3");
5212
5213                         Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5214                         Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5215                 }
5216
5217                 [Test]
5218                 public void TestGetFieldComplete ()
5219                 {
5220                         TypeBuilder tb = module.DefineType (genTypeName ());
5221                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5222
5223                         Type emittedType = tb.CreateType ();
5224
5225                         FieldInfo dynamicField = tb.GetField ("TestField");
5226                         FieldInfo emittedField = emittedType.GetField ("TestField");
5227                         Assert.IsNotNull (dynamicField, "#A1");
5228                         Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5229                         Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5230                         Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5231                         Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5232
5233                         // bug #81638
5234                         object value = Activator.CreateInstance (emittedType);
5235                         emittedField.SetValue (value, 5);
5236                         Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5237                         Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5238                         dynamicField.SetValue (value, 4);
5239                         Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5240                         Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5241                 }
5242
5243                 [Test] // bug #81640
5244                 public void TestGetFieldComplete_Type ()
5245                 {
5246                         TypeBuilder tb = module.DefineType (genTypeName ());
5247                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5248                         Type emittedType = tb.CreateType ();
5249                         FieldInfo dynamicField = tb.GetField ("TestField");
5250                         Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5251
5252                         object value = Activator.CreateInstance (emittedType);
5253                         Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5254                 }
5255
5256                 [Test]
5257                 [Category ("NotWorking")] // mcs depends on this
5258                 public void TestGetFieldFlagsIncomplete_MS ()
5259                 {
5260                         TypeBuilder tb = module.DefineType (genTypeName ());
5261                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5262                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5263                         try {
5264                                 tb.GetField ("test", BindingFlags.Public);
5265                                 Assert.Fail ("#1");
5266                         } catch (NotSupportedException ex) {
5267                                 // The invoked member is not supported in a
5268                                 // dynamic module
5269                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5270                                 Assert.IsNull (ex.InnerException, "#3");
5271                                 Assert.IsNotNull (ex.Message, "#4");
5272                         }
5273                 }
5274
5275                 [Test]
5276                 [Category ("NotDotNet")] // mcs depends on this
5277                 public void TestGetFieldFlagsIncomplete_Mono ()
5278                 {
5279                         TypeBuilder tb = module.DefineType (genTypeName ());
5280                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5281                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5282
5283                         FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5284                                 | BindingFlags.Instance);
5285                         Assert.IsNotNull (field, "#A1");
5286                         Assert.AreEqual ("TestField", field.Name, "#A2");
5287                         Assert.IsTrue (field is FieldBuilder, "#A3");
5288
5289                         field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5290                                 BindingFlags.Instance);
5291                         Assert.IsNotNull (field, "#B1");
5292                         Assert.AreEqual ("OtherField", field.Name, "#B2");
5293                         Assert.IsTrue (field is FieldBuilder, "#B3");
5294
5295                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5296                                 BindingFlags.Instance), "#C1");
5297                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5298                                 BindingFlags.Static), "#C2");
5299                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5300                                 BindingFlags.Instance), "#C3");
5301                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5302                                 BindingFlags.Static), "#C4");
5303                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5304                                 BindingFlags.Instance), "#C5");
5305                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5306                                 BindingFlags.Instance), "#C6");
5307                 }
5308
5309                 [Test]
5310                 public void TestGetFieldFlagsComplete ()
5311                 {
5312                         TypeBuilder tb = module.DefineType (genTypeName ());
5313                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5314
5315                         Type emittedType = tb.CreateType ();
5316
5317                         Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5318                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5319                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5320                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5321                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5322                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5323                 }
5324
5325                 [Test]
5326                 public void TestGetFieldFlagsComplete_Inheritance ()
5327                 {
5328                         BindingFlags flags;
5329
5330                         TypeBuilder blueType = module.DefineType (genTypeName (),
5331                                 TypeAttributes.Public);
5332                         CreateMembers (blueType, "Blue", false);
5333
5334                         TypeBuilder redType = module.DefineType (genTypeName (),
5335                                 TypeAttributes.Public, blueType);
5336                         CreateMembers (redType, "Red", false);
5337
5338                         TypeBuilder greenType = module.DefineType (genTypeName (),
5339                                 TypeAttributes.Public, redType);
5340                         CreateMembers (greenType, "Green", false);
5341
5342                         blueType.CreateType ();
5343                         redType.CreateType ();
5344                         greenType.CreateType ();
5345
5346                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5347
5348                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5349                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5350                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5351                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5352                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5353                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5354                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5355                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5356                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5357                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5358                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5359                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5360                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5361                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5362                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5363                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5364                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5365                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5366                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5367                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5368                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5369                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5370                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5371                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5372                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5373                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5374                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5375                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5376                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5377                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5378                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5379                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5380                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5381                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5382                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5383                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5384
5385                         flags = BindingFlags.Instance | BindingFlags.Public;
5386
5387                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5388                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5389                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5390                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5391                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5392                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5393                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5394                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5395                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5396                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5397                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5398                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5399                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5400                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5401                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5402                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5403                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5404                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5405                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5406                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5407                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5408                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5409                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5410                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5411                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5412                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5413                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5414                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5415                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5416                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5417                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5418                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5419                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5420                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5421                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5422                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5423
5424                         flags = BindingFlags.Static | BindingFlags.Public;
5425
5426                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5427                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5428                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5429                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5430                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5431                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5432                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5433                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5434                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5435                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5436                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5437                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5438                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5439                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5440                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5441                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5442                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5443                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5444                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5445                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5446                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5447                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5448                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5449                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5450                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5451                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5452                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5453                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5454                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5455                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5456                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5457                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5458                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5459                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5460                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5461                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5462
5463                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5464
5465                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5466                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5467                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5468                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5469                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5470                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5471                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5472                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5473                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5474                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5475                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5476                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5477                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5478                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5479                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5480                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5481                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5482                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5483                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5484                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5485                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5486                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5487                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5488                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5489                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5490                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5491                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5492                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5493                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5494                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5495                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5496                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5497                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5498                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5499                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5500                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5501
5502                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5503                                 BindingFlags.FlattenHierarchy;
5504
5505                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5506                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5507                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5508                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5509                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5510                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5511                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5512                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5513                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5514                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5515                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5516                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5517                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5518                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5519                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5520                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5521                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5522                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5523                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5524                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5525                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5526                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5527                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5528                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5529                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5530                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5531                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5532                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5533                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5534                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5535                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5536                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5537                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5538                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5539                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5540                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5541
5542                         flags = BindingFlags.Instance | BindingFlags.Public |
5543                                 BindingFlags.FlattenHierarchy;
5544
5545                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5546                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5547                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5548                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5549                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5550                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5551                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5552                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5553                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5554                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5555                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5556                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5557                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5558                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5559                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5560                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5561                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5562                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5563                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5564                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5565                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5566                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5567                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5568                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5569                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5570                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5571                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5572                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5573                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5574                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5575                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5576                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5577                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5578                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5579                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5580                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5581
5582                         flags = BindingFlags.Static | BindingFlags.Public |
5583                                 BindingFlags.FlattenHierarchy;
5584
5585                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5586                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5587                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5588                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5589                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5590                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5591                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5592                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5593                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5594                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5595                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5596                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5597                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5598                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5599                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5600                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5601                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5602                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5603                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5604                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5605                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5606                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5607                         Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5608                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5609                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5610                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5611                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5612                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5613                         Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5614                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5615                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5616                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5617                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5618                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5619                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5620                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5621
5622                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5623                                 BindingFlags.FlattenHierarchy;
5624
5625                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5626                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5627                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5628                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5629                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5630                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5631                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5632                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5633                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5634                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5635                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5636                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5637                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5638                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5639                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5640                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5641                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5642                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5643                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5644                         Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5645                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5646                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5647                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5648                         Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5649                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5650                         Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5651                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5652                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5653                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5654                         Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5655                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5656                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5657                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5658                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5659                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5660                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5661
5662                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5663                                 BindingFlags.DeclaredOnly;
5664
5665                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5666                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5667                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5668                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5669                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5670                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5671                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5672                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5673                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5674                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5675                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5676                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5677                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5678                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5679                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5680                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5681                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5682                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5683                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5684                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5685                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5686                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5687                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5688                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5689                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5690                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5691                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5692                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5693                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5694                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5695                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5696                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5697                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5698                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5699                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5700                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5701
5702                         flags = BindingFlags.Instance | BindingFlags.Public |
5703                                 BindingFlags.DeclaredOnly;
5704
5705                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5706                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5707                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5708                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5709                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5710                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5711                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5712                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5713                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5714                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5715                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5716                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5717                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5718                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5719                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5720                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5721                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5722                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5723                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5724                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5725                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5726                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5727                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5728                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5729                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5730                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5731                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5732                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5733                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5734                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5735                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5736                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5737                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5738                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5739                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5740                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5741
5742                         flags = BindingFlags.Static | BindingFlags.Public |
5743                                 BindingFlags.DeclaredOnly;
5744
5745                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5746                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5747                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5748                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5749                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5750                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5751                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5752                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5753                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5754                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5755                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5756                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5757                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5758                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5759                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5760                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5761                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5762                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5763                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5764                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5765                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5766                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5767                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5768                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5769                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5770                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5771                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5772                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5773                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5774                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5775                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5776                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5777                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5778                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5779                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5780                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5781
5782                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5783                                 BindingFlags.DeclaredOnly;
5784
5785                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5786                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5787                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5788                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5789                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5790                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5791                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5792                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5793                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5794                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5795                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5796                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5797                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5798                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5799                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5800                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5801                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5802                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5803                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5804                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5805                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5806                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5807                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5808                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5809                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5810                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5811                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5812                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5813                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5814                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5815                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5816                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5817                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5818                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5819                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5820                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5821
5822                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5823                                 BindingFlags.Public;
5824
5825                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5826                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5827                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5828                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5829                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5830                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5831                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5832                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5833                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5834                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5835                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5836                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5837                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5838                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5839                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5840                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5841                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5842                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5843                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5844                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5845                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5846                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5847                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5848                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5849                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5850                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5851                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5852                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5853                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5854                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5855                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5856                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5857                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5858                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5859                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5860                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5861
5862                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5863                                 BindingFlags.Public;
5864
5865                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5866                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5867                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5868                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5869                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5870                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5871                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5872                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5873                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5874                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5875                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5876                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5877                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5878                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5879                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5880                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5881                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5882                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5883                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5884                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5885                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5886                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5887                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5888                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5889                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5890                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5891                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5892                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5893                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5894                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5895                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5896                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5897                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5898                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5899                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5900                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5901                 }
5902
5903                 [Test]
5904                 [Category ("NotDotNet")] // mcs depends on this
5905                 public void TestGetPropertiesIncomplete_Mono ()
5906                 {
5907                         TypeBuilder tb = module.DefineType (genTypeName ());
5908                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5909                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5910                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5911
5912                         PropertyInfo [] properties = tb.GetProperties ();
5913                         Assert.AreEqual (2, properties.Length, "#1");
5914                         Assert.AreEqual ("Name", properties [0].Name, "#2");
5915                         Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5916                 }
5917
5918                 [Test]
5919                 [Category ("NotWorking")] // mcs depends on this
5920                 public void TestGetPropertiesIncomplete_MS ()
5921                 {
5922                         TypeBuilder tb = module.DefineType (genTypeName ());
5923                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5924                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5925                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5926
5927                         try {
5928                                 tb.GetProperties ();
5929                                 Assert.Fail ("#1");
5930                         } catch (NotSupportedException ex) {
5931                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5932                                 Assert.IsNull (ex.InnerException, "#3");
5933                                 Assert.IsNotNull (ex.Message, "#4");
5934                         }
5935                 }
5936
5937                 [Test]
5938                 public void TestGetPropertiesComplete ()
5939                 {
5940                         TypeBuilder tb = module.DefineType (genTypeName ());
5941                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5942
5943                         Type emittedType = tb.CreateType ();
5944
5945                         Assert.AreEqual (1, tb.GetProperties ().Length);
5946                         Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
5947                 }
5948
5949                 [Test]
5950                 [Category ("NotDotNet")] // mcs depends on this
5951                 public void TestGetPropertiesFlagsIncomplete_Mono ()
5952                 {
5953                         PropertyInfo [] properties;
5954
5955                         TypeBuilder tb = module.DefineType (genTypeName ());
5956                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5957                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5958                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5959
5960                         properties = tb.GetProperties (BindingFlags.Public | 
5961                                 BindingFlags.NonPublic | BindingFlags.Instance);
5962                         Assert.AreEqual (3, properties.Length, "#A1");
5963                         Assert.AreEqual ("Name", properties [0].Name, "#A2");
5964                         Assert.AreEqual ("Income", properties [1].Name, "#A3");
5965                         Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
5966
5967                         properties = tb.GetProperties (BindingFlags.Public |
5968                                 BindingFlags.Instance);
5969                         Assert.AreEqual (2, properties.Length, "#B1");
5970                         Assert.AreEqual ("Name", properties [0].Name, "#B2");
5971                         Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
5972
5973                         properties = tb.GetProperties (BindingFlags.NonPublic |
5974                                 BindingFlags.Instance);
5975                         Assert.AreEqual (1, properties.Length, "#C1");
5976                         Assert.AreEqual ("Income", properties [0].Name, "#C2");
5977                 }
5978
5979                 [Test]
5980                 [Category ("NotWorking")] // mcs depends on this
5981                 public void TestGetPropertiesFlagsIncomplete_MS ()
5982                 {
5983                         TypeBuilder tb = module.DefineType (genTypeName ());
5984                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5985                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5986                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5987
5988                         try {
5989                                 tb.GetProperties (BindingFlags.Public);
5990                                 Assert.Fail ("#1");
5991                         } catch (NotSupportedException ex) {
5992                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5993                                 Assert.IsNull (ex.InnerException, "#3");
5994                                 Assert.IsNotNull (ex.Message, "#4");
5995                         }
5996                 }
5997
5998                 [Test]
5999                 public void TestGetPropertiesFlagsComplete ()
6000                 {
6001                         TypeBuilder tb = module.DefineType (genTypeName ());
6002                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6003
6004                         Type emittedType = tb.CreateType ();
6005
6006                         Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6007                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
6008                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6009                         Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6010                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
6011                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6012                 }
6013
6014                 [Test]
6015                 public void TestGetPropertiesFlagsComplete_Inheritance ()
6016                 {
6017                         PropertyInfo [] props;
6018                         BindingFlags flags;
6019
6020                         TypeBuilder blueType = module.DefineType (genTypeName (),
6021                                 TypeAttributes.Public);
6022                         CreateMembers (blueType, "Blue", false);
6023
6024                         TypeBuilder redType = module.DefineType (genTypeName (),
6025                                 TypeAttributes.Public, blueType);
6026                         CreateMembers (redType, "Red", false);
6027
6028                         TypeBuilder greenType = module.DefineType (genTypeName (),
6029                                 TypeAttributes.Public, redType);
6030                         CreateMembers (greenType, "Green", false);
6031
6032                         blueType.CreateType ();
6033                         redType.CreateType ();
6034                         greenType.CreateType ();
6035
6036                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6037                         props = greenType.GetProperties (flags);
6038
6039                         Assert.AreEqual (13, props.Length, "#A1");
6040                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6041                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6042                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6043                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6044                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6045                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6046                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6047                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6048                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6049                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6050                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6051                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6052                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6053
6054                         flags = BindingFlags.Instance | BindingFlags.Public;
6055                         props = greenType.GetProperties (flags);
6056
6057                         Assert.AreEqual (3, props.Length, "#B1");
6058                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6059                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6060                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6061
6062                         flags = BindingFlags.Static | BindingFlags.Public;
6063                         props = greenType.GetProperties (flags);
6064
6065                         Assert.AreEqual (1, props.Length, "#C1");
6066                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6067
6068                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6069                         props = greenType.GetProperties (flags);
6070
6071                         Assert.AreEqual (5, props.Length, "#D1");
6072                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6073                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6074                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6075                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6076                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6077
6078                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6079                                 BindingFlags.FlattenHierarchy;
6080                         props = greenType.GetProperties (flags);
6081
6082                         Assert.AreEqual (13, props.Length, "#E1");
6083                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6084                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6085                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6086                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6087                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6088                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6089                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6090                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6091                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6092                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6093                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6094                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6095                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6096
6097                         flags = BindingFlags.Instance | BindingFlags.Public |
6098                                 BindingFlags.FlattenHierarchy;
6099                         props = greenType.GetProperties (flags);
6100
6101                         Assert.AreEqual (3, props.Length, "#F1");
6102                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6103                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6104                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6105
6106                         flags = BindingFlags.Static | BindingFlags.Public |
6107                                 BindingFlags.FlattenHierarchy;
6108                         props = greenType.GetProperties (flags);
6109
6110                         Assert.AreEqual (3, props.Length, "#G1");
6111                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6112                         Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6113                         Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6114
6115                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6116                                 BindingFlags.FlattenHierarchy;
6117                         props = greenType.GetProperties (flags);
6118
6119                         Assert.AreEqual (13, props.Length, "#H1");
6120                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6121                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6122                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6123                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6124                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6125                         Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6126                         Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6127                         Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6128                         Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6129                         Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6130                         Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6131                         Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6132                         Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6133
6134                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6135                                 BindingFlags.DeclaredOnly;
6136                         props = greenType.GetProperties (flags);
6137
6138                         Assert.AreEqual (5, props.Length, "#I1");
6139                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6140                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6141                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6142                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6143                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6144
6145                         flags = BindingFlags.Instance | BindingFlags.Public |
6146                                 BindingFlags.DeclaredOnly;
6147                         props = greenType.GetProperties (flags);
6148
6149                         Assert.AreEqual (1, props.Length, "#J1");
6150                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6151
6152                         flags = BindingFlags.Static | BindingFlags.Public |
6153                                 BindingFlags.DeclaredOnly;
6154                         props = greenType.GetProperties (flags);
6155
6156                         Assert.AreEqual (1, props.Length, "#K1");
6157                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6158
6159                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6160                                 BindingFlags.DeclaredOnly;
6161                         props = greenType.GetProperties (flags);
6162
6163                         Assert.AreEqual (5, props.Length, "#L1");
6164                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6165                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6166                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6167                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6168                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6169
6170                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6171                                 BindingFlags.Public;
6172                         props = greenType.GetProperties (flags);
6173
6174                         Assert.AreEqual (16, props.Length, "#M1");
6175                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6176                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6177                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6178                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6179                         Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6180                         Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6181                         Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6182                         Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6183                         Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6184                         Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6185                         Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6186                         Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6187                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6188                         Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6189                         Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6190                         Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6191
6192                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6193                                 BindingFlags.Public;
6194                         props = greenType.GetProperties (flags);
6195
6196                         Assert.AreEqual (6, props.Length, "#N1");
6197                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6198                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6199                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6200                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6201                         Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6202                         Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6203                 }
6204
6205                 [Test]
6206                 public void TestGetPropertyIncomplete ()
6207                 {
6208                         TypeBuilder tb = module.DefineType (genTypeName ());
6209                         try {
6210                                 tb.GetProperty ("test");
6211                                 Assert.Fail ("#1");
6212                         } catch (NotSupportedException ex) {
6213                                 // The invoked member is not supported in a
6214                                 // dynamic module
6215                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6216                                 Assert.IsNull (ex.InnerException, "#3");
6217                                 Assert.IsNotNull (ex.Message, "#4");
6218                         }
6219                 }
6220
6221                 [Test]
6222                 public void TestGetPropertyComplete ()
6223                 {
6224                         TypeBuilder tb = module.DefineType (genTypeName ());
6225                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6226
6227                         Type emittedType = tb.CreateType ();
6228
6229                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6230                         Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6231
6232                         try {
6233                                 tb.GetProperty ("CustomerName");
6234                                 Assert.Fail ("#1");
6235                         } catch (NotSupportedException ex) {
6236                                 // The invoked member is not supported in a
6237                                 // dynamic module
6238                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6239                                 Assert.IsNull (ex.InnerException, "#3");
6240                                 Assert.IsNotNull (ex.Message, "#4");
6241                         }
6242                 }
6243
6244                 [Test]
6245                 public void TestGetPropertyFlagsIncomplete ()
6246                 {
6247                         TypeBuilder tb = module.DefineType (genTypeName ());
6248                         try {
6249                                 tb.GetProperty ("test", BindingFlags.Public);
6250                                 Assert.Fail ("#1");
6251                         } catch (NotSupportedException ex) {
6252                                 // The invoked member is not supported in a
6253                                 // dynamic module
6254                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6255                                 Assert.IsNull (ex.InnerException, "#3");
6256                                 Assert.IsNotNull (ex.Message, "#4");
6257                         }
6258                 }
6259
6260                 [Test]
6261                 public void TestGetPropertyFlagsComplete ()
6262                 {
6263                         TypeBuilder tb = module.DefineType (genTypeName ());
6264                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6265
6266                         Type emittedType = tb.CreateType ();
6267
6268                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6269                                 BindingFlags.Public));
6270                         Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6271                                 BindingFlags.NonPublic));
6272
6273                         try {
6274                                 tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6275                                 Assert.Fail ("#1");
6276                         } catch (NotSupportedException ex) {
6277                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6278                                 Assert.IsNull (ex.InnerException, "#3");
6279                                 Assert.IsNotNull (ex.Message, "#4");
6280                         }
6281                 }
6282
6283                 [Test]
6284                 public void TestGetMethodFlagsComplete ()
6285                 {
6286                         BindingFlags flags;
6287
6288                         TypeBuilder blueType = module.DefineType (genTypeName (),
6289                                 TypeAttributes.Public);
6290                         CreateMembers (blueType, "Blue", false);
6291
6292                         TypeBuilder redType = module.DefineType (genTypeName (),
6293                                 TypeAttributes.Public, blueType);
6294                         CreateMembers (redType, "Red", false);
6295
6296                         TypeBuilder greenType = module.DefineType (genTypeName (),
6297                                 TypeAttributes.Public, redType);
6298                         CreateMembers (greenType, "Green", false);
6299
6300                         blueType.CreateType ();
6301                         redType.CreateType ();
6302                         greenType.CreateType ();
6303
6304                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6305
6306                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6307                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6308                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6309                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6310                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6311                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6312                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6313                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6314                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6315                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6316                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6317                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6318                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6319                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6320                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6321                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6322                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6323                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6324                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6325                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6326                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6327                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6328                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6329                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6330                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6331                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6332                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6333                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6334                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6335                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6336                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6337                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6338                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6339                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6340                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6341                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6342
6343                         flags = BindingFlags.Instance | BindingFlags.Public;
6344
6345                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6346                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6347                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6348                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6349                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6350                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6351                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6352                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6353                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6354                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6355                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6356                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6357                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6358                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6359                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6360                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6361                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6362                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6363                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6364                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6365                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6366                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6367                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6368                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6369                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6370                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6371                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6372                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6373                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6374                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6375                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6376                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6377                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6378                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6379                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6380                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6381
6382                         flags = BindingFlags.Static | BindingFlags.Public;
6383
6384                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6385                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6386                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6387                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6388                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6389                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6390                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6391                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6392                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6393                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6394                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6395                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6396                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6397                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6398                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6399                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6400                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6401                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6402                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6403                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6404                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6405                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6406                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6407                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6408                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6409                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6410                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6411                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6412                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6413                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6414                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6415                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6416                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6417                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6418                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6419                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6420
6421                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6422
6423                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6424                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6425                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6426                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6427                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6428                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6429                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6430                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6431                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6432                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6433                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6434                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6435                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6436                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6437                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6438                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6439                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6440                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6441                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6442                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6443                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6444                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6445                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6446                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6447                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6448                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6449                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6450                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6451                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6452                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6453                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6454                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6455                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6456                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6457                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6458                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6459
6460                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6461                                 BindingFlags.FlattenHierarchy;
6462
6463                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6464                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6465                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6466                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6467                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6468                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6469                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6470                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6471                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6472                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6473                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6474                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6475                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6476                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6477                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6478                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6479                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6480                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6481                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6482                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6483                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6484                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6485                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6486                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6487                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6488                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6489                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6490                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6491                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6492                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6493                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6494                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6495                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6496                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6497                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6498                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6499
6500                         flags = BindingFlags.Instance | BindingFlags.Public |
6501                                 BindingFlags.FlattenHierarchy;
6502
6503                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6504                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6505                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6506                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6507                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6508                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6509                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6510                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6511                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6512                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6513                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6514                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6515                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6516                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6517                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6518                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6519                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6520                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6521                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6522                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6523                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6524                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6525                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6526                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6527                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6528                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6529                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6530                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6531                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6532                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6533                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6534                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6535                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6536                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6537                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6538                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6539
6540                         flags = BindingFlags.Static | BindingFlags.Public |
6541                                 BindingFlags.FlattenHierarchy;
6542
6543                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6544                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6545                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6546                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6547                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6548                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6549                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6550                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6551                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6552                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6553                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6554                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6555                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6556                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6557                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6558                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6559                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6560                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6561                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6562                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6563                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6564                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6565                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6566                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6567                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6568                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6569                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6570                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6571                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6572                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6573                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6574                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6575                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6576                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6577                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6578                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6579
6580                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6581                                 BindingFlags.FlattenHierarchy;
6582
6583                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6584                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6585                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6586                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6587                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6588                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6589                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6590                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6591                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6592                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6593                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6594                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6595                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6596                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6597                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6598                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6599                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6600                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6601                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6602                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6603                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6604                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6605                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6606                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6607                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6608                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6609                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6610                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6611                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6612                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6613                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6614                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6615                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6616                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6617                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6618                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6619
6620                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6621                                 BindingFlags.DeclaredOnly;
6622
6623                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6624                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6625                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6626                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6627                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6628                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6629                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6630                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6631                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6632                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6633                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6634                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6635                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6636                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6637                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6638                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6639                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6640                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6641                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6642                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6643                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6644                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6645                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6646                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6647                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6648                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6649                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6650                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6651                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6652                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6653                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6654                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6655                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6656                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6657                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6658                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6659
6660                         flags = BindingFlags.Instance | BindingFlags.Public |
6661                                 BindingFlags.DeclaredOnly;
6662
6663                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6664                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6665                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6666                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6667                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6668                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6669                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6670                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6671                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6672                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6673                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6674                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6675                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6676                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6677                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6678                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6679                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6680                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6681                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6682                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6683                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6684                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6685                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6686                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6687                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6688                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6689                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6690                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6691                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6692                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6693                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6694                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6695                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6696                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6697                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6698                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6699
6700                         flags = BindingFlags.Static | BindingFlags.Public |
6701                                 BindingFlags.DeclaredOnly;
6702
6703                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6704                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6705                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6706                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6707                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6708                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6709                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6710                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6711                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6712                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6713                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6714                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6715                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6716                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6717                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6718                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6719                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6720                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6721                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6722                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6723                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6724                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6725                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6726                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6727                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6728                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6729                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6730                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6731                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6732                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6733                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6734                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6735                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6736                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6737                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6738                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6739
6740                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6741                                 BindingFlags.DeclaredOnly;
6742
6743                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6744                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6745                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6746                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6747                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6748                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6749                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6750                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6751                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6752                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6753                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6754                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6755                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6756                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6757                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6758                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6759                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6760                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6761                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6762                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6763                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6764                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6765                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6766                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6767                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6768                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6769                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6770                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6771                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6772                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6773                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6774                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6775                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6776                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6777                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6778                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6779
6780                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6781                                 BindingFlags.Public;
6782
6783                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6784                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6785                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6786                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6787                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6788                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6789                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6790                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6791                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6792                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6793                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6794                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6795                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6796                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6797                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6798                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6799                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6800                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6801                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6802                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6803                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6804                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6805                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6806                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6807                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6808                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6809                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6810                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6811                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6812                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6813                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6814                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6815                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6816                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6817                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6818                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6819
6820                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6821                                 BindingFlags.Public;
6822
6823                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6824                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6825                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6826                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6827                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6828                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6829                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6830                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6831                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6832                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6833                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6834                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6835                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6836                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6837                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6838                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6839                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6840                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6841                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6842                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6843                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6844                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6845                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6846                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6847                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6848                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6849                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6850                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6851                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6852                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6853                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6854                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6855                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6856                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6857                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6858                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6859                 }
6860
6861                 [Test]
6862                 [Category ("NotDotNet")] // mcs depends on this
6863                 public void TestGetMethodsIncomplete_Mono ()
6864                 {
6865                         MethodBuilder mb;
6866                         ILGenerator ilgen;
6867
6868                         TypeBuilder tb = module.DefineType (genTypeName (),
6869                                 TypeAttributes.Abstract);
6870                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6871                                 typeof (void), Type.EmptyTypes);
6872                         ilgen = mb.GetILGenerator ();
6873                         ilgen.Emit (OpCodes.Ret);
6874
6875                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6876                                 typeof (void), Type.EmptyTypes);
6877                         ilgen = mb.GetILGenerator ();
6878                         ilgen.Emit (OpCodes.Ret);
6879
6880                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6881                                 MethodAttributes.Static,
6882                                 typeof (void), Type.EmptyTypes);
6883                         ilgen = mb.GetILGenerator ();
6884                         ilgen.Emit (OpCodes.Ret);
6885
6886                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6887                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6888                                 typeof (void), Type.EmptyTypes);
6889
6890                         MethodInfo [] methods = tb.GetMethods ();
6891                         Assert.AreEqual (7, methods.Length, "#A");
6892
6893                         Assert.AreEqual ("Equals", methods [0].Name, "#B1");
6894                         Assert.IsFalse (methods [0].IsStatic, "#B2");
6895                         Assert.IsFalse (methods [0].IsAbstract, "#B3");
6896
6897                         Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
6898                         Assert.IsFalse (methods [1].IsStatic, "#C2");
6899                         Assert.IsFalse (methods [1].IsAbstract, "#C3");
6900
6901                         Assert.AreEqual ("GetType", methods [2].Name, "#D1");
6902                         Assert.IsFalse (methods [2].IsStatic, "#D2");
6903                         Assert.IsFalse (methods [2].IsAbstract, "#D3");
6904
6905                         Assert.AreEqual ("ToString", methods [3].Name, "#E1");
6906                         Assert.IsFalse (methods [3].IsStatic, "#E2");
6907                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
6908
6909                         Assert.AreEqual ("Hello", methods [4].Name, "#F1");
6910                         Assert.IsFalse (methods [4].IsStatic, "#F2");
6911                         Assert.IsFalse (methods [4].IsAbstract, "#F3");
6912
6913                         Assert.AreEqual ("Execute", methods [5].Name, "#G1");
6914                         Assert.IsTrue (methods [5].IsStatic, "#G2");
6915                         Assert.IsFalse (methods [5].IsAbstract, "#G3");
6916
6917                         Assert.AreEqual ("Init", methods [6].Name, "#H1");
6918                         Assert.IsFalse (methods [6].IsStatic, "#H2");
6919                         Assert.IsTrue (methods [6].IsAbstract, "#H3");
6920                 }
6921
6922                 [Test]
6923                 [Category ("NotWorking")] // mcs depends on this
6924                 public void TestGetMethodsIncomplete_MS ()
6925                 {
6926                         MethodBuilder mb;
6927                         ILGenerator ilgen;
6928
6929                         TypeBuilder tb = module.DefineType (genTypeName (),
6930                                 TypeAttributes.Abstract);
6931                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6932                                 typeof (void), Type.EmptyTypes);
6933                         ilgen = mb.GetILGenerator ();
6934                         ilgen.Emit (OpCodes.Ret);
6935
6936                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6937                                 typeof (void), Type.EmptyTypes);
6938                         ilgen = mb.GetILGenerator ();
6939                         ilgen.Emit (OpCodes.Ret);
6940
6941                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6942                                 MethodAttributes.Static,
6943                                 typeof (void), Type.EmptyTypes);
6944                         ilgen = mb.GetILGenerator ();
6945                         ilgen.Emit (OpCodes.Ret);
6946
6947                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6948                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6949                                 typeof (void), Type.EmptyTypes);
6950
6951                         try {
6952                                 tb.GetMethods ();
6953                                 Assert.Fail ("#1");
6954                         } catch (NotSupportedException ex) {
6955                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6956                                 Assert.IsNull (ex.InnerException, "#3");
6957                                 Assert.IsNotNull (ex.Message, "#4");
6958                         }
6959                 }
6960
6961                 [Test]
6962                 public void TestGetMethodsComplete ()
6963                 {
6964                         MethodBuilder mb;
6965                         ILGenerator ilgen;
6966                         MethodInfo mi;
6967
6968                         TypeBuilder tb = module.DefineType (genTypeName (),
6969                                 TypeAttributes.Abstract);
6970                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6971                                 typeof (string), Type.EmptyTypes);
6972                         ilgen = mb.GetILGenerator ();
6973                         ilgen.Emit (OpCodes.Ldstr, "Hi! ");
6974                         ilgen.Emit (OpCodes.Ldarg_1);
6975                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
6976                                 new Type [] { typeof (string), typeof (string) });
6977                         ilgen.Emit (OpCodes.Call, infoMethod);
6978                         ilgen.Emit (OpCodes.Ret);
6979
6980                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6981                                 typeof (void), Type.EmptyTypes);
6982                         ilgen = mb.GetILGenerator ();
6983                         ilgen.Emit (OpCodes.Ret);
6984
6985                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6986                                 MethodAttributes.Static,
6987                                 typeof (void), Type.EmptyTypes);
6988                         ilgen = mb.GetILGenerator ();
6989                         ilgen.Emit (OpCodes.Ret);
6990
6991                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6992                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6993                                 typeof (void), Type.EmptyTypes);
6994
6995                         Type emittedType = tb.CreateType ();
6996
6997                         MethodInfo [] methods = emittedType.GetMethods ();
6998                         Assert.AreEqual (7, methods.Length, "#A1");
6999                         Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
7000
7001                         mi = GetMethodByName (methods, "Hello");
7002                         Assert.IsNotNull (mi, "#B1");
7003                         Assert.IsFalse (mi.IsStatic, "#B2");
7004                         Assert.IsFalse (mi.IsAbstract, "#B3");
7005
7006                         mi = GetMethodByName (methods, "Execute");
7007                         Assert.IsNotNull (mi, "#C1");
7008                         Assert.IsTrue (mi.IsStatic, "#C2");
7009                         Assert.IsFalse (mi.IsAbstract, "#C3");
7010
7011                         mi = GetMethodByName (methods, "Init");
7012                         Assert.IsNotNull (mi, "#D1");
7013                         Assert.IsFalse (mi.IsStatic, "#D2");
7014                         Assert.IsTrue (mi.IsAbstract, "#D3");
7015
7016                         mi = GetMethodByName (methods, "GetType");
7017                         Assert.IsNotNull (mi, "#E1");
7018                         Assert.IsFalse (methods [3].IsStatic, "#E2");
7019                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
7020
7021                         mi = GetMethodByName (methods, "ToString");
7022                         Assert.IsNotNull (mi, "#F1");
7023                         Assert.IsFalse (mi.IsStatic, "#F2");
7024                         Assert.IsFalse (mi.IsAbstract, "#F3");
7025
7026                         mi = GetMethodByName (methods, "Equals");
7027                         Assert.IsNotNull (mi, "#G1");
7028                         Assert.IsFalse (mi.IsStatic, "#G2");
7029                         Assert.IsFalse (mi.IsAbstract, "#G3");
7030
7031                         mi = GetMethodByName (methods, "GetHashCode");
7032                         Assert.IsNotNull (mi, "#H1");
7033                         Assert.IsFalse (mi.IsStatic, "#H2");
7034                         Assert.IsFalse (mi.IsAbstract, "#H3");
7035                 }
7036
7037                 [Test]
7038                 [Category ("NotDotNet")] // mcs depends on this
7039                 public void TestGetMethodsFlagsIncomplete_Inheritance ()
7040                 {
7041                         MethodInfo [] methods;
7042                         BindingFlags flags;
7043
7044                         TypeBuilder blueType = module.DefineType (genTypeName (),
7045                                 TypeAttributes.Public);
7046                         CreateMembers (blueType, "Blue", false);
7047
7048                         TypeBuilder redType = module.DefineType (genTypeName (),
7049                                 TypeAttributes.Public, blueType);
7050                         CreateMembers (redType, "Red", false);
7051
7052                         TypeBuilder greenType = module.DefineType (genTypeName (),
7053                                 TypeAttributes.Public, redType);
7054                         CreateMembers (greenType, "Green", false);
7055
7056                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7057                         methods = greenType.GetMethods (flags);
7058
7059                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7060                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7061                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7062                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7063                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7064                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7065                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7066                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7067                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7068                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7069                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7070                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7071                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7072                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7073                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7074                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7075                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7076                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7077                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7078                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7079                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7080                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7081                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7082                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7083                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7084                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7085                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7086                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7087                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7088                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7089                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7090                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7091                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7092                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7093                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7094                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7095
7096                         flags = BindingFlags.Instance | BindingFlags.Public;
7097                         methods = greenType.GetMethods (flags);
7098
7099                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7100                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7101                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7102                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7103                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7104                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7105                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7106                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7107                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7108                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7109                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7110                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7111                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7112                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7113                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7114                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7115                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7116                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7117                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7118                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7119                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7120                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7121                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7122                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7123                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7124                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7125                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7126                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7127                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7128                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7129                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7130                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7131                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7132                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7133                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7134                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7135
7136                         flags = BindingFlags.Static | BindingFlags.Public;
7137                         methods = greenType.GetMethods (flags);
7138
7139                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7140                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7141                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7142                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7143                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7144                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7145                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7146                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7147                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7148                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7149                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7150                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7151                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7152                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7153                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7154                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7155                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7156                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7157                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7158                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7159                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7160                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7161                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7162                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7163                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7164                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7165                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7166                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7167                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7168                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7169                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7170                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7171                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7172                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7173                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7174                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7175
7176                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7177                         methods = greenType.GetMethods (flags);
7178
7179                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7180                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7181                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7182                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7183                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7184                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7185                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7186                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7187                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7188                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7189                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7190                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7191                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7192                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7193                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7194                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7195                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7196                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7197                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7198                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7199                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7200                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7201                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7202                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7203                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7204                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7205                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7206                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7207                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7208                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7209                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7210                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7211                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7212                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7213                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7214                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7215
7216                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7217                                 BindingFlags.FlattenHierarchy;
7218                         methods = greenType.GetMethods (flags);
7219
7220                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7221                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7222                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7223                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7224                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7225                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7226                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7227                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7228                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7229                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7230                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7231                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7232                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7233                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7234                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7235                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7236                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7237                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7238                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7239                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7240                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7241                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7242                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7243                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7244                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7245                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7246                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7247                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7248                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7249                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7250                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7251                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7252                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7253                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7254                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7255                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7256
7257                         flags = BindingFlags.Instance | BindingFlags.Public |
7258                                 BindingFlags.FlattenHierarchy;
7259                         methods = greenType.GetMethods (flags);
7260
7261                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7262                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7263                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7264                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7265                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7266                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7267                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7268                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7269                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7270                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7271                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7272                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7273                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7274                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7275                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7276                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7277                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7278                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7279                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7280                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7281                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7282                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7283                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7284                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7285                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7286                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7287                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7288                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7289                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7290                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7291                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7292                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7293                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7294                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7295                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7296                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7297
7298                         flags = BindingFlags.Static | BindingFlags.Public |
7299                                 BindingFlags.FlattenHierarchy;
7300                         methods = greenType.GetMethods (flags);
7301
7302                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7303                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7304                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7305                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7306                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7307                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7308                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7309                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7310                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7311                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7312                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7313                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7314                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7315                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7316                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7317                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7318                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7319                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7320                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7321                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7322                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7323                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7324                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7325                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7326                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7327                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7328                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7329                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7330                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7331                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7332                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7333                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7334                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7335                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7336                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7337                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7338
7339                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7340                                 BindingFlags.FlattenHierarchy;
7341                         methods = greenType.GetMethods (flags);
7342
7343                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7344                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7345                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7346                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7347                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7348                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7349                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7350                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7351                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7352                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7353                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7354                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7355                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7356                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7357                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7358                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7359                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7360                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7361                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7362                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7363                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7364                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7365                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7366                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7367                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7368                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7369                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7370                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7371                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7372                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7373                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7374                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7375                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7376                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7377                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7378                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7379
7380                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7381                                 BindingFlags.DeclaredOnly;
7382                         methods = greenType.GetMethods (flags);
7383
7384                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7385                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7386                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7387                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7388                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7389                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7390                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7391                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7392                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7393                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7394                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7395                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7396                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7397                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7398                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7399                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7400                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7401                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7402                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7403                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7404                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7405                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7406                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7407                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7408                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7409                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7410                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7411                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7412                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7413                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7414                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7415                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7416                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7417                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7418                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7419                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7420
7421                         flags = BindingFlags.Instance | BindingFlags.Public |
7422                                 BindingFlags.DeclaredOnly;
7423                         methods = greenType.GetMethods (flags);
7424
7425                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7426                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7427                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7428                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7429                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7430                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7431                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7432                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7433                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7434                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7435                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7436                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7437                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7438                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7439                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7440                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7441                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7442                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7443                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7444                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7445                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7446                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7447                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7448                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7449                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7450                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7451                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7452                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7453                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7454                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7455                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7456                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7457                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7458                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7459                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7460                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7461
7462                         flags = BindingFlags.Static | BindingFlags.Public |
7463                                 BindingFlags.DeclaredOnly;
7464                         methods = greenType.GetMethods (flags);
7465
7466                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7467                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7468                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7469                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7470                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7471                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7472                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7473                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7474                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7475                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7476                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7477                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7478                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7479                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7480                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7481                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7482                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7483                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7484                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7485                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7486                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7487                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7488                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7489                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7490                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7491                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7492                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7493                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7494                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7495                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7496                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7497                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7498                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7499                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7500                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7501                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7502
7503                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7504                                 BindingFlags.DeclaredOnly;
7505                         methods = greenType.GetMethods (flags);
7506
7507                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7508                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7509                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7510                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7511                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7512                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7513                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7514                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7515                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7516                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7517                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7518                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7519                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7520                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7521                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7522                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7523                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7524                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7525                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7526                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7527                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7528                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7529                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7530                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7531                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7532                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7533                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7534                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7535                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7536                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7537                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7538                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7539                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7540                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7541                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7542                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7543
7544                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7545                                 BindingFlags.Public;
7546                         methods = greenType.GetMethods (flags);
7547
7548                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7549                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7550                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7551                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7552                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7553                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7554                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7555                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7556                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7557                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7558                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7559                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7560                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7561                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7562                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7563                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7564                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7565                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7566                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7567                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7568                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7569                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7570                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7571                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7572                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7573                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7574                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7575                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7576                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7577                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7578                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7579                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7580                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7581                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7582                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7583                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7584
7585                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7586                                 BindingFlags.Public;
7587                         methods = greenType.GetMethods (flags);
7588
7589                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7590                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7591                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7592                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7593                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7594                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7595                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7596                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7597                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7598                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7599                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7600                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7601                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7602                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7603                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7604                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7605                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7606                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7607                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7608                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7609                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7610                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7611                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7612                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7613                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7614                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7615                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7616                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7617                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7618                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7619                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7620                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7621                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7622                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7623                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7624                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7625                 }
7626
7627                 [Test]
7628                 [Category ("NotDotNet")] // mcs depends on this
7629                 public void TestGetMethodsFlagsIncomplete_Mono ()
7630                 {
7631                         MethodBuilder mb;
7632                         ILGenerator ilgen;
7633                         MethodInfo [] methods;
7634
7635                         TypeBuilder tb = module.DefineType (genTypeName (),
7636                                 TypeAttributes.Abstract);
7637                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7638                                 typeof (void), Type.EmptyTypes);
7639                         ilgen = mb.GetILGenerator ();
7640                         ilgen.Emit (OpCodes.Ret);
7641
7642                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7643                                 typeof (void), Type.EmptyTypes);
7644                         ilgen = mb.GetILGenerator ();
7645                         ilgen.Emit (OpCodes.Ret);
7646
7647                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7648                                 MethodAttributes.Static,
7649                                 typeof (void), Type.EmptyTypes);
7650                         ilgen = mb.GetILGenerator ();
7651                         ilgen.Emit (OpCodes.Ret);
7652
7653                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7654                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7655                                 typeof (void), Type.EmptyTypes);
7656
7657                         methods = tb.GetMethods (BindingFlags.Public |
7658                                 BindingFlags.Instance);
7659                         Assert.AreEqual (6, methods.Length, "#A1");
7660                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7661                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7662                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7663                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7664                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7665
7666                         methods = tb.GetMethods (BindingFlags.Public |
7667                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7668                         Assert.AreEqual (2, methods.Length, "#B1");
7669                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7670                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7671
7672                         methods = tb.GetMethods (BindingFlags.Public |
7673                                 BindingFlags.Instance | BindingFlags.Static);
7674                         Assert.AreEqual (7, methods.Length, "#C1");
7675                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7676                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7677                         Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7678                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7679                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7680                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7681
7682                         methods = tb.GetMethods (BindingFlags.NonPublic |
7683                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7684                         Assert.AreEqual (1, methods.Length, "#D1");
7685                         Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7686                 }
7687
7688
7689                 [Test]
7690                 [Category ("NotWorking")] // mcs depends on this
7691                 public void TestGetMethodsFlagsIncomplete_MS ()
7692                 {
7693                         MethodBuilder mb;
7694                         ILGenerator ilgen;
7695
7696                         TypeBuilder tb = module.DefineType (genTypeName (),
7697                                 TypeAttributes.Abstract);
7698                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7699                                 typeof (void), Type.EmptyTypes);
7700                         ilgen = mb.GetILGenerator ();
7701                         ilgen.Emit (OpCodes.Ret);
7702
7703                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7704                                 typeof (void), Type.EmptyTypes);
7705                         ilgen = mb.GetILGenerator ();
7706                         ilgen.Emit (OpCodes.Ret);
7707
7708                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7709                                 MethodAttributes.Static,
7710                                 typeof (void), Type.EmptyTypes);
7711                         ilgen = mb.GetILGenerator ();
7712                         ilgen.Emit (OpCodes.Ret);
7713
7714                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7715                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7716                                 typeof (void), Type.EmptyTypes);
7717
7718                         try {
7719                                 tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7720                                 Assert.Fail ("#1");
7721                         } catch (NotSupportedException ex) {
7722                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7723                                 Assert.IsNull (ex.InnerException, "#3");
7724                                 Assert.IsNotNull (ex.Message, "#4");
7725                         }
7726                 }
7727
7728                 [Test]
7729                 public void TestGetMethodsFlagsComplete ()
7730                 {
7731                         TypeBuilder tb = module.DefineType (genTypeName ());
7732                         MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7733                                 MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7734                         ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7735                         helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7736                         helloMethodIL.Emit (OpCodes.Ldarg_1);
7737                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7738                                 new Type [] { typeof (string), typeof (string) });
7739                         helloMethodIL.Emit (OpCodes.Call, infoMethod);
7740                         helloMethodIL.Emit (OpCodes.Ret);
7741
7742                         Type emittedType = tb.CreateType ();
7743
7744                         Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7745                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7746                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7747                         Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7748                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7749                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7750                 }
7751
7752                 [Test]
7753                 public void TestGetMethodsFlagsComplete_Inheritance ()
7754                 {
7755                         MethodInfo [] methods;
7756                         BindingFlags flags;
7757
7758                         TypeBuilder blueType = module.DefineType (genTypeName (),
7759                                 TypeAttributes.Public);
7760                         CreateMembers (blueType, "Blue", false);
7761
7762                         TypeBuilder redType = module.DefineType (genTypeName (),
7763                                 TypeAttributes.Public, blueType);
7764                         CreateMembers (redType, "Red", false);
7765
7766                         TypeBuilder greenType = module.DefineType (genTypeName (),
7767                                 TypeAttributes.Public, redType);
7768                         CreateMembers (greenType, "Green", false);
7769
7770                         blueType.CreateType ();
7771                         redType.CreateType ();
7772                         greenType.CreateType ();
7773
7774                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7775                         methods = greenType.GetMethods (flags);
7776
7777                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7778                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7779                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7780                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7781                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7782                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7783                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7784                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7785                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7786                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7787                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7788                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7789                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7790                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7791                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7792                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7793                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7794                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7795                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7796                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7797                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7798                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7799                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7800                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7801                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7802                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7803                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7804                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7805                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7806                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7807                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7808                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7809                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7810                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7811                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7812                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7813
7814                         flags = BindingFlags.Instance | BindingFlags.Public;
7815                         methods = greenType.GetMethods (flags);
7816
7817                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7818                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7819                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7820                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7821                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7822                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7823                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7824                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7825                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7826                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7827                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7828                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7829                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7830                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7831                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7832                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7833                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7834                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7835                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7836                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7837                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7838                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7839                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7840                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7841                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7842                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7843                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7844                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7845                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7846                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7847                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7848                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7849                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7850                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7851                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7852                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7853
7854                         flags = BindingFlags.Static | BindingFlags.Public;
7855                         methods = greenType.GetMethods (flags);
7856
7857                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7858                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7859                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7860                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7861                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7862                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7863                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7864                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7865                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7866                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7867                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7868                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7869                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7870                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7871                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7872                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7873                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7874                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7875                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7876                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7877                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7878                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7879                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7880                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7881                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7882                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7883                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7884                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7885                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7886                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7887                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7888                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7889                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7890                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7891                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7892                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7893
7894                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7895                         methods = greenType.GetMethods (flags);
7896
7897                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7898                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7899                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7900                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7901                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7902                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7903                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7904                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7905                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7906                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7907                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7908                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7909                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7910                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7911                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7912                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7913                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7914                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7915                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7916                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7917                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7918                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7919                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7920                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7921                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7922                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7923                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7924                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7925                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7926                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7927                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7928                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7929                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7930                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7931                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7932                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7933
7934                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7935                                 BindingFlags.FlattenHierarchy;
7936                         methods = greenType.GetMethods (flags);
7937
7938                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7939                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7940                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7941                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7942                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7943                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7944                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7945                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7946                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7947                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7948                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7949                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7950                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7951                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7952                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7953                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7954                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7955                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7956                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7957                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7958                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7959                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7960                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7961                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7962                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7963                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7964                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7965                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7966                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7967                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7968                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7969                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7970                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7971                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7972                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7973                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7974
7975                         flags = BindingFlags.Instance | BindingFlags.Public |
7976                                 BindingFlags.FlattenHierarchy;
7977                         methods = greenType.GetMethods (flags);
7978
7979                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7980                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7981                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7982                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7983                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7984                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7985                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7986                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7987                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7988                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7989                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7990                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7991                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7992                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7993                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7994                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7995                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7996                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7997                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7998                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7999                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
8000                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
8001                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
8002                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
8003                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
8004                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
8005                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
8006                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
8007                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
8008                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
8009                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
8010                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
8011                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
8012                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
8013                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
8014                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
8015
8016                         flags = BindingFlags.Static | BindingFlags.Public |
8017                                 BindingFlags.FlattenHierarchy;
8018                         methods = greenType.GetMethods (flags);
8019
8020                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
8021                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
8022                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
8023                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8024                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8025                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8026                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8027                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8028                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8029                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8030                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8031                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8032                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8033                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8034                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8035                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8036                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8037                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8038                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8039                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8040                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8041                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8042                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8043                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8044                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8045                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8046                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8047                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8048                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8049                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8050                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8051                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8052                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8053                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8054                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8055                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8056
8057                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8058                                 BindingFlags.FlattenHierarchy;
8059                         methods = greenType.GetMethods (flags);
8060
8061                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8062                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8063                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8064                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8065                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8066                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8067                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8068                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8069                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8070                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8071                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8072                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8073                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8074                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8075                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8076                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8077                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8078                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8079                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8080                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8081                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8082                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8083                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8084                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8085                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8086                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8087                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8088                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8089                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8090                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8091                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8092                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8093                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8094                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8095                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8096                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8097
8098                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8099                                 BindingFlags.DeclaredOnly;
8100                         methods = greenType.GetMethods (flags);
8101
8102                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8103                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8104                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8105                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8106                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8107                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8108                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8109                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8110                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8111                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8112                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8113                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8114                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8115                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8116                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8117                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8118                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8119                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8120                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8121                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8122                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8123                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8124                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8125                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8126                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8127                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8128                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8129                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8130                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8131                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8132                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8133                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8134                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8135                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8136                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8137                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8138
8139                         flags = BindingFlags.Instance | BindingFlags.Public |
8140                                 BindingFlags.DeclaredOnly;
8141                         methods = greenType.GetMethods (flags);
8142
8143                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8144                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8145                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8146                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8147                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8148                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8149                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8150                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8151                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8152                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8153                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8154                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8155                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8156                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8157                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8158                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8159                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8160                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8161                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8162                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8163                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8164                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8165                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8166                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8167                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8168                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8169                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8170                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8171                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8172                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8173                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8174                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8175                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8176                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8177                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8178                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8179
8180                         flags = BindingFlags.Static | BindingFlags.Public |
8181                                 BindingFlags.DeclaredOnly;
8182                         methods = greenType.GetMethods (flags);
8183
8184                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8185                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8186                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8187                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8188                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8189                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8190                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8191                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8192                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8193                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8194                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8195                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8196                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8197                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8198                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8199                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8200                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8201                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8202                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8203                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8204                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8205                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8206                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8207                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8208                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8209                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8210                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8211                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8212                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8213                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8214                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8215                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8216                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8217                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8218                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8219                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8220
8221                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8222                                 BindingFlags.DeclaredOnly;
8223                         methods = greenType.GetMethods (flags);
8224
8225                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8226                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8227                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8228                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8229                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8230                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8231                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8232                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8233                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8234                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8235                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8236                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8237                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8238                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8239                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8240                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8241                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8242                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8243                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8244                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8245                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8246                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8247                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8248                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8249                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8250                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8251                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8252                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8253                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8254                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8255                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8256                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8257                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8258                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8259                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8260                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8261
8262                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8263                                 BindingFlags.Public;
8264                         methods = greenType.GetMethods (flags);
8265
8266                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8267                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8268                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8269                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8270                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8271                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8272                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8273                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8274                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8275                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8276                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8277                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8278                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8279                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8280                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8281                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8282                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8283                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8284                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8285                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8286                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8287                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8288                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8289                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8290                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8291                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8292                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8293                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8294                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8295                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8296                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8297                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8298                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8299                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8300                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8301                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8302
8303                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8304                                 BindingFlags.Public;
8305                         methods = greenType.GetMethods (flags);
8306
8307                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8308                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8309                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8310                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8311                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8312                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8313                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8314                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8315                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8316                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8317                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8318                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8319                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8320                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8321                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8322                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8323                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8324                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8325                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8326                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8327                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8328                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8329                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8330                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8331                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8332                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8333                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8334                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8335                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8336                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8337                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8338                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8339                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8340                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8341                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8342                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8343                 }
8344
8345                 [Test]
8346                 public void TestGetMemberIncomplete ()
8347                 {
8348                         TypeBuilder tb = module.DefineType (genTypeName ());
8349                         try {
8350                                 tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8351                                 Assert.Fail ("#1");
8352                         } catch (NotSupportedException ex) {
8353                                 // The invoked member is not supported in a
8354                                 // dynamic module
8355                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8356                                 Assert.IsNull (ex.InnerException, "#3");
8357                                 Assert.IsNotNull (ex.Message, "#4");
8358                         }
8359                 }
8360
8361                 [Test]
8362                 public void TestGetMemberComplete ()
8363                 {
8364                         TypeBuilder tb = module.DefineType (genTypeName ());
8365                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8366
8367                         Type emittedType = tb.CreateType ();
8368
8369                         Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8370                         Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8371                 }
8372
8373                 [Test]
8374                 public void TestGetMembersIncomplete ()
8375                 {
8376                         TypeBuilder tb = module.DefineType (genTypeName ());
8377                         try {
8378                                 tb.GetMembers ();
8379                                 Assert.Fail ("#1");
8380                         } catch (NotSupportedException ex) {
8381                                 // The invoked member is not supported in a
8382                                 // dynamic module
8383                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8384                                 Assert.IsNull (ex.InnerException, "#3");
8385                                 Assert.IsNotNull (ex.Message, "#4");
8386                         }
8387                 }
8388
8389                 [Test]
8390                 public void TestGetMembersComplete ()
8391                 {
8392                         TypeBuilder tb = module.DefineType (genTypeName ());
8393                         Type emittedType = tb.CreateType ();
8394
8395                         Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8396                 }
8397
8398                 [Test]
8399                 public void TestGetMembersFlagsIncomplete ()
8400                 {
8401                         TypeBuilder tb = module.DefineType (genTypeName ());
8402                         try {
8403                                 tb.GetMembers (BindingFlags.Public);
8404                                 Assert.Fail ("#1");
8405                         } catch (NotSupportedException ex) {
8406                                 // The invoked member is not supported in a
8407                                 // dynamic module
8408                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8409                                 Assert.IsNull (ex.InnerException, "#3");
8410                                 Assert.IsNotNull (ex.Message, "#4");
8411                         }
8412                 }
8413
8414                 [Test]
8415                 public void TestGetMembersFlagsComplete ()
8416                 {
8417                         TypeBuilder tb = module.DefineType (genTypeName ());
8418                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8419
8420                         Type emittedType = tb.CreateType ();
8421
8422                         Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8423                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8424                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8425                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8426                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8427                 }
8428
8429                 [Test]
8430                 public void TestGetInterfaceIncomplete ()
8431                 {
8432                         TypeBuilder tb = module.DefineType (genTypeName ());
8433                         try {
8434                                 tb.GetInterface ("FOO", true);
8435                                 Assert.Fail ("#1");
8436                         } catch (NotSupportedException ex) {
8437                                 // The invoked member is not supported in a
8438                                 // dynamic module
8439                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8440                                 Assert.IsNull (ex.InnerException, "#3");
8441                                 Assert.IsNotNull (ex.Message, "#4");
8442                         }
8443                 }
8444
8445                 [Test]
8446                 public void TestGetInterfaces ()
8447                 {
8448                         TypeBuilder tb = module.DefineType (genTypeName ());
8449                         Type [] interfaces = tb.GetInterfaces ();
8450                         Assert.AreEqual (0, interfaces.Length);
8451
8452                         TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8453                         Type emittedInterface = tbInterface.CreateType ();
8454
8455                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8456                         interfaces = tb.GetInterfaces ();
8457                         Assert.AreEqual (1, interfaces.Length);
8458                 }
8459
8460                 [Test]
8461                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8462                 public void TestAddDeclarativeSecurityAlreadyCreated ()
8463                 {
8464                         TypeBuilder tb = module.DefineType (genTypeName ());
8465                         tb.CreateType ();
8466
8467                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8468                         try {
8469                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8470                                 Assert.Fail ("#1");
8471                         } catch (InvalidOperationException ex) {
8472                                 // Unable to change after type has been created
8473                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8474                                 Assert.IsNull (ex.InnerException, "#3");
8475                                 Assert.IsNotNull (ex.Message, "#4");
8476                         }
8477                 }
8478
8479                 [Test]
8480                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8481                 public void TestAddDeclarativeSecurityNullPermissionSet ()
8482                 {
8483                         TypeBuilder tb = module.DefineType (genTypeName ());
8484                         try {
8485                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8486                                 Assert.Fail ("#1");
8487                         } catch (ArgumentNullException ex) {
8488                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8489                                 Assert.IsNull (ex.InnerException, "#3");
8490                                 Assert.IsNotNull (ex.Message, "#4");
8491                                 Assert.AreEqual ("pset", ex.ParamName, "#5");
8492                         }
8493
8494                 }
8495
8496                 [Test]
8497                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8498                 public void TestAddDeclarativeSecurityInvalidAction ()
8499                 {
8500                         TypeBuilder tb = module.DefineType (genTypeName ());
8501
8502                         SecurityAction [] actions = new SecurityAction [] { 
8503                         SecurityAction.RequestMinimum,
8504                         SecurityAction.RequestOptional,
8505                         SecurityAction.RequestRefuse };
8506                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8507
8508                         foreach (SecurityAction action in actions) {
8509                                 try {
8510                                         tb.AddDeclarativeSecurity (action, set);
8511                                         Assert.Fail ();
8512                                 } catch (ArgumentOutOfRangeException) {
8513                                 }
8514                         }
8515                 }
8516
8517                 [Test]
8518                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8519                 public void TestAddDeclarativeSecurityDuplicateAction ()
8520                 {
8521                         TypeBuilder tb = module.DefineType (genTypeName ());
8522
8523                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8524                         tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8525                         try {
8526                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8527                                 Assert.Fail ("#1");
8528                         } catch (InvalidOperationException ex) {
8529                                 // Multiple permission sets specified with the
8530                                 // same SecurityAction
8531                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8532                                 Assert.IsNull (ex.InnerException, "#3");
8533                                 Assert.IsNotNull (ex.Message, "#4");
8534                         }
8535                 }
8536
8537                 [Test]
8538                 public void TestEnums ()
8539                 {
8540                         TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8541                         TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8542                                                                                                                  typeof (Enum));
8543                         enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8544                         // add value__ field, see DefineEnum method of ModuleBuilder
8545                         enumToCreate.DefineField ("value__", typeof (Int32),
8546                                 FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8547
8548                         // add enum entries
8549                         FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8550                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8551                         fb.SetConstant ((Int32) 0);
8552
8553                         fb = enumToCreate.DefineField ("B", enumToCreate,
8554                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8555                         fb.SetConstant ((Int32) 1);
8556
8557                         fb = enumToCreate.DefineField ("C", enumToCreate,
8558                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8559                         fb.SetConstant ((Int32) 2);
8560
8561                         Type enumType = enumToCreate.CreateType ();
8562
8563                         object enumVal = Enum.ToObject (enumType, (Int32) 3);
8564
8565                         Assert.AreEqual ("B, C", enumVal.ToString ());
8566                         Assert.AreEqual (3, (Int32) enumVal);
8567                 }
8568
8569                 [Test]
8570                 public void DefineEnum ()
8571                 {
8572                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8573                                                                                                                  TypeAttributes.Public);
8574                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8575                                                                                                                  TypeAttributes.Public, typeof (int));
8576                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8577                         enumBuilder.CreateType ();
8578                         typeBuilder.CreateType ();
8579                 }
8580
8581                 [Test]
8582                 [Category ("NotWorking")]
8583                 public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8584                 {
8585                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8586                                                                                                                  TypeAttributes.Public);
8587                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8588                                                                                                                  TypeAttributes.Public, typeof (int));
8589                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8590                         try {
8591                                 typeBuilder.CreateType ();
8592                                 Assert.Fail ("#1");
8593                         } catch (TypeLoadException) {
8594                                 // Could not load type '...' from assembly
8595                                 // 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8596                         }
8597                         Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8598                         Assert.IsNull (typeBuilder.CreateType (), "#3");
8599                 }
8600
8601                 [Test]
8602                 public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8603                 {
8604                         TypeBuilder tb = module.DefineType (genTypeName ());
8605                         ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8606                                 GetConstructor (Type.EmptyTypes);
8607                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8608                                 attrCtor, new object [0]);
8609                         Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8610                         tb.SetCustomAttribute (caBuilder);
8611                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8612                         Type emittedType = tb.CreateType ();
8613                         Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8614                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8615                         object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8616                         Assert.AreEqual (1, emittedAttrs.Length, "#5");
8617                 }
8618
8619                 private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8620                 {
8621                         // define the field holding the property value
8622                         FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8623                                 typeof (string), FieldAttributes.Private);
8624
8625                         PropertyBuilder propertyBuilder = tb.DefineProperty (
8626                                 propertyName, PropertyAttributes.HasDefault, typeof (string),
8627                                 new Type [] { typeof (string) });
8628
8629                         // First, we'll define the behavior of the "get" property for CustomerName as a method.
8630                         MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8631                                                                         methodAttribs,
8632                                                                         typeof (string),
8633                                                                         new Type [] { });
8634
8635                         ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8636
8637                         getIL.Emit (OpCodes.Ldarg_0);
8638                         getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8639                         getIL.Emit (OpCodes.Ret);
8640
8641                         // Now, we'll define the behavior of the "set" property for CustomerName.
8642                         MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8643                                                                         methodAttribs,
8644                                                                         null,
8645                                                                         new Type [] { typeof (string) });
8646
8647                         ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8648
8649                         setIL.Emit (OpCodes.Ldarg_0);
8650                         setIL.Emit (OpCodes.Ldarg_1);
8651                         setIL.Emit (OpCodes.Stfld, fieldBuilder);
8652                         setIL.Emit (OpCodes.Ret);
8653
8654                         // Last, we must map the two methods created above to our PropertyBuilder to 
8655                         // their corresponding behaviors, "get" and "set" respectively. 
8656                         propertyBuilder.SetGetMethod (getMethodBuilder);
8657                         propertyBuilder.SetSetMethod (setMethodBuilder);
8658                         return propertyBuilder;
8659                 }
8660
8661                 static int handler_called = 0;
8662
8663                 [Test]
8664                 public void TestTypeResolve ()
8665                 {
8666                         string typeName = genTypeName ();
8667
8668                         ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8669                         AppDomain.CurrentDomain.TypeResolve += handler;
8670                         handler_called = 0;
8671                         Type t = Type.GetType (typeName);
8672                         Assert.AreEqual (typeName, t.Name);
8673                         Assert.AreEqual (1, handler_called);
8674                         AppDomain.CurrentDomain.TypeResolve -= handler;
8675                 }
8676
8677                 Assembly TypeResolve (object sender, ResolveEventArgs args)
8678                 {
8679                         TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8680                         tb.CreateType ();
8681                         handler_called++;
8682                         return tb.Assembly;
8683                 }
8684
8685                 [Test]
8686                 public void IsAssignableFrom_Created ()
8687                 {
8688                         TypeBuilder tb = module.DefineType (genTypeName (),
8689                                 TypeAttributes.Public, typeof (MemoryStream),
8690                                 new Type [] { typeof (IThrowable), typeof (Bar) });
8691                         tb.AddInterfaceImplementation (typeof (IDestroyable));
8692                         Type emitted_type = tb.CreateType ();
8693
8694                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8695                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8696                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8697                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8698                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8699                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8700                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8701                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8702                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8703                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8704                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8705                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8706                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8707                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8708                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8709                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8710                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8711                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8712
8713                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8714                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8715                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8716                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8717                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8718                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8719                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8720                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8721                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8722                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8723
8724                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8725                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8726                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8727                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8728                         Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8729
8730                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8731                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8732                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8733                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8734                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8735                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8736                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8737                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8738                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8739                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8740                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8741                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8742                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8743                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8744                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8745                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8746                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8747                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8748
8749                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8750                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8751                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8752                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8753                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8754                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8755                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8756                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8757                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8758                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8759
8760                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8761                                 tb.FullName + "[]")), "#F1");
8762                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8763                                 tb.FullName + "[]")), "#F2");
8764                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8765                                 tb.FullName + "[]")), "#F3");
8766
8767                         TypeBuilder tb2 = module.DefineType (genTypeName (),
8768                                 TypeAttributes.Public, tb,
8769                                 new Type [] { typeof (IAir) });
8770                         Type emitted_type2 = tb2.CreateType ();
8771
8772                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8773                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8774                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8775                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8776                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8777                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8778                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8779                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8780                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8781                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8782                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8783                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8784                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8785                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8786                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8787                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8788                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8789                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8790
8791                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8792                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8793                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8794                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8795                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8796                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8797                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8798                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8799                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8800                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8801
8802                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
8803                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
8804                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
8805                         Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
8806                         Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
8807                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
8808                         Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
8809                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
8810                         Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
8811                         Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
8812                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
8813                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
8814                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
8815                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
8816
8817                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
8818                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
8819                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
8820                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
8821                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
8822                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
8823                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
8824                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
8825                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
8826                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
8827                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
8828                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
8829                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
8830                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
8831                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
8832                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
8833                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
8834                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
8835
8836                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
8837                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
8838                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
8839                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
8840                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
8841                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
8842                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
8843                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
8844                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
8845                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
8846
8847                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8848                                 tb2.FullName + "[]")), "#L1");
8849                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8850                                 tb2.FullName + "[]")), "#L2");
8851                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8852                                 tb2.FullName + "[]")), "#L3");
8853
8854                         TypeBuilder tb3 = module.DefineType (genTypeName (),
8855                                 TypeAttributes.Public, tb2,
8856                                 new Type [] { typeof (IWater) });
8857                         Type emitted_type3 = tb3.CreateType ();
8858
8859                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
8860                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
8861                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
8862                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
8863                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
8864                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
8865                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
8866                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
8867                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
8868                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
8869                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
8870                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
8871                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
8872                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
8873                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
8874                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
8875                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
8876                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
8877
8878                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
8879                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
8880                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
8881                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
8882                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
8883                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
8884                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
8885                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
8886                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
8887                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
8888
8889                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
8890                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
8891                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
8892                         Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
8893                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
8894                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
8895                         Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
8896                         Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
8897                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
8898                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
8899                         Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
8900                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
8901                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
8902                         Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
8903                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
8904                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
8905                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
8906                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
8907                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
8908                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
8909                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
8910                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
8911
8912                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
8913                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
8914                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
8915                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
8916                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
8917                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
8918                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
8919                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
8920                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
8921                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
8922                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
8923                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
8924                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
8925                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
8926                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
8927                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
8928                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
8929                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
8930
8931                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
8932                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
8933                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
8934                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
8935                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
8936                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
8937                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
8938                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
8939                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
8940                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
8941
8942                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8943                                 tb3.FullName + "[]")), "#R1");
8944                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8945                                 tb3.FullName + "[]")), "#R2");
8946                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8947                                 tb3.FullName + "[]")), "#R3");
8948
8949                         TypeBuilder tb4 = module.DefineType (genTypeName (),
8950                                 TypeAttributes.Public, null,
8951                                 new Type [] { typeof (IWater) });
8952                         tb4.DefineGenericParameters ("T");
8953
8954                         Type inst = tb4.MakeGenericType (typeof (int));
8955                         Type emitted_type4 = tb4.CreateType ();
8956                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
8957                         // This returns True if CreateType () is called _before_ MakeGenericType...
8958                         //Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
8959                 }
8960
8961                 [Test]
8962                 public void IsAssignableFrom_NotCreated ()
8963                 {
8964                         TypeBuilder tb = module.DefineType (genTypeName (),
8965                                 TypeAttributes.Public, typeof (MemoryStream),
8966                                 new Type [] {
8967                                         typeof (IThrowable), typeof (Bar),
8968                                         typeof (IComparable)
8969                                         });
8970
8971                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8972                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8973                         //Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8974                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8975                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
8976                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
8977                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
8978                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
8979                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
8980                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
8981                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
8982                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
8983
8984                         //Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
8985                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
8986                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
8987                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
8988                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
8989                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
8990
8991                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
8992                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
8993                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
8994                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
8995                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
8996                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
8997                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
8998                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
8999                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
9000                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
9001
9002                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
9003                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
9004
9005                         TypeBuilder tb2 = module.DefineType (genTypeName (),
9006                                 TypeAttributes.Public, tb,
9007                                 new Type[] { typeof (IAir) });
9008
9009                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
9010                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
9011                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
9012                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
9013                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
9014                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
9015                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
9016                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
9017                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
9018                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
9019                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
9020                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
9021
9022                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#F1");
9023                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
9024                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#F3");
9025                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
9026                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
9027                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9028
9029                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9030                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9031                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9032                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9033                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9034                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9035                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9036                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9037                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9038                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9039
9040                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9041                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9042                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9043
9044                         TypeBuilder tb3 = module.DefineType (genTypeName (),
9045                                 TypeAttributes.Public, tb2,
9046                                 new Type[] { typeof (IWater) });
9047
9048                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9049                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9050                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9051                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9052                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9053                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9054                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9055                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9056                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9057                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9058                         //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9059                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9060
9061                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9062                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9063                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9064                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9065                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9066                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9067
9068                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9069                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9070                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9071                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9072                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9073                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9074                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9075                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9076                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9077                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9078
9079                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9080                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9081                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9082                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9083                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9084                 }
9085
9086                 [Test]
9087                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9088                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9089                 {
9090                         TypeBuilder tb = module.DefineType (genTypeName (),
9091                                 TypeAttributes.Public, typeof (FormatException),
9092                                 new Type [] { typeof (IThrowable) });
9093                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9094
9095                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9096                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9097
9098                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9099                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9100                 }
9101
9102                 [Test]
9103                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9104                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9105                 {
9106                         TypeBuilder tb = module.DefineType (genTypeName (),
9107                                 TypeAttributes.Public, typeof (FormatException),
9108                                 new Type [] { typeof (IThrowable) });
9109                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9110
9111                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9112                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9113
9114                         Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9115                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9116                 }
9117
9118
9119                 [Test]
9120                 // Casts don't work with unfinished types
9121                 [Category ("NotWorking")]
9122                 [Category ("NotDotNet")]
9123                 public void IsAssignableFrom_NotCreated_Array ()
9124                 {
9125                         TypeBuilder tb = module.DefineType (genTypeName (),
9126                                 TypeAttributes.Public, typeof (FormatException),
9127                                 new Type [] {
9128                                         typeof (IThrowable), typeof (Bar),
9129                                         typeof (IComparable)
9130                                         });
9131
9132                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9133                                 tb.FullName + "[]")), "#1");
9134                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9135                                 tb.FullName + "[]")), "#2");
9136                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9137                                 tb.FullName + "[]")), "#3");
9138                 }
9139
9140                 [Test]
9141                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9142                 public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9143                 {
9144                         TypeBuilder tb = module.DefineType (genTypeName (),
9145                                 TypeAttributes.Public, typeof (FormatException),
9146                                 new Type [] {
9147                                         typeof (IThrowable), typeof (Bar),
9148                                         typeof (IComparable)
9149                                         });
9150
9151                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9152                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9153                 }
9154
9155                 [Test]
9156                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9157                 public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9158                 {
9159                         TypeBuilder tb = module.DefineType (genTypeName (),
9160                                 TypeAttributes.Public, typeof (FormatException),
9161                                 new Type [] {
9162                                         typeof (IThrowable), typeof (Bar),
9163                                         typeof (IComparable)
9164                                         });
9165
9166                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9167                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9168                 }
9169
9170                 [Test]
9171                 public void CreateType_EmptyMethodBody ()
9172                 {
9173                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9174
9175                         tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9176                         try {
9177                                 tb.CreateType ();
9178                                 Assert.Fail ("#1");
9179                         } catch (InvalidOperationException ex) {
9180                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9181                                 Assert.IsNull (ex.InnerException, "#3");
9182                                 Assert.IsNotNull (ex.Message, "#4");
9183                         }
9184                 }
9185
9186                 [Test]
9187                 public void CreateType_EmptyCtorBody ()
9188                 {
9189                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9190
9191                         tb.DefineConstructor (0, CallingConventions.Standard, null);
9192                         try {
9193                                 tb.CreateType ();
9194                                 Assert.Fail ("#1");
9195                         } catch (InvalidOperationException ex) {
9196                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9197                                 Assert.IsNull (ex.InnerException, "#3");
9198                                 Assert.IsNotNull (ex.Message, "#4");
9199                         }
9200                 }
9201
9202                 [Test]
9203                 [Category ("NotWorking")]
9204                 public void CreateType_Interface_ParentInvalid ()
9205                 {
9206                         TypeBuilder tb;
9207
9208                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9209                                 typeof (Exception));
9210                         Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9211                         try {
9212                                 tb.CreateType ();
9213                                 Assert.Fail ("#A2");
9214                         } catch (TypeLoadException ex) {
9215                                 // Could not load interface 't5' from assembly '...'
9216                                 // because it must extend from Object
9217                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9218                                 Assert.IsNull (ex.InnerException, "#A4");
9219                                 Assert.IsNotNull (ex.Message, "#A5");
9220                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9221                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9222                         }
9223
9224                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9225                                 typeof (object));
9226                         Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9227                         try {
9228                                 tb.CreateType ();
9229                                 Assert.Fail ("#B2");
9230                         } catch (TypeLoadException ex) {
9231                                 // Failure has occurred while loading a type
9232                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9233                                 Assert.IsNull (ex.InnerException, "#B4");
9234                                 Assert.IsNotNull (ex.Message, "#B5");
9235                         }
9236
9237                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9238                                 typeof (EmptyInterface));
9239                         Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9240                         try {
9241                                 tb.CreateType ();
9242                                 Assert.Fail ("#C2");
9243                         } catch (TypeLoadException ex) {
9244                                 // Could not load interface 't5' from assembly '...'
9245                                 // because the parent type is an interface
9246                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9247                                 Assert.IsNull (ex.InnerException, "#C4");
9248                                 Assert.IsNotNull (ex.Message, "#C5");
9249                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9250                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9251                         }
9252                 }
9253
9254                 [Test]
9255                 public void CreateType_Parent_DefaultCtorMissing ()
9256                 {
9257                         TypeBuilder tb;
9258
9259                         tb = module.DefineType (genTypeName ());
9260                         ConstructorBuilder cb = tb.DefineConstructor (
9261                                 MethodAttributes.Public,
9262                                 CallingConventions.Standard,
9263                                 new Type [] { typeof (string) });
9264                         cb.GetILGenerator ().Emit (OpCodes.Ret);
9265                         Type parent_type = tb.CreateType ();
9266
9267                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9268                                 parent_type);
9269                         try {
9270                                 tb.CreateType ();
9271                                 Assert.Fail ("#1");
9272                         } catch (NotSupportedException ex) {
9273                                 // Parent does not have a default constructor.
9274                                 // The default constructor must be explicitly defined
9275                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9276                                 Assert.IsNull (ex.InnerException, "#3");
9277                                 Assert.IsNotNull (ex.Message, "#4");
9278                         }
9279                 }
9280
9281                 [Test]
9282                 public void CreateType_Parent_Null ()
9283                 {
9284                         TypeBuilder tb;
9285                         Type emitted_type;
9286                         
9287                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9288                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9289                         emitted_type = tb.CreateType ();
9290                         Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9291
9292                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9293                         Assert.IsNull (tb.BaseType, "#B1");
9294                         emitted_type = tb.CreateType ();
9295                         Assert.IsNull (emitted_type.BaseType, "#B2");
9296                 }
9297
9298                 [Test]
9299                 [Category ("NotWorking")]
9300                 public void DefineGenericParameters_AlreadyDefined ()
9301                 {
9302                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9303                         tb.DefineGenericParameters ("K");
9304                         try {
9305                                 tb.DefineGenericParameters ("V");
9306                                 Assert.Fail ("#1");
9307                         } catch (InvalidOperationException ex) {
9308                                 // Operation is not valid due to the current
9309                                 // state of the object
9310                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9311                                 Assert.IsNull (ex.InnerException, "#3");
9312                                 Assert.IsNotNull (ex.Message, "#4");
9313                         }
9314                 }
9315
9316                 [Test]
9317                 public void DefineGenericParameters_Names_Empty ()
9318                 {
9319                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9320
9321                         try {
9322                                 tb.DefineGenericParameters (new string [0]);
9323                                 Assert.Fail ("#1");
9324                         } catch (ArgumentException ex) {
9325                                 // Value does not fall within the expected range
9326                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9327                                 Assert.IsNull (ex.InnerException, "#3");
9328                                 Assert.IsNotNull (ex.Message, "#4");
9329                                 Assert.IsNull (ex.ParamName, "#5");
9330                         }
9331                 }
9332
9333                 [Test]
9334                 public void DefineGenericParameters_Names_Null ()
9335                 {
9336                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9337
9338                         try {
9339                                 tb.DefineGenericParameters ((string []) null);
9340                                 Assert.Fail ("#A1");
9341                         } catch (ArgumentNullException ex) {
9342                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9343                                 Assert.IsNull (ex.InnerException, "#A3");
9344                                 Assert.IsNotNull (ex.Message, "#A4");
9345                                 Assert.AreEqual ("names", ex.ParamName, "#A5");
9346                         }
9347
9348                         try {
9349                                 tb.DefineGenericParameters ("K", null, "V");
9350                                 Assert.Fail ("#B1");
9351                         } catch (ArgumentNullException ex) {
9352                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9353                                 Assert.IsNull (ex.InnerException, "#B3");
9354                                 Assert.IsNotNull (ex.Message, "#B4");
9355                                 Assert.AreEqual ("names", ex.ParamName, "#B5");
9356                         }
9357                 }
9358
9359                 [Test]
9360                 public void GenericType ()
9361                 {
9362                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9363                         tb.DefineGenericParameters ("T");
9364
9365                         Assert.IsTrue (tb.IsGenericType, "#A1");
9366                         Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9367                         Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9368                         Assert.IsFalse (tb.IsGenericParameter, "#A4");
9369
9370                         Type[] args = tb.GetGenericArguments ();
9371                         Assert.IsFalse (args [0].IsGenericType, "#B1");
9372                         Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9373                         Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9374                         Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9375                 }
9376
9377                 [Test]
9378                 public void MakeGenericType ()
9379                 {
9380                         TypeBuilder tb;
9381                         Type generic_type;
9382                 
9383                         tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9384                         tb.DefineGenericParameters ("T");
9385
9386                         generic_type = tb.MakeGenericType (typeof (int));
9387                         Assert.IsTrue (generic_type.IsGenericType, "#A1");
9388                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9389                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9390                         Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9391
9392                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9393                         Assert.IsTrue (generic_type.IsGenericType, "#B1");
9394                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9395                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9396                         Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9397
9398                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9399                                 | TypeAttributes.Abstract | TypeAttributes.Public);
9400                         tb.DefineGenericParameters ("T");
9401
9402                         generic_type = tb.MakeGenericType (typeof (int));
9403                         Assert.IsTrue (generic_type.IsGenericType, "#C1");
9404                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9405                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9406                         Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9407
9408                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9409                         Assert.IsTrue (generic_type.IsGenericType, "#D1");
9410                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9411                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9412                         Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9413                 }
9414
9415                 [Test]
9416                 public void MakeGenericType_NoGenericTypeDefinition ()
9417                 {
9418                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9419                         try {
9420                                 tb.MakeGenericType (typeof (int));
9421                                 Assert.Fail ("#1");
9422                         } catch (InvalidOperationException ex) {
9423                                 // Operation is not valid due to the current
9424                                 // state of the object
9425                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9426                                 Assert.IsNull (ex.InnerException, "#3");
9427                                 Assert.IsNotNull (ex.Message, "#4");
9428                         }
9429                 }
9430
9431                 [Test]
9432                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9433                 public void MakeGenericType_TypeArguments_Null_Mono ()
9434                 {
9435                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9436                         tb.DefineGenericParameters ("K", "V");
9437
9438                         try {
9439                                 tb.MakeGenericType ((Type []) null);
9440                                 Assert.Fail ("#A1");
9441                         } catch (ArgumentNullException ex) {
9442                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9443                                 Assert.IsNull (ex.InnerException, "#A3");
9444                                 Assert.IsNotNull (ex.Message, "#A4");
9445                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9446                         }
9447
9448                         try {
9449                                 tb.MakeGenericType (typeof (string), (Type) null);
9450                                 Assert.Fail ("#B1");
9451                         } catch (ArgumentNullException ex) {
9452                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9453                                 Assert.IsNull (ex.InnerException, "#B3");
9454                                 Assert.IsNotNull (ex.Message, "#B4");
9455                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9456                         }
9457                 }
9458
9459                 [Test]
9460                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9461                 public void MakeGenericType_TypeArguments_Null_MS ()
9462                 {
9463                         Type generic_type;
9464                         Type [] type_args;
9465
9466                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9467                         tb.DefineGenericParameters ("K", "V");
9468
9469                         generic_type = tb.MakeGenericType ((Type []) null);
9470                         Assert.IsNotNull (generic_type, "#A1");
9471                         Assert.IsTrue (generic_type.IsGenericType, "#A2");
9472                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9473                         type_args = generic_type.GetGenericArguments ();
9474                         Assert.IsNull (type_args, "#A4");
9475
9476                         generic_type  = tb.MakeGenericType (typeof (string), (Type) null);
9477                         Assert.IsNotNull (generic_type, "#B1");
9478                         Assert.IsTrue (generic_type.IsGenericType, "#B2");
9479                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9480                         type_args = generic_type.GetGenericArguments ();
9481                         Assert.IsNotNull (type_args, "#B4");
9482                         Assert.AreEqual (2, type_args.Length, "#B5");
9483                         Assert.AreEqual (typeof (string), type_args [0], "#B6");
9484                         Assert.IsNull (type_args [1], "#B7");
9485                 }
9486
9487                 [Test]
9488                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9489                 public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9490                 {
9491                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9492                         tb.DefineGenericParameters ("K", "V");
9493                         try {
9494                                 tb.MakeGenericType (typeof (int));
9495                                 Assert.Fail ("#1");
9496                         } catch (ArgumentException ex) {
9497                                 // The type or method has 2 generic prarameter(s)
9498                                 // but 1 generic argument(s) were provided. A
9499                                 // generic argument must be provided for each
9500                                 // generic parameter
9501                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9502                                 Assert.IsNull (ex.InnerException, "#3");
9503                                 Assert.IsNotNull (ex.Message, "#4");
9504                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9505                         }
9506                 }
9507
9508                 [Test]
9509                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9510                 public void MakeGenericType_TypeArguments_Mismatch_MS ()
9511                 {
9512                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9513                         tb.DefineGenericParameters ("K", "V");
9514                         
9515                         Type generic_type = tb.MakeGenericType (typeof (int));
9516                         Assert.IsTrue (generic_type.IsGenericType, "#1");
9517                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9518                         Type [] type_args = generic_type.GetGenericArguments ();
9519                         Assert.IsNotNull (type_args, "#3");
9520                         Assert.AreEqual (1, type_args.Length, "#4");
9521                         Assert.AreEqual (typeof (int), type_args [0], "#5");
9522                 }
9523
9524                 [Test]
9525                 public void MakeArrayType_Complete ()
9526                 {
9527                         // reference type
9528                         TypeBuilder tb = module.DefineType (genTypeName (),
9529                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9530                                 typeof (ContextBoundObject));
9531                         Type emittedType = tb.CreateType ();
9532                         Type arrayType = tb.MakeArrayType ();
9533                         Assert.IsTrue (arrayType.IsArray, "#A1");
9534                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9535                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9536                         Assert.IsFalse (tb.HasElementType, "#A4");
9537                         Assert.IsTrue (tb.IsCreated (), "#A5");
9538
9539                         // value type
9540                         tb = module.DefineType (genTypeName (),
9541                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9542                                 typeof (ValueType));
9543                         emittedType = tb.CreateType ();
9544                         arrayType = tb.MakeArrayType ();
9545                         Assert.IsTrue (arrayType.IsArray, "#B1");
9546                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9547                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9548                         Assert.IsFalse (tb.HasElementType, "#B4");
9549                         Assert.IsTrue (tb.IsCreated (), "#B5");
9550
9551                         tb = module.DefineType (genTypeName (),
9552                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9553                                 typeof (Enum));
9554                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9555                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
9556                         emittedType = tb.CreateType ();
9557                         arrayType = tb.MakeArrayType ();
9558                         Assert.IsTrue (arrayType.IsArray, "#C1");
9559                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9560                         Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9561                         Assert.IsFalse (tb.HasElementType, "#C4");
9562                         Assert.IsTrue (tb.IsCreated (), "#C5");
9563                 }
9564
9565                 [Test] // bug #82015
9566                 public void MakeArrayType_Incomplete ()
9567                 {
9568                         // reference type
9569                         TypeBuilder tb = module.DefineType (genTypeName (),
9570                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9571                                 typeof (ContextBoundObject));
9572                         Type arrayType = tb.MakeArrayType ();
9573                         Assert.IsTrue (arrayType.IsArray, "#A1");
9574                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9575                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9576                         Assert.IsFalse (tb.HasElementType, "#A4");
9577                         Assert.IsFalse (tb.IsCreated (), "#A5");
9578
9579                         // value type
9580                         tb = module.DefineType (genTypeName (),
9581                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9582                                 typeof (ValueType));
9583                         arrayType = tb.MakeArrayType ();
9584                         Assert.IsTrue (arrayType.IsArray, "#B1");
9585                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9586                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9587                         Assert.IsFalse (tb.HasElementType, "#B4");
9588                         Assert.IsFalse (tb.IsCreated (), "#B5");
9589
9590                         // enum
9591                         tb = module.DefineType (genTypeName (),
9592                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9593                                 typeof (Enum));
9594                         arrayType = tb.MakeArrayType ();
9595                         Assert.IsTrue (arrayType.IsArray, "#C1");
9596                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9597                         Assert.IsFalse (tb.HasElementType, "#C3");
9598                         Assert.IsFalse (tb.IsCreated (), "#C4");
9599                 }
9600
9601                 [Test]
9602                 public void GetCustomAttributes_InflatedType ()
9603                 {
9604                         TypeBuilder tb = module.DefineType (genTypeName ());
9605                         tb.DefineGenericParameters (new string[] { "FOO" });
9606
9607                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9608                                 new Type [] { typeof (string) });
9609
9610                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9611                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9612
9613                         tb.SetCustomAttribute (caBuilder);
9614                         Type t = tb.CreateType ();
9615
9616                         Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9617
9618                         Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9619                 }
9620
9621                 [Test]
9622                 public void GetField ()
9623                 {
9624                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9625                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9626
9627                         ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9628
9629                         FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9630
9631                         Type t = tb.MakeGenericType (typeof (int));
9632
9633                         // Chect that calling MakeArrayType () does not initialize the class
9634                         // (bug #351172)
9635                         t.MakeArrayType ();
9636
9637                         // Check that the instantiation of a type builder contains live data
9638                         TypeBuilder.GetField (t, fb1);
9639                         FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9640                         FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9641
9642                         MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9643                         ILGenerator ilgen = mb.GetILGenerator ();
9644                         ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9645                         ilgen.Emit (OpCodes.Dup);
9646                         ilgen.Emit (OpCodes.Ldc_I4, 42);
9647                         ilgen.Emit (OpCodes.Stfld, fi2);
9648                         ilgen.Emit (OpCodes.Ldfld, fi2);
9649                         ilgen.Emit (OpCodes.Ret);
9650
9651                         // Check GetField on a type instantiated with type parameters
9652                         Type t3 = tb.MakeGenericType (typeParams [0]);
9653                         FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9654                         FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9655
9656                         MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9657                         ILGenerator ilgen3 = mb3.GetILGenerator ();
9658                         ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9659                         ilgen3.Emit (OpCodes.Ldfld, fi3);
9660                         ilgen3.Emit (OpCodes.Ret);
9661
9662                         Type created = tb.CreateType ();
9663
9664                         Type inst = created.MakeGenericType (typeof (object));
9665
9666                         Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9667
9668                         Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9669                 }
9670                 
9671                 [Test] //bug #354047
9672                 public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9673                 {
9674                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9675                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9676                         Type t = tb.CreateType ();
9677
9678                         Type inst = tb.MakeGenericType (typeParams [0]);
9679                         Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9680                 }
9681
9682                 [Test] //bug #354047
9683                 public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9684                 {
9685                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9686                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9687                         Type t = tb.CreateType ();
9688
9689                         Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9690                         Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9691                 }
9692
9693                 [Test] //bug #354047
9694                 public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9695                 {
9696                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9697                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9698                         Type t = tb.CreateType ();
9699
9700                         Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9701                 }
9702
9703                 [Test] //bug #399047
9704                 public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9705                                 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, tempDir);
9706
9707                                 module = assembly.DefineDynamicModule ("Instance.exe");
9708   
9709                 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9710                 Type T = G.DefineGenericParameters ("T") [0];
9711                                 ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9712                 Type GObj = G.MakeGenericType (new Type [] { T });
9713
9714                 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9715
9716                 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9717
9718                 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9719                 Type TATest = Test.DefineGenericParameters ("TA") [0];
9720                 {
9721                         Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9722
9723                         ILGenerator il = Test.GetILGenerator ();
9724
9725                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9726                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9727                         il.Emit (OpCodes.Pop);
9728
9729                         il.Emit (OpCodes.Ret);
9730                 }
9731
9732                                 MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9733                                 {
9734                                         ILGenerator il = main.GetILGenerator ();
9735                                         il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9736                                         il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9737                                         il.Emit (OpCodes.Ret);
9738                                 }
9739
9740                                 assembly.SetEntryPoint (main);
9741                 G.CreateType ();
9742                 var PCreated = P.CreateType ();
9743
9744                 assembly.Save ("Instance.exe");
9745
9746                 PCreated.InvokeMember ("Main", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, null);
9747                 }
9748
9749                 [Test]
9750                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9751                 {
9752                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9753                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9754                         tb.CreateType ();
9755
9756                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
9757                         module = assembly.DefineDynamicModule ("Instance.exe");
9758
9759                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9760                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9761                         ILGenerator il = mb.GetILGenerator ();
9762
9763                         il.Emit (OpCodes.Ldc_I4_1);
9764                         il.Emit (OpCodes.Newarr, typeof (int));
9765                         il.Emit (OpCodes.Dup);
9766                         il.Emit (OpCodes.Ldtoken, fb);
9767                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9768                         il.Emit (OpCodes.Ret);
9769
9770                         Type t = tb2.CreateType ();
9771                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9772                         //Console.WriteLine (res[0]);
9773                 }
9774
9775                 [Test]
9776                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers2 ()
9777                 {
9778                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9779                         var garg = tb.DefineGenericParameters ("T") [0];
9780                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9781                         tb.CreateType ();
9782
9783                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, tempDir);
9784                         module = assembly.DefineDynamicModule ("Instance.exe");
9785
9786                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9787                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9788                         ILGenerator il = mb.GetILGenerator ();
9789
9790                         il.Emit (OpCodes.Ldc_I4_1);
9791                         il.Emit (OpCodes.Newarr, typeof (int));
9792                         il.Emit (OpCodes.Dup);
9793                         il.Emit (OpCodes.Ldtoken, fb);
9794                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9795                         il.Emit (OpCodes.Ret);
9796
9797                         Type t = tb2.CreateType ();
9798                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9799                         //Console.WriteLine (res[0]);
9800                 }
9801
9802                 public interface IDelegateFactory
9803                 {
9804                         Delegate Create (Delegate del);
9805                 }
9806
9807                 [Test]
9808                 public void CreateType_Ctor_NoBody ()
9809                 {
9810                         TypeBuilder tb = module.DefineType (genTypeName ());
9811                         tb.DefineConstructor (MethodAttributes.Public,
9812                                 CallingConventions.Standard,
9813                                 new Type [] { typeof (string) });
9814                         try {
9815                                 tb.CreateType ();
9816                                 Assert.Fail ("#1");
9817                         } catch (InvalidOperationException ex) {
9818                                 // Method '.ctor' does not have a method body
9819                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9820                                 Assert.IsNull (ex.InnerException, "#3");
9821                                 Assert.IsNotNull (ex.Message, "#4");
9822                                 Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9823                         }
9824                 }
9825
9826                 [Test] //bug #361689
9827                 public void CreateTypeFailsWithInvalidMethodOverride ()
9828                 {
9829                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9830
9831                         MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
9832                         ILGenerator gen = mc.GetILGenerator ();
9833                         gen.Emit (OpCodes.Ldarg_0);
9834                         gen.Emit (OpCodes.Ret);
9835                         tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
9836                         try {
9837                                 tb.CreateType ();
9838                                 Assert.Fail ("#1 create type did not throw TypeLoadException");
9839                         } catch (TypeLoadException) {
9840                         
9841                         }
9842                 }
9843
9844                 [Test] //bug #349194
9845                 public void IsAssignableToWorksWithInterfacesOnParent ()
9846                 {
9847             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9848                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
9849
9850                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9851                         Type t = tb.CreateType ();
9852                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9853                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
9854                         
9855                         
9856                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9857                         Type t2 = tb2.CreateType ();
9858                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9859                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
9860                 }
9861
9862
9863                 [Test] //bug #430508
9864                 public void MakeGenericTypeRespectBaseType ()
9865                 {
9866             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9867                         EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
9868
9869                         MethodBuilder mb = tb.DefineMethod ("Test",
9870                                                                                                 MethodAttributes.Public,
9871                                                                                                 typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
9872                                                                                                 new Type [0]);
9873                         ILGenerator il = mb.GetILGenerator();
9874                         il.Emit (OpCodes.Ldnull);
9875                         il.Emit (OpCodes.Ret);
9876         
9877                         Type e = eb.CreateType ();
9878                         Type c = tb.CreateType ();
9879                 
9880                         Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
9881                 }
9882
9883                 [Test]
9884                 public void GetCustomAttrOnFieldOfInflatedType ()
9885                 {
9886                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9887                         tb.DefineGenericParameters ("T");
9888
9889                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9890                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9891                                 new object [0]);
9892
9893                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9894                         field.SetCustomAttribute (caBuilder);
9895
9896                         Type t = tb.CreateType ();
9897
9898                         FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9899                         object[] cattrs = fi.GetCustomAttributes (false);
9900                         Assert.AreEqual (1, cattrs.Length);
9901
9902                         fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9903                         cattrs = fi.GetCustomAttributes (false);
9904                         Assert.AreEqual (1, cattrs.Length);
9905                 }
9906
9907                 [Test]
9908                 public void GetCustomAttrOnPropertyOfInflatedType ()
9909                 {
9910                         TypeBuilder tb = module.DefineType (genTypeName ());
9911                         tb.DefineGenericParameters ("T");
9912
9913                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9914                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9915                                 new object [0]);
9916
9917                         PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
9918                         property.SetCustomAttribute (caBuilder);
9919
9920                         Type t = tb.CreateType ();
9921
9922                         PropertyInfo pi = t.GetProperties ()[0];
9923                         object[] cattrs = pi.GetCustomAttributes (false);
9924                         Assert.AreEqual (1, cattrs.Length);
9925
9926                         pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
9927                         cattrs = pi.GetCustomAttributes (false);
9928                         Assert.AreEqual (1, cattrs.Length);
9929                 }
9930
9931                 [Test]
9932                 public void GetCustomAttrOnEventOfInflatedType ()
9933                 {
9934                         TypeBuilder tb = module.DefineType (genTypeName ());
9935                         tb.DefineGenericParameters ("T");
9936
9937                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9938                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9939                                 new object [0]);
9940
9941                         EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
9942                         evt.SetCustomAttribute (caBuilder);
9943
9944                         Type t = tb.CreateType ();
9945
9946                         EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9947                         object[] cattrs = ei.GetCustomAttributes (false);
9948                         Assert.AreEqual (1, cattrs.Length);
9949
9950                         ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9951                         cattrs = ei.GetCustomAttributes (false);
9952                         Assert.AreEqual (1, cattrs.Length);
9953                 }
9954
9955                 public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
9956                 {
9957                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9958                         tb.DefineGenericParameters ("T");
9959  
9960                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9961                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9962                                 new object [0]);
9963
9964                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9965                         field.SetCustomAttribute (caBuilder);
9966
9967
9968                         tb.MakeGenericType (typeof (int)).GetMethods ();
9969                         tb.MakeGenericType (typeof (double)).GetMethods ();
9970                         
9971                         Type t = tb.CreateType ();
9972                         
9973                         t.MakeGenericType (typeof (int)).GetMethods ();
9974                         t.MakeGenericType (typeof (double)).GetMethods ();
9975                 }
9976
9977                 [Test]
9978                 public void TestGenericFieldAccess () // bug #467415
9979                 {
9980                         AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
9981                         AppDomain domain = AppDomain.CurrentDomain;
9982                         AssemblyBuilder demoAssembly =
9983                                 domain.DefineDynamicAssembly(asmName,
9984                                                 AssemblyBuilderAccess.RunAndSave);
9985
9986                         // Define the module that contains the code. For an
9987                         // assembly with one module, the module name is the
9988                         // assembly name plus a file extension.
9989                         ModuleBuilder demoModule =
9990                                 demoAssembly.DefineDynamicModule(asmName.Name,
9991                                                 asmName.Name+".dll");
9992
9993                         TypeBuilder demoType =
9994                                 demoModule.DefineType("DemoType", TypeAttributes.Public);
9995
9996                         MethodBuilder factory =
9997                                 demoType.DefineMethod("Factory",
9998                                                 MethodAttributes.Public | MethodAttributes.Static);
9999
10000                         string[] typeParameterNames = {"T"};
10001                         GenericTypeParameterBuilder[] typeParameters =
10002                                 factory.DefineGenericParameters(typeParameterNames);
10003
10004                         GenericTypeParameterBuilder T = typeParameters[0];
10005
10006                         Type[] parms = {};
10007                         factory.SetParameters(parms);
10008
10009                         factory.SetReturnType(T);
10010
10011                         ILGenerator ilgen = factory.GetILGenerator();
10012
10013                         Type G = typeof(Gen<>);
10014                         Type GT = G.MakeGenericType (T);
10015                         FieldInfo GF = G.GetField("field");
10016                         FieldInfo GTF = TypeBuilder.GetField(GT, GF);
10017
10018                         ilgen.Emit(OpCodes.Ldsfld, GTF);
10019                         ilgen.Emit(OpCodes.Ret);
10020
10021                         // Complete the type.
10022                         Type dt = demoType.CreateType();
10023                         // Save the assembly, so it can be examined with Ildasm.exe.
10024                         //demoAssembly.Save(asmName.Name+".dll");
10025
10026                         MethodInfo m = dt.GetMethod("Factory");
10027                         MethodInfo bound = m.MakeGenericMethod(typeof(int));
10028
10029                         // Display a string representing the bound method.
10030                         //Console.WriteLine(bound);
10031
10032                         object[] parameters = {};
10033                         int result = (int)(bound.Invoke(null, parameters));
10034
10035                         Assert.AreEqual (0, result, "#1");
10036                 }
10037
10038                 static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
10039                 {
10040                         foreach (MethodInfo mi in methods)
10041                                 if (mi.Name == name)
10042                                         return mi;
10043                         return null;
10044                 }
10045
10046                 void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
10047                 {
10048                         ConstructorBuilder cb;
10049                         MethodBuilder mb;
10050                         PropertyBuilder pb;
10051                         EventBuilder eb;
10052                         ILGenerator ilgen;
10053
10054                         if (defineCtors) {
10055                                 //
10056                                 // instance constructors
10057                                 //
10058                                 cb = tb.DefineConstructor (MethodAttributes.Private,
10059                                         CallingConventions.Standard,
10060                                         new Type [] { typeof (int), typeof (int) });
10061                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10062
10063                                 cb = tb.DefineConstructor (MethodAttributes.Family,
10064                                         CallingConventions.Standard,
10065                                         new Type [] { typeof (string) });
10066                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10067
10068                                 cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10069                                         CallingConventions.Standard,
10070                                         new Type [] { typeof (string), typeof (string) });
10071                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10072
10073                                 cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10074                                         CallingConventions.Standard,
10075                                         new Type [] { typeof (int) });
10076                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10077
10078                                 cb = tb.DefineConstructor (MethodAttributes.Public,
10079                                         CallingConventions.Standard,
10080                                         new Type [] { typeof (int), typeof (bool) });
10081                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10082
10083                                 cb = tb.DefineConstructor (MethodAttributes.Assembly,
10084                                         CallingConventions.Standard,
10085                                         new Type [] { typeof (string), typeof (int) });
10086                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10087
10088                                 //
10089                                 // static constructors
10090                                 //
10091
10092                                 cb = tb.DefineConstructor (MethodAttributes.Private |
10093                                         MethodAttributes.Static,
10094                                         CallingConventions.Standard,
10095                                         Type.EmptyTypes);
10096                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10097                         }
10098
10099                         //
10100                         // instance methods
10101                         //
10102
10103                         mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10104                                 MethodAttributes.Private, typeof (void),
10105                                 Type.EmptyTypes);
10106                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10107
10108                         mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10109                                 MethodAttributes.Family, typeof (void),
10110                                 Type.EmptyTypes);
10111                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10112
10113                         mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10114                                 MethodAttributes.FamANDAssem, typeof (void),
10115                                 Type.EmptyTypes);
10116                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10117
10118                         mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10119                                 MethodAttributes.FamORAssem, typeof (void),
10120                                 Type.EmptyTypes);
10121                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10122
10123                         mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10124                                 MethodAttributes.Public, typeof (void),
10125                                 Type.EmptyTypes);
10126                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10127
10128                         mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10129                                 MethodAttributes.Assembly, typeof (void),
10130                                 Type.EmptyTypes);
10131                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10132
10133                         //
10134                         // static methods
10135                         //
10136
10137                         mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10138                                 MethodAttributes.Private | MethodAttributes.Static,
10139                                 typeof (void), Type.EmptyTypes);
10140                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10141
10142                         mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10143                                 MethodAttributes.Family | MethodAttributes.Static,
10144                                 typeof (void), Type.EmptyTypes);
10145                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10146
10147                         mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10148                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10149                                 typeof (void), Type.EmptyTypes);
10150                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10151
10152                         mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10153                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10154                                 typeof (void), Type.EmptyTypes);
10155                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10156
10157                         mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10158                                 MethodAttributes.Public | MethodAttributes.Static,
10159                                 typeof (void), Type.EmptyTypes);
10160                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10161
10162                         mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10163                                 MethodAttributes.Assembly | MethodAttributes.Static,
10164                                 typeof (void), Type.EmptyTypes);
10165                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10166
10167                         //
10168                         // instance fields
10169                         //
10170
10171                         tb.DefineField ("privateInstance" + suffix,
10172                                 typeof (string), FieldAttributes.Private);
10173                         tb.DefineField ("familyInstance" + suffix,
10174                                 typeof (string), FieldAttributes.Family);
10175                         tb.DefineField ("famANDAssemInstance" + suffix,
10176                                 typeof (string), FieldAttributes.FamANDAssem);
10177                         tb.DefineField ("famORAssemInstance" + suffix,
10178                                 typeof (string), FieldAttributes.FamORAssem);
10179                         tb.DefineField ("publicInstance" + suffix,
10180                                 typeof (string), FieldAttributes.Public);
10181                         tb.DefineField ("assemblyInstance" + suffix,
10182                                 typeof (string), FieldAttributes.Assembly);
10183
10184                         //
10185                         // static fields
10186                         //
10187
10188                         tb.DefineField ("privateStatic" + suffix,
10189                                 typeof (string), FieldAttributes.Private |
10190                                 FieldAttributes.Static);
10191                         tb.DefineField ("familyStatic" + suffix,
10192                                 typeof (string), FieldAttributes.Family |
10193                                 FieldAttributes.Static);
10194                         tb.DefineField ("famANDAssemStatic" + suffix,
10195                                 typeof (string), FieldAttributes.FamANDAssem |
10196                                 FieldAttributes.Static);
10197                         tb.DefineField ("famORAssemStatic" + suffix,
10198                                 typeof (string), FieldAttributes.FamORAssem |
10199                                 FieldAttributes.Static);
10200                         tb.DefineField ("publicStatic" + suffix,
10201                                 typeof (string), FieldAttributes.Public |
10202                                 FieldAttributes.Static);
10203                         tb.DefineField ("assemblyStatic" + suffix,
10204                                 typeof (string), FieldAttributes.Assembly |
10205                                 FieldAttributes.Static);
10206
10207                         //
10208                         // instance properties
10209                         //
10210
10211                         pb = tb.DefineProperty ("PrivateInstance" + suffix,
10212                                 PropertyAttributes.None, typeof (string),
10213                                 Type.EmptyTypes);
10214                         mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10215                                 MethodAttributes.Private, typeof (string),
10216                                 Type.EmptyTypes);
10217                         ilgen = mb.GetILGenerator ();
10218                         ilgen.Emit (OpCodes.Ldnull);
10219                         ilgen.Emit (OpCodes.Ret);
10220                         pb.SetGetMethod (mb);
10221
10222                         pb = tb.DefineProperty ("FamilyInstance" + suffix,
10223                                 PropertyAttributes.None, typeof (string),
10224                                 Type.EmptyTypes);
10225                         mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10226                                 MethodAttributes.Family, typeof (string),
10227                                 Type.EmptyTypes);
10228                         ilgen = mb.GetILGenerator ();
10229                         ilgen.Emit (OpCodes.Ldnull);
10230                         ilgen.Emit (OpCodes.Ret);
10231                         pb.SetGetMethod (mb);
10232
10233                         pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10234                                 PropertyAttributes.None, typeof (string),
10235                                 Type.EmptyTypes);
10236                         mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10237                                 MethodAttributes.FamANDAssem, typeof (string),
10238                                 Type.EmptyTypes);
10239                         ilgen = mb.GetILGenerator ();
10240                         ilgen.Emit (OpCodes.Ldnull);
10241                         ilgen.Emit (OpCodes.Ret);
10242                         pb.SetGetMethod (mb);
10243
10244                         pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10245                                 PropertyAttributes.None, typeof (string),
10246                                 Type.EmptyTypes);
10247                         mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10248                                 MethodAttributes.FamORAssem, typeof (string),
10249                                 Type.EmptyTypes);
10250                         ilgen = mb.GetILGenerator ();
10251                         ilgen.Emit (OpCodes.Ldnull);
10252                         ilgen.Emit (OpCodes.Ret);
10253                         pb.SetGetMethod (mb);
10254
10255                         pb = tb.DefineProperty ("PublicInstance" + suffix,
10256                                 PropertyAttributes.None, typeof (string),
10257                                 Type.EmptyTypes);
10258                         mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10259                                 MethodAttributes.Public, typeof (string),
10260                                 Type.EmptyTypes);
10261                         ilgen = mb.GetILGenerator ();
10262                         ilgen.Emit (OpCodes.Ldnull);
10263                         ilgen.Emit (OpCodes.Ret);
10264                         pb.SetGetMethod (mb);
10265
10266                         pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10267                                 PropertyAttributes.None, typeof (string),
10268                                 Type.EmptyTypes);
10269                         mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10270                                 MethodAttributes.Assembly, typeof (string),
10271                                 Type.EmptyTypes);
10272                         ilgen = mb.GetILGenerator ();
10273                         ilgen.Emit (OpCodes.Ldnull);
10274                         ilgen.Emit (OpCodes.Ret);
10275                         pb.SetGetMethod (mb);
10276
10277                         //
10278                         // static properties
10279                         //
10280
10281                         pb = tb.DefineProperty ("PrivateStatic" + suffix,
10282                                 PropertyAttributes.None, typeof (string),
10283                                 Type.EmptyTypes);
10284                         mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10285                                 MethodAttributes.Private | MethodAttributes.Static,
10286                                 typeof (string), Type.EmptyTypes);
10287                         ilgen = mb.GetILGenerator ();
10288                         ilgen.Emit (OpCodes.Ldnull);
10289                         ilgen.Emit (OpCodes.Ret);
10290                         pb.SetGetMethod (mb);
10291
10292                         pb = tb.DefineProperty ("FamilyStatic" + suffix,
10293                                 PropertyAttributes.None, typeof (string),
10294                                 Type.EmptyTypes);
10295                         mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10296                                 MethodAttributes.Family | MethodAttributes.Static,
10297                                 typeof (string), Type.EmptyTypes);
10298                         ilgen = mb.GetILGenerator ();
10299                         ilgen.Emit (OpCodes.Ldnull);
10300                         ilgen.Emit (OpCodes.Ret);
10301                         pb.SetGetMethod (mb);
10302
10303                         pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10304                                 PropertyAttributes.None, typeof (string),
10305                                 Type.EmptyTypes);
10306                         mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10307                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10308                                 typeof (string), Type.EmptyTypes);
10309                         ilgen = mb.GetILGenerator ();
10310                         ilgen.Emit (OpCodes.Ldnull);
10311                         ilgen.Emit (OpCodes.Ret);
10312                         pb.SetGetMethod (mb);
10313
10314                         pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10315                                 PropertyAttributes.None, typeof (string),
10316                                 Type.EmptyTypes);
10317                         mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10318                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10319                                 typeof (string), Type.EmptyTypes);
10320                         ilgen = mb.GetILGenerator ();
10321                         ilgen.Emit (OpCodes.Ldnull);
10322                         ilgen.Emit (OpCodes.Ret);
10323                         pb.SetGetMethod (mb);
10324
10325                         pb = tb.DefineProperty ("PublicStatic" + suffix,
10326                                 PropertyAttributes.None, typeof (string),
10327                                 Type.EmptyTypes);
10328                         mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10329                                 MethodAttributes.Public | MethodAttributes.Static,
10330                                 typeof (string), Type.EmptyTypes);
10331                         ilgen = mb.GetILGenerator ();
10332                         ilgen.Emit (OpCodes.Ldnull);
10333                         ilgen.Emit (OpCodes.Ret);
10334                         pb.SetGetMethod (mb);
10335
10336                         pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10337                                 PropertyAttributes.None, typeof (string),
10338                                 Type.EmptyTypes);
10339                         mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10340                                 MethodAttributes.Assembly | MethodAttributes.Static,
10341                                 typeof (string), Type.EmptyTypes);
10342                         ilgen = mb.GetILGenerator ();
10343                         ilgen.Emit (OpCodes.Ldnull);
10344                         ilgen.Emit (OpCodes.Ret);
10345                         pb.SetGetMethod (mb);
10346
10347                         //
10348                         // instance events
10349                         //
10350
10351                         eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10352                                 EventAttributes.None, typeof (EventHandler));
10353                         mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10354                                 MethodAttributes.Private, typeof (void),
10355                                 Type.EmptyTypes);
10356                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10357                         eb.SetAddOnMethod (mb);
10358
10359                         eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10360                                 EventAttributes.None, typeof (EventHandler));
10361                         mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10362                                 MethodAttributes.Family, typeof (void),
10363                                 Type.EmptyTypes);
10364                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10365                         eb.SetAddOnMethod (mb);
10366
10367                         eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10368                                 EventAttributes.None, typeof (EventHandler));
10369                         mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10370                                 MethodAttributes.FamANDAssem, typeof (void),
10371                                 Type.EmptyTypes);
10372                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10373                         eb.SetAddOnMethod (mb);
10374
10375                         eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10376                                 EventAttributes.None, typeof (EventHandler));
10377                         mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10378                                 MethodAttributes.FamORAssem, typeof (void),
10379                                 Type.EmptyTypes);
10380                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10381                         eb.SetAddOnMethod (mb);
10382
10383                         eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10384                                 EventAttributes.None, typeof (EventHandler));
10385                         mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10386                                 MethodAttributes.Public, typeof (void),
10387                                 Type.EmptyTypes);
10388                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10389                         eb.SetAddOnMethod (mb);
10390
10391                         eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10392                                 EventAttributes.None, typeof (EventHandler));
10393                         mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10394                                 MethodAttributes.Family, typeof (void),
10395                                 Type.EmptyTypes);
10396                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10397                         eb.SetAddOnMethod (mb);
10398
10399                         //
10400                         // static events
10401                         //
10402
10403                         eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10404                                 EventAttributes.None, typeof (EventHandler));
10405                         mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10406                                 MethodAttributes.Private | MethodAttributes.Static,
10407                                 typeof (void), Type.EmptyTypes);
10408                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10409                         eb.SetAddOnMethod (mb);
10410
10411                         eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10412                                 EventAttributes.None, typeof (EventHandler));
10413                         mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10414                                 MethodAttributes.Family | MethodAttributes.Static,
10415                                 typeof (void), Type.EmptyTypes);
10416                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10417                         eb.SetAddOnMethod (mb);
10418
10419                         eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10420                                 EventAttributes.None, typeof (EventHandler));
10421                         mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10422                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10423                                 typeof (void), Type.EmptyTypes);
10424                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10425                         eb.SetAddOnMethod (mb);
10426
10427                         eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10428                                 EventAttributes.None, typeof (EventHandler));
10429                         mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10430                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10431                                 typeof (void), Type.EmptyTypes);
10432                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10433                         eb.SetAddOnMethod (mb);
10434
10435                         eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10436                                 EventAttributes.None, typeof (EventHandler));
10437                         mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10438                                 MethodAttributes.Public | MethodAttributes.Static,
10439                                 typeof (void), Type.EmptyTypes);
10440                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10441                         eb.SetAddOnMethod (mb);
10442
10443                         eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10444                                 EventAttributes.None, typeof (EventHandler));
10445                         mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10446                                 MethodAttributes.Family | MethodAttributes.Static,
10447                                 typeof (void), Type.EmptyTypes);
10448                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10449                         eb.SetAddOnMethod (mb);
10450                 }
10451
10452                 static TypeBuilder Resolve1_Tb;
10453                 static bool Resolve1_Called;
10454
10455                 public class Lookup<T>
10456                 {
10457                         public static Type t = typeof(T);
10458                 }
10459
10460                 Assembly Resolve1 (object sender, ResolveEventArgs args) {
10461                         Resolve1_Called = true;
10462                         Resolve1_Tb.CreateType ();
10463                         return Resolve1_Tb.Assembly;
10464                 }
10465
10466                 [Test]
10467                 public void TypeResolveGenericInstances () {
10468                         // Test that TypeResolve is called for generic instances (#483852)
10469                         TypeBuilder tb1 = null;
10470
10471                         AppDomain.CurrentDomain.TypeResolve += Resolve1;
10472
10473                         tb1 = module.DefineType("Foo");
10474                         Resolve1_Tb = tb1;
10475                         FieldInfo field = TypeBuilder.GetField(typeof(Lookup<>).MakeGenericType(tb1), typeof(Lookup<>).GetField("t"));
10476                         TypeBuilder tb2 = module.DefineType("Bar");
10477                         ConstructorBuilder cb = tb2.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
10478                         ILGenerator ilgen = cb.GetILGenerator();
10479                         
10480                         ilgen.Emit(OpCodes.Ldarg_0);
10481                         ilgen.Emit(OpCodes.Call, tb2.BaseType.GetConstructor(Type.EmptyTypes));
10482
10483                         ilgen.Emit(OpCodes.Ldsfld, field);
10484                         ilgen.Emit(OpCodes.Pop);
10485                         ilgen.Emit(OpCodes.Ret);
10486                         Activator.CreateInstance(tb2.CreateType());
10487
10488                         Assert.IsTrue (Resolve1_Called);
10489                 }
10490
10491                 [Test]
10492                 public void CreateConcreteTypeWithAbstractMethod ()
10493                 {
10494                         TypeBuilder tb = module.DefineType (genTypeName ());
10495                         tb.DefineMethod("method", MethodAttributes.Abstract | MethodAttributes.Public, typeof (void), Type.EmptyTypes);
10496                         try {
10497                                 tb.CreateType ();
10498                                 Assert.Fail ("#1");
10499                         } catch (InvalidOperationException) {}
10500                 }
10501
10502                 [Test]
10503                 public void ConcreteTypeDontLeakGenericParamFromItSelf ()
10504                 {
10505             var tb = module.DefineType (genTypeName ());
10506                         var gps = tb.DefineGenericParameters ("T");
10507             var mb = tb.DefineMethod ("m", MethodAttributes.Public | MethodAttributes.Static);
10508             mb.SetParameters (gps);
10509             mb.GetILGenerator ().Emit (OpCodes.Ret);
10510
10511             var ti = tb.CreateType ();
10512             var mi = ti.GetMethod ("m");
10513                         var arg0 = mi.GetParameters () [0].ParameterType;
10514
10515                         Assert.AreNotSame (arg0, gps [0], "#1");
10516                 }
10517
10518                 [Test]
10519                 public void ConcreteTypeDontLeakGenericParamFromMethods ()
10520                 {
10521             var tb = module.DefineType (genTypeName ());
10522             var mb = tb.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Static);
10523             var gps = mb.DefineGenericParameters ("T");
10524             mb.SetParameters (gps);
10525             mb.GetILGenerator ().Emit (OpCodes.Ret);
10526
10527             var ti = tb.CreateType ();
10528             var mi = ti.GetMethod ("m");
10529                         var arg0 = mi.GetParameters () [0].ParameterType;
10530
10531                         Assert.AreNotSame (arg0, gps [0], "#1");
10532                 }
10533
10534                 [Test]
10535                 public void DeclaringMethodReturnsNull ()
10536                 {
10537                         TypeBuilder tb = module.DefineType (genTypeName ());
10538                         Assert.IsNull (tb.DeclaringMethod, null, "#1");
10539                 }
10540
10541                 [Test]
10542                 public void GenericParameterPositionReturns0 ()
10543                 {
10544                         TypeBuilder tb = module.DefineType (genTypeName ());
10545                         Assert.AreEqual (0, tb.GenericParameterPosition, "#1");
10546                 }
10547
10548                 [Test]
10549                 public void GetGenericTypeDefinitionBehavior ()
10550                 {
10551                         TypeBuilder tb = module.DefineType (genTypeName ());
10552                         try {
10553                                 tb.GetGenericTypeDefinition ();
10554                                 Assert.Fail ("#1");
10555                         } catch (InvalidOperationException) {}
10556
10557                         tb.DefineGenericParameters ("T");
10558                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#2");
10559
10560                         tb.CreateType ();
10561                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#3");
10562                 }
10563
10564                 [Test]
10565                 public void GetElementTypeNotSupported ()
10566                 {
10567                         TypeBuilder tb = module.DefineType (genTypeName ());
10568                         try {
10569                                 tb.GetElementType ();
10570                                 Assert.Fail ("#1");
10571                         } catch (NotSupportedException) {}
10572                 }
10573
10574                 [Test]
10575                 public void GenericParameterAttributesReturnsNone ()
10576                 {
10577                         TypeBuilder tb = module.DefineType (genTypeName ());
10578                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#1");
10579
10580                         tb.DefineGenericParameters ("T");
10581                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#2");
10582
10583                         tb.CreateType ();
10584                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#3");
10585                 }
10586
10587                 [Test]
10588                 public void GetGenericArgumentsReturnsNullForNonGenericTypeBuilder ()
10589                 {
10590                         TypeBuilder tb = module.DefineType (genTypeName ());
10591                         Assert.IsNull (tb.GetGenericArguments (), "#1");
10592                 }
10593
10594                 public interface IFaceA {}
10595                 public interface IFaceB : IFaceA {}
10596                 [Test]
10597                 public void GetInterfacesAfterCreate ()
10598                 {
10599                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type[] { typeof (IFaceB) });
10600
10601                         Type[] ifaces = tb.GetInterfaces ();
10602                         Assert.AreEqual (1, ifaces.Length, "#1");
10603                         Assert.AreEqual (typeof (IFaceB), ifaces [0], "#2");
10604
10605                         tb.CreateType ();
10606                         ifaces = tb.GetInterfaces ();
10607                         Assert.AreEqual (2, ifaces.Length, "#3");
10608                         //Interfaces can come in any particular order
10609                         if (ifaces [0] == typeof (IFaceB)) {
10610                                 Assert.AreEqual (typeof (IFaceB), ifaces [0], "#4");
10611                                 Assert.AreEqual (typeof (IFaceA), ifaces [1], "#5");
10612                         } else {
10613                                 Assert.AreEqual (typeof (IFaceB), ifaces [1], "#4");
10614                                 Assert.AreEqual (typeof (IFaceA), ifaces [0], "#5");
10615                         }
10616                 }
10617
10618                 public interface MB_Iface
10619                 {
10620                     int Test ();
10621                 }
10622
10623                 public class MB_Impl : MB_Iface
10624                 {
10625                     public virtual int Test () { return 1; }
10626                 }
10627                 [Test]
10628                 public void MethodOverrideBodyMustBelongToTypeBuilder ()
10629                 {
10630                         TypeBuilder tb = module.DefineType (genTypeName ());
10631                         MethodInfo md = typeof (MB_Iface).GetMethod("Test");
10632             MethodInfo md2 = typeof (MB_Impl).GetMethod("Test");
10633                         try {
10634                 tb.DefineMethodOverride (md, md2);
10635                 Assert.Fail ("#1");
10636                         } catch (ArgumentException) {}
10637                 }
10638
10639                 [Test]
10640                 public void GetConstructorsThrowWhenIncomplete ()
10641                 {
10642                         TypeBuilder tb = module.DefineType (genTypeName ());
10643                         try {
10644                                 tb.GetConstructors (BindingFlags.Instance);
10645                                 Assert.Fail ("#1");
10646                         } catch (NotSupportedException) { }
10647
10648                         tb.CreateType ();
10649                         Assert.IsNotNull (tb.GetConstructors (BindingFlags.Instance), "#2");
10650                 }
10651
10652                 [Test]
10653                 public void GetEventsThrowWhenIncomplete ()
10654                 {
10655                         TypeBuilder tb = module.DefineType (genTypeName ());
10656                         try {
10657                                 tb.GetEvents (BindingFlags.Instance);
10658                                 Assert.Fail ("#1");
10659                         } catch (NotSupportedException) { }
10660
10661                         tb.CreateType ();
10662                         Assert.IsNotNull (tb.GetEvents (BindingFlags.Instance), "#2");
10663                 }
10664
10665                 [Test]
10666                 public void GetNestedTypeCreatedAfterTypeIsCreated ()
10667                 {
10668                         TypeBuilder tb = module.DefineType (genTypeName ());
10669                         TypeBuilder nested = tb.DefineNestedType ("Bar", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10670                         tb.CreateType ();
10671                         Assert.IsNull (tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#1");
10672                         Type res = nested.CreateType ();
10673                         Assert.AreEqual (res, tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#2");
10674
10675                         TypeBuilder nested2 = tb.DefineNestedType ("Bar2", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10676                         Assert.IsNull (tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#3");
10677                         res = nested2.CreateType ();
10678                         Assert.AreEqual (res, tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#4");
10679                 }
10680
10681
10682                 [Test]
10683                 public void IsDefinedThrowWhenIncomplete ()
10684                 {
10685                         TypeBuilder tb = module.DefineType (genTypeName ());
10686                         try {
10687                                 tb.IsDefined (typeof (string), true);
10688                                 Assert.Fail ("#1");
10689                         } catch (NotSupportedException) { }
10690
10691                         tb.CreateType ();
10692                         Assert.IsNotNull (tb.IsDefined (typeof (string), true), "#2");
10693                 }
10694
10695                 [Test] //Bug #594728
10696                 public void IsSubclassOfWorksIfSetParentIsCalledOnParent ()
10697                 {
10698                         var tb_a = module.DefineType ("A", TypeAttributes.Public);
10699                         var tb_b = module.DefineType ("B", TypeAttributes.Public);
10700         
10701                         tb_b.SetParent (tb_a);
10702                         tb_a.SetParent (typeof (Attribute));
10703         
10704                         Assert.IsTrue (tb_b.IsSubclassOf (tb_a), "#1");
10705                         Assert.IsTrue (tb_b.IsSubclassOf (typeof (Attribute)), "#2");
10706                         Assert.IsFalse (tb_a.IsSubclassOf (tb_b), "#3");
10707         
10708         
10709                         var a = tb_a.CreateType ();
10710                         var b = tb_b.CreateType ();
10711         
10712                         Assert.IsTrue (b.IsSubclassOf (a), "#4");
10713                         Assert.IsTrue (b.IsSubclassOf (typeof (Attribute)), "#5");
10714                         Assert.IsFalse (a.IsSubclassOf (b), "#6");
10715                 }
10716
10717                 [Test]
10718                 public void DefinedDefaultConstructorWorksWithGenericBaseType ()
10719                 {
10720                         AssemblyName assemblyName = new AssemblyName ("a");
10721                         AssemblyBuilder ass = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.RunAndSave);
10722                         var mb = ass.DefineDynamicModule ("a.dll");
10723
10724                         var tb = mb.DefineType ("Base");
10725                         tb.DefineGenericParameters ("F");
10726
10727                         var inst = tb.MakeGenericType (typeof (int));
10728                         var tb2 = mb.DefineType ("Child", TypeAttributes.Public, inst);
10729
10730                         tb.CreateType ();
10731                         var res = tb2.CreateType ();
10732
10733                         Assert.IsNotNull (res, "#1");
10734                         Assert.AreEqual (1, res.GetConstructors ().Length, "#2");
10735                 }
10736
10737                 /* 
10738                  * Tests for passing user types to Ref.Emit. Currently these only test
10739                  * whenever the runtime code can handle them without crashing, since we
10740                  * don't support user types yet.
10741                  * These tests are disabled for windows since the MS runtime trips on them.
10742                  */
10743                 [Test]
10744                 [Category ("NotDotNet")] //Proper UT handling is a mono extension to SRE bugginess
10745                 public void UserTypes () {
10746                         TypeDelegator t = new TypeDelegator (typeof (int));
10747
10748                         try {
10749                                 /* Parent */
10750                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10751                         } catch {
10752                         }
10753
10754                         try {
10755                                 /* Interfaces */
10756                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10757                                 tb.CreateType ();
10758                         } catch {
10759                         }
10760
10761                         try {
10762                                 /* Fields */
10763                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10764                                 tb.DefineField ("Foo", t, FieldAttributes.Public);
10765                                 tb.CreateType ();
10766                         } catch {
10767                         }
10768
10769                         try {
10770                                 /* Custom modifiers on fields */
10771                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10772                                 tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10773                                 tb.CreateType ();
10774                         } catch {
10775                         }
10776 /* this is mono only
10777                         try {
10778                                 UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10779                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10780                                 FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10781                                 fb.SetMarshal (m);
10782                                 tb.CreateType ();
10783                         } catch {
10784                         }
10785 */
10786                         try {
10787                                 /* Properties */
10788                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10789                                 tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10790                                 tb.CreateType ();
10791                         } catch {
10792                         }
10793
10794                         try {
10795                                 /* Custom modifiers on properties */
10796                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10797                                 // FIXME: These seems to be ignored
10798                                 tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10799                                 tb.CreateType ();
10800                         } catch {
10801                         }
10802
10803                         try {
10804                                 /* Method return types */
10805                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10806                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10807                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10808                                 tb.CreateType ();
10809                         } catch {
10810                         }
10811
10812                         try {
10813                                 /* Custom modifiers on method return types */
10814                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10815                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10816                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10817                                 tb.CreateType ();
10818                         } catch {
10819                         }
10820
10821                         try {
10822                                 /* Method parameters */
10823                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10824                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10825                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10826                                 tb.CreateType ();
10827                         } catch {
10828                         }
10829
10830                         try {
10831                                 /* Custom modifiers on method parameters */
10832                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10833                                 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 }});
10834                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10835                                 tb.CreateType ();
10836                         } catch {
10837                         }
10838
10839                         try {
10840                                 /* Ctor parameters */
10841                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10842                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10843                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10844                                 tb.CreateType ();
10845                         } catch {
10846                         }
10847                         
10848                         try {
10849                                 /* Custom modifiers on ctor parameters */
10850                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10851                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10852                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10853                                 tb.CreateType ();
10854                         } catch {
10855                         }
10856
10857                         try {
10858                                 /* SignatureHelper arguments */
10859                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10860                                 sighelper.AddArgument (t, false);
10861                                 byte[] arr = sighelper.GetSignature ();
10862                         } catch {
10863                         }
10864
10865                         try {
10866                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10867                                 sighelper.AddArgument (t, false);
10868                                 byte[] arr = sighelper.GetSignature ();
10869                         } catch {
10870                         }
10871
10872                         try {
10873                                 /* Custom modifiers on SignatureHelper arguments */
10874                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10875                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10876                                 byte[] arr = sighelper.GetSignature ();
10877                         } catch {
10878                         }
10879
10880                         try {
10881                                 /* Custom modifiers on SignatureHelper arguments */
10882                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10883                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10884                                 byte[] arr = sighelper.GetSignature ();
10885                         } catch {
10886                         }
10887
10888                         /* Arguments to ILGenerator methods */
10889                         try {
10890                                 /* Emit () */
10891                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10892                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10893                                 ILGenerator ig = mb.GetILGenerator ();
10894                                 ig.Emit (OpCodes.Ldnull);
10895                                 ig.Emit (OpCodes.Castclass, t);
10896                                 ig.Emit (OpCodes.Pop);
10897                                 ig.Emit (OpCodes.Ret);
10898                                 tb.CreateType ();
10899                         } catch {
10900                         }
10901
10902                         try {
10903                                 /* DeclareLocal () */
10904                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10905                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10906                                 ILGenerator ig = mb.GetILGenerator ();
10907                                 ig.DeclareLocal (t);
10908                                 ig.Emit (OpCodes.Ret);
10909                                 tb.CreateType ();
10910                         } catch {
10911                         }
10912
10913                         try {
10914                                 /* BeginExceptionCatchBlock () */
10915                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10916                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10917                                 ILGenerator ig = mb.GetILGenerator ();
10918                                 ig.BeginExceptionBlock ();
10919                                 ig.BeginCatchBlock (t);
10920                                 ig.Emit (OpCodes.Ret);
10921                                 tb.CreateType ();
10922                         } catch {
10923                         }
10924
10925                         try {
10926                                 /* EmitCalli () */
10927                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10928                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10929                                 ILGenerator ig = mb.GetILGenerator ();
10930                                 ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
10931                                 ig.Emit (OpCodes.Ret);
10932                                 tb.CreateType ();
10933                         } catch {
10934                         }
10935                 }
10936
10937                 //Test for #572660
10938         [Test]
10939         [Category ("MobileNotWorking")] // Mono.CompilerServices.SymbolWriter not available in XA
10940         public void CircularArrayType()
10941         {
10942                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndSave);
10943                         var moduleBuilder = assemblyBuilder.DefineDynamicModule("Test", "Test.dll", true);
10944                         var typeBuilder = moduleBuilder.DefineType("Foo", TypeAttributes.Public);
10945                         var fieldBuilder = typeBuilder.DefineField("Foos", typeBuilder.MakeArrayType(), FieldAttributes.Public);
10946
10947                         var fooType = typeBuilder.CreateType();
10948                         Assert.AreSame(fooType.MakeArrayType(), fooType.GetField("Foos").FieldType);
10949         }
10950
10951
10952                 [Test] //Test for #422113
10953                 [ExpectedException (typeof (TypeLoadException))]
10954                 public void CreateInstanceOfIncompleteType ()
10955                 {
10956                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class, null, new Type[] { typeof (IComparable) });
10957                         Type proxyType = tb.CreateType();
10958                         Activator.CreateInstance(proxyType);
10959                 }
10960
10961                 [Test] //Test for #640780
10962                 public void StaticMethodNotUsedInIfaceVtable ()
10963                 {
10964                         TypeBuilder tb1 = module.DefineType("Interface", TypeAttributes.Interface | TypeAttributes.Abstract);
10965                         tb1.DefineTypeInitializer().GetILGenerator().Emit(OpCodes.Ret);
10966                         tb1.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract);
10967                         tb1.CreateType();
10968                         
10969                         TypeBuilder tb2 = module.DefineType("Class", TypeAttributes.Sealed);
10970                         tb2.AddInterfaceImplementation(tb1);
10971                         tb2.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual)
10972                             .GetILGenerator().Emit(OpCodes.Ret);
10973                         tb2.DefineDefaultConstructor(MethodAttributes.Public);
10974                         
10975                         Activator.CreateInstance(tb2.CreateType());
10976                 }
10977
10978                 [Test] //Test for #648391
10979                 public void GetConstructorCheckCtorDeclaringType ()
10980                 {
10981                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10982                         string[] typeParamNames = { "TFirst" };
10983                         GenericTypeParameterBuilder[] typeParams = myType.DefineGenericParameters (typeParamNames);
10984                         var ctor = myType.DefineDefaultConstructor (MethodAttributes.Public);
10985                         var ctori = TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (int)), ctor);
10986                         try {
10987                                 TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (bool)), ctori);
10988                                 Assert.Fail ("#1");
10989                         } catch (ArgumentException) {
10990                                 //OK
10991                         }
10992                 }
10993
10994                 [Test] //Test for #649237
10995                 public void GetFieldCheckFieldDeclaringType () {
10996                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10997                         myType.DefineGenericParameters ( "TFirst");
10998                         TypeBuilder otherType = module.DefineType ("Sample2", TypeAttributes.Public);
10999                         otherType.DefineGenericParameters ( "TFirst");
11000
11001                         var field = myType.DefineField ("field", typeof (object), FieldAttributes.Public);
11002
11003                         try {
11004                                 TypeBuilder.GetField (otherType.MakeGenericType (typeof (int)), field);
11005                                 Assert.Fail ("#1");
11006                         } catch (ArgumentException) {
11007                                 //OK
11008                         }
11009                 }
11010
11011                 [Test]
11012                 public void TypeWithFieldRVAWorksUnderSgen () {
11013                 AssemblyName an = new AssemblyName("MAIN");
11014                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an,
11015                     AssemblyBuilderAccess.Run, ".");
11016                 ModuleBuilder mob = ab.DefineDynamicModule("MAIN");
11017                 TypeBuilder tb = mob.DefineType("MAIN", TypeAttributes.Public |
11018                     TypeAttributes.Sealed | TypeAttributes.Abstract |
11019                     TypeAttributes.Class | TypeAttributes.BeforeFieldInit);
11020
11021                 byte[] source = new byte[] { 42 };
11022                 FieldBuilder fb = tb.DefineInitializedData("A0", source, 0);
11023
11024                 MethodBuilder mb = tb.DefineMethod("EVAL", MethodAttributes.Static |
11025                     MethodAttributes.Public, typeof(byte[]), new Type[] { });
11026                 ILGenerator il = mb.GetILGenerator();
11027
11028                 il.Emit(OpCodes.Ldc_I4_1);
11029                 il.Emit(OpCodes.Newarr, typeof(byte));
11030                 il.Emit(OpCodes.Dup);
11031                 il.Emit(OpCodes.Ldtoken, fb);
11032                 il.Emit(OpCodes.Call, typeof(RuntimeHelpers).GetMethod("InitializeArray"));
11033                 il.Emit(OpCodes.Ret);
11034
11035                 Type t = tb.CreateType();
11036
11037                 GC.Collect();
11038
11039                 byte[] res = (byte[]) t.InvokeMember("EVAL", BindingFlags.Public |
11040                     BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
11041                     new object[] { });
11042
11043                 Assert.AreEqual (42, res[0]);
11044             }
11045
11046
11047                 [Test]
11048                 public void Ldfld_Regress_9531 () {
11049                         Build<Example<int>> ();
11050                 }
11051
11052                 void Build<T> () {
11053             var base_class = typeof(T);
11054
11055             var builder = module.DefineType(genTypeName (),
11056                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11057                 base_class);
11058
11059             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11060             
11061             var cb = builder.DefineConstructor(
11062                 MethodAttributes.Public | MethodAttributes.SpecialName,
11063                 CallingConventions.HasThis,
11064                 new[] { typeof(string) });
11065             
11066             var il = cb.GetILGenerator();
11067             
11068             if (field == null)
11069             {
11070                 throw new InvalidOperationException("wtf");
11071             }
11072             
11073             il.Emit(OpCodes.Ldarg_0);
11074             il.Emit(OpCodes.Ldarg_1);
11075             il.Emit(OpCodes.Stfld, field);
11076             il.Emit(OpCodes.Ret);
11077             
11078             builder.CreateType();
11079                 }
11080
11081                 public class Example<T> {
11082                         public string Field;
11083                         public T Field2;
11084                 }
11085
11086                 [Test]
11087                 [Category ("AndroidNotWorking")]
11088                 // It's not possible to save the assembly in the current directory on Android and AssemblyBuilder.DefineDynamicModule will not
11089                 // allow a full path to the assembly to be passed to it. Trying to change the current directory before saving will not work either as
11090                 // FileStream will then prepend / to the file name (perhaps it's another bug) and write access to the filesystem root is, obviously, denied
11091                 public void Ldfld_Encoding_10122 () {
11092                         Build2<Example<int>> ();
11093                 }
11094
11095                 void Build2<T> () {
11096                         var base_class = typeof(T);
11097
11098                 string AssemblyName = genTypeName ();
11099                 string AssemblyFileName = AssemblyName + ".dll";
11100
11101                         var assemblyBuilderAccess = AssemblyBuilderAccess.Save;
11102                         var assemblyName = new AssemblyName(AssemblyName);
11103                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
11104                         var moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName, AssemblyFileName);
11105
11106
11107                         var builder = moduleBuilder.DefineType("Wrapped",
11108                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11109                 base_class);
11110
11111             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11112             
11113             var cb = builder.DefineConstructor(
11114                 MethodAttributes.Public | MethodAttributes.SpecialName,
11115                 CallingConventions.HasThis,
11116                 new[] { typeof(string) });
11117             
11118             var il = cb.GetILGenerator();
11119             
11120             if (field == null)
11121             {
11122                 throw new InvalidOperationException("wtf");
11123             }
11124             
11125             il.Emit(OpCodes.Ldarg_0);
11126             il.Emit(OpCodes.Ldarg_1);
11127             il.Emit(OpCodes.Stfld, field);
11128             il.Emit(OpCodes.Ret);
11129             
11130             builder.CreateType();
11131
11132                         assemblyBuilder.Save (AssemblyFileName);
11133
11134                         var fromDisk = Assembly.Load (AssemblyName);
11135                         Console.WriteLine (fromDisk);
11136                         var t = fromDisk.GetType ("Wrapped");
11137                         Activator.CreateInstance (t, new object[] { "string"});
11138                 }
11139
11140                 public interface IFace16096 {
11141                         object Bar ();
11142                 }
11143
11144                 [Test]
11145                 public void MemberRef_Caching_16096 () {
11146                         var outer_class = module.DefineType(
11147                                 "container",
11148                                 TypeAttributes.Class | TypeAttributes.Public,
11149                                 typeof(object));
11150
11151                         var builder = outer_class.DefineNestedType(
11152                                 "bind@32-1",
11153                                 TypeAttributes.Class | TypeAttributes.Public,
11154                                 typeof(object));
11155
11156                         builder.AddInterfaceImplementation (typeof (IFace16096));
11157
11158                         var ctor = builder.DefineDefaultConstructor (MethodAttributes.Public);
11159                         var field = builder.DefineField ("Field", typeof (object), FieldAttributes.Public);
11160                         var g_args = builder.DefineGenericParameters("b","a");
11161                         var method = builder.DefineMethod ("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof (object), new Type [0]);
11162
11163                         var il = method.GetILGenerator();
11164                         il.Emit (OpCodes.Ldarg_0);
11165                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (builder.MakeGenericType (g_args), field));
11166                         il.Emit (OpCodes.Pop);
11167                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (builder.MakeGenericType (g_args), ctor));
11168                         il.Emit (OpCodes.Ret);
11169
11170                         var type = builder.CreateType ();
11171
11172                         /*Build a gshared instance. */
11173                         var ginst = type.MakeGenericType (typeof (List<char>), typeof (object));
11174                         var ins = (IFace16096)Activator.CreateInstance (ginst);
11175
11176                         /* This will trigger the runtime to cache the MEMBER_REF to the .ctor as it won't have a context. */
11177                         var ins2 = ins.Bar ();
11178                         Assert.IsNotNull (ins2);
11179
11180                         /* Build an unsharable version. */
11181                         var ginst2 = type.MakeGenericType (typeof (List<char>), typeof (char));
11182                         var ins3 = (IFace16096)Activator.CreateInstance (ginst2);
11183
11184                         /* This will trigger the runtime to use the cached version, which is wrong as it's an open type. */
11185                         var ins4 = ins3.Bar ();
11186                         Assert.IsNotNull (ins4);
11187                 }
11188
11189                 [Test]
11190                 public void CircularReferences () {
11191                         // A: C<D<A>>
11192                         var a_type = module.DefineType(
11193                                 "A",
11194                                 TypeAttributes.Class,
11195                                 typeof(object));
11196
11197                         var cba = a_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11198                         cba.GetILGenerator ().Emit (OpCodes.Ret);
11199
11200                         var c_type = module.DefineType(
11201                                 "B",
11202                                 TypeAttributes.Class,
11203                                 typeof(object));
11204                         var cbb = c_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11205                         cbb.GetILGenerator ().Emit (OpCodes.Ret);
11206                         c_type.DefineGenericParameters ("d_a_param");
11207
11208                         var d_type = module.DefineType(
11209                                 "D",
11210                                 TypeAttributes.Class,
11211                                 typeof(object));
11212                         var cbd = d_type.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
11213                         cbd.GetILGenerator ().Emit (OpCodes.Ret);
11214                         d_type.DefineGenericParameters ("a_param");
11215
11216
11217                         var d_instantiated = c_type.MakeGenericType (d_type.MakeGenericType (a_type));
11218                         a_type.SetParent (d_instantiated);
11219                         a_type.CreateType ();
11220
11221                         Assert.IsNotNull (a_type);
11222                 }
11223
11224                 // #22059
11225                 [Test]
11226                 [ExpectedException (typeof (TypeLoadException))]
11227                 public void PrivateIface ()
11228                 {
11229                         TypeBuilder tb = module.DefineType ("Sample", TypeAttributes.Public, typeof (object), new[] { typeof (IFoo) });
11230             tb.CreateType();
11231                 }
11232
11233                 interface IFoo {
11234                 }
11235
11236                 [Test]
11237                 public void GenericFieldInCreatedType () {
11238                         /*
11239                          * Regression test for #47867.
11240                          * We construct the following, but only call CreateType on R.
11241                          *
11242                          * public class S<T> {
11243                          *   public T t;
11244                          * }
11245                          * public class R {
11246                          *   public static S<R> sr;
11247                          * }
11248                          */
11249                         var aname = new AssemblyName ("example1");
11250                         var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11251                         var mb = ab.DefineDynamicModule (aname.Name);
11252                         var tbS = mb.DefineType ("S", TypeAttributes.Public);
11253                         tbS.DefineGenericParameters (new String [] { "T" });
11254                         var tbR = mb.DefineType ("R", TypeAttributes.Public);
11255                         tbR.DefineField ("sr", tbS.MakeGenericType(new Type[] { tbR }), FieldAttributes.Public | FieldAttributes.Static);
11256
11257                         Type r = tbR.CreateType ();
11258
11259                         Assert.IsNotNull  (r);
11260                 }
11261
11262                 [Test]
11263                 public void GenericFieldInCreatedTypeIncompleteTypeTLE () {
11264                         /*
11265                          * Regression test for #47867.
11266                          * We construct the following, but only call CreateType on R.
11267                          * Then we try to use R.sr which is expected throw a
11268                          * TLE because S hasn't been created yet.
11269                          *
11270                          * public class S<T> {
11271                          *   public T t;
11272                          * }
11273                          * public class R {
11274                          *   public static S<R> sr;
11275                          * }
11276                          */
11277                         var aname = new AssemblyName ("example1");
11278                         var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11279                         var mb = ab.DefineDynamicModule (aname.Name);
11280                         var tbS = mb.DefineType ("S", TypeAttributes.Public);
11281                         tbS.DefineGenericParameters (new String [] { "T" });
11282                         var tbR = mb.DefineType ("R", TypeAttributes.Public);
11283                         tbR.DefineField ("sr", tbS.MakeGenericType(new Type[] { tbR }), FieldAttributes.Public | FieldAttributes.Static);
11284
11285                         Type r = tbR.CreateType ();
11286
11287                         Assert.IsNotNull  (r);
11288
11289                         // N.B.  tbS has not had CreateType called yet, so expect this to fail.
11290                         Assert.Throws<TypeLoadException> (delegate { var ft = r.GetField("sr").FieldType; });
11291                 }
11292                 
11293                 [Test]
11294                 public void GetGenericTypeDefinitionAfterCreateReturnsBuilder () {
11295                         var aname = new AssemblyName ("genericDefnAfterCreate");
11296                         var ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
11297                         var mb = ab.DefineDynamicModule (aname.Name);
11298                         var buildX = mb.DefineType ("X", TypeAttributes.Public);
11299                         buildX.DefineGenericParameters ("T", "U");
11300                         var x = buildX.CreateType ();
11301                         var inst = x.MakeGenericType (typeof (string), typeof (int));
11302                         var defX = inst.GetGenericTypeDefinition ();
11303
11304                         Assert.AreSame (buildX, defX);
11305                 }
11306
11307                 [Test]
11308                 public void FieldsWithSameName () {
11309                         // Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11310                         var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11311
11312                         var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11313                         var mainMethodIl = mainMethod.GetILGenerator ();
11314
11315                         var f1 = typeBuilder.DefineField ("x", typeof (byte), FieldAttributes.Private | FieldAttributes.Static);
11316                         var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11317
11318                         mainMethodIl.Emit (OpCodes.Ldsflda, f1);
11319                         mainMethodIl.Emit (OpCodes.Ldsflda, f2);
11320                         mainMethodIl.Emit (OpCodes.Pop);
11321                         mainMethodIl.Emit (OpCodes.Pop);
11322                         mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11323                         mainMethodIl.Emit (OpCodes.Ret);
11324
11325                         typeBuilder.CreateType ();
11326                         assembly.SetEntryPoint (mainMethod);
11327
11328                         assembly.Save (ASSEMBLY_NAME + ".dll");
11329                 }
11330                 [Test]
11331                 public void FieldsWithSameNameAndType () {
11332                         // https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11333                         var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11334
11335                         var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11336                         var mainMethodIl = mainMethod.GetILGenerator ();
11337
11338                         var f1 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11339                         var f2 = typeBuilder.DefineField ("x", typeof (sbyte), FieldAttributes.Private | FieldAttributes.Static);
11340
11341                         mainMethodIl.Emit (OpCodes.Ldsflda, f1);
11342                         mainMethodIl.Emit (OpCodes.Ldsflda, f2);
11343                         mainMethodIl.Emit (OpCodes.Pop);
11344                         mainMethodIl.Emit (OpCodes.Pop);
11345                         mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11346                         mainMethodIl.Emit (OpCodes.Ret);
11347
11348                         typeBuilder.CreateType ();
11349                         assembly.SetEntryPoint (mainMethod);
11350
11351                         assembly.Save (ASSEMBLY_NAME + ".dll");
11352                 }
11353
11354                 [Test]
11355                 public void MethodsWithSameNameAndSig () {
11356                         // https://bugzilla.xamarin.com/show_bug.cgi?id=57222
11357                         var typeBuilder = module.DefineType ("type1", TypeAttributes.Public | TypeAttributes.Class);
11358
11359                         var mainMethod = typeBuilder.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (int), new Type[0]);
11360                         var mainMethodIl = mainMethod.GetILGenerator ();
11361
11362                         var m1 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
11363                         var m2 = typeBuilder.DefineMethod ("X", MethodAttributes.Private | MethodAttributes.Static, typeof (void), new Type [0]);
11364                         m1.GetILGenerator ().Emit (OpCodes.Ret);
11365                         m2.GetILGenerator ().Emit (OpCodes.Ret);
11366
11367                         mainMethodIl.Emit (OpCodes.Call, m1);
11368                         mainMethodIl.Emit (OpCodes.Call, m2);
11369                         mainMethodIl.Emit (OpCodes.Ldc_I4_0);
11370                         mainMethodIl.Emit (OpCodes.Ret);
11371
11372                         typeBuilder.CreateType ();
11373                         assembly.SetEntryPoint (mainMethod);
11374
11375                         assembly.Save (ASSEMBLY_NAME + ".dll");
11376                 }
11377         }
11378 }