[corlib] Type from reference sources
[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                 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
104
105                 [SetUp]
106                 protected void SetUp ()
107                 {
108                         AssemblyName assemblyName = new AssemblyName ();
109                         assemblyName.Name = ASSEMBLY_NAME;
110
111                         assembly =
112                                 Thread.GetDomain ().DefineDynamicAssembly (
113                                         assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
114
115                         module = assembly.DefineDynamicModule ("module1");
116                 }
117
118                 static int typeIndexer = 0;
119
120                 // Return a unique type name
121                 private string genTypeName ()
122                 {
123                         return "t" + (typeIndexer++);
124                 }
125
126                 private string nullName ()
127                 {
128                         return String.Format ("{0}", (char) 0);
129                 }
130
131                 [Test]
132                 public void TestAssembly ()
133                 {
134                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
135                         Assert.AreEqual (assembly, tb.Assembly);
136                 }
137
138                 [Test]
139                 public void TestAssemblyQualifiedName ()
140                 {
141                         TypeBuilder tb = module.DefineType ("A.B.C.D", TypeAttributes.Public);
142                         Assert.AreEqual ("A.B.C.D, " + assembly.GetName ().FullName,
143                                 tb.AssemblyQualifiedName);
144                 }
145
146                 [Test]
147                 public void TestAttributes ()
148                 {
149                         TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
150                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
151                         Assert.AreEqual (attrs, tb.Attributes);
152                 }
153
154                 [Test]
155                 public void TestBaseTypeClass ()
156                 {
157                         TypeAttributes attrs = TypeAttributes.Public;
158                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
159                         Assert.AreEqual (typeof (object), tb.BaseType, "#1");
160
161                         TypeBuilder tb2 = module.DefineType (genTypeName (), attrs, tb);
162                         Assert.AreEqual (tb, tb2.BaseType, "#2");
163                 }
164
165                 [Test] // bug #71301
166                 public void TestBaseTypeInterface ()
167                 {
168                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
169                         Assert.IsNull (tb3.BaseType);
170                 }
171
172                 [Test]
173                 public void TestDeclaringType ()
174                 {
175                         TypeAttributes attrs = 0;
176                         TypeBuilder tb = module.DefineType (genTypeName (), attrs);
177                         Assert.IsNull (tb.DeclaringType, "#1");
178
179                         attrs = TypeAttributes.NestedPublic;
180                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName (), attrs);
181                         TypeBuilder tb3 = tb2.DefineNestedType (genTypeName (), attrs);
182                         Assert.AreEqual (tb3.DeclaringType.DeclaringType, tb, "#2");
183                 }
184
185                 [Test]
186                 public void TestFullName ()
187                 {
188                         string name = genTypeName ();
189                         TypeAttributes attrs = 0;
190                         TypeBuilder tb = module.DefineType (name, attrs);
191                         Assert.AreEqual (name, tb.FullName, "#1");
192
193                         string name2 = genTypeName ();
194                         attrs = TypeAttributes.NestedPublic;
195                         TypeBuilder tb2 = tb.DefineNestedType (name2, attrs);
196
197                         string name3 = genTypeName ();
198                         attrs = TypeAttributes.NestedPublic;
199                         TypeBuilder tb3 = tb2.DefineNestedType (name3, attrs);
200
201                         Assert.AreEqual (name + "+" + name2 + "+" + name3, tb3.FullName, "#2");
202                 }
203
204                 [Test]
205                 public void DefineCtorUsingDefineMethod ()
206                 {
207                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Class);
208                         MethodBuilder mb = tb.DefineMethod(
209                                 ".ctor", MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
210                                 null, null);
211                         ILGenerator ilgen = mb.GetILGenerator();
212                         ilgen.Emit(OpCodes.Ldarg_0);
213                         ilgen.Emit(OpCodes.Call,
214                                            typeof(object).GetConstructor(Type.EmptyTypes));
215                         ilgen.Emit(OpCodes.Ret);
216                         Type t = tb.CreateType();
217
218                         Assert.AreEqual (1, t.GetConstructors ().Length);
219                 }
220
221                 [Test]
222                 public void TestGUIDIncomplete ()
223                 {
224                         TypeBuilder tb = module.DefineType (genTypeName ());
225                         try {
226                                 Guid g = tb.GUID;
227                                 Assert.Fail ("#1");
228                         } catch (NotSupportedException ex) {
229                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
230                                 Assert.IsNull (ex.InnerException, "#3");
231                                 Assert.IsNotNull (ex.Message, "#4");
232                         }
233                 }
234
235                 [Test] // bug #71302
236                 [Category ("NotWorking")]
237                 public void TestGUIDComplete ()
238                 {
239                         TypeBuilder tb = module.DefineType (genTypeName ());
240                         tb.CreateType ();
241                         Assert.IsTrue (tb.GUID != Guid.Empty);
242                 }
243
244                 [Test]
245                 [Category ("NotWorking")]
246                 public void TestFixedGUIDComplete ()
247                 {
248                         TypeBuilder tb = module.DefineType (genTypeName ());
249
250                         Guid guid = Guid.NewGuid ();
251
252                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
253                                 new Type [] { typeof (string) });
254
255                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
256                                 new object [] { guid.ToString ("D") }, new FieldInfo [0], new object [0]);
257
258                         tb.SetCustomAttribute (caBuilder);
259                         tb.CreateType ();
260                         Assert.AreEqual (guid, tb.GUID);
261                 }
262
263                 [Test]
264                 public void TestHasElementType_Incomplete ()
265                 {
266                         // According to the MSDN docs, this member works, but in reality, it
267                         // returns a NotSupportedException
268                         TypeBuilder tb = module.DefineType (genTypeName ());
269                         Assert.IsFalse (tb.HasElementType);
270                 }
271
272                 [Test]
273                 public void TestHasElementType_Complete ()
274                 {
275                         // According to the MSDN docs, this member works, but in reality, it
276                         // returns a NotSupportedException
277                         TypeBuilder tb = module.DefineType (genTypeName ());
278                         tb.CreateType ();
279                         Assert.IsFalse (tb.HasElementType);
280                 }
281
282                 [Test] // bug #324692
283                 public void CreateType_Enum_NoInstanceField ()
284                 {
285                         TypeBuilder tb = module.DefineType (genTypeName (),
286                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
287                                 typeof (Enum));
288
289                         try {
290                                 tb.CreateType ();
291                                 Assert.Fail ("#1: must throw TypeLoadException");
292                         } catch (TypeLoadException) {
293                         }
294
295                         Assert.IsTrue (tb.IsCreated (), "#2");
296                 }
297
298                 [Test] // bug #324692
299                 public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
300                 {
301                         TypeBuilder tb = module.DefineType (genTypeName (),
302                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
303                                 typeof (Enum));
304
305                         try {
306                                 tb.CreateType ();
307                                 Assert.Fail ("#A1");
308                         } catch (TypeLoadException ex) {
309                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
310                                 Assert.IsNull (ex.InnerException, "#A3");
311                                 Assert.IsNotNull (ex.Message, "#A4");
312                         }
313
314                         Assert.IsTrue (tb.IsCreated (), "#B1");
315                         Assert.IsNull (tb.CreateType (), "#B2");
316                         Assert.IsTrue (tb.IsCreated (), "#B3");
317                 }
318
319                 [Test]
320                 public void TestEnumWithEmptyInterfaceBuildsOk ()
321                 {
322                         TypeBuilder tb = module.DefineType (genTypeName (),
323                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
324                                 typeof (Enum));
325                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
326                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
327
328                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
329
330                         try {
331                                 tb.CreateType ();
332                         } catch (TypeLoadException) {
333                                 Assert.Fail ("#1: must build enum type ok");
334                         }
335
336                         Assert.IsTrue (tb.IsCreated (), "#2");
337                 }
338
339                 [Test]
340                 [Category ("NotWorking")]
341                 public void TestEnumWithNonEmptyInterfaceBuildsFails ()
342                 {
343                         TypeBuilder tb = module.DefineType (genTypeName (),
344                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
345                                 typeof (Enum));
346                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
347                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
348
349                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
350
351                         try {
352                                 tb.CreateType ();
353                                 Assert.Fail ("#1: type doesn't have all interface methods");
354                         } catch (TypeLoadException) {
355                         }
356
357                         Assert.IsTrue (tb.IsCreated (), "#2");
358                 }
359
360                 [Test]
361                 [Category ("NotWorking")]
362                 public void TestTypeDontImplementInterfaceMethodBuildsFails ()
363                 {
364                         TypeBuilder tb = module.DefineType (genTypeName (),
365                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
366                                 typeof (object));
367
368                         tb.AddInterfaceImplementation (typeof (OneMethodInterface));
369
370                         try {
371                                 tb.CreateType ();
372                                 Assert.Fail ("#1: type doesn't have all interface methods");
373                         } catch (TypeLoadException) {
374                         }
375
376                         Assert.IsTrue (tb.IsCreated (), "#2");
377                 }
378
379                 [Test]
380                 public void TestEnumWithSequentialLayoutBuildsFails ()
381                 {
382                         TypeBuilder tb = module.DefineType (genTypeName (),
383                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
384                                 TypeAttributes.SequentialLayout, typeof (Enum));
385                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
386                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
387
388                         try {
389                                 tb.CreateType ();
390                                 Assert.Fail ("#1: type doesn't have all interface methods");
391                         } catch (TypeLoadException) {
392                         }
393
394                         Assert.IsTrue (tb.IsCreated (), "#2");
395                 }
396
397                 [Test]
398                 public void TestEnumWithExplicitLayoutBuildsFails ()
399                 {
400                         TypeBuilder tb = module.DefineType (genTypeName (),
401                                 TypeAttributes.Sealed | TypeAttributes.Serializable |
402                                 TypeAttributes.ExplicitLayout, typeof (Enum));
403                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
404                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
405
406                         try {
407                                 tb.CreateType ();
408                                 Assert.Fail ("#1: type doesn't have all interface methods");
409                         } catch (TypeLoadException) {
410                         }
411
412                         Assert.IsTrue (tb.IsCreated (), "#2");
413                 }
414
415                 [Test]
416                 public void TestEnumWithMethodsBuildFails ()
417                 {
418                         TypeBuilder tb = module.DefineType ("FooEnum7",
419                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
420                                 typeof (Enum));
421                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
422                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
423
424                         MethodBuilder methodBuilder = tb.DefineMethod("mmm",
425                                 MethodAttributes.Public | MethodAttributes.Virtual,
426                                 null,
427                                 new Type[] { });
428
429                         methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
430                         try {
431                                 tb.CreateType ();
432                                 Assert.Fail ("#1: enum has method");
433                         } catch (TypeLoadException) {
434                         }
435
436                         Assert.IsTrue (tb.IsCreated (), "#2");
437                 }
438
439                 [Test]
440                 public void TestEnumWithBadTypeValueFieldBuildFails ()
441                 {
442                         Type[] badTypes = {
443                                 typeof (object),
444                                 typeof (string),
445                                 typeof (DateTime)
446                         };
447
448                         foreach (Type type in badTypes) {
449                                 TypeBuilder tb = module.DefineType (genTypeName (),
450                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
451                                         typeof (Enum));
452                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
453                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
454
455                                 try {
456                                         tb.CreateType ();
457                                         Assert.Fail ("#1: enum using bad type: " + type);
458                                 } catch (TypeLoadException) {
459                                 }
460
461                                 Assert.IsTrue (tb.IsCreated (), "#2");
462                         }
463                 }
464
465                 [Test]
466                 public void TestEnumWithGoodTypeValueFieldBuildOk ()
467                 {
468                         Type[] goodTypes = {
469                                 typeof (byte),typeof (sbyte),typeof (bool),
470                                 typeof (ushort),typeof (short),typeof (char),
471                                 typeof (uint),typeof (int),
472                                 typeof (ulong),typeof (long),
473                                 typeof (UIntPtr),typeof (IntPtr),
474                         };
475
476                         foreach (Type type in goodTypes) {
477                                 TypeBuilder tb = module.DefineType (genTypeName (),
478                                         TypeAttributes.Sealed | TypeAttributes.Serializable,
479                                         typeof (Enum));
480                                 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
481                                         FieldAttributes.Private | FieldAttributes.RTSpecialName);
482
483                                 try {
484                                         tb.CreateType ();
485                                 } catch (TypeLoadException) {
486                                         Assert.Fail ("#1: enum using good type: " + type);
487                                 }
488                         }
489                 }
490
491                 [Test]
492                 public void TestEnumWithMultipleValueFieldsBuildFals ()
493                 {
494                         TypeBuilder tb = module.DefineType (genTypeName (),
495                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
496                                 typeof (Enum));
497                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
498                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
499                         tb.DefineField ("value2__", typeof (int), FieldAttributes.SpecialName |
500                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
501
502                         try {
503                                 tb.CreateType ();
504                                 Assert.Fail ("#1: invalid enum type");
505                         } catch (TypeLoadException) {
506                         }
507
508                         Assert.IsTrue (tb.IsCreated (), "#2");
509                 }
510
511                 [Test]
512                 [Category ("NotWorking")]
513                 public void TestEnumWithEmptyInterfaceCanBeCasted ()
514                 {
515                         TypeBuilder tb = module.DefineType (genTypeName (),
516                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
517                                 typeof (Enum));
518                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
519                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
520                         tb.AddInterfaceImplementation (typeof (EmptyInterface));
521
522                         try {
523                                 tb.CreateType ();
524                         } catch (TypeLoadException) {
525                                 Assert.Fail ("#1: must build enum type ok");
526                         }
527
528                         try {
529                                 EmptyInterface obj = (EmptyInterface) Activator.CreateInstance (tb);
530                                 Assert.IsNotNull (obj, "#2");
531                         } catch (TypeLoadException) {
532                                 Assert.Fail ("#3: must cast enum to interface");
533                         }
534                 }
535
536                 [Test]
537                 public void TestEnumWithValueFieldBuildOk ()
538                 {
539                         TypeBuilder tb = module.DefineType (genTypeName (),
540                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
541                                 typeof (Enum));
542                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
543                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
544
545                         try {
546                                 tb.CreateType ();
547                         } catch (TypeLoadException) {
548                                 Assert.Fail ("#1: must build enum type ok");
549                         }
550                 }
551
552                 [Test]
553                 public void TestIsAbstract ()
554                 {
555                         TypeBuilder tb = module.DefineType (genTypeName ());
556                         Assert.IsFalse (tb.IsAbstract, "#1");
557
558                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Abstract);
559                         Assert.IsTrue (tb2.IsAbstract, "#2");
560                 }
561
562                 [Test]
563                 public void TestIsAnsiClass ()
564                 {
565                         TypeBuilder tb = module.DefineType (genTypeName ());
566                         Assert.IsTrue (tb.IsAnsiClass, "#1");
567
568                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
569                         Assert.IsFalse (tb2.IsAnsiClass, "#2");
570                 }
571
572                 [Test]
573                 public void TestIsArray ()
574                 {
575                         // How can a TypeBuilder be an array ?
576                         string name = genTypeName ();
577                         TypeBuilder tb = module.DefineType (name);
578                         Assert.IsFalse (tb.IsArray);
579                 }
580
581                 [Test]
582                 public void TestIsAutoClass ()
583                 {
584                         TypeBuilder tb = module.DefineType (genTypeName ());
585                         Assert.IsFalse (tb.IsAutoClass, "#1");
586
587                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.AutoClass);
588                         Assert.IsTrue (tb2.IsAutoClass, "#2");
589                 }
590
591                 [Test]
592                 public void TestIsAutoLayout ()
593                 {
594                         TypeBuilder tb = module.DefineType (genTypeName ());
595                         Assert.IsTrue (tb.IsAutoLayout, "#1");
596
597                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
598                         Assert.IsFalse (tb2.IsAutoLayout, "#2");
599                 }
600
601                 [Test]
602                 public void TestIsByRef ()
603                 {
604                         // How can a TypeBuilder be ByRef ?
605                         TypeBuilder tb = module.DefineType (genTypeName ());
606                         Assert.IsFalse (tb.IsByRef);
607                 }
608
609                 [Test]
610                 public void TestIsClass ()
611                 {
612                         TypeBuilder tb = module.DefineType (genTypeName ());
613                         Assert.IsTrue (tb.IsClass, "#1");
614
615                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
616                         Assert.IsFalse (tb2.IsClass, "#2");
617
618                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
619                         Assert.IsFalse (tb3.IsClass, "#3");
620
621                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
622                         Assert.IsFalse (tb4.IsClass, "#4");
623                 }
624
625                 [Test] // bug #71304
626                 public void TestIsCOMObject ()
627                 {
628                         TypeBuilder tb = module.DefineType (genTypeName ());
629                         Assert.IsFalse (tb.IsCOMObject, "#1");
630
631                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
632                         Assert.IsTrue (tb.IsCOMObject, "#2");
633                 }
634
635                 [Test]
636                 public void TestIsContextful ()
637                 {
638                         TypeBuilder tb = module.DefineType (genTypeName ());
639                         Assert.IsFalse (tb.IsContextful, "#1");
640
641                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
642                         Assert.IsTrue (tb2.IsContextful, "#2");
643                 }
644
645                 [Test]
646                 public void TestIsEnum ()
647                 {
648                         TypeBuilder tb = module.DefineType (genTypeName ());
649                         Assert.IsFalse (tb.IsEnum, "#1");
650
651                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ValueType));
652                         Assert.IsFalse (tb2.IsEnum, "#2");
653
654                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (Enum));
655                         Assert.IsTrue (tb3.IsEnum, "#3");
656                 }
657
658                 [Test]
659                 public void TestIsExplicitLayout ()
660                 {
661                         TypeBuilder tb = module.DefineType (genTypeName ());
662                         Assert.IsFalse (tb.IsExplicitLayout, "#1");
663
664                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
665                         Assert.IsTrue (tb2.IsExplicitLayout, "#2");
666                 }
667
668                 [Test]
669                 public void TestIsImport ()
670                 {
671                         TypeBuilder tb = module.DefineType (genTypeName ());
672                         Assert.IsFalse (tb.IsImport, "#1");
673
674                         tb = module.DefineType (genTypeName (), TypeAttributes.Import);
675                         Assert.IsTrue (tb.IsImport, "#2");
676                 }
677
678                 [Test]
679                 public void TestIsInterface ()
680                 {
681                         TypeBuilder tb = module.DefineType (genTypeName ());
682                         Assert.IsFalse (tb.IsInterface, "#1");
683
684                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
685                         Assert.IsTrue (tb2.IsInterface, "#2");
686
687                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
688                         Assert.IsFalse (tb3.IsInterface, "#3");
689                 }
690
691                 [Test]
692                 public void TestIsLayoutSequential ()
693                 {
694                         TypeBuilder tb = module.DefineType (genTypeName ());
695                         Assert.IsFalse (tb.IsLayoutSequential, "#1");
696
697                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SequentialLayout);
698                         Assert.IsTrue (tb2.IsLayoutSequential, "#2");
699                 }
700
701                 [Test]
702                 public void TestIsMarshalByRef ()
703                 {
704                         TypeBuilder tb = module.DefineType (genTypeName ());
705                         Assert.IsFalse (tb.IsMarshalByRef, "#1");
706
707                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (MarshalByRefObject));
708                         Assert.IsTrue (tb2.IsMarshalByRef, "#2");
709
710                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
711                         Assert.IsTrue (tb3.IsMarshalByRef, "#3");
712                 }
713
714                 // TODO: Visibility properties
715
716                 [Test]
717                 public void TestIsPointer ()
718                 {
719                         // How can this be true?
720                         TypeBuilder tb = module.DefineType (genTypeName ());
721                         Assert.IsFalse (tb.IsPointer);
722                 }
723
724                 [Test]
725                 public void TestIsPrimitive ()
726                 {
727                         TypeBuilder tb = module.DefineType ("int");
728                         Assert.IsFalse (tb.IsPrimitive);
729                 }
730
731                 [Test]
732                 public void IsSealed ()
733                 {
734                         TypeBuilder tb = module.DefineType (genTypeName ());
735                         Assert.IsFalse (tb.IsSealed, "#1");
736
737                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
738                         Assert.IsTrue (tb2.IsSealed, "#2");
739                 }
740
741                 static string CreateTempAssembly ()
742                 {
743                         FileStream f = null;
744                         string path;
745                         Random rnd;
746                         int num = 0;
747
748                         rnd = new Random ();
749                         do {
750                                 num = rnd.Next ();
751                                 num++;
752                                 path = Path.Combine (Path.GetTempPath (), "tmp" + num.ToString ("x") + ".dll");
753
754                                 try {
755                                         f = new FileStream (path, FileMode.CreateNew);
756                                 } catch { }
757                         } while (f == null);
758
759                         f.Close ();
760
761
762                         return "tmp" + num.ToString ("x") + ".dll";
763                 }
764
765                 [Test]
766                 public void IsSerializable ()
767                 {
768                         TypeBuilder tb = module.DefineType (genTypeName ());
769                         Assert.IsFalse (tb.IsSerializable, "#1");
770
771                         ConstructorInfo [] ctors = typeof (SerializableAttribute).GetConstructors (BindingFlags.Instance | BindingFlags.Public);
772                         Assert.IsTrue (ctors.Length > 0, "#2");
773
774                         tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
775                         Type createdType = tb.CreateType ();
776
777                         string an = CreateTempAssembly ();
778                         assembly.Save (an);
779                         Assert.IsTrue (createdType.IsSerializable, "#3");
780                         File.Delete (Path.Combine (Path.GetTempPath (), an));
781                 }
782
783                 [Test]
784                 public void TestIsSpecialName ()
785                 {
786                         TypeBuilder tb = module.DefineType (genTypeName ());
787                         Assert.IsFalse (tb.IsSpecialName, "#1");
788
789                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SpecialName);
790                         Assert.IsTrue (tb2.IsSpecialName, "#2");
791                 }
792
793                 [Test]
794                 public void TestIsUnicodeClass ()
795                 {
796                         TypeBuilder tb = module.DefineType (genTypeName ());
797                         Assert.IsFalse (tb.IsUnicodeClass, "#1");
798
799                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
800                         Assert.IsTrue (tb2.IsUnicodeClass, "#2");
801                 }
802
803                 [Test]
804                 public void TestIsValueType ()
805                 {
806                         TypeBuilder tb = module.DefineType (genTypeName ());
807                         Assert.IsFalse (tb.IsValueType, "#1");
808
809                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
810                         Assert.IsFalse (tb2.IsValueType, "#2");
811
812                         TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
813                         Assert.IsTrue (tb3.IsValueType, "#3");
814
815                         TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
816                         Assert.IsTrue (tb4.IsValueType, "#4");
817                 }
818
819                 [Test]
820                 public void TestMemberType ()
821                 {
822                         TypeBuilder tb = module.DefineType (genTypeName ());
823                         Assert.AreEqual (MemberTypes.TypeInfo, tb.MemberType);
824                 }
825
826                 [Test]
827                 public void TestModule ()
828                 {
829                         TypeBuilder tb = module.DefineType (genTypeName ());
830                         Assert.AreEqual (module, tb.Module);
831                 }
832
833                 [Test]
834                 public void TestName ()
835                 {
836                         TypeBuilder tb = module.DefineType ("A");
837                         Assert.AreEqual ("A", tb.Name, "#1");
838
839                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
840                         Assert.AreEqual ("E", tb2.Name, "#2");
841
842                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
843                         Assert.AreEqual ("A", tb3.Name, "#3");
844
845                         /* Is .E a valid name ?
846                         TypeBuilder tb4 = module.DefineType (".E");
847                         Assert.AreEqual ("E", tb4.Name);
848                         */
849                 }
850
851                 [Test]
852                 public void TestNamespace ()
853                 {
854                         TypeBuilder tb = module.DefineType ("A");
855                         Assert.AreEqual (string.Empty, tb.Namespace, "#1");
856
857                         TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
858                         Assert.AreEqual ("A.B.C.D", tb2.Namespace, "#2");
859
860                         TypeBuilder tb3 = tb2.DefineNestedType ("A");
861                         Assert.AreEqual (string.Empty, tb3.Namespace, "#3");
862
863                         /* Is .E a valid name ?
864                         TypeBuilder tb4 = module.DefineType (".E");
865                         Assert.AreEqual ("E", tb4.Name);
866                         */
867                 }
868
869                 [Test]
870                 public void TestPackingSize ()
871                 {
872                         TypeBuilder tb = module.DefineType (genTypeName ());
873                         Assert.AreEqual (PackingSize.Unspecified, tb.PackingSize, "#1");
874
875                         TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (object),
876                                 PackingSize.Size16, 16);
877                         Assert.AreEqual (PackingSize.Size16, tb2.PackingSize, "#2");
878                 }
879
880                 [Test]
881                 public void TestReflectedType ()
882                 {
883                         // It is the same as DeclaringType, but why?
884                         TypeBuilder tb = module.DefineType (genTypeName ());
885                         Assert.IsNull (tb.ReflectedType, "#1");
886
887                         TypeBuilder tb2 = tb.DefineNestedType (genTypeName ());
888                         Assert.AreEqual (tb, tb2.ReflectedType, "#2");
889                 }
890
891                 [Test]
892                 public void SetParent_Parent_Null ()
893                 {
894                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class,
895                                 typeof (Attribute));
896                         tb.SetParent (null);
897                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
898
899                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
900                                 TypeAttributes.Abstract);
901                         tb.SetParent (null);
902                         Assert.IsNull (tb.BaseType, "#B1");
903
904                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
905                                 TypeAttributes.Abstract, typeof (ICloneable));
906                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#C1");
907                         tb.SetParent (null);
908                         Assert.IsNull (tb.BaseType, "#C2");
909
910                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
911                                 typeof (IDisposable));
912                         try {
913                                 tb.SetParent (null);
914                                 Assert.Fail ("#D1");
915                         } catch (InvalidOperationException ex) {
916                                 // Interface must be declared abstract
917                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
918                                 Assert.IsNull (ex.InnerException, "#D3");
919                                 Assert.IsNotNull (ex.Message, "#D4");
920                         }
921                 }
922
923                 [Test]
924                 public void SetParent_Parent_Interface ()
925                 {
926                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class);
927                         tb.SetParent (typeof (ICloneable));
928                         Assert.AreEqual (typeof (ICloneable), tb.BaseType);
929                 }
930
931                 [Test]
932                 public void TestSetParentIncomplete ()
933                 {
934                         TypeBuilder tb = module.DefineType (genTypeName ());
935                         tb.SetParent (typeof (Attribute));
936                         Assert.AreEqual (typeof (Attribute), tb.BaseType, "#1");
937
938                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
939                                 TypeAttributes.Abstract);
940                         tb.SetParent (typeof (IDisposable));
941                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#2");
942
943                         tb = module.DefineType (genTypeName ());
944                         tb.SetParent (typeof (IDisposable));
945                         Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#3");
946
947                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
948                                 TypeAttributes.Abstract, typeof (IDisposable));
949                         tb.SetParent (typeof (ICloneable));
950                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#4");
951
952                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
953                                 TypeAttributes.Abstract, typeof (IDisposable));
954                         tb.SetParent (typeof (ICloneable));
955                         Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#5");
956                 }
957
958                 [Test]
959                 public void TestSetParentComplete ()
960                 {
961                         TypeBuilder tb = module.DefineType (genTypeName ());
962                         tb.CreateType ();
963                         try {
964                                 tb.SetParent (typeof (Attribute));
965                                 Assert.Fail ("#1");
966                         } catch (InvalidOperationException ex) {
967                                 // Unable to change after type has been created
968                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
969                                 Assert.IsNull (ex.InnerException, "#3");
970                                 Assert.IsNotNull (ex.Message, "#4");
971                         }
972                 }
973
974                 [Test]
975                 public void TestSize ()
976                 {
977                         {
978                                 TypeBuilder tb = module.DefineType (genTypeName ());
979                                 Assert.AreEqual (0, tb.Size, "#1");
980                                 tb.CreateType ();
981                                 Assert.AreEqual (0, tb.Size, "#2");
982                         }
983
984                         {
985                                 TypeBuilder tb = module.DefineType (genTypeName (), 0, typeof (object),
986                                         PackingSize.Size16, 32);
987                                 Assert.AreEqual (32, tb.Size, "#3");
988                         }
989                 }
990
991                 [Test]
992                 public void TestTypeHandle ()
993                 {
994                         TypeBuilder tb = module.DefineType (genTypeName ());
995                         try {
996                                 RuntimeTypeHandle handle = tb.TypeHandle;
997                                 Assert.Fail ("#1:" + handle);
998                         } catch (NotSupportedException ex) {
999                                 // The invoked member is not supported in a
1000                                 // dynamic module
1001                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1002                                 Assert.IsNull (ex.InnerException, "#3");
1003                                 Assert.IsNotNull (ex.Message, "#4");
1004                         }
1005                 }
1006
1007                 [Test]
1008                 public void TestTypeInitializerIncomplete ()
1009                 {
1010                         TypeBuilder tb = module.DefineType (genTypeName ());
1011                         try {
1012                                 ConstructorInfo cb = tb.TypeInitializer;
1013                                 Assert.Fail ("#1:" + (cb != null));
1014                         } catch (NotSupportedException ex) {
1015                                 // The invoked member is not supported in a
1016                                 // dynamic module
1017                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1018                                 Assert.IsNull (ex.InnerException, "#3");
1019                                 Assert.IsNotNull (ex.Message, "#4");
1020                         }
1021                 }
1022
1023                 [Test]
1024                 public void TestTypeInitializerComplete ()
1025                 {
1026                         TypeBuilder tb = module.DefineType (genTypeName ());
1027                         tb.CreateType ();
1028                         ConstructorInfo cb = tb.TypeInitializer;
1029                 }
1030
1031                 [Test]
1032                 public void TestTypeToken ()
1033                 {
1034                         TypeBuilder tb = module.DefineType (genTypeName ());
1035                         TypeToken token = tb.TypeToken;
1036                 }
1037
1038                 [Test]
1039                 public void UnderlyingSystemType ()
1040                 {
1041                         TypeBuilder tb;
1042                         Type emitted_type;
1043
1044                         tb = module.DefineType (genTypeName ());
1045                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#A1");
1046                         emitted_type = tb.CreateType ();
1047                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#A2");
1048
1049                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1050                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#B1");
1051                         emitted_type = tb.CreateType ();
1052                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#B2");
1053
1054                         tb = module.DefineType (genTypeName (), 0, typeof (ValueType));
1055                         Assert.AreSame (tb, tb.UnderlyingSystemType, "#C1");
1056                         emitted_type = tb.CreateType ();
1057                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#C2");
1058
1059                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1060                         try {
1061                                 Type t = tb.UnderlyingSystemType;
1062                                 Assert.Fail ("#D1:" + t);
1063                         } catch (InvalidOperationException ex) {
1064                                 // Underlying type information on enumeration
1065                                 // is not specified
1066                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1067                                 Assert.IsNull (ex.InnerException, "#D3");
1068                                 Assert.IsNotNull (ex.Message, "#D4");
1069                         }
1070                         tb.DefineField ("val", typeof (int), FieldAttributes.Private);
1071                         Assert.AreEqual (typeof (int), tb.UnderlyingSystemType, "#D5");
1072                         emitted_type = tb.CreateType ();
1073                         Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#D6");
1074
1075                         tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1076                         tb.DefineField ("val", typeof (int), FieldAttributes.Static);
1077                         try {
1078                                 Type t = tb.UnderlyingSystemType;
1079                                 Assert.Fail ("#E1:" + t);
1080                         } catch (InvalidOperationException ex) {
1081                                 // Underlying type information on enumeration
1082                                 // is not specified
1083                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1084                                 Assert.IsNull (ex.InnerException, "#E3");
1085                                 Assert.IsNotNull (ex.Message, "#E4");
1086                         }
1087                         tb.DefineField ("foo", typeof (long), FieldAttributes.Private);
1088                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E5");
1089                         tb.DefineField ("bar", typeof (short), FieldAttributes.Private);
1090                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E6");
1091                         tb.DefineField ("boo", typeof (int), FieldAttributes.Static);
1092                         Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E7");
1093                 }
1094
1095                 [Test]
1096                 public void AddInterfaceImplementation_InterfaceType_Null ()
1097                 {
1098                         TypeBuilder tb = module.DefineType (genTypeName ());
1099                         try {
1100                                 tb.AddInterfaceImplementation (null);
1101                                 Assert.Fail ("#1");
1102                         } catch (ArgumentNullException ex) {
1103                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1104                                 Assert.IsNull (ex.InnerException, "#3");
1105                                 Assert.IsNotNull (ex.Message, "#4");
1106                                 Assert.AreEqual ("interfaceType", ex.ParamName, "#5");
1107                         }
1108                 }
1109
1110                 [Test]
1111                 public void TestAddInterfaceImplementation ()
1112                 {
1113                         TypeBuilder tb = module.DefineType (genTypeName ());
1114                         tb.AddInterfaceImplementation (typeof (AnInterface));
1115                         tb.AddInterfaceImplementation (typeof (AnInterface));
1116
1117                         Type t = tb.CreateType ();
1118                         Assert.AreEqual (1, tb.GetInterfaces ().Length, "#2");
1119
1120                         // Can not be called on a created type
1121                         try {
1122                                 tb.AddInterfaceImplementation (typeof (AnInterface));
1123                                 Assert.Fail ("#3");
1124                         } catch (InvalidOperationException) {
1125                         }
1126                 }
1127
1128                 [Test]
1129                 public void TestCreateType_Created ()
1130                 {
1131                         TypeBuilder tb = module.DefineType (genTypeName ());
1132                         Assert.IsFalse (tb.IsCreated (), "#A1");
1133
1134                         Type emittedType1 = tb.CreateType ();
1135                         Assert.IsTrue (tb.IsCreated (), "#A2");
1136                         Assert.IsNotNull (emittedType1, "#A3");
1137
1138                         Type emittedType2 = tb.CreateType ();
1139                         Assert.IsNotNull (emittedType2, "#B1");
1140                         Assert.IsTrue (tb.IsCreated (), "#B2");
1141                         Assert.AreSame (emittedType1, emittedType2, "#B3");
1142                 }
1143
1144                 [Test]
1145                 public void TestDefineConstructor ()
1146                 {
1147                         TypeBuilder tb = module.DefineType (genTypeName ());
1148
1149                         ConstructorBuilder cb = tb.DefineConstructor (0, 0, null);
1150                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1151                         tb.CreateType ();
1152
1153                         // Can not be called on a created type
1154                         try {
1155                                 tb.DefineConstructor (0, 0, null);
1156                                 Assert.Fail ("#1");
1157                         } catch (InvalidOperationException ex) {
1158                                 // Unable to change after type has been created
1159                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1160                                 Assert.IsNull (ex.InnerException, "#3");
1161                                 Assert.IsNotNull (ex.Message, "#4");
1162                         }
1163                 }
1164
1165                 [Test]
1166                 public void DefineDefaultConstructor ()
1167                 {
1168                         TypeBuilder tb = module.DefineType (genTypeName ());
1169                         tb.DefineDefaultConstructor (0);
1170                         tb.CreateType ();
1171
1172                         // Can not be called on a created type, altough the MSDN docs does not mention this
1173                         try {
1174                                 tb.DefineDefaultConstructor (0);
1175                                 Assert.Fail ("#1");
1176                         } catch (InvalidOperationException ex) {
1177                                 // Unable to change after type has been created
1178                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1179                                 Assert.IsNull (ex.InnerException, "#3");
1180                                 Assert.IsNotNull (ex.Message, "#4");
1181                         }
1182                 }
1183
1184                 [Test]
1185                 public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1186                 {
1187                         TypeBuilder tb;
1188                         
1189                         tb = module.DefineType (genTypeName ());
1190                         tb.DefineDefaultConstructor (MethodAttributes.Private);
1191                         Type parent_type = tb.CreateType ();
1192
1193                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1194                                 parent_type);
1195                         tb.DefineDefaultConstructor (MethodAttributes.Public);
1196                         Type emitted_type = tb.CreateType ();
1197                         try {
1198                                 Activator.CreateInstance (emitted_type);
1199                                 Assert.Fail ("#1");
1200                         } catch (TargetInvocationException ex) {
1201                                 Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1202                                 Assert.IsNotNull (ex.InnerException, "#3");
1203                                 Assert.IsNotNull (ex.Message, "#4");
1204
1205                                 MethodAccessException mae = ex.InnerException as MethodAccessException;
1206                                 Assert.IsNotNull (mae, "#5");
1207                                 Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1208                                 Assert.IsNull (mae.InnerException, "#7");
1209                                 Assert.IsNotNull (mae.Message, "#8");
1210                                 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1211                                 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1212                         }
1213                 }
1214
1215                 [Test]
1216                 public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1217                 {
1218                         TypeBuilder tb;
1219
1220                         tb = module.DefineType (genTypeName ());
1221                         ConstructorBuilder cb = tb.DefineConstructor (
1222                                 MethodAttributes.Public,
1223                                 CallingConventions.Standard,
1224                                 new Type [] { typeof (string) });
1225                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1226                         Type parent_type = tb.CreateType ();
1227
1228                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1229                                 parent_type);
1230                         try {
1231                                 tb.DefineDefaultConstructor (MethodAttributes.Public);
1232                                 Assert.Fail ("#1");
1233                         } catch (NotSupportedException ex) {
1234                                 // Parent does not have a default constructor.
1235                                 // The default constructor must be explicitly defined
1236                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1237                                 Assert.IsNull (ex.InnerException, "#3");
1238                                 Assert.IsNotNull (ex.Message, "#4");
1239                         }
1240                 }
1241
1242                 [Test]
1243                 public void DefineEvent_Name_NullChar ()
1244                 {
1245                         TypeBuilder tb = module.DefineType (genTypeName ());
1246
1247                         try {
1248                                 tb.DefineEvent ("\0test", EventAttributes.None,
1249                                         typeof (int));
1250                                 Assert.Fail ("#A1");
1251                         } catch (ArgumentException ex) {
1252                                 // Illegal name
1253                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1254                                 Assert.IsNull (ex.InnerException, "#A3");
1255                                 Assert.IsNotNull (ex.Message, "#A4");
1256                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1257                         }
1258
1259                         EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1260                                 typeof (int));
1261                         Assert.IsNotNull (eb, "#B1");
1262                 }
1263
1264                 [Test]
1265                 public void TestDefineEvent ()
1266                 {
1267                         TypeBuilder tb = module.DefineType (genTypeName ());
1268
1269                         // Test invalid arguments
1270                         try {
1271                                 tb.DefineEvent (null, 0, typeof (int));
1272                                 Assert.Fail ("#A1");
1273                         } catch (ArgumentNullException ex) {
1274                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1275                                 Assert.IsNull (ex.InnerException, "#A3");
1276                                 Assert.IsNotNull (ex.Message, "#A4");
1277                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1278                         }
1279
1280                         try {
1281                                 tb.DefineEvent ("FOO", 0, null);
1282                                 Assert.Fail ("#B1");
1283                         } catch (ArgumentNullException ex) {
1284                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1285                                 Assert.IsNull (ex.InnerException, "#B3");
1286                                 Assert.IsNotNull (ex.Message, "#B4");
1287                                 Assert.AreEqual ("type", ex.ParamName, "#B5");
1288                         }
1289
1290                         try {
1291                                 tb.DefineEvent (string.Empty, 0, typeof (int));
1292                                 Assert.Fail ("#C1");
1293                         } catch (ArgumentException ex) {
1294                                 // Empty name is not legal
1295                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1296                                 Assert.IsNull (ex.InnerException, "#C3");
1297                                 Assert.IsNotNull (ex.Message, "#C4");
1298                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1299                         }
1300
1301                         tb.CreateType ();
1302
1303                         // Can not be called on a created type
1304                         try {
1305                                 tb.DefineEvent ("BAR", 0, typeof (int));
1306                                 Assert.Fail ("#D1");
1307                         } catch (InvalidOperationException ex) {
1308                                 // Unable to change after type has been created
1309                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1310                                 Assert.IsNull (ex.InnerException, "#D3");
1311                                 Assert.IsNotNull (ex.Message, "#D4");
1312                         }
1313                 }
1314
1315                 [Test] // DefineField (String, Type, FieldAttributes)
1316                 public void DefineField1 ()
1317                 {
1318                         TypeBuilder tb = module.DefineType (genTypeName ());
1319
1320                         // Check invalid arguments
1321                         try {
1322                                 tb.DefineField (null, typeof (int), 0);
1323                                 Assert.Fail ("#A1");
1324                         } catch (ArgumentNullException ex) {
1325                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1326                                 Assert.IsNull (ex.InnerException, "#A3");
1327                                 Assert.IsNotNull (ex.Message, "#A4");
1328                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1329                         }
1330
1331                         try {
1332                                 tb.DefineField (string.Empty, typeof (int), 0);
1333                                 Assert.Fail ("#B1");
1334                         } catch (ArgumentException ex) {
1335                                 // Empty name is not legal
1336                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1337                                 Assert.IsNull (ex.InnerException, "#B3");
1338                                 Assert.IsNotNull (ex.Message, "#B4");
1339                                 Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1340                         }
1341
1342                         try {
1343                                 // Strangely, 'A<NULL>' is accepted...
1344                                 string name = String.Format ("{0}", (char) 0);
1345                                 tb.DefineField (name, typeof (int), 0);
1346                                 Assert.Fail ("#C1");
1347                         } catch (ArgumentException ex) {
1348                                 // Illegal name
1349                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1350                                 Assert.IsNull (ex.InnerException, "#C3");
1351                                 Assert.IsNotNull (ex.Message, "#C4");
1352                                 Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1353                         }
1354
1355                         try {
1356                                 tb.DefineField ("A", typeof (void), 0);
1357                                 Assert.Fail ("#D1");
1358                         } catch (ArgumentException ex) {
1359                                 // Bad field type in defining field
1360                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1361                                 Assert.IsNull (ex.InnerException, "#D3");
1362                                 Assert.IsNotNull (ex.Message, "#D4");
1363                                 Assert.IsNull (ex.ParamName, "#D5");
1364                         }
1365
1366                         tb.CreateType ();
1367
1368                         // Can not be called on a created type
1369                         try {
1370                                 tb.DefineField ("B", typeof (int), 0);
1371                                 Assert.Fail ("#E1");
1372                         } catch (InvalidOperationException ex) {
1373                                 // Unable to change after type has been created
1374                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1375                                 Assert.IsNull (ex.InnerException, "#E3");
1376                                 Assert.IsNotNull (ex.Message, "#E4");
1377                         }
1378                 }
1379
1380                 [Test] // DefineField (String, Type, FieldAttributes)
1381                 public void DefineField1_Name_NullChar ()
1382                 {
1383                         TypeBuilder tb = module.DefineType (genTypeName ());
1384
1385                         try {
1386                                 tb.DefineField ("\0test", typeof (int),
1387                                         FieldAttributes.Private);
1388                                 Assert.Fail ("#A1");
1389                         } catch (ArgumentException ex) {
1390                                 // Illegal name
1391                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1392                                 Assert.IsNull (ex.InnerException, "#A3");
1393                                 Assert.IsNotNull (ex.Message, "#A4");
1394                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1395                         }
1396
1397                         FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1398                                 FieldAttributes.Private);
1399                         Assert.IsNotNull (fb, "#B1");
1400                         Assert.AreEqual ("te\0st", fb.Name, "#B2");
1401                 }
1402
1403                 [Test] // DefineField (String, Type, FieldAttributes)
1404                 public void DefineField1_Type_Null ()
1405                 {
1406                         TypeBuilder tb = module.DefineType (genTypeName ());
1407
1408                         try {
1409                                 tb.DefineField ("test", (Type) null,
1410                                         FieldAttributes.Private);
1411                                 Assert.Fail ("#1");
1412                         } catch (ArgumentNullException ex) {
1413                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1414                                 Assert.IsNull (ex.InnerException, "#3");
1415                                 Assert.IsNotNull (ex.Message, "#4");
1416                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1417                         }
1418                 }
1419
1420                 [Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
1421                 public void DefineField2_Type_Null ()
1422                 {
1423                         TypeBuilder tb = module.DefineType (genTypeName ());
1424
1425                         try {
1426                                 tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1427                                         Type.EmptyTypes, FieldAttributes.Private);
1428                                 Assert.Fail ("#1");
1429                         } catch (ArgumentNullException ex) {
1430                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1431                                 Assert.IsNull (ex.InnerException, "#3");
1432                                 Assert.IsNotNull (ex.Message, "#4");
1433                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1434                         }
1435                 }
1436
1437                 [Test]
1438                 public void TestDefineInitializedData ()
1439                 {
1440                         TypeBuilder tb = module.DefineType (genTypeName ());
1441
1442                         // Check invalid arguments
1443                         try {
1444                                 tb.DefineInitializedData (null, new byte [1], 0);
1445                                 Assert.Fail ("#A1");
1446                         } catch (ArgumentNullException ex) {
1447                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1448                                 Assert.IsNull (ex.InnerException, "#A3");
1449                                 Assert.IsNotNull (ex.Message, "#A4");
1450                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1451                         }
1452
1453                         try {
1454                                 tb.DefineInitializedData ("FOO", null, 0);
1455                                 Assert.Fail ("#B1");
1456                         } catch (ArgumentNullException ex) {
1457                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1458                                 Assert.IsNull (ex.InnerException, "#B3");
1459                                 Assert.IsNotNull (ex.Message, "#B4");
1460                                 Assert.AreEqual ("data", ex.ParamName, "#B5");
1461                         }
1462
1463                         try {
1464                                 tb.DefineInitializedData (string.Empty, new byte [1], 0);
1465                                 Assert.Fail ("#C1");
1466                         } catch (ArgumentException ex) {
1467                                 // Empty name is not legal
1468                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1469                                 Assert.IsNull (ex.InnerException, "#C3");
1470                                 Assert.IsNotNull (ex.Message, "#C4");
1471                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1472                         }
1473
1474                         // The size of the data is less than or equal to zero ???
1475                         try {
1476                                 tb.DefineInitializedData ("BAR", new byte [0], 0);
1477                                 Assert.Fail ("#D1");
1478                         } catch (ArgumentException ex) {
1479                                 // Data size must be > 0 and < 0x3f0000
1480                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1481                                 Assert.IsNull (ex.InnerException, "#D3");
1482                                 Assert.IsNotNull (ex.Message, "#D4");
1483                                 Assert.IsNull (ex.ParamName, "#D5");
1484                         }
1485
1486                         try {
1487                                 string name = String.Format ("{0}", (char) 0);
1488                                 tb.DefineInitializedData (name, new byte [1], 0);
1489                                 Assert.Fail ("#E1");
1490                         } catch (ArgumentException ex) {
1491                                 // Illegal name
1492                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1493                                 Assert.IsNull (ex.InnerException, "#E3");
1494                                 Assert.IsNotNull (ex.Message, "#E4");
1495                                 Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1496                         }
1497
1498                         tb.CreateType ();
1499
1500                         // Can not be called on a created type, altough the MSDN docs does not mention this
1501                         try {
1502                                 tb.DefineInitializedData ("BAR2", new byte [1], 0);
1503                                 Assert.Fail ("#F1");
1504                         } catch (InvalidOperationException ex) {
1505                                 // Unable to change after type has been created
1506                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1507                                 Assert.IsNull (ex.InnerException, "#F3");
1508                                 Assert.IsNotNull (ex.Message, "#F4");
1509                         }
1510                 }
1511
1512                 [Test]
1513                 public void DefineUninitializedDataInvalidArgs ()
1514                 {
1515                         TypeBuilder tb = module.DefineType (genTypeName ());
1516
1517                         try {
1518                                 tb.DefineUninitializedData (null, 1, 0);
1519                                 Assert.Fail ("#A1");
1520                         } catch (ArgumentNullException ex) {
1521                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1522                                 Assert.IsNull (ex.InnerException, "#A3");
1523                                 Assert.IsNotNull (ex.Message, "#A4");
1524                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1525                         }
1526
1527                         try {
1528                                 tb.DefineUninitializedData (string.Empty, 1, 0);
1529                                 Assert.Fail ("#B1");
1530                         } catch (ArgumentException ex) {
1531                                 // Empty name is not legal
1532                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1533                                 Assert.IsNull (ex.InnerException, "#B3");
1534                                 Assert.IsNotNull (ex.Message, "#B4");
1535                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1536                         }
1537
1538                         // The size of the data is less than or equal to zero ???
1539                         try {
1540                                 tb.DefineUninitializedData ("BAR", 0, 0);
1541                                 Assert.Fail ("#C1");
1542                         } catch (ArgumentException ex) {
1543                                 // Data size must be > 0 and < 0x3f0000
1544                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1545                                 Assert.IsNull (ex.InnerException, "#C3");
1546                                 Assert.IsNotNull (ex.Message, "#C4");
1547                                 Assert.IsNull (ex.ParamName, "#C5");
1548                         }
1549
1550                         try {
1551                                 string name = String.Format ("{0}", (char) 0);
1552                                 tb.DefineUninitializedData (name, 1, 0);
1553                                 Assert.Fail ("#D1");
1554                         } catch (ArgumentException ex) {
1555                                 // Illegal name
1556                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1557                                 Assert.IsNull (ex.InnerException, "#D3");
1558                                 Assert.IsNotNull (ex.Message, "#D4");
1559                                 Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1560                         }
1561                 }
1562
1563                 [Test]
1564                 public void DefineUninitializedDataAlreadyCreated ()
1565                 {
1566                         TypeBuilder tb = module.DefineType (genTypeName ());
1567                         tb.CreateType ();
1568                         try {
1569                                 tb.DefineUninitializedData ("BAR2", 1, 0);
1570                                 Assert.Fail ("#1");
1571                         } catch (InvalidOperationException ex) {
1572                                 // Unable to change after type has been created
1573                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1574                                 Assert.IsNull (ex.InnerException, "#3");
1575                                 Assert.IsNotNull (ex.Message, "#4");
1576                         }
1577                 }
1578
1579                 [Test]
1580                 public void DefineUninitializedData ()
1581                 {
1582                         TypeBuilder tb = module.DefineType (genTypeName ());
1583
1584                         tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1585
1586                         Type t = tb.CreateType ();
1587
1588                         object o = Activator.CreateInstance (t);
1589
1590                         FieldInfo fi = t.GetField ("foo");
1591
1592                         object fieldVal = fi.GetValue (o);
1593
1594                         IntPtr ptr = Marshal.AllocHGlobal (4);
1595                         Marshal.StructureToPtr (fieldVal, ptr, true);
1596                         Marshal.FreeHGlobal (ptr);
1597                 }
1598
1599                 [Test]
1600                 public void DefineMethod_Name_NullChar ()
1601                 {
1602                         TypeBuilder tb = module.DefineType (genTypeName ());
1603                         try {
1604                                 tb.DefineMethod ("\0test", MethodAttributes.Private,
1605                                         typeof (string), Type.EmptyTypes);
1606                                 Assert.Fail ("#A1");
1607                         } catch (ArgumentException ex) {
1608                                 // Illegal name
1609                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1610                                 Assert.IsNull (ex.InnerException, "#A3");
1611                                 Assert.IsNotNull (ex.Message, "#A4");
1612                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1613                         }
1614
1615                         MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1616                                 typeof (string), Type.EmptyTypes);
1617                         Assert.IsNotNull (mb, "#B1");
1618                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1619                 }
1620
1621                 [Test]
1622                 public void TestDefineMethod ()
1623                 {
1624                         TypeBuilder tb = module.DefineType (genTypeName ());
1625
1626                         // Check invalid arguments
1627                         try {
1628                                 tb.DefineMethod (null, 0, null, null);
1629                                 Assert.Fail ("#A1");
1630                         } catch (ArgumentNullException ex) {
1631                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1632                                 Assert.IsNull (ex.InnerException, "#A3");
1633                                 Assert.IsNotNull (ex.Message, "#A4");
1634                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1635                         }
1636
1637                         try {
1638                                 tb.DefineMethod (string.Empty, 0, null, null);
1639                                 Assert.Fail ("#B1");
1640                         } catch (ArgumentException ex) {
1641                                 // Empty name is not legal
1642                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1643                                 Assert.IsNull (ex.InnerException, "#B3");
1644                                 Assert.IsNotNull (ex.Message, "#B4");
1645                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1646                         }
1647
1648                         // Check non-virtual methods on an interface
1649                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1650                         try {
1651                                 tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1652                                 Assert.Fail ("#C1");
1653                         } catch (ArgumentException ex) {
1654                                 // Interface method must be abstract and virtual
1655                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1656                                 Assert.IsNull (ex.InnerException, "#C3");
1657                                 Assert.IsNotNull (ex.Message, "#C4");
1658                                 Assert.IsNull (ex.ParamName, "#C5");
1659                         }
1660
1661                         // Check static methods on an interface
1662                         tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1663                                                           typeof (void),
1664                                                           Type.EmptyTypes);
1665
1666                         tb.CreateType ();
1667                         // Can not be called on a created type
1668                         try {
1669                                 tb.DefineMethod ("bar", 0, null, null);
1670                                 Assert.Fail ("#D1");
1671                         } catch (InvalidOperationException ex) {
1672                                 // Unable to change after type has been created
1673                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1674                                 Assert.IsNull (ex.InnerException, "#D3");
1675                                 Assert.IsNotNull (ex.Message, "#D4");
1676                         }
1677                 }
1678
1679                 [Test] // bug #327484
1680                 [Category ("NotWorking")]
1681                 public void TestDefineMethod_Abstract ()
1682                 {
1683                         TypeBuilder tb = module.DefineType (genTypeName ());
1684                         tb.DefineMethod ("Run", MethodAttributes.Public |
1685                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1686                                 typeof (void), Type.EmptyTypes);
1687
1688                         try {
1689                                 tb.CreateType ();
1690                                 Assert.Fail ("#A1");
1691                         } catch (InvalidOperationException ex) {
1692                                 // Type must be declared abstract if any of its
1693                                 // methods are abstract
1694                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1695                                 Assert.IsNull (ex.InnerException, "#A3");
1696                                 Assert.IsNotNull (ex.Message, "#A4");
1697                         }
1698
1699                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1700                         tb.DefineMethod ("Run", MethodAttributes.Public |
1701                                 MethodAttributes.Abstract, typeof (void),
1702                                 Type.EmptyTypes);
1703
1704                         try {
1705                                 tb.CreateType ();
1706                                 Assert.Fail ("#B1");
1707                         } catch (TypeLoadException ex) {
1708                                 // Non-virtual abstract method
1709                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1710                                 Assert.IsNull (ex.InnerException, "#B3");
1711                                 Assert.IsNotNull (ex.Message, "#B4");
1712                         }
1713
1714                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1715                                 TypeAttributes.Public);
1716                         tb.DefineMethod ("Run", MethodAttributes.Public |
1717                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1718                                 typeof (void), Type.EmptyTypes);
1719                         Type emittedType = tb.CreateType ();
1720
1721                         MethodInfo mi1 = emittedType.GetMethod ("Run");
1722                         Assert.IsNotNull (mi1, "#C1");
1723                         Assert.IsTrue (mi1.IsAbstract, "#C2");
1724
1725                         MethodInfo mi2 = tb.GetMethod ("Run");
1726                         Assert.IsNotNull (mi2, "#D1");
1727                         Assert.IsTrue (mi2.IsAbstract, "#D2");
1728                 }
1729
1730                 // TODO: DefineMethodOverride
1731
1732                 [Test]
1733                 public void TestDefineNestedType ()
1734                 {
1735                         TypeBuilder tb = module.DefineType (genTypeName ());
1736
1737                         // Check invalid arguments
1738                         try {
1739                                 tb.DefineNestedType (null);
1740                                 Assert.Fail ("#A1");
1741                         } catch (ArgumentNullException ex) {
1742                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1743                                 Assert.IsNull (ex.InnerException, "#A3");
1744                                 Assert.IsNotNull (ex.Message, "#A4");
1745                                 Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1746                         }
1747
1748                         try {
1749                                 tb.DefineNestedType (string.Empty);
1750                                 Assert.Fail ("#B1");
1751                         } catch (ArgumentException ex) {
1752                                 // Empty name is not legal
1753                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1754                                 Assert.IsNull (ex.InnerException, "#B3");
1755                                 Assert.IsNotNull (ex.Message, "#B4");
1756                                 Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1757                         }
1758
1759                         try {
1760                                 tb.DefineNestedType (nullName ());
1761                                 Assert.Fail ("#C1");
1762                         } catch (ArgumentException ex) {
1763                                 // Illegal name
1764                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1765                                 Assert.IsNull (ex.InnerException, "#C3");
1766                                 Assert.IsNotNull (ex.Message, "#C4");
1767                                 Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1768                         }
1769
1770                         // If I fix the code so this works then mcs breaks -> how can mcs
1771                         // works under MS .NET in the first place ???
1772                         /*
1773                         try {
1774                                 tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1775                                 Fail ("Nested visibility must be specified.");
1776                         }
1777                         catch (ArgumentException) {
1778                         }
1779                         */
1780
1781                         try {
1782                                 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1783                                                                          new Type [1]);
1784                                 Assert.Fail ("#D1");
1785                         } catch (ArgumentNullException ex) {
1786                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1787                                 Assert.IsNull (ex.InnerException, "#D3");
1788                                 Assert.IsNotNull (ex.Message, "#D4");
1789                                 Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1790                         }
1791
1792                         // I think this should reject non-interfaces, but it does not
1793                         tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1794                                                                  new Type [1] { typeof (object) });
1795
1796                         // Normal invocation
1797                         tb.DefineNestedType ("Nest");
1798
1799                         tb.CreateType ();
1800
1801                         // According to the MSDN docs, this cannnot be called after the type
1802                         // is created, but it works.
1803                         tb.DefineNestedType ("Nest2");
1804
1805                         // According to the MSDN docs, a Sealed class can't contain nested 
1806                         // types, but this is not true
1807                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1808                         tb2.DefineNestedType ("AA");
1809
1810                         // According to the MSDN docs, interfaces can only contain interfaces,
1811                         // but this is not true
1812                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1813
1814                         tb3.DefineNestedType ("AA");
1815
1816                         // Check shorter versions
1817                         {
1818                                 TypeBuilder nested = tb.DefineNestedType ("N1");
1819
1820                                 Assert.AreEqual ("N1", nested.Name, "#E1");
1821                                 Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1822                                 Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1823                                 Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1824                         }
1825
1826                         // TODO:
1827                 }
1828
1829                 [Test]
1830                 public void DefinePInvokeMethod_Name_NullChar ()
1831                 {
1832                         TypeBuilder tb = module.DefineType (genTypeName ());
1833                         try {
1834                                 tb.DefinePInvokeMethod ("\0test", "B", "C",
1835                                         MethodAttributes.Private, CallingConventions.Standard,
1836                                         typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1837                                         CharSet.Unicode);
1838                                 Assert.Fail ("#A1");
1839                         } catch (ArgumentException ex) {
1840                                 // Illegal name
1841                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1842                                 Assert.IsNull (ex.InnerException, "#A3");
1843                                 Assert.IsNotNull (ex.Message, "#A4");
1844                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1845                         }
1846
1847                         MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1848                                 MethodAttributes.Private, CallingConventions.Standard,
1849                                 typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1850                                 CharSet.Unicode);
1851                         Assert.IsNotNull (mb, "#B1");
1852                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1853                 }
1854
1855                 [Test]
1856                 public void TestDefinePInvokeMethod ()
1857                 {
1858                         TypeBuilder tb = module.DefineType (genTypeName ());
1859
1860                         tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1861
1862                         // Try invalid parameters
1863                         try {
1864                                 tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1865                                 Assert.Fail ("#A1");
1866                         } catch (ArgumentNullException ex) {
1867                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1868                                 Assert.IsNull (ex.InnerException, "#A3");
1869                                 Assert.IsNotNull (ex.Message, "#A4");
1870                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1871                         }
1872                         // etc...
1873
1874                         // Try invalid attributes
1875                         try {
1876                                 tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1877                                 Assert.Fail ("#B1");
1878                         } catch (ArgumentException ex) {
1879                                 // PInvoke methods must be static and native and
1880                                 // cannot be abstract
1881                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1882                                 Assert.IsNull (ex.InnerException, "#B3");
1883                                 Assert.IsNotNull (ex.Message, "#B4");
1884                                 Assert.IsNull (ex.ParamName, "#B5");
1885                         }
1886
1887                         // Try an interface parent
1888                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1889
1890                         try {
1891                                 tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1892                                 Assert.Fail ("#C1");
1893                         } catch (ArgumentException ex) {
1894                                 // PInvoke methods cannot exist on interfaces
1895                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1896                                 Assert.IsNull (ex.InnerException, "#B3");
1897                                 Assert.IsNotNull (ex.Message, "#B4");
1898                                 Assert.IsNull (ex.ParamName, "#B5");
1899                         }
1900                 }
1901
1902                 [Test]
1903                 public void DefineProperty_Name_NullChar ()
1904                 {
1905                         TypeBuilder tb = module.DefineType (genTypeName ());
1906
1907                         try {
1908                                 tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
1909                                 Assert.Fail ("#A1");
1910                         } catch (ArgumentException ex) {
1911                                 // Illegal name
1912                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1913                                 Assert.IsNull (ex.InnerException, "#A3");
1914                                 Assert.IsNotNull (ex.Message, "#A4");
1915                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1916                         }
1917
1918                         PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
1919                                 typeof (string), Type.EmptyTypes); 
1920                         Assert.IsNotNull (pb, "#B1");
1921                         Assert.AreEqual ("te\0st", pb.Name, "#B2");
1922                 }
1923
1924                 [Test]
1925                 public void DefineProperty_ParameterTypes_ItemNull ()
1926                 {
1927                         TypeBuilder tb = module.DefineType (genTypeName ());
1928
1929                         try {
1930                                 tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
1931                                 Assert.Fail ("#1");
1932                         } catch (ArgumentNullException ex) {
1933                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1934                                 Assert.IsNull (ex.InnerException, "#3");
1935                                 Assert.IsNotNull (ex.Message, "#4");
1936                         }
1937                 }
1938
1939                 [Test]
1940                 public void DefineProperty_ReturnType_Null ()
1941                 {
1942                         TypeBuilder tb = module.DefineType (genTypeName ());
1943                         tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
1944                 }
1945
1946                 [Test]
1947                 public void GetMethod_WorksWithTypeBuilderParameter () {
1948                         TypeBuilder tb = module.DefineType (genTypeName ());
1949                         var garg = tb.DefineGenericParameters ("T") [0];
1950                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
1951                 
1952                         var mi = TypeBuilder.GetMethod (tb, mb);
1953                         var decl = mi.DeclaringType;
1954
1955                         Assert.IsTrue (decl.IsGenericType, "#1");
1956                         Assert.IsFalse (decl.IsGenericTypeDefinition, "#2");
1957                         Assert.AreEqual (tb, decl.GetGenericTypeDefinition (), "#3");
1958                         Assert.AreEqual (garg, decl.GetGenericArguments () [0], "#4");
1959                 }
1960
1961                 [Test]
1962                 public void GetConstructor_FailWithTypeBuilderParameter () {
1963                         TypeBuilder tb = module.DefineType (genTypeName ());
1964                         var garg = tb.DefineGenericParameters ("T") [0];
1965                         var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
1966
1967                         try {
1968                                 TypeBuilder.GetConstructor (tb, cb);
1969                                 Assert.Fail ("#1");
1970                         } catch (ArgumentException ex) {
1971                                 Assert.AreEqual ("type", ex.ParamName, "#2");
1972                         }
1973                 }
1974
1975                 [Test]
1976                 public void GetField_FailWithTypeBuilderParameter () {
1977                         TypeBuilder tb = module.DefineType (genTypeName ());
1978                         var garg = tb.DefineGenericParameters ("T") [0];
1979                         var fb = tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
1980
1981                         try {
1982                                 TypeBuilder.GetField (tb, fb);
1983                                 Assert.Fail ("#1");
1984                         } catch (ArgumentException ex) {
1985                                 Assert.AreEqual ("type", ex.ParamName, "#2");
1986                         }
1987                 }
1988
1989                 [Test]
1990                 public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
1991                         TypeBuilder tb = module.DefineType (genTypeName ());
1992                         tb.DefineGenericParameters ("T");
1993                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
1994
1995                         Type ginst = tb.MakeGenericType (typeof (int));
1996                         
1997                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
1998                         try {
1999                                 TypeBuilder.GetMethod (ginst, mi);
2000                                 Assert.Fail ("#1");
2001                         } catch (ArgumentException ex) {
2002                                 Assert.AreEqual ("method", ex.ParamName, "#5");
2003                         }
2004                 }
2005
2006                 [Test]
2007                 public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2008                         TypeBuilder tb = module.DefineType (genTypeName ());
2009                         tb.DefineGenericParameters ("T");
2010                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2011                         ILGenerator ig = mb.GetILGenerator ();
2012                         ig.Emit (OpCodes.Ret);
2013                         
2014                         tb.CreateType ();
2015                         
2016                         MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2017                         Assert.IsNotNull (mi);
2018                 }
2019
2020                 [Test]
2021                 [Category ("NotDotNet")]
2022                 [Category ("NotWorking")]
2023                 public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2024                         AssemblyName assemblyName = new AssemblyName ();
2025                         assemblyName.Name = ASSEMBLY_NAME;
2026
2027                         assembly =
2028                                 Thread.GetDomain ().DefineDynamicAssembly (
2029                                         assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, Path.GetTempPath ());
2030
2031                         module = assembly.DefineDynamicModule ("module1");
2032                         
2033                         TypeBuilder tb = module.DefineType (genTypeName ());
2034                         tb.DefineGenericParameters ("T");
2035                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2036
2037                         Type ginst = tb.MakeGenericType (typeof (int));
2038                         
2039                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2040
2041                         try {
2042                                 TypeBuilder.GetMethod (ginst, mi);
2043                         } catch (ArgumentException ex) {
2044                                 Assert.Fail ("#1");
2045                         }
2046                 }
2047
2048
2049                 [Test]
2050                 // Test that changes made to the method builder after a call to GetMethod ()
2051                 // are visible
2052                 public void TestGetMethod ()
2053                 {
2054                         TypeBuilder tb = module.DefineType (genTypeName ());
2055                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2056
2057                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2058                         ILGenerator ig;
2059                         ig = cb.GetILGenerator ();
2060                         ig.Emit (OpCodes.Ret);
2061
2062                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2063
2064                         // Create a method builder but do not emit IL yet
2065                         MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2066
2067                         Type t = tb.MakeGenericType (typeof (int));
2068
2069                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2070
2071                         ig = mb.GetILGenerator ();
2072                         ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2073                         ig.Emit (OpCodes.Ret);
2074
2075                         // Finish the method
2076                         ig = mb1.GetILGenerator ();
2077                         ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2078                         ig.Emit (OpCodes.Ret);
2079
2080                         Type t2 = tb.CreateType ();
2081
2082                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2083                 }
2084
2085                 [Test]
2086                 public void TestGetConstructor ()
2087                 {
2088                         TypeBuilder tb = module.DefineType (genTypeName ());
2089                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2090
2091                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2092                         ILGenerator ig;
2093
2094                         Type t = tb.MakeGenericType (typeof (int));
2095
2096                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2097
2098                         ig = mb.GetILGenerator ();
2099
2100                         ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2101                         
2102                         ig.Emit (OpCodes.Newobj, ci);
2103                         ig.Emit (OpCodes.Ret);
2104
2105                         // Finish the ctorbuilder
2106                         ig = cb.GetILGenerator ();
2107                         ig.Emit(OpCodes.Ldarg_0);
2108                         ig.Emit(OpCodes.Call, tb.BaseType.GetConstructor(Type.EmptyTypes));             
2109                         ig.Emit (OpCodes.Ret);
2110
2111                         Type t2 = tb.CreateType ();
2112
2113                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2114                 }
2115
2116                 [Test]
2117                 [ExpectedException (typeof (ArgumentException))]
2118                 public void Static_GetConstructor_TypeNull ()
2119                 {
2120                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2121                         // null is non-generic (from exception message)
2122                         TypeBuilder.GetConstructor (null, ci);
2123                 }
2124
2125                 [Test]
2126                 [ExpectedException (typeof (ArgumentException))]
2127                 public void Static_GetConstructor_TypeGeneric ()
2128                 {
2129                         Type t = typeof (List<>).MakeGenericType (typeof (int));
2130                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2131                         // type is not 'TypeBuilder' (from exception message)
2132                         TypeBuilder.GetConstructor (t, ci);
2133                 }
2134
2135                 [Test]
2136                 public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
2137                 {
2138                         TypeBuilder tb = module.DefineType ("XXX");
2139                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2140                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2141                         try {
2142                                 TypeBuilder.GetConstructor (fooOfT, null);
2143                                 Assert.Fail ("Expected NullReferenceException");
2144                         }
2145                         catch (NullReferenceException) {
2146                         }
2147                 }
2148
2149                 [Test] //#536243
2150                 public void CreateTypeThrowsForMethodsWithBadLabels ()
2151                 {
2152                         TypeBuilder tb = module.DefineType (genTypeName ());
2153
2154                         MethodBuilder mb = tb.DefineMethod("F", MethodAttributes.Public, typeof(string), null);
2155                         ILGenerator il_gen = mb.GetILGenerator ();
2156                         il_gen.DefineLabel ();
2157                         il_gen.Emit (OpCodes.Leave, new Label ());
2158                         try {
2159                                 tb.CreateType ();
2160                                 Assert.Fail ();
2161                         } catch (ArgumentException) {}
2162                 }
2163
2164                 [Test]
2165                 [Category ("NotWorking")]
2166                 public void TestIsDefinedIncomplete ()
2167                 {
2168                         TypeBuilder tb = module.DefineType (genTypeName ());
2169                         try {
2170                                 tb.IsDefined (typeof (int), true);
2171                                 Assert.Fail ("#1");
2172                         } catch (NotSupportedException ex) {
2173                                 // The invoked member is not supported in a
2174                                 // dynamic module
2175                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2176                                 Assert.IsNull (ex.InnerException, "#3");
2177                                 Assert.IsNotNull (ex.Message, "#4");
2178                         }
2179                 }
2180
2181                 [Test]
2182                 public void TestIsDefinedComplete ()
2183                 {
2184                         TypeBuilder tb = module.DefineType (genTypeName ());
2185
2186                         ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2187                                 new Type [] { typeof (string) });
2188
2189                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2190                                 new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2191
2192                         tb.SetCustomAttribute (caBuilder);
2193                         tb.CreateType ();
2194                         Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2195                 }
2196
2197                 [Test]
2198                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
2199                 public void IsDefined_AttributeType_Null ()
2200                 {
2201                         TypeBuilder tb = module.DefineType (genTypeName ());
2202                         tb.CreateType ();
2203
2204                         try {
2205                                 tb.IsDefined ((Type) null, false);
2206                                 Assert.Fail ("#1");
2207                         } catch (ArgumentNullException ex) {
2208                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2209                                 Assert.IsNull (ex.InnerException, "#3");
2210                                 Assert.IsNotNull (ex.Message, "#4");
2211                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2212                         }
2213                 }
2214
2215                 [Test] // GetConstructor (Type [])
2216                 public void GetConstructor1_Incomplete ()
2217                 {
2218                         TypeBuilder tb = module.DefineType (genTypeName ());
2219                         ConstructorBuilder cb = tb.DefineConstructor (
2220                                 MethodAttributes.Public,
2221                                 CallingConventions.Standard,
2222                                 Type.EmptyTypes);
2223                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2224
2225                         try {
2226                                 tb.GetConstructor (Type.EmptyTypes);
2227                                 Assert.Fail ("#1");
2228                         } catch (NotSupportedException ex) {
2229                                 // The invoked member is not supported in a
2230                                 // dynamic module
2231                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2232                                 Assert.IsNull (ex.InnerException, "#3");
2233                                 Assert.IsNotNull (ex.Message, "#4");
2234                         }
2235                 }
2236
2237                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2238                 public void GetConstructor2_Complete ()
2239                 {
2240                         BindingFlags flags;
2241                         ConstructorInfo ctor;
2242
2243                         TypeBuilder redType = module.DefineType (genTypeName (),
2244                                 TypeAttributes.Public);
2245                         CreateMembers (redType, "Red", true);
2246
2247                         TypeBuilder greenType = module.DefineType (genTypeName (),
2248                                 TypeAttributes.Public, redType);
2249                         CreateMembers (greenType, "Green", false);
2250                         ConstructorBuilder cb = greenType.DefineConstructor (
2251                                 MethodAttributes.Public,
2252                                 CallingConventions.Standard,
2253                                 Type.EmptyTypes);
2254                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2255
2256                         redType.CreateType ();
2257                         greenType.CreateType ();
2258
2259                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
2260
2261                         ctor = greenType.GetConstructor (flags, null,
2262                                 new Type [] { typeof (int), typeof (int) },
2263                                 new ParameterModifier [0]);
2264                         Assert.IsNull (ctor, "#A1");
2265
2266                         ctor = greenType.GetConstructor (flags, null,
2267                                 new Type [] { typeof (string) },
2268                                 new ParameterModifier [0]);
2269                         Assert.IsNull (ctor, "#A2");
2270
2271                         ctor = greenType.GetConstructor (flags, null,
2272                                 new Type [] { typeof (string), typeof (string) },
2273                                 new ParameterModifier [0]);
2274                         Assert.IsNull (ctor, "#A3");
2275
2276                         ctor = greenType.GetConstructor (flags, null,
2277                                 new Type [] { typeof (int) },
2278                                 new ParameterModifier [0]);
2279                         Assert.IsNull (ctor, "#A4");
2280
2281                         ctor = greenType.GetConstructor (flags, null,
2282                                 new Type [] { typeof (int), typeof (bool) },
2283                                 new ParameterModifier [0]);
2284                         Assert.IsNull (ctor, "#A5");
2285
2286                         ctor = greenType.GetConstructor (flags, null,
2287                                 new Type [] { typeof (string), typeof (int) },
2288                                 new ParameterModifier [0]);
2289                         Assert.IsNull (ctor, "#A6");
2290
2291                         ctor = greenType.GetConstructor (flags, null,
2292                                 Type.EmptyTypes,
2293                                 new ParameterModifier [0]);
2294                         Assert.IsNull (ctor, "#A7");
2295
2296                         ctor = redType.GetConstructor (flags, null,
2297                                 new Type [] { typeof (int), typeof (int) },
2298                                 new ParameterModifier [0]);
2299                         Assert.IsNotNull (ctor, "#A8a");
2300                         Assert.IsTrue (ctor.IsPrivate, "#A8b");
2301                         Assert.IsFalse (ctor.IsStatic, "#A8c");
2302                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2303                         Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2304
2305                         ctor = redType.GetConstructor (flags, null,
2306                                 new Type [] { typeof (string) },
2307                                 new ParameterModifier [0]);
2308                         Assert.IsNotNull (ctor, "#A9a");
2309                         Assert.IsTrue (ctor.IsFamily, "#A9b");
2310                         Assert.IsFalse (ctor.IsStatic, "#A9c");
2311                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2312                         Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2313
2314                         ctor = redType.GetConstructor (flags, null,
2315                                 new Type [] { typeof (string), typeof (string) },
2316                                 new ParameterModifier [0]);
2317                         Assert.IsNotNull (ctor, "#A10a");
2318                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2319                         Assert.IsFalse (ctor.IsStatic, "#A10c");
2320                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2321                         Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2322
2323                         ctor = redType.GetConstructor (flags, null,
2324                                 new Type [] { typeof (int) },
2325                                 new ParameterModifier [0]);
2326                         Assert.IsNotNull (ctor, "#A11a");
2327                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2328                         Assert.IsFalse (ctor.IsStatic, "#A11c");
2329                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2330                         Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2331
2332                         ctor = redType.GetConstructor (flags, null,
2333                                 new Type [] { typeof (int), typeof (bool) },
2334                                 new ParameterModifier [0]);
2335                         Assert.IsNull (ctor, "#A12");
2336
2337                         ctor = redType.GetConstructor (flags, null,
2338                                 new Type [] { typeof (string), typeof (int) },
2339                                 new ParameterModifier [0]);
2340                         Assert.IsNotNull (ctor, "#A13a");
2341                         Assert.IsTrue (ctor.IsAssembly, "#A13b");
2342                         Assert.IsFalse (ctor.IsStatic, "#A13c");
2343                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2344                         Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2345
2346                         ctor = redType.GetConstructor (flags, null,
2347                                 Type.EmptyTypes,
2348                                 new ParameterModifier [0]);
2349                         Assert.IsNull (ctor, "#A14");
2350
2351                         flags = BindingFlags.Instance | BindingFlags.Public;
2352
2353                         ctor = greenType.GetConstructor (flags, null,
2354                                 new Type [] { typeof (int), typeof (int) },
2355                                 new ParameterModifier [0]);
2356                         Assert.IsNull (ctor, "#B1");
2357
2358                         ctor = greenType.GetConstructor (flags, null,
2359                                 new Type [] { typeof (string) },
2360                                 new ParameterModifier [0]);
2361                         Assert.IsNull (ctor, "#B2");
2362
2363                         ctor = greenType.GetConstructor (flags, null,
2364                                 new Type [] { typeof (string), typeof (string) },
2365                                 new ParameterModifier [0]);
2366                         Assert.IsNull (ctor, "#B3");
2367
2368                         ctor = greenType.GetConstructor (flags, null,
2369                                 new Type [] { typeof (int) },
2370                                 new ParameterModifier [0]);
2371                         Assert.IsNull (ctor, "#B4");
2372
2373                         ctor = greenType.GetConstructor (flags, null,
2374                                 new Type [] { typeof (int), typeof (bool) },
2375                                 new ParameterModifier [0]);
2376                         Assert.IsNull (ctor, "#B5");
2377
2378                         ctor = greenType.GetConstructor (flags, null,
2379                                 new Type [] { typeof (string), typeof (int) },
2380                                 new ParameterModifier [0]);
2381                         Assert.IsNull (ctor, "#B6");
2382
2383                         ctor = greenType.GetConstructor (flags, null,
2384                                 Type.EmptyTypes,
2385                                 new ParameterModifier [0]);
2386                         Assert.IsNotNull (ctor, "#B7a");
2387                         Assert.IsTrue (ctor.IsPublic, "#B7b");
2388                         Assert.IsFalse (ctor.IsStatic, "#B7c");
2389                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2390                         Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2391
2392                         ctor = redType.GetConstructor (flags, null,
2393                                 new Type [] { typeof (int), typeof (int) },
2394                                 new ParameterModifier [0]);
2395                         Assert.IsNull (ctor, "#B8");
2396
2397                         ctor = redType.GetConstructor (flags, null,
2398                                 new Type [] { typeof (string) },
2399                                 new ParameterModifier [0]);
2400                         Assert.IsNull (ctor, "#B9");
2401
2402                         ctor = redType.GetConstructor (flags, null,
2403                                 new Type [] { typeof (string), typeof (string) },
2404                                 new ParameterModifier [0]);
2405                         Assert.IsNull (ctor, "#B10");
2406
2407                         ctor = redType.GetConstructor (flags, null,
2408                                 new Type [] { typeof (int) },
2409                                 new ParameterModifier [0]);
2410                         Assert.IsNull (ctor, "#B11");
2411
2412                         ctor = redType.GetConstructor (flags, null,
2413                                 new Type [] { typeof (int), typeof (bool) },
2414                                 new ParameterModifier [0]);
2415                         Assert.IsNotNull (ctor, "#B12a");
2416                         Assert.IsTrue (ctor.IsPublic, "#B12b");
2417                         Assert.IsFalse (ctor.IsStatic, "#B12c");
2418                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2419                         Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2420
2421                         ctor = redType.GetConstructor (flags, null,
2422                                 new Type [] { typeof (string), typeof (int) },
2423                                 new ParameterModifier [0]);
2424                         Assert.IsNull (ctor, "#B13");
2425
2426                         ctor = redType.GetConstructor (flags, null,
2427                                 Type.EmptyTypes,
2428                                 new ParameterModifier [0]);
2429                         Assert.IsNull (ctor, "#B14");
2430
2431                         flags = BindingFlags.Static | BindingFlags.Public;
2432
2433                         ctor = greenType.GetConstructor (flags, null,
2434                                 new Type [] { typeof (int), typeof (int) },
2435                                 new ParameterModifier [0]);
2436                         Assert.IsNull (ctor, "#C1");
2437
2438                         ctor = greenType.GetConstructor (flags, null,
2439                                 new Type [] { typeof (string) },
2440                                 new ParameterModifier [0]);
2441                         Assert.IsNull (ctor, "#C2");
2442
2443                         ctor = greenType.GetConstructor (flags, null,
2444                                 new Type [] { typeof (string), typeof (string) },
2445                                 new ParameterModifier [0]);
2446                         Assert.IsNull (ctor, "#C3");
2447
2448                         ctor = greenType.GetConstructor (flags, null,
2449                                 new Type [] { typeof (int) },
2450                                 new ParameterModifier [0]);
2451                         Assert.IsNull (ctor, "#C4");
2452
2453                         ctor = greenType.GetConstructor (flags, null,
2454                                 new Type [] { typeof (int), typeof (bool) },
2455                                 new ParameterModifier [0]);
2456                         Assert.IsNull (ctor, "#C5");
2457
2458                         ctor = greenType.GetConstructor (flags, null,
2459                                 new Type [] { typeof (string), typeof (int) },
2460                                 new ParameterModifier [0]);
2461                         Assert.IsNull (ctor, "#C6");
2462
2463                         ctor = greenType.GetConstructor (flags, null,
2464                                 Type.EmptyTypes,
2465                                 new ParameterModifier [0]);
2466                         Assert.IsNull (ctor, "#C7");
2467
2468                         ctor = redType.GetConstructor (flags, null,
2469                                 new Type [] { typeof (int), typeof (int) },
2470                                 new ParameterModifier [0]);
2471                         Assert.IsNull (ctor, "#C8");
2472
2473                         ctor = redType.GetConstructor (flags, null,
2474                                 new Type [] { typeof (string) },
2475                                 new ParameterModifier [0]);
2476                         Assert.IsNull (ctor, "#C9");
2477
2478                         ctor = redType.GetConstructor (flags, null,
2479                                 new Type [] { typeof (string), typeof (string) },
2480                                 new ParameterModifier [0]);
2481                         Assert.IsNull (ctor, "#C10");
2482
2483                         ctor = redType.GetConstructor (flags, null,
2484                                 new Type [] { typeof (int) },
2485                                 new ParameterModifier [0]);
2486                         Assert.IsNull (ctor, "#C11a");
2487
2488                         ctor = redType.GetConstructor (flags, null,
2489                                 new Type [] { typeof (int), typeof (bool) },
2490                                 new ParameterModifier [0]);
2491                         Assert.IsNull (ctor, "#C12");
2492
2493                         ctor = redType.GetConstructor (flags, null,
2494                                 new Type [] { typeof (string), typeof (int) },
2495                                 new ParameterModifier [0]);
2496                         Assert.IsNull (ctor, "#C13");
2497
2498                         ctor = redType.GetConstructor (flags, null,
2499                                 Type.EmptyTypes,
2500                                 new ParameterModifier [0]);
2501                         Assert.IsNull (ctor, "#C14");
2502
2503                         flags = BindingFlags.Static | BindingFlags.NonPublic;
2504
2505                         ctor = greenType.GetConstructor (flags, null,
2506                                 new Type [] { typeof (int), typeof (int) },
2507                                 new ParameterModifier [0]);
2508                         Assert.IsNull (ctor, "#D1");
2509
2510                         ctor = greenType.GetConstructor (flags, null,
2511                                 new Type [] { typeof (string) },
2512                                 new ParameterModifier [0]);
2513                         Assert.IsNull (ctor, "#D2");
2514
2515                         ctor = greenType.GetConstructor (flags, null,
2516                                 new Type [] { typeof (string), typeof (string) },
2517                                 new ParameterModifier [0]);
2518                         Assert.IsNull (ctor, "#D3");
2519
2520                         ctor = greenType.GetConstructor (flags, null,
2521                                 new Type [] { typeof (int) },
2522                                 new ParameterModifier [0]);
2523                         Assert.IsNull (ctor, "#D4");
2524
2525                         ctor = greenType.GetConstructor (flags, null,
2526                                 new Type [] { typeof (int), typeof (bool) },
2527                                 new ParameterModifier [0]);
2528                         Assert.IsNull (ctor, "#D5");
2529
2530                         ctor = greenType.GetConstructor (flags, null,
2531                                 new Type [] { typeof (string), typeof (int) },
2532                                 new ParameterModifier [0]);
2533                         Assert.IsNull (ctor, "#D6");
2534
2535                         ctor = greenType.GetConstructor (flags, null,
2536                                 Type.EmptyTypes,
2537                                 new ParameterModifier [0]);
2538                         Assert.IsNull (ctor, "#D7");
2539
2540                         ctor = redType.GetConstructor (flags, null,
2541                                 new Type [] { typeof (int), typeof (int) },
2542                                 new ParameterModifier [0]);
2543                         Assert.IsNull (ctor, "#D8");
2544
2545                         ctor = redType.GetConstructor (flags, null,
2546                                 new Type [] { typeof (string) },
2547                                 new ParameterModifier [0]);
2548                         Assert.IsNull (ctor, "#D9");
2549
2550                         ctor = redType.GetConstructor (flags, null,
2551                                 new Type [] { typeof (string), typeof (string) },
2552                                 new ParameterModifier [0]);
2553                         Assert.IsNull (ctor, "#D10");
2554
2555                         ctor = redType.GetConstructor (flags, null,
2556                                 new Type [] { typeof (int) },
2557                                 new ParameterModifier [0]);
2558                         Assert.IsNull (ctor, "#D11");
2559
2560                         ctor = redType.GetConstructor (flags, null,
2561                                 new Type [] { typeof (int), typeof (bool) },
2562                                 new ParameterModifier [0]);
2563                         Assert.IsNull (ctor, "#D12");
2564
2565                         ctor = redType.GetConstructor (flags, null,
2566                                 new Type [] { typeof (string), typeof (int) },
2567                                 new ParameterModifier [0]);
2568                         Assert.IsNull (ctor, "#D13");
2569
2570                         ctor = redType.GetConstructor (flags, null,
2571                                 Type.EmptyTypes,
2572                                 new ParameterModifier [0]);
2573                         Assert.IsNotNull (ctor, "#D14a");
2574                         Assert.IsTrue (ctor.IsPrivate, "#D14b");
2575                         Assert.IsTrue (ctor.IsStatic, "#B14c");
2576                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2577                         Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2578
2579                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2580                                 BindingFlags.FlattenHierarchy;
2581
2582                         ctor = greenType.GetConstructor (flags, null,
2583                                 new Type [] { typeof (int), typeof (int) },
2584                                 new ParameterModifier [0]);
2585                         Assert.IsNull (ctor, "#E1");
2586
2587                         ctor = greenType.GetConstructor (flags, null,
2588                                 new Type [] { typeof (string) },
2589                                 new ParameterModifier [0]);
2590                         Assert.IsNull (ctor, "#E2");
2591
2592                         ctor = greenType.GetConstructor (flags, null,
2593                                 new Type [] { typeof (string), typeof (string) },
2594                                 new ParameterModifier [0]);
2595                         Assert.IsNull (ctor, "#E3");
2596
2597                         ctor = greenType.GetConstructor (flags, null,
2598                                 new Type [] { typeof (int) },
2599                                 new ParameterModifier [0]);
2600                         Assert.IsNull (ctor, "#E4");
2601
2602                         ctor = greenType.GetConstructor (flags, null,
2603                                 new Type [] { typeof (int), typeof (bool) },
2604                                 new ParameterModifier [0]);
2605                         Assert.IsNull (ctor, "#E5");
2606
2607                         ctor = greenType.GetConstructor (flags, null,
2608                                 new Type [] { typeof (string), typeof (int) },
2609                                 new ParameterModifier [0]);
2610                         Assert.IsNull (ctor, "#E6");
2611
2612                         ctor = greenType.GetConstructor (flags, null,
2613                                 Type.EmptyTypes,
2614                                 new ParameterModifier [0]);
2615                         Assert.IsNull (ctor, "#E7");
2616
2617                         ctor = redType.GetConstructor (flags, null,
2618                                 new Type [] { typeof (int), typeof (int) },
2619                                 new ParameterModifier [0]);
2620                         Assert.IsNotNull (ctor, "#E8a");
2621                         Assert.IsTrue (ctor.IsPrivate, "#E8b");
2622                         Assert.IsFalse (ctor.IsStatic, "#E8c");
2623                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2624                         Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2625
2626                         ctor = redType.GetConstructor (flags, null,
2627                                 new Type [] { typeof (string) },
2628                                 new ParameterModifier [0]);
2629                         Assert.IsNotNull (ctor, "#E9a");
2630                         Assert.IsTrue (ctor.IsFamily, "#E9b");
2631                         Assert.IsFalse (ctor.IsStatic, "#E9c");
2632                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2633                         Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2634
2635                         ctor = redType.GetConstructor (flags, null,
2636                                 new Type [] { typeof (string), typeof (string) },
2637                                 new ParameterModifier [0]);
2638                         Assert.IsNotNull (ctor, "#E10a");
2639                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2640                         Assert.IsFalse (ctor.IsStatic, "#E10c");
2641                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2642                         Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2643
2644                         ctor = redType.GetConstructor (flags, null,
2645                                 new Type [] { typeof (int) },
2646                                 new ParameterModifier [0]);
2647                         Assert.IsNotNull (ctor, "#E11a");
2648                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2649                         Assert.IsFalse (ctor.IsStatic, "#E11c");
2650                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2651                         Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2652
2653                         ctor = redType.GetConstructor (flags, null,
2654                                 new Type [] { typeof (int), typeof (bool) },
2655                                 new ParameterModifier [0]);
2656                         Assert.IsNull (ctor, "#E12");
2657
2658                         ctor = redType.GetConstructor (flags, null,
2659                                 new Type [] { typeof (string), typeof (int) },
2660                                 new ParameterModifier [0]);
2661                         Assert.IsNotNull (ctor, "#E13a");
2662                         Assert.IsTrue (ctor.IsAssembly, "#E13b");
2663                         Assert.IsFalse (ctor.IsStatic, "#E13c");
2664                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2665                         Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2666
2667                         ctor = redType.GetConstructor (flags, null,
2668                                 Type.EmptyTypes,
2669                                 new ParameterModifier [0]);
2670                         Assert.IsNull (ctor, "#E14");
2671
2672                         flags = BindingFlags.Instance | BindingFlags.Public |
2673                                 BindingFlags.FlattenHierarchy;
2674
2675                         ctor = greenType.GetConstructor (flags, null,
2676                                 new Type [] { typeof (int), typeof (int) },
2677                                 new ParameterModifier [0]);
2678                         Assert.IsNull (ctor, "#F1");
2679
2680                         ctor = greenType.GetConstructor (flags, null,
2681                                 new Type [] { typeof (string) },
2682                                 new ParameterModifier [0]);
2683                         Assert.IsNull (ctor, "#F2");
2684
2685                         ctor = greenType.GetConstructor (flags, null,
2686                                 new Type [] { typeof (string), typeof (string) },
2687                                 new ParameterModifier [0]);
2688                         Assert.IsNull (ctor, "#F3");
2689
2690                         ctor = greenType.GetConstructor (flags, null,
2691                                 new Type [] { typeof (int) },
2692                                 new ParameterModifier [0]);
2693                         Assert.IsNull (ctor, "#F4");
2694
2695                         ctor = greenType.GetConstructor (flags, null,
2696                                 new Type [] { typeof (int), typeof (bool) },
2697                                 new ParameterModifier [0]);
2698                         Assert.IsNull (ctor, "#F5");
2699
2700                         ctor = greenType.GetConstructor (flags, null,
2701                                 new Type [] { typeof (string), typeof (int) },
2702                                 new ParameterModifier [0]);
2703                         Assert.IsNull (ctor, "#F6");
2704
2705                         ctor = greenType.GetConstructor (flags, null,
2706                                 Type.EmptyTypes,
2707                                 new ParameterModifier [0]);
2708                         Assert.IsNotNull (ctor, "#F7a");
2709                         Assert.IsTrue (ctor.IsPublic, "#F7b");
2710                         Assert.IsFalse (ctor.IsStatic, "#F7c");
2711                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2712                         Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2713
2714                         ctor = redType.GetConstructor (flags, null,
2715                                 new Type [] { typeof (int), typeof (int) },
2716                                 new ParameterModifier [0]);
2717                         Assert.IsNull (ctor, "#F8");
2718
2719                         ctor = redType.GetConstructor (flags, null,
2720                                 new Type [] { typeof (string) },
2721                                 new ParameterModifier [0]);
2722                         Assert.IsNull (ctor, "#F9");
2723
2724                         ctor = redType.GetConstructor (flags, null,
2725                                 new Type [] { typeof (string), typeof (string) },
2726                                 new ParameterModifier [0]);
2727                         Assert.IsNull (ctor, "#F10");
2728
2729                         ctor = redType.GetConstructor (flags, null,
2730                                 new Type [] { typeof (int) },
2731                                 new ParameterModifier [0]);
2732                         Assert.IsNull (ctor, "#F11");
2733
2734                         ctor = redType.GetConstructor (flags, null,
2735                                 new Type [] { typeof (int), typeof (bool) },
2736                                 new ParameterModifier [0]);
2737                         Assert.IsNotNull (ctor, "#F12a");
2738                         Assert.IsTrue (ctor.IsPublic, "#F12b");
2739                         Assert.IsFalse (ctor.IsStatic, "#F12c");
2740                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2741                         Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2742
2743                         ctor = redType.GetConstructor (flags, null,
2744                                 new Type [] { typeof (string), typeof (int) },
2745                                 new ParameterModifier [0]);
2746                         Assert.IsNull (ctor, "#F13");
2747
2748                         ctor = redType.GetConstructor (flags, null,
2749                                 Type.EmptyTypes,
2750                                 new ParameterModifier [0]);
2751                         Assert.IsNull (ctor, "#F14");
2752
2753                         flags = BindingFlags.Static | BindingFlags.Public |
2754                                 BindingFlags.FlattenHierarchy;
2755
2756                         ctor = greenType.GetConstructor (flags, null,
2757                                 new Type [] { typeof (int), typeof (int) },
2758                                 new ParameterModifier [0]);
2759                         Assert.IsNull (ctor, "#G1");
2760
2761                         ctor = greenType.GetConstructor (flags, null,
2762                                 new Type [] { typeof (string) },
2763                                 new ParameterModifier [0]);
2764                         Assert.IsNull (ctor, "#G2");
2765
2766                         ctor = greenType.GetConstructor (flags, null,
2767                                 new Type [] { typeof (string), typeof (string) },
2768                                 new ParameterModifier [0]);
2769                         Assert.IsNull (ctor, "#G3");
2770
2771                         ctor = greenType.GetConstructor (flags, null,
2772                                 new Type [] { typeof (int) },
2773                                 new ParameterModifier [0]);
2774                         Assert.IsNull (ctor, "#G4");
2775
2776                         ctor = greenType.GetConstructor (flags, null,
2777                                 new Type [] { typeof (int), typeof (bool) },
2778                                 new ParameterModifier [0]);
2779                         Assert.IsNull (ctor, "#G5");
2780
2781                         ctor = greenType.GetConstructor (flags, null,
2782                                 new Type [] { typeof (string), typeof (int) },
2783                                 new ParameterModifier [0]);
2784                         Assert.IsNull (ctor, "#G6");
2785
2786                         ctor = greenType.GetConstructor (flags, null,
2787                                 Type.EmptyTypes,
2788                                 new ParameterModifier [0]);
2789                         Assert.IsNull (ctor, "#G7");
2790
2791                         ctor = redType.GetConstructor (flags, null,
2792                                 new Type [] { typeof (int), typeof (int) },
2793                                 new ParameterModifier [0]);
2794                         Assert.IsNull (ctor, "#G8");
2795
2796                         ctor = redType.GetConstructor (flags, null,
2797                                 new Type [] { typeof (string) },
2798                                 new ParameterModifier [0]);
2799                         Assert.IsNull (ctor, "#G9");
2800
2801                         ctor = redType.GetConstructor (flags, null,
2802                                 new Type [] { typeof (string), typeof (string) },
2803                                 new ParameterModifier [0]);
2804                         Assert.IsNull (ctor, "#G10");
2805
2806                         ctor = redType.GetConstructor (flags, null,
2807                                 new Type [] { typeof (int) },
2808                                 new ParameterModifier [0]);
2809                         Assert.IsNull (ctor, "#G11");
2810
2811                         ctor = redType.GetConstructor (flags, null,
2812                                 new Type [] { typeof (int), typeof (bool) },
2813                                 new ParameterModifier [0]);
2814                         Assert.IsNull (ctor, "#G12");
2815
2816                         ctor = redType.GetConstructor (flags, null,
2817                                 new Type [] { typeof (string), typeof (int) },
2818                                 new ParameterModifier [0]);
2819                         Assert.IsNull (ctor, "#G13");
2820
2821                         ctor = redType.GetConstructor (flags, null,
2822                                 Type.EmptyTypes,
2823                                 new ParameterModifier [0]);
2824                         Assert.IsNull (ctor, "#G14");
2825
2826                         flags = BindingFlags.Static | BindingFlags.NonPublic |
2827                                 BindingFlags.FlattenHierarchy;
2828
2829                         ctor = greenType.GetConstructor (flags, null,
2830                                 new Type [] { typeof (int), typeof (int) },
2831                                 new ParameterModifier [0]);
2832                         Assert.IsNull (ctor, "#H1");
2833
2834                         ctor = greenType.GetConstructor (flags, null,
2835                                 new Type [] { typeof (string) },
2836                                 new ParameterModifier [0]);
2837                         Assert.IsNull (ctor, "#H2");
2838
2839                         ctor = greenType.GetConstructor (flags, null,
2840                                 new Type [] { typeof (string), typeof (string) },
2841                                 new ParameterModifier [0]);
2842                         Assert.IsNull (ctor, "#H3");
2843
2844                         ctor = greenType.GetConstructor (flags, null,
2845                                 new Type [] { typeof (int) },
2846                                 new ParameterModifier [0]);
2847                         Assert.IsNull (ctor, "#H4");
2848
2849                         ctor = greenType.GetConstructor (flags, null,
2850                                 new Type [] { typeof (int), typeof (bool) },
2851                                 new ParameterModifier [0]);
2852                         Assert.IsNull (ctor, "#H5");
2853
2854                         ctor = greenType.GetConstructor (flags, null,
2855                                 new Type [] { typeof (string), typeof (int) },
2856                                 new ParameterModifier [0]);
2857                         Assert.IsNull (ctor, "#H6");
2858
2859                         ctor = greenType.GetConstructor (flags, null,
2860                                 Type.EmptyTypes,
2861                                 new ParameterModifier [0]);
2862                         Assert.IsNull (ctor, "#H7");
2863
2864                         ctor = redType.GetConstructor (flags, null,
2865                                 new Type [] { typeof (int), typeof (int) },
2866                                 new ParameterModifier [0]);
2867                         Assert.IsNull (ctor, "#H8");
2868
2869                         ctor = redType.GetConstructor (flags, null,
2870                                 new Type [] { typeof (string) },
2871                                 new ParameterModifier [0]);
2872                         Assert.IsNull (ctor, "#H9");
2873
2874                         ctor = redType.GetConstructor (flags, null,
2875                                 new Type [] { typeof (string), typeof (string) },
2876                                 new ParameterModifier [0]);
2877                         Assert.IsNull (ctor, "#H10");
2878
2879                         ctor = redType.GetConstructor (flags, null,
2880                                 new Type [] { typeof (int) },
2881                                 new ParameterModifier [0]);
2882                         Assert.IsNull (ctor, "#H11");
2883
2884                         ctor = redType.GetConstructor (flags, null,
2885                                 new Type [] { typeof (int), typeof (bool) },
2886                                 new ParameterModifier [0]);
2887                         Assert.IsNull (ctor, "#H12");
2888
2889                         ctor = redType.GetConstructor (flags, null,
2890                                 new Type [] { typeof (string), typeof (int) },
2891                                 new ParameterModifier [0]);
2892                         Assert.IsNull (ctor, "#H13");
2893
2894                         ctor = redType.GetConstructor (flags, null,
2895                                 Type.EmptyTypes,
2896                                 new ParameterModifier [0]);
2897                         Assert.IsNotNull (ctor, "#H14");
2898                         Assert.IsTrue (ctor.IsPrivate, "#H14b");
2899                         Assert.IsTrue (ctor.IsStatic, "#H14c");
2900                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2901                         Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2902
2903                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2904                                 BindingFlags.DeclaredOnly;
2905
2906                         ctor = greenType.GetConstructor (flags, null,
2907                                 new Type [] { typeof (int), typeof (int) },
2908                                 new ParameterModifier [0]);
2909                         Assert.IsNull (ctor, "#I1");
2910
2911                         ctor = greenType.GetConstructor (flags, null,
2912                                 new Type [] { typeof (string) },
2913                                 new ParameterModifier [0]);
2914                         Assert.IsNull (ctor, "#I2");
2915
2916                         ctor = greenType.GetConstructor (flags, null,
2917                                 new Type [] { typeof (string), typeof (string) },
2918                                 new ParameterModifier [0]);
2919                         Assert.IsNull (ctor, "#I3");
2920
2921                         ctor = greenType.GetConstructor (flags, null,
2922                                 new Type [] { typeof (int) },
2923                                 new ParameterModifier [0]);
2924                         Assert.IsNull (ctor, "#I4");
2925
2926                         ctor = greenType.GetConstructor (flags, null,
2927                                 new Type [] { typeof (int), typeof (bool) },
2928                                 new ParameterModifier [0]);
2929                         Assert.IsNull (ctor, "#I5");
2930
2931                         ctor = greenType.GetConstructor (flags, null,
2932                                 new Type [] { typeof (string), typeof (int) },
2933                                 new ParameterModifier [0]);
2934                         Assert.IsNull (ctor, "#I6");
2935
2936                         ctor = greenType.GetConstructor (flags, null,
2937                                 Type.EmptyTypes,
2938                                 new ParameterModifier [0]);
2939                         Assert.IsNull (ctor, "#I7");
2940
2941                         ctor = redType.GetConstructor (flags, null,
2942                                 new Type [] { typeof (int), typeof (int) },
2943                                 new ParameterModifier [0]);
2944                         Assert.IsNotNull (ctor, "#I8a");
2945                         Assert.IsTrue (ctor.IsPrivate, "#I8b");
2946                         Assert.IsFalse (ctor.IsStatic, "#I8c");
2947                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
2948                         Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
2949
2950                         ctor = redType.GetConstructor (flags, null,
2951                                 new Type [] { typeof (string) },
2952                                 new ParameterModifier [0]);
2953                         Assert.IsNotNull (ctor, "#I9a");
2954                         Assert.IsTrue (ctor.IsFamily, "#I9b");
2955                         Assert.IsFalse (ctor.IsStatic, "#I9c");
2956                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
2957                         Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
2958
2959                         ctor = redType.GetConstructor (flags, null,
2960                                 new Type [] { typeof (string), typeof (string) },
2961                                 new ParameterModifier [0]);
2962                         Assert.IsNotNull (ctor, "#I10a");
2963                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
2964                         Assert.IsFalse (ctor.IsStatic, "#I10c");
2965                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
2966                         Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
2967
2968                         ctor = redType.GetConstructor (flags, null,
2969                                 new Type [] { typeof (int) },
2970                                 new ParameterModifier [0]);
2971                         Assert.IsNotNull (ctor, "#I11a");
2972                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
2973                         Assert.IsFalse (ctor.IsStatic, "#I11c");
2974                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
2975                         Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
2976
2977                         ctor = redType.GetConstructor (flags, null,
2978                                 new Type [] { typeof (int), typeof (bool) },
2979                                 new ParameterModifier [0]);
2980                         Assert.IsNull (ctor, "#I12");
2981
2982                         ctor = redType.GetConstructor (flags, null,
2983                                 new Type [] { typeof (string), typeof (int) },
2984                                 new ParameterModifier [0]);
2985                         Assert.IsNotNull (ctor, "#I13a");
2986                         Assert.IsTrue (ctor.IsAssembly, "#I13b");
2987                         Assert.IsFalse (ctor.IsStatic, "#I13c");
2988                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
2989                         Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
2990
2991                         ctor = redType.GetConstructor (flags, null,
2992                                 Type.EmptyTypes,
2993                                 new ParameterModifier [0]);
2994                         Assert.IsNull (ctor, "#I14");
2995
2996                         flags = BindingFlags.Instance | BindingFlags.Public |
2997                                 BindingFlags.DeclaredOnly;
2998
2999                         ctor = greenType.GetConstructor (flags, null,
3000                                 new Type [] { typeof (int), typeof (int) },
3001                                 new ParameterModifier [0]);
3002                         Assert.IsNull (ctor, "#J1");
3003
3004                         ctor = greenType.GetConstructor (flags, null,
3005                                 new Type [] { typeof (string) },
3006                                 new ParameterModifier [0]);
3007                         Assert.IsNull (ctor, "#J2");
3008
3009                         ctor = greenType.GetConstructor (flags, null,
3010                                 new Type [] { typeof (string), typeof (string) },
3011                                 new ParameterModifier [0]);
3012                         Assert.IsNull (ctor, "#J3");
3013
3014                         ctor = greenType.GetConstructor (flags, null,
3015                                 new Type [] { typeof (int) },
3016                                 new ParameterModifier [0]);
3017                         Assert.IsNull (ctor, "#J4");
3018
3019                         ctor = greenType.GetConstructor (flags, null,
3020                                 new Type [] { typeof (int), typeof (bool) },
3021                                 new ParameterModifier [0]);
3022                         Assert.IsNull (ctor, "#J5");
3023
3024                         ctor = greenType.GetConstructor (flags, null,
3025                                 new Type [] { typeof (string), typeof (int) },
3026                                 new ParameterModifier [0]);
3027                         Assert.IsNull (ctor, "#J6");
3028
3029                         ctor = greenType.GetConstructor (flags, null,
3030                                 Type.EmptyTypes,
3031                                 new ParameterModifier [0]);
3032                         Assert.IsNotNull (ctor, "#J7a");
3033                         Assert.IsTrue (ctor.IsPublic, "#J7b");
3034                         Assert.IsFalse (ctor.IsStatic, "#J7c");
3035                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3036                         Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3037
3038                         ctor = redType.GetConstructor (flags, null,
3039                                 new Type [] { typeof (int), typeof (int) },
3040                                 new ParameterModifier [0]);
3041                         Assert.IsNull (ctor, "#J8");
3042
3043                         ctor = redType.GetConstructor (flags, null,
3044                                 new Type [] { typeof (string) },
3045                                 new ParameterModifier [0]);
3046                         Assert.IsNull (ctor, "#J9");
3047
3048                         ctor = redType.GetConstructor (flags, null,
3049                                 new Type [] { typeof (string), typeof (string) },
3050                                 new ParameterModifier [0]);
3051                         Assert.IsNull (ctor, "#J10");
3052
3053                         ctor = redType.GetConstructor (flags, null,
3054                                 new Type [] { typeof (int) },
3055                                 new ParameterModifier [0]);
3056                         Assert.IsNull (ctor, "#J11");
3057
3058                         ctor = redType.GetConstructor (flags, null,
3059                                 new Type [] { typeof (int), typeof (bool) },
3060                                 new ParameterModifier [0]);
3061                         Assert.IsNotNull (ctor, "#J12a");
3062                         Assert.IsTrue (ctor.IsPublic, "#J12b");
3063                         Assert.IsFalse (ctor.IsStatic, "#J12c");
3064                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3065                         Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3066
3067                         ctor = redType.GetConstructor (flags, null,
3068                                 new Type [] { typeof (string), typeof (int) },
3069                                 new ParameterModifier [0]);
3070                         Assert.IsNull (ctor, "#J13");
3071
3072                         ctor = redType.GetConstructor (flags, null,
3073                                 Type.EmptyTypes,
3074                                 new ParameterModifier [0]);
3075                         Assert.IsNull (ctor, "#J14");
3076
3077                         flags = BindingFlags.Static | BindingFlags.Public |
3078                                 BindingFlags.DeclaredOnly;
3079
3080                         ctor = greenType.GetConstructor (flags, null,
3081                                 new Type [] { typeof (int), typeof (int) },
3082                                 new ParameterModifier [0]);
3083                         Assert.IsNull (ctor, "#K1");
3084
3085                         ctor = greenType.GetConstructor (flags, null,
3086                                 new Type [] { typeof (string) },
3087                                 new ParameterModifier [0]);
3088                         Assert.IsNull (ctor, "#K2");
3089
3090                         ctor = greenType.GetConstructor (flags, null,
3091                                 new Type [] { typeof (string), typeof (string) },
3092                                 new ParameterModifier [0]);
3093                         Assert.IsNull (ctor, "#K3");
3094
3095                         ctor = greenType.GetConstructor (flags, null,
3096                                 new Type [] { typeof (int) },
3097                                 new ParameterModifier [0]);
3098                         Assert.IsNull (ctor, "#K4");
3099
3100                         ctor = greenType.GetConstructor (flags, null,
3101                                 new Type [] { typeof (int), typeof (bool) },
3102                                 new ParameterModifier [0]);
3103                         Assert.IsNull (ctor, "#K5");
3104
3105                         ctor = greenType.GetConstructor (flags, null,
3106                                 new Type [] { typeof (string), typeof (int) },
3107                                 new ParameterModifier [0]);
3108                         Assert.IsNull (ctor, "#K6");
3109
3110                         ctor = greenType.GetConstructor (flags, null,
3111                                 Type.EmptyTypes,
3112                                 new ParameterModifier [0]);
3113                         Assert.IsNull (ctor, "#K7");
3114
3115                         ctor = redType.GetConstructor (flags, null,
3116                                 new Type [] { typeof (int), typeof (int) },
3117                                 new ParameterModifier [0]);
3118                         Assert.IsNull (ctor, "#K8");
3119
3120                         ctor = redType.GetConstructor (flags, null,
3121                                 new Type [] { typeof (string) },
3122                                 new ParameterModifier [0]);
3123                         Assert.IsNull (ctor, "#K9");
3124
3125                         ctor = redType.GetConstructor (flags, null,
3126                                 new Type [] { typeof (string), typeof (string) },
3127                                 new ParameterModifier [0]);
3128                         Assert.IsNull (ctor, "#K10");
3129
3130                         ctor = redType.GetConstructor (flags, null,
3131                                 new Type [] { typeof (int) },
3132                                 new ParameterModifier [0]);
3133                         Assert.IsNull (ctor, "#K11");
3134
3135                         ctor = redType.GetConstructor (flags, null,
3136                                 new Type [] { typeof (int), typeof (bool) },
3137                                 new ParameterModifier [0]);
3138                         Assert.IsNull (ctor, "#K12");
3139
3140                         ctor = redType.GetConstructor (flags, null,
3141                                 new Type [] { typeof (string), typeof (int) },
3142                                 new ParameterModifier [0]);
3143                         Assert.IsNull (ctor, "#K13");
3144
3145                         ctor = redType.GetConstructor (flags, null,
3146                                 Type.EmptyTypes,
3147                                 new ParameterModifier [0]);
3148                         Assert.IsNull (ctor, "#K14");
3149
3150                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3151                                 BindingFlags.DeclaredOnly;
3152
3153                         ctor = greenType.GetConstructor (flags, null,
3154                                 new Type [] { typeof (int), typeof (int) },
3155                                 new ParameterModifier [0]);
3156                         Assert.IsNull (ctor, "#L1");
3157
3158                         ctor = greenType.GetConstructor (flags, null,
3159                                 new Type [] { typeof (string) },
3160                                 new ParameterModifier [0]);
3161                         Assert.IsNull (ctor, "#L2");
3162
3163                         ctor = greenType.GetConstructor (flags, null,
3164                                 new Type [] { typeof (string), typeof (string) },
3165                                 new ParameterModifier [0]);
3166                         Assert.IsNull (ctor, "#L3");
3167
3168                         ctor = greenType.GetConstructor (flags, null,
3169                                 new Type [] { typeof (int) },
3170                                 new ParameterModifier [0]);
3171                         Assert.IsNull (ctor, "#L4");
3172
3173                         ctor = greenType.GetConstructor (flags, null,
3174                                 new Type [] { typeof (int), typeof (bool) },
3175                                 new ParameterModifier [0]);
3176                         Assert.IsNull (ctor, "#L5");
3177
3178                         ctor = greenType.GetConstructor (flags, null,
3179                                 new Type [] { typeof (string), typeof (int) },
3180                                 new ParameterModifier [0]);
3181                         Assert.IsNull (ctor, "#L6");
3182
3183                         ctor = greenType.GetConstructor (flags, null,
3184                                 Type.EmptyTypes,
3185                                 new ParameterModifier [0]);
3186                         Assert.IsNull (ctor, "#L7");
3187
3188                         ctor = redType.GetConstructor (flags, null,
3189                                 new Type [] { typeof (int), typeof (int) },
3190                                 new ParameterModifier [0]);
3191                         Assert.IsNull (ctor, "#L8");
3192
3193                         ctor = redType.GetConstructor (flags, null,
3194                                 new Type [] { typeof (string) },
3195                                 new ParameterModifier [0]);
3196                         Assert.IsNull (ctor, "#L9");
3197
3198                         ctor = redType.GetConstructor (flags, null,
3199                                 new Type [] { typeof (string), typeof (string) },
3200                                 new ParameterModifier [0]);
3201                         Assert.IsNull (ctor, "#L10");
3202
3203                         ctor = redType.GetConstructor (flags, null,
3204                                 new Type [] { typeof (int) },
3205                                 new ParameterModifier [0]);
3206                         Assert.IsNull (ctor, "#L11");
3207
3208                         ctor = redType.GetConstructor (flags, null,
3209                                 new Type [] { typeof (int), typeof (bool) },
3210                                 new ParameterModifier [0]);
3211                         Assert.IsNull (ctor, "#L12");
3212
3213                         ctor = redType.GetConstructor (flags, null,
3214                                 new Type [] { typeof (string), typeof (int) },
3215                                 new ParameterModifier [0]);
3216                         Assert.IsNull (ctor, "#L13");
3217
3218                         ctor = redType.GetConstructor (flags, null,
3219                                 Type.EmptyTypes,
3220                                 new ParameterModifier [0]);
3221                         Assert.IsNotNull (ctor, "#L14a");
3222                         Assert.IsTrue (ctor.IsPrivate, "#L14b");
3223                         Assert.IsTrue (ctor.IsStatic, "#L14c");
3224                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3225                         Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3226
3227                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3228                                 BindingFlags.Public;
3229
3230                         ctor = greenType.GetConstructor (flags, null,
3231                                 new Type [] { typeof (int), typeof (int) },
3232                                 new ParameterModifier [0]);
3233                         Assert.IsNull (ctor, "#M1");
3234
3235                         ctor = greenType.GetConstructor (flags, null,
3236                                 new Type [] { typeof (string) },
3237                                 new ParameterModifier [0]);
3238                         Assert.IsNull (ctor, "#M2");
3239
3240                         ctor = greenType.GetConstructor (flags, null,
3241                                 new Type [] { typeof (string), typeof (string) },
3242                                 new ParameterModifier [0]);
3243                         Assert.IsNull (ctor, "#M3");
3244
3245                         ctor = greenType.GetConstructor (flags, null,
3246                                 new Type [] { typeof (int) },
3247                                 new ParameterModifier [0]);
3248                         Assert.IsNull (ctor, "#M4");
3249
3250                         ctor = greenType.GetConstructor (flags, null,
3251                                 new Type [] { typeof (int), typeof (bool) },
3252                                 new ParameterModifier [0]);
3253                         Assert.IsNull (ctor, "#M5");
3254
3255                         ctor = greenType.GetConstructor (flags, null,
3256                                 new Type [] { typeof (string), typeof (int) },
3257                                 new ParameterModifier [0]);
3258                         Assert.IsNull (ctor, "#M6");
3259
3260                         ctor = greenType.GetConstructor (flags, null,
3261                                 Type.EmptyTypes,
3262                                 new ParameterModifier [0]);
3263                         Assert.IsNotNull (ctor, "#M7a");
3264                         Assert.IsTrue (ctor.IsPublic, "#M7b");
3265                         Assert.IsFalse (ctor.IsStatic, "#M7c");
3266                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3267                         Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3268
3269                         ctor = redType.GetConstructor (flags, null,
3270                                 new Type [] { typeof (int), typeof (int) },
3271                                 new ParameterModifier [0]);
3272                         Assert.IsNotNull (ctor, "#M8a");
3273                         Assert.IsTrue (ctor.IsPrivate, "#M8b");
3274                         Assert.IsFalse (ctor.IsStatic, "#M8c");
3275                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3276                         Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3277
3278                         ctor = redType.GetConstructor (flags, null,
3279                                 new Type [] { typeof (string) },
3280                                 new ParameterModifier [0]);
3281                         Assert.IsNotNull (ctor, "#M9a");
3282                         Assert.IsTrue (ctor.IsFamily, "#M9b");
3283                         Assert.IsFalse (ctor.IsStatic, "#M9c");
3284                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3285                         Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3286
3287                         ctor = redType.GetConstructor (flags, null,
3288                                 new Type [] { typeof (string), typeof (string) },
3289                                 new ParameterModifier [0]);
3290                         Assert.IsNotNull (ctor, "#M10a");
3291                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3292                         Assert.IsFalse (ctor.IsStatic, "#M10c");
3293                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3294                         Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3295
3296                         ctor = redType.GetConstructor (flags, null,
3297                                 new Type [] { typeof (int) },
3298                                 new ParameterModifier [0]);
3299                         Assert.IsNotNull (ctor, "#M11a");
3300                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3301                         Assert.IsFalse (ctor.IsStatic, "#M11c");
3302                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3303                         Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3304
3305                         ctor = redType.GetConstructor (flags, null,
3306                                 new Type [] { typeof (int), typeof (bool) },
3307                                 new ParameterModifier [0]);
3308                         Assert.IsNotNull (ctor, "#M12a");
3309                         Assert.IsTrue (ctor.IsPublic, "#M12b");
3310                         Assert.IsFalse (ctor.IsStatic, "#M12c");
3311                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3312                         Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3313
3314                         ctor = redType.GetConstructor (flags, null,
3315                                 new Type [] { typeof (string), typeof (int) },
3316                                 new ParameterModifier [0]);
3317                         Assert.IsNotNull (ctor, "#M13a");
3318                         Assert.IsTrue (ctor.IsAssembly, "#M13b");
3319                         Assert.IsFalse (ctor.IsStatic, "#M13c");
3320                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3321                         Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3322
3323                         ctor = redType.GetConstructor (flags, null,
3324                                 Type.EmptyTypes,
3325                                 new ParameterModifier [0]);
3326                         Assert.IsNull (ctor, "#M14");
3327
3328                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3329                                 BindingFlags.Public;
3330
3331                         ctor = greenType.GetConstructor (flags, null,
3332                                 new Type [] { typeof (int), typeof (int) },
3333                                 new ParameterModifier [0]);
3334                         Assert.IsNull (ctor, "#N1");
3335
3336                         ctor = greenType.GetConstructor (flags, null,
3337                                 new Type [] { typeof (string) },
3338                                 new ParameterModifier [0]);
3339                         Assert.IsNull (ctor, "#N2");
3340
3341                         ctor = greenType.GetConstructor (flags, null,
3342                                 new Type [] { typeof (string), typeof (string) },
3343                                 new ParameterModifier [0]);
3344                         Assert.IsNull (ctor, "#N3");
3345
3346                         ctor = greenType.GetConstructor (flags, null,
3347                                 new Type [] { typeof (int) },
3348                                 new ParameterModifier [0]);
3349                         Assert.IsNull (ctor, "#N4");
3350
3351                         ctor = greenType.GetConstructor (flags, null,
3352                                 new Type [] { typeof (int), typeof (bool) },
3353                                 new ParameterModifier [0]);
3354                         Assert.IsNull (ctor, "#N5");
3355
3356                         ctor = greenType.GetConstructor (flags, null,
3357                                 new Type [] { typeof (string), typeof (int) },
3358                                 new ParameterModifier [0]);
3359                         Assert.IsNull (ctor, "#N6");
3360
3361                         ctor = greenType.GetConstructor (flags, null,
3362                                 Type.EmptyTypes,
3363                                 new ParameterModifier [0]);
3364                         Assert.IsNull (ctor, "#N7");
3365
3366                         ctor = redType.GetConstructor (flags, null,
3367                                 new Type [] { typeof (int), typeof (int) },
3368                                 new ParameterModifier [0]);
3369                         Assert.IsNull (ctor, "#N8");
3370
3371                         ctor = redType.GetConstructor (flags, null,
3372                                 new Type [] { typeof (string) },
3373                                 new ParameterModifier [0]);
3374                         Assert.IsNull (ctor, "#N9");
3375
3376                         ctor = redType.GetConstructor (flags, null,
3377                                 new Type [] { typeof (string), typeof (string) },
3378                                 new ParameterModifier [0]);
3379                         Assert.IsNull (ctor, "#N10");
3380
3381                         ctor = redType.GetConstructor (flags, null,
3382                                 new Type [] { typeof (int) },
3383                                 new ParameterModifier [0]);
3384                         Assert.IsNull (ctor, "#N11");
3385
3386                         ctor = redType.GetConstructor (flags, null,
3387                                 new Type [] { typeof (int), typeof (bool) },
3388                                 new ParameterModifier [0]);
3389                         Assert.IsNull (ctor, "#N12");
3390
3391                         ctor = redType.GetConstructor (flags, null,
3392                                 new Type [] { typeof (string), typeof (int) },
3393                                 new ParameterModifier [0]);
3394                         Assert.IsNull (ctor, "#N13");
3395
3396                         ctor = redType.GetConstructor (flags, null,
3397                                 Type.EmptyTypes,
3398                                 new ParameterModifier [0]);
3399                         Assert.IsNotNull (ctor, "#N14a");
3400                         Assert.IsTrue (ctor.IsPrivate, "#N14b");
3401                         Assert.IsTrue (ctor.IsStatic, "#N14c");
3402                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3403                         Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3404                 }
3405
3406                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
3407                 public void GetConstructor2_Incomplete ()
3408                 {
3409                         TypeBuilder tb = module.DefineType (genTypeName ());
3410                         ConstructorBuilder cb = tb.DefineConstructor (
3411                                 MethodAttributes.Public,
3412                                 CallingConventions.Standard,
3413                                 Type.EmptyTypes);
3414                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3415
3416                         try {
3417                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3418                                         null, Type.EmptyTypes, new ParameterModifier [0]);
3419                                 Assert.Fail ("#1");
3420                         } catch (NotSupportedException ex) {
3421                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3422                                 Assert.IsNull (ex.InnerException, "#3");
3423                                 Assert.IsNotNull (ex.Message, "#4");
3424                         }
3425                 }
3426
3427                 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
3428                 public void GetConstructor3_Incomplete ()
3429                 {
3430                         TypeBuilder tb = module.DefineType (genTypeName ());
3431                         ConstructorBuilder cb = tb.DefineConstructor (
3432                                 MethodAttributes.Public,
3433                                 CallingConventions.Standard,
3434                                 Type.EmptyTypes);
3435                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3436
3437                         try {
3438                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3439                                         null, CallingConventions.Standard, Type.EmptyTypes,
3440                                         new ParameterModifier [0]);
3441                                 Assert.Fail ("#1");
3442                         } catch (NotSupportedException ex) {
3443                                 // The invoked member is not supported in a
3444                                 // dynamic module
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] // GetConstructors ()
3452                 [Category ("NotWorking")] // mcs depends on this
3453                 public void GetConstructors1_Incomplete ()
3454                 {
3455                         TypeBuilder tb = module.DefineType (genTypeName ());
3456                         ConstructorBuilder cb = tb.DefineConstructor (
3457                                 MethodAttributes.Public,
3458                                 CallingConventions.Standard,
3459                                 Type.EmptyTypes);
3460                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3461
3462                         try {
3463                                 tb.GetConstructors ();
3464                                 Assert.Fail ("#1");
3465                         } catch (NotSupportedException ex) {
3466                                 // The invoked member is not supported in a
3467                                 // dynamic module
3468                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3469                                 Assert.IsNull (ex.InnerException, "#3");
3470                                 Assert.IsNotNull (ex.Message, "#4");
3471                         }
3472                 }
3473
3474                 [Test] // GetConstructors (BindingFlags)
3475                 public void GetConstructors2_Complete ()
3476                 {
3477                         BindingFlags flags;
3478                         ConstructorInfo [] ctors;
3479
3480                         TypeBuilder redType = module.DefineType (genTypeName (),
3481                                 TypeAttributes.Public);
3482                         CreateMembers (redType, "Red", true);
3483
3484                         TypeBuilder greenType = module.DefineType (genTypeName (),
3485                                 TypeAttributes.Public, redType);
3486                         CreateMembers (greenType, "Green", false);
3487                         ConstructorBuilder cb = greenType.DefineConstructor (
3488                                 MethodAttributes.Public,
3489                                 CallingConventions.Standard,
3490                                 Type.EmptyTypes);
3491                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3492
3493                         redType.CreateType ();
3494                         greenType.CreateType ();
3495
3496                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3497
3498                         ctors = greenType.GetConstructors (flags);
3499                         Assert.AreEqual (0, ctors.Length, "#A1");
3500
3501                         ctors = redType.GetConstructors (flags);
3502                         Assert.AreEqual (5, ctors.Length, "#A2");
3503                         Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3504                         Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3505                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3506                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3507                         Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3508                         Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3509                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3510                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3511                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3512                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3513                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3514                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3515                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3516                         Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3517                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3518                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3519                         Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3520                         Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3521                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3522                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3523
3524                         flags = BindingFlags.Instance | BindingFlags.Public;
3525
3526                         ctors = greenType.GetConstructors (flags);
3527                         Assert.AreEqual (1, ctors.Length, "#B1");
3528                         Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3529                         Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3530                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3531                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3532
3533                         ctors = redType.GetConstructors (flags);
3534                         Assert.AreEqual (1, ctors.Length, "#B3");
3535                         Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3536                         Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3537                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3538                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3539
3540                         flags = BindingFlags.Static | BindingFlags.Public;
3541
3542                         ctors = greenType.GetConstructors (flags);
3543                         Assert.AreEqual (0, ctors.Length, "#C1");
3544
3545                         ctors = redType.GetConstructors (flags);
3546                         Assert.AreEqual (0, ctors.Length, "#C2");
3547
3548                         flags = BindingFlags.Static | BindingFlags.NonPublic;
3549
3550                         ctors = greenType.GetConstructors (flags);
3551                         Assert.AreEqual (0, ctors.Length, "#D1");
3552
3553                         ctors = redType.GetConstructors (flags);
3554                         Assert.AreEqual (1, ctors.Length, "#D2");
3555                         Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3556                         Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3557                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3558                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3559
3560                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3561                                 BindingFlags.FlattenHierarchy;
3562
3563                         ctors = greenType.GetConstructors (flags);
3564                         Assert.AreEqual (0, ctors.Length, "#E1");
3565
3566                         ctors = redType.GetConstructors (flags);
3567                         Assert.AreEqual (5, ctors.Length, "#E2");
3568                         Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3569                         Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3570                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3571                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3572                         Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3573                         Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3574                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3575                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3576                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3577                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3578                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3579                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3580                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3581                         Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3582                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3583                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3584                         Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3585                         Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3586                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3587                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3588
3589                         flags = BindingFlags.Instance | BindingFlags.Public |
3590                                 BindingFlags.FlattenHierarchy;
3591
3592                         ctors = greenType.GetConstructors (flags);
3593                         Assert.AreEqual (1, ctors.Length, "#F1");
3594                         Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3595                         Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3596                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3597                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3598
3599                         ctors = redType.GetConstructors (flags);
3600                         Assert.AreEqual (1, ctors.Length, "#F3");
3601                         Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3602                         Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3603                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3604                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3605
3606                         flags = BindingFlags.Static | BindingFlags.Public |
3607                                 BindingFlags.FlattenHierarchy;
3608
3609                         ctors = greenType.GetConstructors (flags);
3610                         Assert.AreEqual (0, ctors.Length, "#G1");
3611
3612                         ctors = redType.GetConstructors (flags);
3613                         Assert.AreEqual (0, ctors.Length, "#G2");
3614
3615                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3616                                 BindingFlags.FlattenHierarchy;
3617
3618                         ctors = greenType.GetConstructors (flags);
3619                         Assert.AreEqual (0, ctors.Length, "#H1");
3620
3621                         ctors = redType.GetConstructors (flags);
3622                         Assert.AreEqual (1, ctors.Length, "#H2");
3623                         Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3624                         Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3625                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3626                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3627
3628                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3629                                 BindingFlags.DeclaredOnly;
3630
3631                         ctors = greenType.GetConstructors (flags);
3632                         Assert.AreEqual (0, ctors.Length, "#I1");
3633
3634                         ctors = redType.GetConstructors (flags);
3635                         Assert.AreEqual (5, ctors.Length, "#I2");
3636                         Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3637                         Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3638                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3639                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3640                         Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3641                         Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3642                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3643                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3644                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3645                         Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3646                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3647                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3648                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3649                         Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3650                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3651                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3652                         Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3653                         Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3654                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3655                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3656
3657                         flags = BindingFlags.Instance | BindingFlags.Public |
3658                                 BindingFlags.DeclaredOnly;
3659
3660                         ctors = greenType.GetConstructors (flags);
3661                         Assert.AreEqual (1, ctors.Length, "#J1");
3662                         Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3663                         Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3664                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3665                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3666
3667                         ctors = redType.GetConstructors (flags);
3668                         Assert.AreEqual (1, ctors.Length, "#J3");
3669                         Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3670                         Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3671                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3672                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3673
3674                         flags = BindingFlags.Static | BindingFlags.Public |
3675                                 BindingFlags.DeclaredOnly;
3676
3677                         ctors = greenType.GetConstructors (flags);
3678                         Assert.AreEqual (0, ctors.Length, "#K1");
3679
3680                         ctors = redType.GetConstructors (flags);
3681                         Assert.AreEqual (0, ctors.Length, "#K2");
3682
3683                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3684                                 BindingFlags.DeclaredOnly;
3685
3686                         ctors = greenType.GetConstructors (flags);
3687                         Assert.AreEqual (0, ctors.Length, "#L1");
3688
3689                         ctors = redType.GetConstructors (flags);
3690                         Assert.AreEqual (1, ctors.Length, "#L2");
3691                         Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3692                         Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3693                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3694                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3695
3696                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3697                                 BindingFlags.Public;
3698
3699                         ctors = greenType.GetConstructors (flags);
3700                         Assert.AreEqual (1, ctors.Length, "#M1");
3701                         Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3702                         Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3703                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3704                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3705
3706                         ctors = redType.GetConstructors (flags);
3707                         Assert.AreEqual (6, ctors.Length, "#M3");
3708                         Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3709                         Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3710                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3711                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3712                         Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3713                         Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3714                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3715                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3716                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3717                         Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3718                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3719                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3720                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3721                         Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3722                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3723                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3724                         Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3725                         Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3726                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3727                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3728                         Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3729                         Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3730                         Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3731                         Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3732
3733                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3734                                 BindingFlags.Public;
3735
3736                         ctors = greenType.GetConstructors (flags);
3737                         Assert.AreEqual (0, ctors.Length, "#N1");
3738
3739                         ctors = redType.GetConstructors (flags);
3740                         Assert.AreEqual (1, ctors.Length, "#N2");
3741                         Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3742                         Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3743                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3744                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3745                 }
3746
3747                 [Test] // GetConstructors (BindingFlags)
3748                 [Category ("NotWorking")] // mcs depends on this
3749                 public void GetConstructors2_Incomplete ()
3750                 {
3751                         TypeBuilder tb = module.DefineType (genTypeName ());
3752                         ConstructorBuilder cb = tb.DefineConstructor (
3753                                 MethodAttributes.Public,
3754                                 CallingConventions.Standard,
3755                                 Type.EmptyTypes);
3756                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3757
3758                         try {
3759                                 tb.GetConstructors (BindingFlags.Public |
3760                                         BindingFlags.Instance);
3761                                 Assert.Fail ("#1");
3762                         } catch (NotSupportedException ex) {
3763                                 // The invoked member is not supported in a
3764                                 // dynamic module
3765                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3766                                 Assert.IsNull (ex.InnerException, "#3");
3767                                 Assert.IsNotNull (ex.Message, "#4");
3768                         }
3769                 }
3770
3771                 [Test]
3772                 public void TestGetCustomAttributesIncomplete ()
3773                 {
3774                         TypeBuilder tb = module.DefineType (genTypeName ());
3775                         try {
3776                                 tb.GetCustomAttributes (false);
3777                                 Assert.Fail ("#1");
3778                         } catch (NotSupportedException ex) {
3779                                 // The invoked member is not supported in a
3780                                 // dynamic module
3781                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3782                                 Assert.IsNull (ex.InnerException, "#3");
3783                                 Assert.IsNotNull (ex.Message, "#4");
3784                         }
3785                 }
3786
3787                 [Test]
3788                 public void TestGetCustomAttributesComplete ()
3789                 {
3790                         TypeBuilder tb = module.DefineType (genTypeName ());
3791
3792                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3793                                 new Type [] { typeof (string) });
3794
3795                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3796                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3797
3798                         tb.SetCustomAttribute (caBuilder);
3799                         tb.CreateType ();
3800
3801                         Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3802                 }
3803
3804                 [Test]
3805                 public void TestGetCustomAttributesOfTypeIncomplete ()
3806                 {
3807                         TypeBuilder tb = module.DefineType (genTypeName ());
3808                         try {
3809                                 tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3810                                 Assert.Fail ("#1");
3811                         } catch (NotSupportedException ex) {
3812                                 // The invoked member is not supported in a
3813                                 // dynamic module
3814                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3815                                 Assert.IsNull (ex.InnerException, "#3");
3816                                 Assert.IsNotNull (ex.Message, "#4");
3817                         }
3818                 }
3819
3820                 [Test]
3821                 public void TestGetCustomAttributesOfTypeComplete ()
3822                 {
3823                         TypeBuilder tb = module.DefineType (genTypeName ());
3824
3825                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3826                                 new Type [] { typeof (string) });
3827
3828                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3829                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3830
3831                         tb.SetCustomAttribute (caBuilder);
3832                         tb.CreateType ();
3833
3834                         Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3835                         Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3836                 }
3837
3838                 [Test]
3839                 public void TestGetCustomAttributesOfNullTypeComplete ()
3840                 {
3841                         TypeBuilder tb = module.DefineType (genTypeName ());
3842                         tb.CreateType ();
3843                         try {
3844                                 tb.GetCustomAttributes (null, false);
3845                                 Assert.Fail ("#1");
3846                         } catch (ArgumentNullException ex) {
3847                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3848                                 Assert.IsNull (ex.InnerException, "#3");
3849                                 Assert.IsNotNull (ex.Message, "#4");
3850                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3851                         }
3852                 }
3853
3854                 [Test]
3855                 [Ignore ("mcs depends on this")]
3856                 public void TestGetEventsIncomplete ()
3857                 {
3858                         TypeBuilder tb = module.DefineType (genTypeName ());
3859                         try {
3860                                 tb.GetEvents ();
3861                                 Assert.Fail ("#1");
3862                         } catch (NotSupportedException ex) {
3863                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3864                                 Assert.IsNull (ex.InnerException, "#3");
3865                                 Assert.IsNotNull (ex.Message, "#4");
3866                                 throw;
3867                         }
3868                 }
3869
3870                 [Test]
3871                 public void TestGetEventsComplete ()
3872                 {
3873                         TypeBuilder tb = module.DefineType (genTypeName ());
3874
3875                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3876                                 typeof (void), new Type [] { typeof (Object) });
3877                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3878
3879                         // create public event
3880                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3881                                 typeof (ResolveEventHandler));
3882                         eventbuilder.SetRaiseMethod (onclickMethod);
3883
3884                         Type emittedType = tb.CreateType ();
3885
3886                         Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3887                         Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3888                 }
3889
3890
3891                 [Test]
3892                 [Ignore ("mcs depends on this")]
3893                 public void TestGetEventsFlagsIncomplete ()
3894                 {
3895                         TypeBuilder tb = module.DefineType (genTypeName ());
3896                         try {
3897                                 tb.GetEvents (BindingFlags.Public);
3898                                 Assert.Fail ("#1");
3899                         } catch (NotSupportedException ex) {
3900                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3901                                 Assert.IsNull (ex.InnerException, "#3");
3902                                 Assert.IsNotNull (ex.Message, "#4");
3903                                 throw;
3904                         }
3905                 }
3906
3907                 [Test]
3908                 public void TestGetEventsFlagsComplete ()
3909                 {
3910                         TypeBuilder tb = module.DefineType (genTypeName ());
3911
3912                         MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3913                                 typeof (void), new Type [] { typeof (Object) });
3914                         onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3915
3916                         // create public event
3917                         EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3918                                 typeof (ResolveEventHandler));
3919                         changeEvent.SetRaiseMethod (onchangeMethod);
3920
3921                         // create non-public event
3922                         EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3923                                 typeof (ResolveEventHandler));
3924
3925                         Type emittedType = tb.CreateType ();
3926
3927                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3928                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3929                         Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3930                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
3931                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3932                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
3933                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3934                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
3935                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3936                 }
3937
3938                 [Test]
3939                 public void TestGetEventsFlagsComplete_Inheritance ()
3940                 {
3941                         EventInfo [] events;
3942                         BindingFlags flags;
3943
3944                         TypeBuilder blueType = module.DefineType (genTypeName (),
3945                                 TypeAttributes.Public);
3946                         CreateMembers (blueType, "Blue", false);
3947
3948                         TypeBuilder redType = module.DefineType (genTypeName (),
3949                                 TypeAttributes.Public, blueType);
3950                         CreateMembers (redType, "Red", false);
3951
3952                         TypeBuilder greenType = module.DefineType (genTypeName (),
3953                                 TypeAttributes.Public, redType);
3954                         CreateMembers (greenType, "Green", false);
3955
3956                         blueType.CreateType ();
3957                         redType.CreateType ();
3958                         greenType.CreateType ();
3959
3960                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3961                         events = greenType.GetEvents (flags);
3962
3963                         Assert.AreEqual (13, events.Length, "#A1");
3964                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
3965                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
3966                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
3967                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
3968                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
3969                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
3970                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
3971                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
3972                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
3973                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
3974                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
3975                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
3976                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
3977
3978                         flags = BindingFlags.Instance | BindingFlags.Public;
3979                         events = greenType.GetEvents (flags);
3980
3981                         Assert.AreEqual (3, events.Length, "#B1");
3982                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
3983                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
3984                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
3985
3986                         flags = BindingFlags.Static | BindingFlags.Public;
3987                         events = greenType.GetEvents (flags);
3988
3989                         Assert.AreEqual (1, events.Length, "#C1");
3990                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
3991
3992                         flags = BindingFlags.Static | BindingFlags.NonPublic;
3993                         events = greenType.GetEvents (flags);
3994
3995                         Assert.AreEqual (5, events.Length, "#D1");
3996                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
3997                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
3998                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
3999                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4000                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4001
4002                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4003                                 BindingFlags.FlattenHierarchy;
4004                         events = greenType.GetEvents (flags);
4005
4006                         Assert.AreEqual (13, events.Length, "#E1");
4007                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4008                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4009                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4010                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4011                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4012                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4013                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4014                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4015                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4016                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4017                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4018                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4019                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4020
4021                         flags = BindingFlags.Instance | BindingFlags.Public |
4022                                 BindingFlags.FlattenHierarchy;
4023                         events = greenType.GetEvents (flags);
4024
4025                         Assert.AreEqual (3, events.Length, "#F1");
4026                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4027                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4028                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4029
4030                         flags = BindingFlags.Static | BindingFlags.Public |
4031                                 BindingFlags.FlattenHierarchy;
4032                         events = greenType.GetEvents (flags);
4033
4034                         Assert.AreEqual (3, events.Length, "#G1");
4035                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4036                         Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4037                         Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4038
4039                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4040                                 BindingFlags.FlattenHierarchy;
4041                         events = greenType.GetEvents (flags);
4042
4043                         Assert.AreEqual (13, events.Length, "#H1");
4044                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4045                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4046                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4047                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4048                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4049                         Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4050                         Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4051                         Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4052                         Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4053                         Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4054                         Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4055                         Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4056                         Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4057
4058                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4059                                 BindingFlags.DeclaredOnly;
4060                         events = greenType.GetEvents (flags);
4061
4062                         Assert.AreEqual (5, events.Length, "#I1");
4063                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4064                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4065                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4066                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4067                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4068
4069                         flags = BindingFlags.Instance | BindingFlags.Public |
4070                                 BindingFlags.DeclaredOnly;
4071                         events = greenType.GetEvents (flags);
4072
4073                         Assert.AreEqual (1, events.Length, "#J1");
4074                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4075
4076                         flags = BindingFlags.Static | BindingFlags.Public |
4077                                 BindingFlags.DeclaredOnly;
4078                         events = greenType.GetEvents (flags);
4079
4080                         Assert.AreEqual (1, events.Length, "#K1");
4081                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4082
4083                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4084                                 BindingFlags.DeclaredOnly;
4085                         events = greenType.GetEvents (flags);
4086
4087                         Assert.AreEqual (5, events.Length, "#L1");
4088                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4089                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4090                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4091                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4092                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4093
4094                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4095                                 BindingFlags.Public;
4096                         events = greenType.GetEvents (flags);
4097
4098                         Assert.AreEqual (16, events.Length, "#M1");
4099                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4100                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4101                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4102                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4103                         Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4104                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4105                         Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4106                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4107                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4108                         Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4109                         Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4110                         Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4111                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4112                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4113                         Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4114                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4115
4116                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4117                                 BindingFlags.Public;
4118                         events = greenType.GetEvents (flags);
4119
4120                         Assert.AreEqual (6, events.Length, "#N1");
4121                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4122                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4123                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4124                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4125                         Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4126                         Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4127                 }
4128
4129                 [Test]
4130                 [Ignore ("mcs depends on this")]
4131                 public void TestGetEventIncomplete ()
4132                 {
4133                         TypeBuilder tb = module.DefineType (genTypeName ());
4134                         try {
4135                                 tb.GetEvent ("FOO");
4136                                 Assert.Fail ("#1");
4137                         } catch (NotSupportedException ex) {
4138                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4139                                 Assert.IsNull (ex.InnerException, "#3");
4140                                 Assert.IsNotNull (ex.Message, "#4");
4141                                 throw;
4142                         }
4143                 }
4144
4145                 [Test]
4146                 public void TestGetEventComplete ()
4147                 {
4148                         TypeBuilder tb = module.DefineType (genTypeName ());
4149
4150                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4151                                 typeof (void), new Type [] { typeof (Object) });
4152                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4153
4154                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4155                                 typeof (ResolveEventHandler));
4156                         eventbuilder.SetRaiseMethod (onclickMethod);
4157
4158                         Type emittedType = tb.CreateType ();
4159
4160                         Assert.IsNotNull (tb.GetEvent ("Change"));
4161                         Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4162                         Assert.IsNull (tb.GetEvent ("NotChange"));
4163                         Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4164                 }
4165
4166                 [Test]
4167                 [Ignore ("mcs depends on this")]
4168                 public void TestGetEventFlagsIncomplete ()
4169                 {
4170                         TypeBuilder tb = module.DefineType (genTypeName ());
4171                         try {
4172                                 tb.GetEvent ("FOO", BindingFlags.Public);
4173                                 Assert.Fail ("#1");
4174                         } catch (NotSupportedException ex) {
4175                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4176                                 Assert.IsNull (ex.InnerException, "#3");
4177                                 Assert.IsNotNull (ex.Message, "#4");
4178                                 throw;
4179                         }
4180                 }
4181
4182                 [Test]
4183                 public void TestGetEventFlagsComplete ()
4184                 {
4185                         TypeBuilder tb = module.DefineType (genTypeName ());
4186
4187                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4188                                 typeof (void), new Type [] { typeof (Object) });
4189                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4190
4191                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4192                                 typeof (ResolveEventHandler));
4193                         eventbuilder.SetRaiseMethod (onclickMethod);
4194
4195                         Type emittedType = tb.CreateType ();
4196
4197                         Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4198                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4199                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4200                         Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4201                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4202                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4203                 }
4204
4205                 [Test]
4206                 public void TestGetEventFlagsComplete_Inheritance ()
4207                 {
4208                         BindingFlags flags;
4209
4210                         TypeBuilder blueType = module.DefineType (genTypeName (),
4211                                 TypeAttributes.Public);
4212                         CreateMembers (blueType, "Blue", false);
4213
4214                         TypeBuilder redType = module.DefineType (genTypeName (),
4215                                 TypeAttributes.Public, blueType);
4216                         CreateMembers (redType, "Red", false);
4217
4218                         TypeBuilder greenType = module.DefineType (genTypeName (),
4219                                 TypeAttributes.Public, redType);
4220                         CreateMembers (greenType, "Green", false);
4221
4222                         blueType.CreateType ();
4223                         redType.CreateType ();
4224                         greenType.CreateType ();
4225
4226                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4227
4228                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4229                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4230                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4231                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4232                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4233                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4234                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4235                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4236                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4237                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4238                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4239                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4240                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4241                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4242                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4243                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4244                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4245                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4246                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4247                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4248                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4249                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4250                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4251                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4252                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4253                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4254                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4255                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4256                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4257                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4258                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4259                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4260                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4261                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4262                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4263                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4264
4265                         flags = BindingFlags.Instance | BindingFlags.Public;
4266
4267                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4268                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4269                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4270                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4271                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4272                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4273                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4274                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4275                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4276                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4277                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4278                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4279                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4280                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4281                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4282                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4283                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4284                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4285                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4286                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4287                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4288                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4289                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4290                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4291                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4292                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4293                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4294                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4295                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4296                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4297                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4298                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4299                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4300                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4301                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4302                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4303
4304                         flags = BindingFlags.Static | BindingFlags.Public;
4305
4306                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4307                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4308                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4309                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4310                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4311                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4312                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4313                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4314                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4315                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4316                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4317                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4318                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4319                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4320                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4321                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4322                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4323                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4324                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4325                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4326                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4327                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4328                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4329                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4330                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4331                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4332                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4333                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4334                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4335                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4336                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4337                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4338                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4339                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4340                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4341                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4342
4343                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4344
4345                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4346                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4347                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4348                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4349                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4350                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4351                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4352                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4353                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4354                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4355                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4356                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4357                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4358                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4359                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4360                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4361                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4362                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4363                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4364                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4365                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4366                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4367                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4368                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4369                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4370                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4371                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4372                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4373                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4374                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4375                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4376                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4377                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4378                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4379                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4380                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4381
4382                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4383                                 BindingFlags.FlattenHierarchy;
4384
4385                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4386                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4387                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4388                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4389                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4390                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4391                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4392                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4393                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4394                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4395                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4396                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4397                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4398                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4399                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4400                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4401                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4402                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4403                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4404                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4405                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4406                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4407                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4408                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4409                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4410                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4411                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4412                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4413                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4414                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4415                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4416                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4417                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4418                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4419                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4420                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4421
4422                         flags = BindingFlags.Instance | BindingFlags.Public |
4423                                 BindingFlags.FlattenHierarchy;
4424
4425                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4426                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4427                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4428                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4429                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4430                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4431                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4432                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4433                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4434                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4435                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4436                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4437                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4438                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4439                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4440                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4441                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4442                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4443                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4444                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4445                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4446                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4447                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4448                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4449                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4450                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4451                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4452                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4453                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4454                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4455                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4456                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4457                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4458                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4459                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4460                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4461
4462                         flags = BindingFlags.Static | BindingFlags.Public |
4463                                 BindingFlags.FlattenHierarchy;
4464
4465                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4466                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4467                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4468                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4469                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4470                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4471                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4472                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4473                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4474                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4475                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4476                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4477                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4478                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4479                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4480                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4481                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4482                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4483                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4484                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4485                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4486                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4487                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4488                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4489                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4490                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4491                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4492                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4493                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4494                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4495                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4496                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4497                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4498                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4499                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4500                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4501
4502                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4503                                 BindingFlags.FlattenHierarchy;
4504
4505                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4506                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4507                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4508                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4509                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4510                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4511                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4512                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4513                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4514                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4515                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4516                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4517                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4518                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4519                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4520                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4521                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4522                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4523                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4524                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4525                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4526                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4527                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4528                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4529                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4530                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4531                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4532                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4533                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4534                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4535                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4536                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4537                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4538                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4539                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4540                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4541
4542                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4543                                 BindingFlags.DeclaredOnly;
4544
4545                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4546                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4547                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4548                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4549                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4550                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4551                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4552                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4553                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4554                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4555                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4556                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4557                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4558                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4559                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4560                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4561                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4562                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4563                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4564                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4565                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4566                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4567                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4568                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4569                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4570                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4571                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4572                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4573                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4574                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4575                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4576                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4577                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4578                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4579                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4580                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4581
4582                         flags = BindingFlags.Instance | BindingFlags.Public |
4583                                 BindingFlags.DeclaredOnly;
4584
4585                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4586                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4587                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4588                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4589                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4590                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4591                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4592                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4593                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4594                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4595                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4596                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4597                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4598                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4599                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4600                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4601                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4602                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4603                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4604                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4605                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4606                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4607                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4608                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4609                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4610                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4611                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4612                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4613                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4614                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4615                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4616                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4617                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4618                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4619                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4620                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4621
4622                         flags = BindingFlags.Static | BindingFlags.Public |
4623                                 BindingFlags.DeclaredOnly;
4624
4625                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4626                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4627                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4628                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4629                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4630                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4631                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4632                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4633                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4634                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4635                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4636                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4637                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4638                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4639                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4640                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4641                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4642                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4643                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4644                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4645                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4646                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4647                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4648                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4649                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4650                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4651                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4652                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4653                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4654                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4655                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4656                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4657                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4658                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4659                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4660                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4661
4662                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4663                                 BindingFlags.DeclaredOnly;
4664
4665                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4666                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4667                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4668                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4669                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4670                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4671                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4672                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4673                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4674                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4675                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4676                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4677                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4678                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4679                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4680                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4681                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4682                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4683                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4684                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4685                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4686                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4687                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4688                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4689                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4690                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4691                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4692                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4693                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4694                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4695                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4696                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4697                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4698                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4699                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4700                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4701
4702                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4703                                 BindingFlags.Public;
4704
4705                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4706                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4707                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4708                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4709                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4710                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4711                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4712                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4713                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4714                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4715                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4716                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4717                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4718                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4719                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4720                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4721                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4722                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4723                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4724                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4725                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4726                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4727                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4728                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4729                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4730                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4731                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4732                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4733                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4734                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4735                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4736                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4737                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4738                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4739                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4740                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4741
4742                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4743                                 BindingFlags.Public;
4744
4745                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4746                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4747                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4748                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4749                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4750                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4751                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4752                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4753                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4754                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4755                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4756                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4757                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4758                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4759                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4760                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4761                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4762                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4763                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4764                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4765                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4766                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4767                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4768                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4769                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4770                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4771                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4772                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4773                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4774                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4775                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4776                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4777                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4778                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4779                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4780                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4781                 }
4782
4783                 [Test]
4784                 [Category ("NotWorking")] // mcs depends on this
4785                 public void TestGetFieldsIncomplete_MS ()
4786                 {
4787                         TypeBuilder tb = module.DefineType (genTypeName ());
4788                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4789                         try {
4790                                 tb.GetFields ();
4791                                 Assert.Fail ("#1");
4792                         } catch (NotSupportedException ex) {
4793                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4794                                 Assert.IsNull (ex.InnerException, "#3");
4795                                 Assert.IsNotNull (ex.Message, "#4");
4796                         }
4797                 }
4798
4799                 [Test]
4800                 [Category ("NotDotNet")] // mcs depends on this
4801                 public void TestGetFieldsIncomplete_Mono ()
4802                 {
4803                         TypeBuilder tb = module.DefineType (genTypeName ());
4804                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4805                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4806                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4807                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4808
4809                         FieldInfo [] fields = tb.GetFields ();
4810                         Assert.AreEqual (2, fields.Length, "#A1");
4811                         Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4812                         Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4813
4814                         tb = module.DefineType (genTypeName ());
4815                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4816                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4817                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4818                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4819                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4820                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4821
4822                         fields = tb.GetFields ();
4823                         Assert.AreEqual (4, fields.Length, "#B1");
4824                         Assert.AreEqual ("First", fields [0].Name, "#B2");
4825                         Assert.AreEqual ("Second", fields [1].Name, "#B3");
4826                         Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4827                         Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4828                 }
4829
4830                 [Test]
4831                 public void TestGetFieldsComplete ()
4832                 {
4833                         TypeBuilder tb = module.DefineType (genTypeName ());
4834                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4835
4836                         Type emittedType = tb.CreateType ();
4837                         FieldInfo [] dynamicFields = tb.GetFields ();
4838                         FieldInfo [] emittedFields = emittedType.GetFields ();
4839
4840                         Assert.AreEqual (1, dynamicFields.Length, "#A1");
4841                         Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4842                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4843                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4844
4845                         // bug #81638
4846                         object value = Activator.CreateInstance (emittedType);
4847                         emittedFields [0].SetValue (value, 5);
4848                         Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4849                         Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4850                         dynamicFields [0].SetValue (value, 4);
4851                         Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4852                         Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4853                 }
4854
4855                 [Test] // bug #82625 / 325292
4856                 public void TestGetFieldsComplete_Generic ()
4857                 {
4858                         // FIXME: merge this with TestGetFieldsComplete when
4859                         // bug #82625 is fixed
4860
4861                         TypeBuilder tb;
4862                         Type emittedType;
4863                         FieldInfo [] dynamicFields;
4864                         FieldInfo [] emittedFields;
4865
4866                         tb = module.DefineType (genTypeName ());
4867                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4868                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4869                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4870                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4871                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4872                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4873
4874                         emittedType = tb.CreateType ();
4875                         dynamicFields = tb.GetFields ();
4876                         emittedFields = emittedType.GetFields ();
4877
4878                         Assert.AreEqual (4, dynamicFields.Length, "#C1");
4879                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4880                         Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4881                         Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4882                         Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4883                         Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4884                         Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4885                         Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4886                         Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4887
4888                         Assert.AreEqual (4, emittedFields.Length, "#D1");
4889                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4890                         Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4891                         Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4892                         Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4893                         Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4894                         Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4895                         Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4896                         Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4897                 }
4898
4899                 [Test]
4900                 [Category ("NotWorking")] // mcs depends on this
4901                 public void TestGetFieldsFlagsIncomplete_MS ()
4902                 {
4903                         TypeBuilder tb = module.DefineType (genTypeName ());
4904                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4905                         try {
4906                                 tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4907                                 Assert.Fail ("#1");
4908                         } catch (NotSupportedException ex) {
4909                                 // The invoked member is not supported in a
4910                                 // dynamic module
4911                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4912                                 Assert.IsNull (ex.InnerException, "#3");
4913                                 Assert.IsNotNull (ex.Message, "#4");
4914                         }
4915                 }
4916
4917                 [Test]
4918                 [Category ("NotDotNet")] // mcs depends on this
4919                 public void TestGetFieldsFlagsIncomplete_Mono ()
4920                 {
4921                         FieldInfo [] fields;
4922
4923                         TypeBuilder tb = module.DefineType (genTypeName ());
4924                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4925                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4926                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4927                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4928
4929                         fields = tb.GetFields (BindingFlags.Public |
4930                                 BindingFlags.NonPublic | BindingFlags.Instance);
4931                         Assert.AreEqual (2, fields.Length, "#A1");
4932                         Assert.AreEqual ("name", fields [0].Name, "#A2");
4933                         Assert.AreEqual ("Sex", fields [1].Name, "#A3");
4934
4935                         fields = tb.GetFields (BindingFlags.Public |
4936                                 BindingFlags.Instance | BindingFlags.Static);
4937                         Assert.AreEqual (2, fields.Length, "#B1");
4938                         Assert.AreEqual ("Sex", fields [0].Name, "#B2");
4939                         Assert.AreEqual ("MALE", fields [1].Name, "#B3");
4940
4941                         fields = tb.GetFields (BindingFlags.Public |
4942                                 BindingFlags.NonPublic | BindingFlags.Instance |
4943                                 BindingFlags.Static);
4944                         Assert.AreEqual (4, fields.Length, "#C1");
4945                         Assert.AreEqual ("name", fields [0].Name, "#C2");
4946                         Assert.AreEqual ("Sex", fields [1].Name, "#C3");
4947                         Assert.AreEqual ("MALE", fields [2].Name, "#C4");
4948                         Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
4949                 }
4950
4951                 [Test]
4952                 public void TestGetFieldsFlagsComplete ()
4953                 {
4954                         TypeBuilder tb = module.DefineType (genTypeName ());
4955                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4956
4957                         Type emittedType = tb.CreateType ();
4958
4959                         Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4960                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
4961                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4962                         Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4963                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
4964                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4965                 }
4966
4967                 [Test]
4968                 public void TestGetFieldsFlagsComplete_Inheritance ()
4969                 {
4970                         FieldInfo [] fields;
4971                         BindingFlags flags;
4972
4973                         TypeBuilder blueType = module.DefineType (genTypeName (),
4974                                 TypeAttributes.Public);
4975                         CreateMembers (blueType, "Blue", false);
4976
4977                         TypeBuilder redType = module.DefineType (genTypeName (),
4978                                 TypeAttributes.Public, blueType);
4979                         CreateMembers (redType, "Red", false);
4980
4981                         TypeBuilder greenType = module.DefineType (genTypeName (),
4982                                 TypeAttributes.Public, redType);
4983                         CreateMembers (greenType, "Green", false);
4984
4985                         blueType.CreateType ();
4986                         redType.CreateType ();
4987                         greenType.CreateType ();
4988
4989                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4990                         fields = greenType.GetFields (flags);
4991
4992                         Assert.AreEqual (13, fields.Length, "#A1");
4993                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
4994                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
4995                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
4996                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
4997                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
4998                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
4999                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5000                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5001                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5002                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5003                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5004                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5005                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5006
5007                         flags = BindingFlags.Instance | BindingFlags.Public;
5008                         fields = greenType.GetFields (flags);
5009
5010                         Assert.AreEqual (3, fields.Length, "#B1");
5011                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5012                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5013                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5014
5015                         flags = BindingFlags.Static | BindingFlags.Public;
5016                         fields = greenType.GetFields (flags);
5017
5018                         Assert.AreEqual (1, fields.Length, "#C1");
5019                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5020
5021                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5022                         fields = greenType.GetFields (flags);
5023
5024                         Assert.AreEqual (5, fields.Length, "#D1");
5025                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5026                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5027                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5028                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5029                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5030
5031                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5032                                 BindingFlags.FlattenHierarchy;
5033                         fields = greenType.GetFields (flags);
5034
5035                         Assert.AreEqual (13, fields.Length, "#E1");
5036                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5037                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5038                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5039                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5040                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5041                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5042                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5043                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5044                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5045                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5046                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5047                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5048                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5049
5050                         flags = BindingFlags.Instance | BindingFlags.Public |
5051                                 BindingFlags.FlattenHierarchy;
5052                         fields = greenType.GetFields (flags);
5053
5054                         Assert.AreEqual (3, fields.Length, "#F1");
5055                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5056                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5057                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5058
5059                         flags = BindingFlags.Static | BindingFlags.Public |
5060                                 BindingFlags.FlattenHierarchy;
5061                         fields = greenType.GetFields (flags);
5062
5063                         Assert.AreEqual (3, fields.Length, "#G1");
5064                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5065                         Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5066                         Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5067
5068                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5069                                 BindingFlags.FlattenHierarchy;
5070                         fields = greenType.GetFields (flags);
5071
5072                         Assert.AreEqual (13, fields.Length, "#H1");
5073                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5074                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5075                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5076                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5077                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5078                         Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5079                         Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5080                         Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5081                         Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5082                         Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5083                         Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5084                         Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5085                         Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5086
5087                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5088                                 BindingFlags.DeclaredOnly;
5089                         fields = greenType.GetFields (flags);
5090
5091                         Assert.AreEqual (5, fields.Length, "#I1");
5092                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5093                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5094                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5095                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5096                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5097
5098                         flags = BindingFlags.Instance | BindingFlags.Public |
5099                                 BindingFlags.DeclaredOnly;
5100                         fields = greenType.GetFields (flags);
5101
5102                         Assert.AreEqual (1, fields.Length, "#J1");
5103                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5104
5105                         flags = BindingFlags.Static | BindingFlags.Public |
5106                                 BindingFlags.DeclaredOnly;
5107                         fields = greenType.GetFields (flags);
5108
5109                         Assert.AreEqual (1, fields.Length, "#K1");
5110                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5111
5112                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5113                                 BindingFlags.DeclaredOnly;
5114                         fields = greenType.GetFields (flags);
5115
5116                         Assert.AreEqual (5, fields.Length, "#L1");
5117                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5118                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5119                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5120                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5121                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5122
5123                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5124                                 BindingFlags.Public;
5125                         fields = greenType.GetFields (flags);
5126
5127                         Assert.AreEqual (16, fields.Length, "#M1");
5128                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5129                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5130                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5131                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5132                         Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5133                         Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5134                         Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5135                         Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5136                         Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5137                         Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5138                         Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5139                         Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5140                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5141                         Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5142                         Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5143                         Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5144
5145                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5146                                 BindingFlags.Public;
5147                         fields = greenType.GetFields (flags);
5148
5149                         Assert.AreEqual (6, fields.Length, "#N1");
5150                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5151                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5152                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5153                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5154                         Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5155                         Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5156                 }
5157
5158                 [Test]
5159                 [Category ("NotWorking")] // mcs depends on this
5160                 public void TestGetFieldIncomplete_MS ()
5161                 {
5162                         TypeBuilder tb = module.DefineType (genTypeName ());
5163                         tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5164                         try {
5165                                 tb.GetField ("test");
5166                                 Assert.Fail ("#1");
5167                         } catch (NotSupportedException ex) {
5168                                 // The invoked member is not supported in a
5169                                 // dynamic module
5170                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5171                                 Assert.IsNull (ex.InnerException, "#3");
5172                                 Assert.IsNotNull (ex.Message, "#4");
5173                         }
5174                 }
5175
5176                 [Test]
5177                 [Category ("NotDotNet")] // mcs depends on this
5178                 public void TestGetFieldIncomplete_Mono ()
5179                 {
5180                         TypeBuilder tb = module.DefineType (genTypeName ());
5181                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5182                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5183
5184                         FieldInfo field = tb.GetField ("TestField");
5185                         Assert.IsNotNull (field, "#A1");
5186                         Assert.AreEqual ("TestField", field.Name, "#A2");
5187                         Assert.IsTrue (field is FieldBuilder, "#A3");
5188
5189                         Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5190                         Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5191                 }
5192
5193                 [Test]
5194                 public void TestGetFieldComplete ()
5195                 {
5196                         TypeBuilder tb = module.DefineType (genTypeName ());
5197                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5198
5199                         Type emittedType = tb.CreateType ();
5200
5201                         FieldInfo dynamicField = tb.GetField ("TestField");
5202                         FieldInfo emittedField = emittedType.GetField ("TestField");
5203                         Assert.IsNotNull (dynamicField, "#A1");
5204                         Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5205                         Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5206                         Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5207                         Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5208
5209                         // bug #81638
5210                         object value = Activator.CreateInstance (emittedType);
5211                         emittedField.SetValue (value, 5);
5212                         Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5213                         Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5214                         dynamicField.SetValue (value, 4);
5215                         Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5216                         Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5217                 }
5218
5219                 [Test] // bug #81640
5220                 public void TestGetFieldComplete_Type ()
5221                 {
5222                         TypeBuilder tb = module.DefineType (genTypeName ());
5223                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5224                         Type emittedType = tb.CreateType ();
5225                         FieldInfo dynamicField = tb.GetField ("TestField");
5226                         Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5227
5228                         object value = Activator.CreateInstance (emittedType);
5229                         Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5230                 }
5231
5232                 [Test]
5233                 [Category ("NotWorking")] // mcs depends on this
5234                 public void TestGetFieldFlagsIncomplete_MS ()
5235                 {
5236                         TypeBuilder tb = module.DefineType (genTypeName ());
5237                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5238                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5239                         try {
5240                                 tb.GetField ("test", BindingFlags.Public);
5241                                 Assert.Fail ("#1");
5242                         } catch (NotSupportedException ex) {
5243                                 // The invoked member is not supported in a
5244                                 // dynamic module
5245                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5246                                 Assert.IsNull (ex.InnerException, "#3");
5247                                 Assert.IsNotNull (ex.Message, "#4");
5248                         }
5249                 }
5250
5251                 [Test]
5252                 [Category ("NotDotNet")] // mcs depends on this
5253                 public void TestGetFieldFlagsIncomplete_Mono ()
5254                 {
5255                         TypeBuilder tb = module.DefineType (genTypeName ());
5256                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5257                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5258
5259                         FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5260                                 | BindingFlags.Instance);
5261                         Assert.IsNotNull (field, "#A1");
5262                         Assert.AreEqual ("TestField", field.Name, "#A2");
5263                         Assert.IsTrue (field is FieldBuilder, "#A3");
5264
5265                         field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5266                                 BindingFlags.Instance);
5267                         Assert.IsNotNull (field, "#B1");
5268                         Assert.AreEqual ("OtherField", field.Name, "#B2");
5269                         Assert.IsTrue (field is FieldBuilder, "#B3");
5270
5271                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5272                                 BindingFlags.Instance), "#C1");
5273                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5274                                 BindingFlags.Static), "#C2");
5275                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5276                                 BindingFlags.Instance), "#C3");
5277                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5278                                 BindingFlags.Static), "#C4");
5279                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5280                                 BindingFlags.Instance), "#C5");
5281                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5282                                 BindingFlags.Instance), "#C6");
5283                 }
5284
5285                 [Test]
5286                 public void TestGetFieldFlagsComplete ()
5287                 {
5288                         TypeBuilder tb = module.DefineType (genTypeName ());
5289                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5290
5291                         Type emittedType = tb.CreateType ();
5292
5293                         Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5294                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5295                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5296                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5297                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5298                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5299                 }
5300
5301                 [Test]
5302                 public void TestGetFieldFlagsComplete_Inheritance ()
5303                 {
5304                         BindingFlags flags;
5305
5306                         TypeBuilder blueType = module.DefineType (genTypeName (),
5307                                 TypeAttributes.Public);
5308                         CreateMembers (blueType, "Blue", false);
5309
5310                         TypeBuilder redType = module.DefineType (genTypeName (),
5311                                 TypeAttributes.Public, blueType);
5312                         CreateMembers (redType, "Red", false);
5313
5314                         TypeBuilder greenType = module.DefineType (genTypeName (),
5315                                 TypeAttributes.Public, redType);
5316                         CreateMembers (greenType, "Green", false);
5317
5318                         blueType.CreateType ();
5319                         redType.CreateType ();
5320                         greenType.CreateType ();
5321
5322                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5323
5324                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5325                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5326                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5327                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5328                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5329                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5330                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5331                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5332                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5333                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5334                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5335                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5336                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5337                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5338                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5339                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5340                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5341                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5342                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5343                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5344                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5345                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5346                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5347                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5348                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5349                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5350                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5351                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5352                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5353                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5354                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5355                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5356                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5357                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5358                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5359                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5360
5361                         flags = BindingFlags.Instance | BindingFlags.Public;
5362
5363                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5364                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5365                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5366                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5367                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5368                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5369                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5370                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5371                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5372                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5373                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5374                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5375                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5376                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5377                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5378                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5379                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5380                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5381                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5382                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5383                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5384                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5385                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5386                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5387                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5388                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5389                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5390                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5391                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5392                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5393                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5394                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5395                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5396                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5397                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5398                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5399
5400                         flags = BindingFlags.Static | BindingFlags.Public;
5401
5402                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5403                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5404                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5405                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5406                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5407                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5408                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5409                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5410                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5411                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5412                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5413                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5414                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5415                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5416                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5417                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5418                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5419                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5420                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5421                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5422                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5423                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5424                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5425                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5426                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5427                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5428                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5429                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5430                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5431                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5432                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5433                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5434                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5435                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5436                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5437                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5438
5439                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5440
5441                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5442                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5443                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5444                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5445                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5446                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5447                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5448                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5449                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5450                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5451                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5452                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5453                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5454                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5455                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5456                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5457                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5458                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5459                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5460                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5461                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5462                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5463                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5464                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5465                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5466                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5467                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5468                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5469                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5470                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5471                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5472                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5473                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5474                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5475                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5476                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5477
5478                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5479                                 BindingFlags.FlattenHierarchy;
5480
5481                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5482                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5483                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5484                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5485                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5486                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5487                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5488                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5489                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5490                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5491                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5492                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5493                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5494                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5495                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5496                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5497                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5498                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5499                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5500                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5501                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5502                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5503                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5504                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5505                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5506                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5507                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5508                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5509                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5510                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5511                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5512                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5513                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5514                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5515                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5516                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5517
5518                         flags = BindingFlags.Instance | BindingFlags.Public |
5519                                 BindingFlags.FlattenHierarchy;
5520
5521                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5522                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5523                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5524                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5525                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5526                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5527                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5528                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5529                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5530                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5531                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5532                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5533                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5534                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5535                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5536                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5537                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5538                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5539                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5540                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5541                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5542                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5543                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5544                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5545                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5546                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5547                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5548                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5549                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5550                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5551                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5552                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5553                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5554                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5555                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5556                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5557
5558                         flags = BindingFlags.Static | BindingFlags.Public |
5559                                 BindingFlags.FlattenHierarchy;
5560
5561                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5562                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5563                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5564                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5565                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5566                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5567                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5568                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5569                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5570                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5571                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5572                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5573                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5574                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5575                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5576                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5577                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5578                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5579                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5580                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5581                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5582                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5583                         Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5584                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5585                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5586                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5587                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5588                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5589                         Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5590                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5591                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5592                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5593                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5594                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5595                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5596                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5597
5598                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5599                                 BindingFlags.FlattenHierarchy;
5600
5601                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5602                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5603                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5604                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5605                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5606                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5607                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5608                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5609                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5610                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5611                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5612                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5613                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5614                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5615                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5616                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5617                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5618                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5619                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5620                         Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5621                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5622                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5623                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5624                         Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5625                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5626                         Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5627                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5628                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5629                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5630                         Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5631                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5632                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5633                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5634                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5635                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5636                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5637
5638                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5639                                 BindingFlags.DeclaredOnly;
5640
5641                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5642                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5643                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5644                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5645                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5646                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5647                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5648                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5649                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5650                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5651                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5652                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5653                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5654                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5655                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5656                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5657                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5658                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5659                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5660                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5661                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5662                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5663                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5664                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5665                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5666                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5667                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5668                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5669                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5670                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5671                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5672                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5673                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5674                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5675                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5676                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5677
5678                         flags = BindingFlags.Instance | BindingFlags.Public |
5679                                 BindingFlags.DeclaredOnly;
5680
5681                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5682                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5683                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5684                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5685                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5686                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5687                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5688                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5689                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5690                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5691                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5692                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5693                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5694                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5695                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5696                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5697                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5698                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5699                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5700                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5701                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5702                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5703                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5704                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5705                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5706                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5707                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5708                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5709                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5710                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5711                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5712                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5713                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5714                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5715                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5716                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5717
5718                         flags = BindingFlags.Static | BindingFlags.Public |
5719                                 BindingFlags.DeclaredOnly;
5720
5721                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5722                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5723                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5724                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5725                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5726                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5727                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5728                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5729                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5730                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5731                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5732                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5733                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5734                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5735                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5736                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5737                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5738                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5739                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5740                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5741                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5742                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5743                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5744                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5745                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5746                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5747                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5748                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5749                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5750                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5751                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5752                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5753                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5754                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5755                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5756                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5757
5758                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5759                                 BindingFlags.DeclaredOnly;
5760
5761                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5762                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5763                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5764                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5765                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5766                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5767                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5768                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5769                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5770                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5771                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5772                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5773                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5774                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5775                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5776                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5777                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5778                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5779                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5780                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5781                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5782                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5783                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5784                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5785                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5786                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5787                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5788                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5789                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5790                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5791                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5792                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5793                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5794                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5795                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5796                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5797
5798                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5799                                 BindingFlags.Public;
5800
5801                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5802                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5803                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5804                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5805                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5806                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5807                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5808                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5809                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5810                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5811                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5812                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5813                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5814                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5815                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5816                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5817                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5818                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5819                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5820                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5821                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5822                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5823                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5824                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5825                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5826                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5827                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5828                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5829                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5830                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5831                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5832                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5833                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5834                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5835                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5836                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5837
5838                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5839                                 BindingFlags.Public;
5840
5841                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5842                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5843                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5844                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5845                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5846                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5847                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5848                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5849                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5850                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5851                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5852                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5853                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5854                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5855                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5856                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5857                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5858                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5859                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5860                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5861                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5862                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5863                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5864                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5865                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5866                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5867                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5868                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5869                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5870                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5871                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5872                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5873                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5874                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5875                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5876                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5877                 }
5878
5879                 [Test]
5880                 [Category ("NotDotNet")] // mcs depends on this
5881                 public void TestGetPropertiesIncomplete_Mono ()
5882                 {
5883                         TypeBuilder tb = module.DefineType (genTypeName ());
5884                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5885                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5886                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5887
5888                         PropertyInfo [] properties = tb.GetProperties ();
5889                         Assert.AreEqual (2, properties.Length, "#1");
5890                         Assert.AreEqual ("Name", properties [0].Name, "#2");
5891                         Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5892                 }
5893
5894                 [Test]
5895                 [Category ("NotWorking")] // mcs depends on this
5896                 public void TestGetPropertiesIncomplete_MS ()
5897                 {
5898                         TypeBuilder tb = module.DefineType (genTypeName ());
5899                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5900                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5901                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5902
5903                         try {
5904                                 tb.GetProperties ();
5905                                 Assert.Fail ("#1");
5906                         } catch (NotSupportedException ex) {
5907                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5908                                 Assert.IsNull (ex.InnerException, "#3");
5909                                 Assert.IsNotNull (ex.Message, "#4");
5910                         }
5911                 }
5912
5913                 [Test]
5914                 public void TestGetPropertiesComplete ()
5915                 {
5916                         TypeBuilder tb = module.DefineType (genTypeName ());
5917                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5918
5919                         Type emittedType = tb.CreateType ();
5920
5921                         Assert.AreEqual (1, tb.GetProperties ().Length);
5922                         Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
5923                 }
5924
5925                 [Test]
5926                 [Category ("NotDotNet")] // mcs depends on this
5927                 public void TestGetPropertiesFlagsIncomplete_Mono ()
5928                 {
5929                         PropertyInfo [] properties;
5930
5931                         TypeBuilder tb = module.DefineType (genTypeName ());
5932                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5933                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5934                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5935
5936                         properties = tb.GetProperties (BindingFlags.Public | 
5937                                 BindingFlags.NonPublic | BindingFlags.Instance);
5938                         Assert.AreEqual (3, properties.Length, "#A1");
5939                         Assert.AreEqual ("Name", properties [0].Name, "#A2");
5940                         Assert.AreEqual ("Income", properties [1].Name, "#A3");
5941                         Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
5942
5943                         properties = tb.GetProperties (BindingFlags.Public |
5944                                 BindingFlags.Instance);
5945                         Assert.AreEqual (2, properties.Length, "#B1");
5946                         Assert.AreEqual ("Name", properties [0].Name, "#B2");
5947                         Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
5948
5949                         properties = tb.GetProperties (BindingFlags.NonPublic |
5950                                 BindingFlags.Instance);
5951                         Assert.AreEqual (1, properties.Length, "#C1");
5952                         Assert.AreEqual ("Income", properties [0].Name, "#C2");
5953                 }
5954
5955                 [Test]
5956                 [Category ("NotWorking")] // mcs depends on this
5957                 public void TestGetPropertiesFlagsIncomplete_MS ()
5958                 {
5959                         TypeBuilder tb = module.DefineType (genTypeName ());
5960                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5961                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5962                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5963
5964                         try {
5965                                 tb.GetProperties (BindingFlags.Public);
5966                                 Assert.Fail ("#1");
5967                         } catch (NotSupportedException ex) {
5968                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5969                                 Assert.IsNull (ex.InnerException, "#3");
5970                                 Assert.IsNotNull (ex.Message, "#4");
5971                         }
5972                 }
5973
5974                 [Test]
5975                 public void TestGetPropertiesFlagsComplete ()
5976                 {
5977                         TypeBuilder tb = module.DefineType (genTypeName ());
5978                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5979
5980                         Type emittedType = tb.CreateType ();
5981
5982                         Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
5983                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
5984                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
5985                         Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5986                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
5987                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
5988                 }
5989
5990                 [Test]
5991                 public void TestGetPropertiesFlagsComplete_Inheritance ()
5992                 {
5993                         PropertyInfo [] props;
5994                         BindingFlags flags;
5995
5996                         TypeBuilder blueType = module.DefineType (genTypeName (),
5997                                 TypeAttributes.Public);
5998                         CreateMembers (blueType, "Blue", false);
5999
6000                         TypeBuilder redType = module.DefineType (genTypeName (),
6001                                 TypeAttributes.Public, blueType);
6002                         CreateMembers (redType, "Red", false);
6003
6004                         TypeBuilder greenType = module.DefineType (genTypeName (),
6005                                 TypeAttributes.Public, redType);
6006                         CreateMembers (greenType, "Green", false);
6007
6008                         blueType.CreateType ();
6009                         redType.CreateType ();
6010                         greenType.CreateType ();
6011
6012                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6013                         props = greenType.GetProperties (flags);
6014
6015                         Assert.AreEqual (13, props.Length, "#A1");
6016                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6017                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6018                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6019                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6020                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6021                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6022                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6023                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6024                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6025                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6026                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6027                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6028                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6029
6030                         flags = BindingFlags.Instance | BindingFlags.Public;
6031                         props = greenType.GetProperties (flags);
6032
6033                         Assert.AreEqual (3, props.Length, "#B1");
6034                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6035                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6036                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6037
6038                         flags = BindingFlags.Static | BindingFlags.Public;
6039                         props = greenType.GetProperties (flags);
6040
6041                         Assert.AreEqual (1, props.Length, "#C1");
6042                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6043
6044                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6045                         props = greenType.GetProperties (flags);
6046
6047                         Assert.AreEqual (5, props.Length, "#D1");
6048                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6049                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6050                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6051                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6052                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6053
6054                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6055                                 BindingFlags.FlattenHierarchy;
6056                         props = greenType.GetProperties (flags);
6057
6058                         Assert.AreEqual (13, props.Length, "#E1");
6059                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6060                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6061                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6062                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6063                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6064                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6065                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6066                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6067                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6068                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6069                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6070                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6071                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6072
6073                         flags = BindingFlags.Instance | BindingFlags.Public |
6074                                 BindingFlags.FlattenHierarchy;
6075                         props = greenType.GetProperties (flags);
6076
6077                         Assert.AreEqual (3, props.Length, "#F1");
6078                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6079                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6080                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6081
6082                         flags = BindingFlags.Static | BindingFlags.Public |
6083                                 BindingFlags.FlattenHierarchy;
6084                         props = greenType.GetProperties (flags);
6085
6086                         Assert.AreEqual (3, props.Length, "#G1");
6087                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6088                         Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6089                         Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6090
6091                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6092                                 BindingFlags.FlattenHierarchy;
6093                         props = greenType.GetProperties (flags);
6094
6095                         Assert.AreEqual (13, props.Length, "#H1");
6096                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6097                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6098                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6099                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6100                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6101                         Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6102                         Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6103                         Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6104                         Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6105                         Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6106                         Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6107                         Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6108                         Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6109
6110                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6111                                 BindingFlags.DeclaredOnly;
6112                         props = greenType.GetProperties (flags);
6113
6114                         Assert.AreEqual (5, props.Length, "#I1");
6115                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6116                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6117                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6118                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6119                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6120
6121                         flags = BindingFlags.Instance | BindingFlags.Public |
6122                                 BindingFlags.DeclaredOnly;
6123                         props = greenType.GetProperties (flags);
6124
6125                         Assert.AreEqual (1, props.Length, "#J1");
6126                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6127
6128                         flags = BindingFlags.Static | BindingFlags.Public |
6129                                 BindingFlags.DeclaredOnly;
6130                         props = greenType.GetProperties (flags);
6131
6132                         Assert.AreEqual (1, props.Length, "#K1");
6133                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6134
6135                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6136                                 BindingFlags.DeclaredOnly;
6137                         props = greenType.GetProperties (flags);
6138
6139                         Assert.AreEqual (5, props.Length, "#L1");
6140                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6141                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6142                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6143                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6144                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6145
6146                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6147                                 BindingFlags.Public;
6148                         props = greenType.GetProperties (flags);
6149
6150                         Assert.AreEqual (16, props.Length, "#M1");
6151                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6152                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6153                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6154                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6155                         Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6156                         Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6157                         Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6158                         Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6159                         Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6160                         Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6161                         Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6162                         Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6163                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6164                         Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6165                         Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6166                         Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6167
6168                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6169                                 BindingFlags.Public;
6170                         props = greenType.GetProperties (flags);
6171
6172                         Assert.AreEqual (6, props.Length, "#N1");
6173                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6174                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6175                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6176                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6177                         Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6178                         Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6179                 }
6180
6181                 [Test]
6182                 public void TestGetPropertyIncomplete ()
6183                 {
6184                         TypeBuilder tb = module.DefineType (genTypeName ());
6185                         try {
6186                                 tb.GetProperty ("test");
6187                                 Assert.Fail ("#1");
6188                         } catch (NotSupportedException ex) {
6189                                 // The invoked member is not supported in a
6190                                 // dynamic module
6191                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6192                                 Assert.IsNull (ex.InnerException, "#3");
6193                                 Assert.IsNotNull (ex.Message, "#4");
6194                         }
6195                 }
6196
6197                 [Test]
6198                 public void TestGetPropertyComplete ()
6199                 {
6200                         TypeBuilder tb = module.DefineType (genTypeName ());
6201                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6202
6203                         Type emittedType = tb.CreateType ();
6204
6205                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6206                         Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6207
6208                         try {
6209                                 tb.GetProperty ("CustomerName");
6210                                 Assert.Fail ("#1");
6211                         } catch (NotSupportedException ex) {
6212                                 // The invoked member is not supported in a
6213                                 // dynamic module
6214                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6215                                 Assert.IsNull (ex.InnerException, "#3");
6216                                 Assert.IsNotNull (ex.Message, "#4");
6217                         }
6218                 }
6219
6220                 [Test]
6221                 public void TestGetPropertyFlagsIncomplete ()
6222                 {
6223                         TypeBuilder tb = module.DefineType (genTypeName ());
6224                         try {
6225                                 tb.GetProperty ("test", BindingFlags.Public);
6226                                 Assert.Fail ("#1");
6227                         } catch (NotSupportedException ex) {
6228                                 // The invoked member is not supported in a
6229                                 // dynamic module
6230                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6231                                 Assert.IsNull (ex.InnerException, "#3");
6232                                 Assert.IsNotNull (ex.Message, "#4");
6233                         }
6234                 }
6235
6236                 [Test]
6237                 public void TestGetPropertyFlagsComplete ()
6238                 {
6239                         TypeBuilder tb = module.DefineType (genTypeName ());
6240                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6241
6242                         Type emittedType = tb.CreateType ();
6243
6244                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6245                                 BindingFlags.Public));
6246                         Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6247                                 BindingFlags.NonPublic));
6248
6249                         try {
6250                                 tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6251                                 Assert.Fail ("#1");
6252                         } catch (NotSupportedException ex) {
6253                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6254                                 Assert.IsNull (ex.InnerException, "#3");
6255                                 Assert.IsNotNull (ex.Message, "#4");
6256                         }
6257                 }
6258
6259                 [Test]
6260                 public void TestGetMethodFlagsComplete ()
6261                 {
6262                         BindingFlags flags;
6263
6264                         TypeBuilder blueType = module.DefineType (genTypeName (),
6265                                 TypeAttributes.Public);
6266                         CreateMembers (blueType, "Blue", false);
6267
6268                         TypeBuilder redType = module.DefineType (genTypeName (),
6269                                 TypeAttributes.Public, blueType);
6270                         CreateMembers (redType, "Red", false);
6271
6272                         TypeBuilder greenType = module.DefineType (genTypeName (),
6273                                 TypeAttributes.Public, redType);
6274                         CreateMembers (greenType, "Green", false);
6275
6276                         blueType.CreateType ();
6277                         redType.CreateType ();
6278                         greenType.CreateType ();
6279
6280                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6281
6282                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6283                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6284                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6285                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6286                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6287                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6288                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6289                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6290                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6291                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6292                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6293                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6294                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6295                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6296                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6297                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6298                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6299                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6300                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6301                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6302                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6303                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6304                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6305                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6306                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6307                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6308                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6309                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6310                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6311                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6312                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6313                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6314                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6315                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6316                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6317                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6318
6319                         flags = BindingFlags.Instance | BindingFlags.Public;
6320
6321                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6322                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6323                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6324                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6325                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6326                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6327                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6328                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6329                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6330                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6331                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6332                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6333                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6334                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6335                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6336                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6337                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6338                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6339                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6340                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6341                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6342                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6343                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6344                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6345                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6346                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6347                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6348                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6349                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6350                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6351                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6352                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6353                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6354                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6355                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6356                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6357
6358                         flags = BindingFlags.Static | BindingFlags.Public;
6359
6360                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6361                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6362                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6363                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6364                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6365                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6366                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6367                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6368                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6369                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6370                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6371                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6372                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6373                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6374                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6375                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6376                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6377                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6378                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6379                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6380                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6381                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6382                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6383                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6384                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6385                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6386                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6387                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6388                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6389                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6390                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6391                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6392                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6393                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6394                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6395                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6396
6397                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6398
6399                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6400                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6401                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6402                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6403                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6404                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6405                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6406                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6407                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6408                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6409                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6410                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6411                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6412                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6413                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6414                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6415                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6416                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6417                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6418                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6419                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6420                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6421                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6422                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6423                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6424                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6425                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6426                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6427                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6428                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6429                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6430                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6431                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6432                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6433                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6434                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6435
6436                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6437                                 BindingFlags.FlattenHierarchy;
6438
6439                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6440                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6441                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6442                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6443                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6444                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6445                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6446                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6447                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6448                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6449                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6450                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6451                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6452                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6453                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6454                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6455                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6456                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6457                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6458                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6459                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6460                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6461                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6462                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6463                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6464                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6465                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6466                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6467                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6468                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6469                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6470                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6471                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6472                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6473                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6474                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6475
6476                         flags = BindingFlags.Instance | BindingFlags.Public |
6477                                 BindingFlags.FlattenHierarchy;
6478
6479                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6480                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6481                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6482                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6483                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6484                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6485                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6486                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6487                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6488                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6489                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6490                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6491                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6492                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6493                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6494                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6495                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6496                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6497                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6498                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6499                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6500                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6501                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6502                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6503                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6504                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6505                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6506                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6507                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6508                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6509                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6510                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6511                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6512                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6513                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6514                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6515
6516                         flags = BindingFlags.Static | BindingFlags.Public |
6517                                 BindingFlags.FlattenHierarchy;
6518
6519                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6520                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6521                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6522                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6523                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6524                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6525                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6526                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6527                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6528                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6529                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6530                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6531                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6532                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6533                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6534                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6535                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6536                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6537                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6538                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6539                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6540                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6541                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6542                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6543                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6544                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6545                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6546                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6547                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6548                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6549                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6550                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6551                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6552                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6553                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6554                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6555
6556                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6557                                 BindingFlags.FlattenHierarchy;
6558
6559                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6560                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6561                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6562                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6563                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6564                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6565                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6566                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6567                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6568                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6569                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6570                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6571                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6572                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6573                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6574                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6575                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6576                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6577                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6578                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6579                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6580                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6581                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6582                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6583                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6584                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6585                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6586                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6587                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6588                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6589                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6590                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6591                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6592                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6593                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6594                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6595
6596                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6597                                 BindingFlags.DeclaredOnly;
6598
6599                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6600                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6601                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6602                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6603                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6604                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6605                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6606                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6607                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6608                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6609                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6610                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6611                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6612                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6613                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6614                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6615                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6616                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6617                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6618                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6619                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6620                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6621                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6622                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6623                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6624                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6625                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6626                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6627                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6628                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6629                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6630                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6631                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6632                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6633                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6634                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6635
6636                         flags = BindingFlags.Instance | BindingFlags.Public |
6637                                 BindingFlags.DeclaredOnly;
6638
6639                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6640                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6641                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6642                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6643                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6644                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6645                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6646                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6647                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6648                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6649                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6650                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6651                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6652                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6653                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6654                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6655                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6656                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6657                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6658                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6659                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6660                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6661                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6662                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6663                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6664                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6665                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6666                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6667                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6668                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6669                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6670                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6671                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6672                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6673                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6674                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6675
6676                         flags = BindingFlags.Static | BindingFlags.Public |
6677                                 BindingFlags.DeclaredOnly;
6678
6679                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6680                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6681                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6682                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6683                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6684                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6685                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6686                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6687                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6688                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6689                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6690                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6691                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6692                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6693                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6694                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6695                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6696                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6697                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6698                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6699                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6700                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6701                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6702                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6703                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6704                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6705                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6706                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6707                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6708                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6709                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6710                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6711                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6712                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6713                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6714                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6715
6716                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6717                                 BindingFlags.DeclaredOnly;
6718
6719                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6720                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6721                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6722                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6723                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6724                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6725                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6726                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6727                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6728                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6729                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6730                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6731                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6732                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6733                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6734                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6735                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6736                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6737                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6738                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6739                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6740                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6741                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6742                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6743                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6744                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6745                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6746                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6747                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6748                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6749                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6750                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6751                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6752                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6753                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6754                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6755
6756                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6757                                 BindingFlags.Public;
6758
6759                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6760                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6761                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6762                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6763                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6764                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6765                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6766                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6767                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6768                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6769                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6770                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6771                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6772                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6773                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6774                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6775                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6776                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6777                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6778                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6779                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6780                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6781                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6782                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6783                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6784                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6785                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6786                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6787                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6788                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6789                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6790                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6791                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6792                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6793                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6794                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6795
6796                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6797                                 BindingFlags.Public;
6798
6799                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6800                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6801                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6802                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6803                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6804                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6805                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6806                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6807                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6808                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6809                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6810                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6811                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6812                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6813                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6814                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6815                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6816                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6817                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6818                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6819                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6820                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6821                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6822                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6823                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6824                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6825                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6826                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6827                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6828                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6829                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6830                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6831                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6832                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6833                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6834                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6835                 }
6836
6837                 [Test]
6838                 [Category ("NotDotNet")] // mcs depends on this
6839                 public void TestGetMethodsIncomplete_Mono ()
6840                 {
6841                         MethodBuilder mb;
6842                         ILGenerator ilgen;
6843
6844                         TypeBuilder tb = module.DefineType (genTypeName (),
6845                                 TypeAttributes.Abstract);
6846                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6847                                 typeof (void), Type.EmptyTypes);
6848                         ilgen = mb.GetILGenerator ();
6849                         ilgen.Emit (OpCodes.Ret);
6850
6851                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6852                                 typeof (void), Type.EmptyTypes);
6853                         ilgen = mb.GetILGenerator ();
6854                         ilgen.Emit (OpCodes.Ret);
6855
6856                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6857                                 MethodAttributes.Static,
6858                                 typeof (void), Type.EmptyTypes);
6859                         ilgen = mb.GetILGenerator ();
6860                         ilgen.Emit (OpCodes.Ret);
6861
6862                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6863                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6864                                 typeof (void), Type.EmptyTypes);
6865
6866                         MethodInfo [] methods = tb.GetMethods ();
6867                         Assert.AreEqual (7, methods.Length, "#A");
6868
6869                         Assert.AreEqual ("Equals", methods [0].Name, "#B1");
6870                         Assert.IsFalse (methods [0].IsStatic, "#B2");
6871                         Assert.IsFalse (methods [0].IsAbstract, "#B3");
6872
6873                         Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
6874                         Assert.IsFalse (methods [1].IsStatic, "#C2");
6875                         Assert.IsFalse (methods [1].IsAbstract, "#C3");
6876
6877                         Assert.AreEqual ("GetType", methods [2].Name, "#D1");
6878                         Assert.IsFalse (methods [2].IsStatic, "#D2");
6879                         Assert.IsFalse (methods [2].IsAbstract, "#D3");
6880
6881                         Assert.AreEqual ("ToString", methods [3].Name, "#E1");
6882                         Assert.IsFalse (methods [3].IsStatic, "#E2");
6883                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
6884
6885                         Assert.AreEqual ("Hello", methods [4].Name, "#F1");
6886                         Assert.IsFalse (methods [4].IsStatic, "#F2");
6887                         Assert.IsFalse (methods [4].IsAbstract, "#F3");
6888
6889                         Assert.AreEqual ("Execute", methods [5].Name, "#G1");
6890                         Assert.IsTrue (methods [5].IsStatic, "#G2");
6891                         Assert.IsFalse (methods [5].IsAbstract, "#G3");
6892
6893                         Assert.AreEqual ("Init", methods [6].Name, "#H1");
6894                         Assert.IsFalse (methods [6].IsStatic, "#H2");
6895                         Assert.IsTrue (methods [6].IsAbstract, "#H3");
6896                 }
6897
6898                 [Test]
6899                 [Category ("NotWorking")] // mcs depends on this
6900                 public void TestGetMethodsIncomplete_MS ()
6901                 {
6902                         MethodBuilder mb;
6903                         ILGenerator ilgen;
6904
6905                         TypeBuilder tb = module.DefineType (genTypeName (),
6906                                 TypeAttributes.Abstract);
6907                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6908                                 typeof (void), Type.EmptyTypes);
6909                         ilgen = mb.GetILGenerator ();
6910                         ilgen.Emit (OpCodes.Ret);
6911
6912                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6913                                 typeof (void), Type.EmptyTypes);
6914                         ilgen = mb.GetILGenerator ();
6915                         ilgen.Emit (OpCodes.Ret);
6916
6917                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6918                                 MethodAttributes.Static,
6919                                 typeof (void), Type.EmptyTypes);
6920                         ilgen = mb.GetILGenerator ();
6921                         ilgen.Emit (OpCodes.Ret);
6922
6923                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6924                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6925                                 typeof (void), Type.EmptyTypes);
6926
6927                         try {
6928                                 tb.GetMethods ();
6929                                 Assert.Fail ("#1");
6930                         } catch (NotSupportedException ex) {
6931                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6932                                 Assert.IsNull (ex.InnerException, "#3");
6933                                 Assert.IsNotNull (ex.Message, "#4");
6934                         }
6935                 }
6936
6937                 [Test]
6938                 public void TestGetMethodsComplete ()
6939                 {
6940                         MethodBuilder mb;
6941                         ILGenerator ilgen;
6942                         MethodInfo mi;
6943
6944                         TypeBuilder tb = module.DefineType (genTypeName (),
6945                                 TypeAttributes.Abstract);
6946                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6947                                 typeof (string), Type.EmptyTypes);
6948                         ilgen = mb.GetILGenerator ();
6949                         ilgen.Emit (OpCodes.Ldstr, "Hi! ");
6950                         ilgen.Emit (OpCodes.Ldarg_1);
6951                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
6952                                 new Type [] { typeof (string), typeof (string) });
6953                         ilgen.Emit (OpCodes.Call, infoMethod);
6954                         ilgen.Emit (OpCodes.Ret);
6955
6956                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6957                                 typeof (void), Type.EmptyTypes);
6958                         ilgen = mb.GetILGenerator ();
6959                         ilgen.Emit (OpCodes.Ret);
6960
6961                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6962                                 MethodAttributes.Static,
6963                                 typeof (void), Type.EmptyTypes);
6964                         ilgen = mb.GetILGenerator ();
6965                         ilgen.Emit (OpCodes.Ret);
6966
6967                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6968                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6969                                 typeof (void), Type.EmptyTypes);
6970
6971                         Type emittedType = tb.CreateType ();
6972
6973                         MethodInfo [] methods = emittedType.GetMethods ();
6974                         Assert.AreEqual (7, methods.Length, "#A1");
6975                         Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
6976
6977                         mi = GetMethodByName (methods, "Hello");
6978                         Assert.IsNotNull (mi, "#B1");
6979                         Assert.IsFalse (mi.IsStatic, "#B2");
6980                         Assert.IsFalse (mi.IsAbstract, "#B3");
6981
6982                         mi = GetMethodByName (methods, "Execute");
6983                         Assert.IsNotNull (mi, "#C1");
6984                         Assert.IsTrue (mi.IsStatic, "#C2");
6985                         Assert.IsFalse (mi.IsAbstract, "#C3");
6986
6987                         mi = GetMethodByName (methods, "Init");
6988                         Assert.IsNotNull (mi, "#D1");
6989                         Assert.IsFalse (mi.IsStatic, "#D2");
6990                         Assert.IsTrue (mi.IsAbstract, "#D3");
6991
6992                         mi = GetMethodByName (methods, "GetType");
6993                         Assert.IsNotNull (mi, "#E1");
6994                         Assert.IsFalse (methods [3].IsStatic, "#E2");
6995                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
6996
6997                         mi = GetMethodByName (methods, "ToString");
6998                         Assert.IsNotNull (mi, "#F1");
6999                         Assert.IsFalse (mi.IsStatic, "#F2");
7000                         Assert.IsFalse (mi.IsAbstract, "#F3");
7001
7002                         mi = GetMethodByName (methods, "Equals");
7003                         Assert.IsNotNull (mi, "#G1");
7004                         Assert.IsFalse (mi.IsStatic, "#G2");
7005                         Assert.IsFalse (mi.IsAbstract, "#G3");
7006
7007                         mi = GetMethodByName (methods, "GetHashCode");
7008                         Assert.IsNotNull (mi, "#H1");
7009                         Assert.IsFalse (mi.IsStatic, "#H2");
7010                         Assert.IsFalse (mi.IsAbstract, "#H3");
7011                 }
7012
7013                 [Test]
7014                 [Category ("NotDotNet")] // mcs depends on this
7015                 public void TestGetMethodsFlagsIncomplete_Inheritance ()
7016                 {
7017                         MethodInfo [] methods;
7018                         BindingFlags flags;
7019
7020                         TypeBuilder blueType = module.DefineType (genTypeName (),
7021                                 TypeAttributes.Public);
7022                         CreateMembers (blueType, "Blue", false);
7023
7024                         TypeBuilder redType = module.DefineType (genTypeName (),
7025                                 TypeAttributes.Public, blueType);
7026                         CreateMembers (redType, "Red", false);
7027
7028                         TypeBuilder greenType = module.DefineType (genTypeName (),
7029                                 TypeAttributes.Public, redType);
7030                         CreateMembers (greenType, "Green", false);
7031
7032                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7033                         methods = greenType.GetMethods (flags);
7034
7035                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7036                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7037                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7038                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7039                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7040                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7041                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7042                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7043                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7044                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7045                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7046                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7047                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7048                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7049                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7050                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7051                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7052                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7053                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7054                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7055                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7056                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7057                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7058                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7059                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7060                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7061                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7062                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7063                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7064                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7065                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7066                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7067                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7068                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7069                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7070                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7071
7072                         flags = BindingFlags.Instance | BindingFlags.Public;
7073                         methods = greenType.GetMethods (flags);
7074
7075                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7076                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7077                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7078                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7079                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7080                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7081                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7082                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7083                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7084                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7085                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7086                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7087                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7088                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7089                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7090                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7091                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7092                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7093                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7094                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7095                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7096                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7097                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7098                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7099                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7100                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7101                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7102                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7103                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7104                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7105                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7106                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7107                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7108                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7109                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7110                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7111
7112                         flags = BindingFlags.Static | BindingFlags.Public;
7113                         methods = greenType.GetMethods (flags);
7114
7115                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7116                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7117                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7118                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7119                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7120                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7121                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7122                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7123                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7124                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7125                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7126                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7127                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7128                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7129                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7130                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7131                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7132                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7133                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7134                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7135                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7136                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7137                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7138                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7139                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7140                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7141                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7142                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7143                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7144                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7145                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7146                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7147                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7148                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7149                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7150                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7151
7152                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7153                         methods = greenType.GetMethods (flags);
7154
7155                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7156                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7157                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7158                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7159                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7160                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7161                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7162                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7163                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7164                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7165                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7166                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7167                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7168                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7169                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7170                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7171                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7172                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7173                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7174                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7175                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7176                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7177                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7178                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7179                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7180                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7181                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7182                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7183                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7184                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7185                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7186                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7187                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7188                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7189                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7190                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7191
7192                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7193                                 BindingFlags.FlattenHierarchy;
7194                         methods = greenType.GetMethods (flags);
7195
7196                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7197                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7198                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7199                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7200                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7201                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7202                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7203                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7204                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7205                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7206                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7207                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7208                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7209                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7210                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7211                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7212                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7213                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7214                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7215                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7216                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7217                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7218                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7219                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7220                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7221                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7222                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7223                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7224                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7225                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7226                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7227                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7228                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7229                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7230                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7231                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7232
7233                         flags = BindingFlags.Instance | BindingFlags.Public |
7234                                 BindingFlags.FlattenHierarchy;
7235                         methods = greenType.GetMethods (flags);
7236
7237                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7238                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7239                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7240                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7241                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7242                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7243                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7244                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7245                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7246                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7247                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7248                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7249                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7250                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7251                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7252                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7253                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7254                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7255                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7256                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7257                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7258                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7259                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7260                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7261                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7262                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7263                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7264                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7265                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7266                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7267                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7268                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7269                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7270                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7271                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7272                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7273
7274                         flags = BindingFlags.Static | BindingFlags.Public |
7275                                 BindingFlags.FlattenHierarchy;
7276                         methods = greenType.GetMethods (flags);
7277
7278                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7279                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7280                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7281                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7282                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7283                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7284                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7285                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7286                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7287                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7288                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7289                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7290                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7291                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7292                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7293                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7294                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7295                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7296                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7297                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7298                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7299                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7300                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7301                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7302                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7303                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7304                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7305                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7306                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7307                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7308                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7309                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7310                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7311                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7312                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7313                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7314
7315                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7316                                 BindingFlags.FlattenHierarchy;
7317                         methods = greenType.GetMethods (flags);
7318
7319                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7320                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7321                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7322                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7323                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7324                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7325                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7326                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7327                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7328                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7329                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7330                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7331                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7332                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7333                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7334                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7335                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7336                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7337                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7338                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7339                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7340                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7341                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7342                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7343                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7344                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7345                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7346                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7347                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7348                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7349                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7350                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7351                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7352                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7353                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7354                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7355
7356                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7357                                 BindingFlags.DeclaredOnly;
7358                         methods = greenType.GetMethods (flags);
7359
7360                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7361                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7362                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7363                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7364                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7365                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7366                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7367                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7368                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7369                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7370                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7371                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7372                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7373                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7374                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7375                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7376                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7377                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7378                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7379                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7380                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7381                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7382                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7383                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7384                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7385                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7386                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7387                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7388                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7389                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7390                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7391                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7392                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7393                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7394                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7395                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7396
7397                         flags = BindingFlags.Instance | BindingFlags.Public |
7398                                 BindingFlags.DeclaredOnly;
7399                         methods = greenType.GetMethods (flags);
7400
7401                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7402                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7403                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7404                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7405                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7406                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7407                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7408                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7409                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7410                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7411                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7412                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7413                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7414                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7415                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7416                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7417                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7418                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7419                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7420                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7421                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7422                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7423                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7424                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7425                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7426                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7427                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7428                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7429                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7430                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7431                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7432                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7433                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7434                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7435                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7436                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7437
7438                         flags = BindingFlags.Static | BindingFlags.Public |
7439                                 BindingFlags.DeclaredOnly;
7440                         methods = greenType.GetMethods (flags);
7441
7442                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7443                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7444                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7445                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7446                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7447                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7448                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7449                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7450                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7451                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7452                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7453                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7454                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7455                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7456                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7457                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7458                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7459                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7460                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7461                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7462                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7463                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7464                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7465                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7466                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7467                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7468                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7469                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7470                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7471                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7472                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7473                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7474                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7475                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7476                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7477                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7478
7479                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7480                                 BindingFlags.DeclaredOnly;
7481                         methods = greenType.GetMethods (flags);
7482
7483                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7484                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7485                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7486                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7487                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7488                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7489                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7490                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7491                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7492                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7493                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7494                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7495                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7496                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7497                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7498                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7499                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7500                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7501                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7502                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7503                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7504                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7505                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7506                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7507                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7508                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7509                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7510                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7511                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7512                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7513                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7514                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7515                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7516                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7517                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7518                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7519
7520                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7521                                 BindingFlags.Public;
7522                         methods = greenType.GetMethods (flags);
7523
7524                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7525                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7526                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7527                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7528                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7529                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7530                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7531                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7532                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7533                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7534                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7535                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7536                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7537                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7538                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7539                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7540                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7541                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7542                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7543                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7544                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7545                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7546                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7547                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7548                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7549                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7550                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7551                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7552                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7553                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7554                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7555                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7556                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7557                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7558                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7559                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7560
7561                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7562                                 BindingFlags.Public;
7563                         methods = greenType.GetMethods (flags);
7564
7565                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7566                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7567                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7568                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7569                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7570                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7571                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7572                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7573                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7574                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7575                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7576                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7577                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7578                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7579                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7580                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7581                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7582                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7583                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7584                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7585                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7586                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7587                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7588                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7589                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7590                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7591                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7592                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7593                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7594                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7595                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7596                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7597                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7598                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7599                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7600                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7601                 }
7602
7603                 [Test]
7604                 [Category ("NotDotNet")] // mcs depends on this
7605                 public void TestGetMethodsFlagsIncomplete_Mono ()
7606                 {
7607                         MethodBuilder mb;
7608                         ILGenerator ilgen;
7609                         MethodInfo [] methods;
7610
7611                         TypeBuilder tb = module.DefineType (genTypeName (),
7612                                 TypeAttributes.Abstract);
7613                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7614                                 typeof (void), Type.EmptyTypes);
7615                         ilgen = mb.GetILGenerator ();
7616                         ilgen.Emit (OpCodes.Ret);
7617
7618                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7619                                 typeof (void), Type.EmptyTypes);
7620                         ilgen = mb.GetILGenerator ();
7621                         ilgen.Emit (OpCodes.Ret);
7622
7623                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7624                                 MethodAttributes.Static,
7625                                 typeof (void), Type.EmptyTypes);
7626                         ilgen = mb.GetILGenerator ();
7627                         ilgen.Emit (OpCodes.Ret);
7628
7629                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7630                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7631                                 typeof (void), Type.EmptyTypes);
7632
7633                         methods = tb.GetMethods (BindingFlags.Public |
7634                                 BindingFlags.Instance);
7635                         Assert.AreEqual (6, methods.Length, "#A1");
7636                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7637                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7638                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7639                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7640                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7641
7642                         methods = tb.GetMethods (BindingFlags.Public |
7643                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7644                         Assert.AreEqual (2, methods.Length, "#B1");
7645                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7646                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7647
7648                         methods = tb.GetMethods (BindingFlags.Public |
7649                                 BindingFlags.Instance | BindingFlags.Static);
7650                         Assert.AreEqual (7, methods.Length, "#C1");
7651                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7652                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7653                         Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7654                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7655                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7656                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7657
7658                         methods = tb.GetMethods (BindingFlags.NonPublic |
7659                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7660                         Assert.AreEqual (1, methods.Length, "#D1");
7661                         Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7662                 }
7663
7664
7665                 [Test]
7666                 [Category ("NotWorking")] // mcs depends on this
7667                 public void TestGetMethodsFlagsIncomplete_MS ()
7668                 {
7669                         MethodBuilder mb;
7670                         ILGenerator ilgen;
7671
7672                         TypeBuilder tb = module.DefineType (genTypeName (),
7673                                 TypeAttributes.Abstract);
7674                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7675                                 typeof (void), Type.EmptyTypes);
7676                         ilgen = mb.GetILGenerator ();
7677                         ilgen.Emit (OpCodes.Ret);
7678
7679                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7680                                 typeof (void), Type.EmptyTypes);
7681                         ilgen = mb.GetILGenerator ();
7682                         ilgen.Emit (OpCodes.Ret);
7683
7684                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7685                                 MethodAttributes.Static,
7686                                 typeof (void), Type.EmptyTypes);
7687                         ilgen = mb.GetILGenerator ();
7688                         ilgen.Emit (OpCodes.Ret);
7689
7690                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7691                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7692                                 typeof (void), Type.EmptyTypes);
7693
7694                         try {
7695                                 tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7696                                 Assert.Fail ("#1");
7697                         } catch (NotSupportedException ex) {
7698                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7699                                 Assert.IsNull (ex.InnerException, "#3");
7700                                 Assert.IsNotNull (ex.Message, "#4");
7701                         }
7702                 }
7703
7704                 [Test]
7705                 public void TestGetMethodsFlagsComplete ()
7706                 {
7707                         TypeBuilder tb = module.DefineType (genTypeName ());
7708                         MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7709                                 MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7710                         ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7711                         helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7712                         helloMethodIL.Emit (OpCodes.Ldarg_1);
7713                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7714                                 new Type [] { typeof (string), typeof (string) });
7715                         helloMethodIL.Emit (OpCodes.Call, infoMethod);
7716                         helloMethodIL.Emit (OpCodes.Ret);
7717
7718                         Type emittedType = tb.CreateType ();
7719
7720                         Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7721                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7722                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7723                         Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7724                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7725                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7726                 }
7727
7728                 [Test]
7729                 public void TestGetMethodsFlagsComplete_Inheritance ()
7730                 {
7731                         MethodInfo [] methods;
7732                         BindingFlags flags;
7733
7734                         TypeBuilder blueType = module.DefineType (genTypeName (),
7735                                 TypeAttributes.Public);
7736                         CreateMembers (blueType, "Blue", false);
7737
7738                         TypeBuilder redType = module.DefineType (genTypeName (),
7739                                 TypeAttributes.Public, blueType);
7740                         CreateMembers (redType, "Red", false);
7741
7742                         TypeBuilder greenType = module.DefineType (genTypeName (),
7743                                 TypeAttributes.Public, redType);
7744                         CreateMembers (greenType, "Green", false);
7745
7746                         blueType.CreateType ();
7747                         redType.CreateType ();
7748                         greenType.CreateType ();
7749
7750                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7751                         methods = greenType.GetMethods (flags);
7752
7753                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7754                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7755                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7756                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7757                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7758                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7759                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7760                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7761                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7762                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7763                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7764                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7765                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7766                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7767                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7768                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7769                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7770                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7771                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7772                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7773                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7774                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7775                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7776                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7777                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7778                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7779                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7780                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7781                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7782                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7783                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7784                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7785                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7786                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7787                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7788                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7789
7790                         flags = BindingFlags.Instance | BindingFlags.Public;
7791                         methods = greenType.GetMethods (flags);
7792
7793                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7794                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7795                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7796                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7797                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7798                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7799                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7800                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7801                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7802                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7803                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7804                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7805                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7806                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7807                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7808                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7809                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7810                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7811                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7812                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7813                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7814                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7815                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7816                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7817                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7818                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7819                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7820                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7821                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7822                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7823                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7824                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7825                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7826                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7827                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7828                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7829
7830                         flags = BindingFlags.Static | BindingFlags.Public;
7831                         methods = greenType.GetMethods (flags);
7832
7833                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7834                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7835                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7836                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7837                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7838                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7839                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7840                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7841                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7842                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7843                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7844                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7845                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7846                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7847                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7848                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7849                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7850                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7851                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7852                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7853                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7854                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7855                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7856                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7857                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7858                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7859                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7860                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7861                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7862                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7863                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7864                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7865                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7866                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7867                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7868                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7869
7870                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7871                         methods = greenType.GetMethods (flags);
7872
7873                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7874                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7875                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7876                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7877                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7878                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7879                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7880                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7881                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7882                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7883                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7884                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7885                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7886                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7887                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7888                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7889                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7890                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7891                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7892                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7893                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7894                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7895                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7896                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7897                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7898                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7899                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7900                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7901                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7902                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7903                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7904                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7905                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7906                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7907                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7908                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7909
7910                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7911                                 BindingFlags.FlattenHierarchy;
7912                         methods = greenType.GetMethods (flags);
7913
7914                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7915                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7916                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7917                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7918                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7919                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7920                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7921                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7922                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7923                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7924                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7925                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7926                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7927                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7928                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7929                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7930                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7931                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7932                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7933                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7934                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7935                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7936                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7937                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7938                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7939                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7940                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7941                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7942                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7943                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7944                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7945                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7946                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7947                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7948                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7949                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7950
7951                         flags = BindingFlags.Instance | BindingFlags.Public |
7952                                 BindingFlags.FlattenHierarchy;
7953                         methods = greenType.GetMethods (flags);
7954
7955                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7956                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7957                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7958                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7959                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7960                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7961                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7962                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7963                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7964                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7965                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7966                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7967                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7968                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7969                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7970                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7971                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7972                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7973                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7974                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7975                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7976                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7977                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7978                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7979                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7980                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7981                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7982                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7983                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7984                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7985                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7986                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7987                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7988                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7989                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7990                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7991
7992                         flags = BindingFlags.Static | BindingFlags.Public |
7993                                 BindingFlags.FlattenHierarchy;
7994                         methods = greenType.GetMethods (flags);
7995
7996                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7997                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7998                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7999                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8000                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8001                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8002                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8003                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8004                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8005                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8006                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8007                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8008                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8009                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8010                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8011                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8012                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8013                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8014                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8015                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8016                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8017                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8018                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8019                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8020                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8021                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8022                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8023                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8024                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8025                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8026                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8027                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8028                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8029                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8030                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8031                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8032
8033                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8034                                 BindingFlags.FlattenHierarchy;
8035                         methods = greenType.GetMethods (flags);
8036
8037                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8038                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8039                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8040                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8041                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8042                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8043                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8044                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8045                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8046                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8047                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8048                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8049                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8050                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8051                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8052                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8053                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8054                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8055                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8056                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8057                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8058                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8059                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8060                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8061                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8062                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8063                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8064                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8065                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8066                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8067                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8068                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8069                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8070                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8071                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8072                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8073
8074                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8075                                 BindingFlags.DeclaredOnly;
8076                         methods = greenType.GetMethods (flags);
8077
8078                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8079                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8080                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8081                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8082                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8083                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8084                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8085                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8086                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8087                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8088                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8089                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8090                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8091                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8092                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8093                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8094                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8095                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8096                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8097                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8098                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8099                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8100                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8101                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8102                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8103                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8104                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8105                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8106                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8107                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8108                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8109                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8110                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8111                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8112                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8113                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8114
8115                         flags = BindingFlags.Instance | BindingFlags.Public |
8116                                 BindingFlags.DeclaredOnly;
8117                         methods = greenType.GetMethods (flags);
8118
8119                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8120                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8121                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8122                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8123                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8124                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8125                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8126                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8127                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8128                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8129                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8130                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8131                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8132                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8133                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8134                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8135                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8136                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8137                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8138                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8139                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8140                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8141                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8142                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8143                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8144                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8145                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8146                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8147                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8148                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8149                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8150                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8151                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8152                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8153                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8154                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8155
8156                         flags = BindingFlags.Static | BindingFlags.Public |
8157                                 BindingFlags.DeclaredOnly;
8158                         methods = greenType.GetMethods (flags);
8159
8160                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8161                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8162                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8163                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8164                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8165                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8166                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8167                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8168                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8169                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8170                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8171                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8172                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8173                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8174                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8175                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8176                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8177                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8178                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8179                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8180                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8181                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8182                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8183                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8184                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8185                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8186                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8187                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8188                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8189                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8190                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8191                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8192                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8193                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8194                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8195                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8196
8197                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8198                                 BindingFlags.DeclaredOnly;
8199                         methods = greenType.GetMethods (flags);
8200
8201                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8202                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8203                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8204                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8205                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8206                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8207                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8208                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8209                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8210                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8211                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8212                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8213                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8214                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8215                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8216                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8217                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8218                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8219                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8220                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8221                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8222                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8223                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8224                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8225                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8226                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8227                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8228                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8229                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8230                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8231                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8232                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8233                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8234                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8235                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8236                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8237
8238                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8239                                 BindingFlags.Public;
8240                         methods = greenType.GetMethods (flags);
8241
8242                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8243                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8244                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8245                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8246                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8247                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8248                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8249                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8250                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8251                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8252                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8253                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8254                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8255                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8256                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8257                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8258                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8259                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8260                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8261                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8262                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8263                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8264                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8265                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8266                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8267                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8268                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8269                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8270                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8271                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8272                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8273                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8274                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8275                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8276                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8277                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8278
8279                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8280                                 BindingFlags.Public;
8281                         methods = greenType.GetMethods (flags);
8282
8283                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8284                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8285                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8286                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8287                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8288                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8289                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8290                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8291                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8292                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8293                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8294                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8295                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8296                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8297                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8298                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8299                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8300                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8301                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8302                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8303                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8304                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8305                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8306                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8307                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8308                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8309                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8310                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8311                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8312                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8313                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8314                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8315                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8316                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8317                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8318                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8319                 }
8320
8321                 [Test]
8322                 public void TestGetMemberIncomplete ()
8323                 {
8324                         TypeBuilder tb = module.DefineType (genTypeName ());
8325                         try {
8326                                 tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8327                                 Assert.Fail ("#1");
8328                         } catch (NotSupportedException ex) {
8329                                 // The invoked member is not supported in a
8330                                 // dynamic module
8331                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8332                                 Assert.IsNull (ex.InnerException, "#3");
8333                                 Assert.IsNotNull (ex.Message, "#4");
8334                         }
8335                 }
8336
8337                 [Test]
8338                 public void TestGetMemberComplete ()
8339                 {
8340                         TypeBuilder tb = module.DefineType (genTypeName ());
8341                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8342
8343                         Type emittedType = tb.CreateType ();
8344
8345                         Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8346                         Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8347                 }
8348
8349                 [Test]
8350                 public void TestGetMembersIncomplete ()
8351                 {
8352                         TypeBuilder tb = module.DefineType (genTypeName ());
8353                         try {
8354                                 tb.GetMembers ();
8355                                 Assert.Fail ("#1");
8356                         } catch (NotSupportedException ex) {
8357                                 // The invoked member is not supported in a
8358                                 // dynamic module
8359                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8360                                 Assert.IsNull (ex.InnerException, "#3");
8361                                 Assert.IsNotNull (ex.Message, "#4");
8362                         }
8363                 }
8364
8365                 [Test]
8366                 public void TestGetMembersComplete ()
8367                 {
8368                         TypeBuilder tb = module.DefineType (genTypeName ());
8369                         Type emittedType = tb.CreateType ();
8370
8371                         Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8372                 }
8373
8374                 [Test]
8375                 public void TestGetMembersFlagsIncomplete ()
8376                 {
8377                         TypeBuilder tb = module.DefineType (genTypeName ());
8378                         try {
8379                                 tb.GetMembers (BindingFlags.Public);
8380                                 Assert.Fail ("#1");
8381                         } catch (NotSupportedException ex) {
8382                                 // The invoked member is not supported in a
8383                                 // dynamic module
8384                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8385                                 Assert.IsNull (ex.InnerException, "#3");
8386                                 Assert.IsNotNull (ex.Message, "#4");
8387                         }
8388                 }
8389
8390                 [Test]
8391                 public void TestGetMembersFlagsComplete ()
8392                 {
8393                         TypeBuilder tb = module.DefineType (genTypeName ());
8394                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8395
8396                         Type emittedType = tb.CreateType ();
8397
8398                         Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8399                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8400                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8401                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8402                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8403                 }
8404
8405                 [Test]
8406                 public void TestGetInterfaceIncomplete ()
8407                 {
8408                         TypeBuilder tb = module.DefineType (genTypeName ());
8409                         try {
8410                                 tb.GetInterface ("FOO", true);
8411                                 Assert.Fail ("#1");
8412                         } catch (NotSupportedException ex) {
8413                                 // The invoked member is not supported in a
8414                                 // dynamic module
8415                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8416                                 Assert.IsNull (ex.InnerException, "#3");
8417                                 Assert.IsNotNull (ex.Message, "#4");
8418                         }
8419                 }
8420
8421                 [Test]
8422                 public void TestGetInterfaces ()
8423                 {
8424                         TypeBuilder tb = module.DefineType (genTypeName ());
8425                         Type [] interfaces = tb.GetInterfaces ();
8426                         Assert.AreEqual (0, interfaces.Length);
8427
8428                         TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8429                         Type emittedInterface = tbInterface.CreateType ();
8430
8431                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8432                         interfaces = tb.GetInterfaces ();
8433                         Assert.AreEqual (1, interfaces.Length);
8434                 }
8435
8436                 [Test]
8437                 public void TestAddDeclarativeSecurityAlreadyCreated ()
8438                 {
8439                         TypeBuilder tb = module.DefineType (genTypeName ());
8440                         tb.CreateType ();
8441
8442                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8443                         try {
8444                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8445                                 Assert.Fail ("#1");
8446                         } catch (InvalidOperationException ex) {
8447                                 // Unable to change after type has been created
8448                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8449                                 Assert.IsNull (ex.InnerException, "#3");
8450                                 Assert.IsNotNull (ex.Message, "#4");
8451                         }
8452                 }
8453
8454                 [Test]
8455                 public void TestAddDeclarativeSecurityNullPermissionSet ()
8456                 {
8457                         TypeBuilder tb = module.DefineType (genTypeName ());
8458                         try {
8459                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8460                                 Assert.Fail ("#1");
8461                         } catch (ArgumentNullException ex) {
8462                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8463                                 Assert.IsNull (ex.InnerException, "#3");
8464                                 Assert.IsNotNull (ex.Message, "#4");
8465                                 Assert.AreEqual ("pset", ex.ParamName, "#5");
8466                         }
8467
8468                 }
8469
8470                 [Test]
8471                 public void TestAddDeclarativeSecurityInvalidAction ()
8472                 {
8473                         TypeBuilder tb = module.DefineType (genTypeName ());
8474
8475                         SecurityAction [] actions = new SecurityAction [] { 
8476                         SecurityAction.RequestMinimum,
8477                         SecurityAction.RequestOptional,
8478                         SecurityAction.RequestRefuse };
8479                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8480
8481                         foreach (SecurityAction action in actions) {
8482                                 try {
8483                                         tb.AddDeclarativeSecurity (action, set);
8484                                         Assert.Fail ();
8485                                 } catch (ArgumentOutOfRangeException) {
8486                                 }
8487                         }
8488                 }
8489
8490                 [Test]
8491                 public void TestAddDeclarativeSecurityDuplicateAction ()
8492                 {
8493                         TypeBuilder tb = module.DefineType (genTypeName ());
8494
8495                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8496                         tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8497                         try {
8498                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8499                                 Assert.Fail ("#1");
8500                         } catch (InvalidOperationException ex) {
8501                                 // Multiple permission sets specified with the
8502                                 // same SecurityAction
8503                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8504                                 Assert.IsNull (ex.InnerException, "#3");
8505                                 Assert.IsNotNull (ex.Message, "#4");
8506                         }
8507                 }
8508
8509                 [Test]
8510                 public void TestEnums ()
8511                 {
8512                         TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8513                         TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8514                                                                                                                  typeof (Enum));
8515                         enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8516                         // add value__ field, see DefineEnum method of ModuleBuilder
8517                         enumToCreate.DefineField ("value__", typeof (Int32),
8518                                 FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8519
8520                         // add enum entries
8521                         FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8522                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8523                         fb.SetConstant ((Int32) 0);
8524
8525                         fb = enumToCreate.DefineField ("B", enumToCreate,
8526                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8527                         fb.SetConstant ((Int32) 1);
8528
8529                         fb = enumToCreate.DefineField ("C", enumToCreate,
8530                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8531                         fb.SetConstant ((Int32) 2);
8532
8533                         Type enumType = enumToCreate.CreateType ();
8534
8535                         object enumVal = Enum.ToObject (enumType, (Int32) 3);
8536
8537                         Assert.AreEqual ("B, C", enumVal.ToString ());
8538                         Assert.AreEqual (3, (Int32) enumVal);
8539                 }
8540
8541                 [Test]
8542                 public void DefineEnum ()
8543                 {
8544                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8545                                                                                                                  TypeAttributes.Public);
8546                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8547                                                                                                                  TypeAttributes.Public, typeof (int));
8548                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8549                         enumBuilder.CreateType ();
8550                         typeBuilder.CreateType ();
8551                 }
8552
8553                 [Test]
8554                 [Category ("NotWorking")]
8555                 public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8556                 {
8557                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8558                                                                                                                  TypeAttributes.Public);
8559                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8560                                                                                                                  TypeAttributes.Public, typeof (int));
8561                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8562                         try {
8563                                 typeBuilder.CreateType ();
8564                                 Assert.Fail ("#1");
8565                         } catch (TypeLoadException) {
8566                                 // Could not load type '...' from assembly
8567                                 // 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8568                         }
8569                         Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8570                         Assert.IsNull (typeBuilder.CreateType (), "#3");
8571                 }
8572
8573                 [Test]
8574                 public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8575                 {
8576                         TypeBuilder tb = module.DefineType (genTypeName ());
8577                         ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8578                                 GetConstructor (Type.EmptyTypes);
8579                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8580                                 attrCtor, new object [0]);
8581                         Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8582                         tb.SetCustomAttribute (caBuilder);
8583                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8584                         Type emittedType = tb.CreateType ();
8585                         Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8586                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8587                         object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8588                         Assert.AreEqual (1, emittedAttrs.Length, "#5");
8589                 }
8590
8591                 private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8592                 {
8593                         // define the field holding the property value
8594                         FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8595                                 typeof (string), FieldAttributes.Private);
8596
8597                         PropertyBuilder propertyBuilder = tb.DefineProperty (
8598                                 propertyName, PropertyAttributes.HasDefault, typeof (string),
8599                                 new Type [] { typeof (string) });
8600
8601                         // First, we'll define the behavior of the "get" property for CustomerName as a method.
8602                         MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8603                                                                         methodAttribs,
8604                                                                         typeof (string),
8605                                                                         new Type [] { });
8606
8607                         ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8608
8609                         getIL.Emit (OpCodes.Ldarg_0);
8610                         getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8611                         getIL.Emit (OpCodes.Ret);
8612
8613                         // Now, we'll define the behavior of the "set" property for CustomerName.
8614                         MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8615                                                                         methodAttribs,
8616                                                                         null,
8617                                                                         new Type [] { typeof (string) });
8618
8619                         ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8620
8621                         setIL.Emit (OpCodes.Ldarg_0);
8622                         setIL.Emit (OpCodes.Ldarg_1);
8623                         setIL.Emit (OpCodes.Stfld, fieldBuilder);
8624                         setIL.Emit (OpCodes.Ret);
8625
8626                         // Last, we must map the two methods created above to our PropertyBuilder to 
8627                         // their corresponding behaviors, "get" and "set" respectively. 
8628                         propertyBuilder.SetGetMethod (getMethodBuilder);
8629                         propertyBuilder.SetSetMethod (setMethodBuilder);
8630                         return propertyBuilder;
8631                 }
8632
8633                 static int handler_called = 0;
8634
8635                 [Test]
8636                 public void TestTypeResolve ()
8637                 {
8638                         string typeName = genTypeName ();
8639
8640                         ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8641                         AppDomain.CurrentDomain.TypeResolve += handler;
8642                         handler_called = 0;
8643                         Type t = Type.GetType (typeName);
8644                         Assert.AreEqual (typeName, t.Name);
8645                         Assert.AreEqual (1, handler_called);
8646                         AppDomain.CurrentDomain.TypeResolve -= handler;
8647                 }
8648
8649                 Assembly TypeResolve (object sender, ResolveEventArgs args)
8650                 {
8651                         TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8652                         tb.CreateType ();
8653                         handler_called++;
8654                         return tb.Assembly;
8655                 }
8656
8657                 [Test]
8658                 public void IsAssignableFrom_Created ()
8659                 {
8660                         TypeBuilder tb = module.DefineType (genTypeName (),
8661                                 TypeAttributes.Public, typeof (MemoryStream),
8662                                 new Type [] { typeof (IThrowable), typeof (Bar) });
8663                         tb.AddInterfaceImplementation (typeof (IDestroyable));
8664                         Type emitted_type = tb.CreateType ();
8665
8666                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8667                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8668                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8669                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8670                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8671                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8672                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8673                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8674                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8675                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8676                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8677                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8678                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8679                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8680                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8681                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8682                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8683                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8684
8685                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8686                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8687                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8688                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8689                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8690                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8691                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8692                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8693                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8694                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8695
8696                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8697                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8698                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8699                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8700                         Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8701
8702                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8703                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8704                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8705                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8706                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8707                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8708                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8709                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8710                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8711                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8712                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8713                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8714                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8715                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8716                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8717                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8718                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8719                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8720
8721                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8722                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8723                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8724                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8725                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8726                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8727                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8728                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8729                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8730                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8731
8732                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8733                                 tb.FullName + "[]")), "#F1");
8734                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8735                                 tb.FullName + "[]")), "#F2");
8736                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8737                                 tb.FullName + "[]")), "#F3");
8738
8739                         TypeBuilder tb2 = module.DefineType (genTypeName (),
8740                                 TypeAttributes.Public, tb,
8741                                 new Type [] { typeof (IAir) });
8742                         Type emitted_type2 = tb2.CreateType ();
8743
8744                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8745                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8746                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8747                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8748                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8749                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8750                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8751                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8752                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8753                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8754                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8755                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8756                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8757                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8758                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8759                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8760                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8761                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8762
8763                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8764                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8765                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8766                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8767                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8768                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8769                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8770                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8771                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8772                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8773
8774                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
8775                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
8776                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
8777                         Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
8778                         Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
8779                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
8780                         Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
8781                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
8782                         Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
8783                         Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
8784                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
8785                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
8786                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
8787                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
8788
8789                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
8790                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
8791                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
8792                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
8793                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
8794                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
8795                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
8796                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
8797                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
8798                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
8799                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
8800                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
8801                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
8802                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
8803                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
8804                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
8805                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
8806                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
8807
8808                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
8809                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
8810                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
8811                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
8812                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
8813                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
8814                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
8815                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
8816                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
8817                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
8818
8819                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8820                                 tb2.FullName + "[]")), "#L1");
8821                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8822                                 tb2.FullName + "[]")), "#L2");
8823                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8824                                 tb2.FullName + "[]")), "#L3");
8825
8826                         TypeBuilder tb3 = module.DefineType (genTypeName (),
8827                                 TypeAttributes.Public, tb2,
8828                                 new Type [] { typeof (IWater) });
8829                         Type emitted_type3 = tb3.CreateType ();
8830
8831                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
8832                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
8833                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
8834                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
8835                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
8836                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
8837                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
8838                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
8839                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
8840                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
8841                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
8842                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
8843                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
8844                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
8845                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
8846                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
8847                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
8848                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
8849
8850                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
8851                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
8852                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
8853                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
8854                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
8855                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
8856                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
8857                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
8858                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
8859                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
8860
8861                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
8862                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
8863                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
8864                         Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
8865                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
8866                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
8867                         Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
8868                         Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
8869                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
8870                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
8871                         Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
8872                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
8873                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
8874                         Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
8875                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
8876                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
8877                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
8878                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
8879                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
8880                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
8881                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
8882                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
8883
8884                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
8885                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
8886                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
8887                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
8888                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
8889                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
8890                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
8891                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
8892                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
8893                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
8894                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
8895                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
8896                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
8897                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
8898                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
8899                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
8900                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
8901                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
8902
8903                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
8904                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
8905                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
8906                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
8907                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
8908                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
8909                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
8910                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
8911                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
8912                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
8913
8914                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8915                                 tb3.FullName + "[]")), "#R1");
8916                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8917                                 tb3.FullName + "[]")), "#R2");
8918                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8919                                 tb3.FullName + "[]")), "#R3");
8920
8921                         TypeBuilder tb4 = module.DefineType (genTypeName (),
8922                                 TypeAttributes.Public, null,
8923                                 new Type [] { typeof (IWater) });
8924                         tb4.DefineGenericParameters ("T");
8925
8926                         Type inst = tb4.MakeGenericType (typeof (int));
8927                         Type emitted_type4 = tb4.CreateType ();
8928                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
8929                         // This returns True if CreateType () is called _before_ MakeGenericType...
8930                         //Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
8931                 }
8932
8933                 [Test]
8934                 public void IsAssignableFrom_NotCreated ()
8935                 {
8936                         TypeBuilder tb = module.DefineType (genTypeName (),
8937                                 TypeAttributes.Public, typeof (MemoryStream),
8938                                 new Type [] {
8939                                         typeof (IThrowable), typeof (Bar),
8940                                         typeof (IComparable)
8941                                         });
8942
8943                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8944                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8945                         //Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8946                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8947                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
8948                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
8949                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
8950                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
8951                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
8952                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
8953                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
8954                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
8955
8956                         //Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
8957                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
8958                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
8959                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
8960                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
8961                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
8962
8963                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
8964                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
8965                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
8966                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
8967                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
8968                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
8969                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
8970                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
8971                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
8972                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
8973
8974                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
8975                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
8976
8977                         TypeBuilder tb2 = module.DefineType (genTypeName (),
8978                                 TypeAttributes.Public, tb,
8979                                 new Type[] { typeof (IAir) });
8980
8981                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
8982                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
8983                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
8984                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
8985                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
8986                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
8987                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
8988                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
8989                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
8990                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
8991                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
8992                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
8993
8994                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#F1");
8995                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
8996                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#F3");
8997                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
8998                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
8999                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9000
9001                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9002                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9003                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9004                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9005                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9006                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9007                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9008                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9009                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9010                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9011
9012                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9013                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9014                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9015
9016                         TypeBuilder tb3 = module.DefineType (genTypeName (),
9017                                 TypeAttributes.Public, tb2,
9018                                 new Type[] { typeof (IWater) });
9019
9020                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9021                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9022                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9023                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9024                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9025                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9026                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9027                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9028                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9029                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9030                         //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9031                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9032
9033                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9034                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9035                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9036                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9037                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9038                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9039
9040                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9041                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9042                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9043                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9044                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9045                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9046                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9047                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9048                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9049                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9050
9051                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9052                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9053                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9054                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9055                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9056                 }
9057
9058                 [Test]
9059                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9060                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9061                 {
9062                         TypeBuilder tb = module.DefineType (genTypeName (),
9063                                 TypeAttributes.Public, typeof (FormatException),
9064                                 new Type [] { typeof (IThrowable) });
9065                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9066
9067                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9068                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9069
9070                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9071                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9072                 }
9073
9074                 [Test]
9075                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9076                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9077                 {
9078                         TypeBuilder tb = module.DefineType (genTypeName (),
9079                                 TypeAttributes.Public, typeof (FormatException),
9080                                 new Type [] { typeof (IThrowable) });
9081                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9082
9083                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9084                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9085
9086                         Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9087                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9088                 }
9089
9090
9091                 [Test]
9092                 [Category ("NotDotNet")]
9093                 public void IsAssignableFrom_NotCreated_Array ()
9094                 {
9095                         TypeBuilder tb = module.DefineType (genTypeName (),
9096                                 TypeAttributes.Public, typeof (FormatException),
9097                                 new Type [] {
9098                                         typeof (IThrowable), typeof (Bar),
9099                                         typeof (IComparable)
9100                                         });
9101
9102                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9103                                 tb.FullName + "[]")), "#1");
9104                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9105                                 tb.FullName + "[]")), "#2");
9106                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9107                                 tb.FullName + "[]")), "#3");
9108                 }
9109
9110                 [Test]
9111                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9112                 public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9113                 {
9114                         TypeBuilder tb = module.DefineType (genTypeName (),
9115                                 TypeAttributes.Public, typeof (FormatException),
9116                                 new Type [] {
9117                                         typeof (IThrowable), typeof (Bar),
9118                                         typeof (IComparable)
9119                                         });
9120
9121                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9122                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9123                 }
9124
9125                 [Test]
9126                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9127                 public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9128                 {
9129                         TypeBuilder tb = module.DefineType (genTypeName (),
9130                                 TypeAttributes.Public, typeof (FormatException),
9131                                 new Type [] {
9132                                         typeof (IThrowable), typeof (Bar),
9133                                         typeof (IComparable)
9134                                         });
9135
9136                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9137                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9138                 }
9139
9140                 [Test]
9141                 public void CreateType_EmptyMethodBody ()
9142                 {
9143                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9144
9145                         tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9146                         try {
9147                                 tb.CreateType ();
9148                                 Assert.Fail ("#1");
9149                         } catch (InvalidOperationException ex) {
9150                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9151                                 Assert.IsNull (ex.InnerException, "#3");
9152                                 Assert.IsNotNull (ex.Message, "#4");
9153                         }
9154                 }
9155
9156                 [Test]
9157                 public void CreateType_EmptyCtorBody ()
9158                 {
9159                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9160
9161                         tb.DefineConstructor (0, CallingConventions.Standard, null);
9162                         try {
9163                                 tb.CreateType ();
9164                                 Assert.Fail ("#1");
9165                         } catch (InvalidOperationException ex) {
9166                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9167                                 Assert.IsNull (ex.InnerException, "#3");
9168                                 Assert.IsNotNull (ex.Message, "#4");
9169                         }
9170                 }
9171
9172                 [Test]
9173                 [Category ("NotWorking")]
9174                 public void CreateType_Interface_ParentInvalid ()
9175                 {
9176                         TypeBuilder tb;
9177
9178                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9179                                 typeof (Exception));
9180                         Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9181                         try {
9182                                 tb.CreateType ();
9183                                 Assert.Fail ("#A2");
9184                         } catch (TypeLoadException ex) {
9185                                 // Could not load interface 't5' from assembly '...'
9186                                 // because it must extend from Object
9187                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9188                                 Assert.IsNull (ex.InnerException, "#A4");
9189                                 Assert.IsNotNull (ex.Message, "#A5");
9190                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9191                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9192                         }
9193
9194                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9195                                 typeof (object));
9196                         Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9197                         try {
9198                                 tb.CreateType ();
9199                                 Assert.Fail ("#B2");
9200                         } catch (TypeLoadException ex) {
9201                                 // Failure has occurred while loading a type
9202                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9203                                 Assert.IsNull (ex.InnerException, "#B4");
9204                                 Assert.IsNotNull (ex.Message, "#B5");
9205                         }
9206
9207                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9208                                 typeof (EmptyInterface));
9209                         Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9210                         try {
9211                                 tb.CreateType ();
9212                                 Assert.Fail ("#C2");
9213                         } catch (TypeLoadException ex) {
9214                                 // Could not load interface 't5' from assembly '...'
9215                                 // because the parent type is an interface
9216                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9217                                 Assert.IsNull (ex.InnerException, "#C4");
9218                                 Assert.IsNotNull (ex.Message, "#C5");
9219                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9220                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9221                         }
9222                 }
9223
9224                 [Test]
9225                 public void CreateType_Parent_DefaultCtorMissing ()
9226                 {
9227                         TypeBuilder tb;
9228
9229                         tb = module.DefineType (genTypeName ());
9230                         ConstructorBuilder cb = tb.DefineConstructor (
9231                                 MethodAttributes.Public,
9232                                 CallingConventions.Standard,
9233                                 new Type [] { typeof (string) });
9234                         cb.GetILGenerator ().Emit (OpCodes.Ret);
9235                         Type parent_type = tb.CreateType ();
9236
9237                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9238                                 parent_type);
9239                         try {
9240                                 tb.CreateType ();
9241                                 Assert.Fail ("#1");
9242                         } catch (NotSupportedException ex) {
9243                                 // Parent does not have a default constructor.
9244                                 // The default constructor must be explicitly defined
9245                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9246                                 Assert.IsNull (ex.InnerException, "#3");
9247                                 Assert.IsNotNull (ex.Message, "#4");
9248                         }
9249                 }
9250
9251                 [Test]
9252                 public void CreateType_Parent_Null ()
9253                 {
9254                         TypeBuilder tb;
9255                         Type emitted_type;
9256                         
9257                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9258                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9259                         emitted_type = tb.CreateType ();
9260                         Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9261
9262                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9263                         Assert.IsNull (tb.BaseType, "#B1");
9264                         emitted_type = tb.CreateType ();
9265                         Assert.IsNull (emitted_type.BaseType, "#B2");
9266                 }
9267
9268                 [Test]
9269                 [Category ("NotWorking")]
9270                 public void DefineGenericParameters_AlreadyDefined ()
9271                 {
9272                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9273                         tb.DefineGenericParameters ("K");
9274                         try {
9275                                 tb.DefineGenericParameters ("V");
9276                                 Assert.Fail ("#1");
9277                         } catch (InvalidOperationException ex) {
9278                                 // Operation is not valid due to the current
9279                                 // state of the object
9280                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9281                                 Assert.IsNull (ex.InnerException, "#3");
9282                                 Assert.IsNotNull (ex.Message, "#4");
9283                         }
9284                 }
9285
9286                 [Test]
9287                 public void DefineGenericParameters_Names_Empty ()
9288                 {
9289                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9290
9291                         try {
9292                                 tb.DefineGenericParameters (new string [0]);
9293                                 Assert.Fail ("#1");
9294                         } catch (ArgumentException ex) {
9295                                 // Value does not fall within the expected range
9296                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9297                                 Assert.IsNull (ex.InnerException, "#3");
9298                                 Assert.IsNotNull (ex.Message, "#4");
9299                                 Assert.IsNull (ex.ParamName, "#5");
9300                         }
9301                 }
9302
9303                 [Test]
9304                 public void DefineGenericParameters_Names_Null ()
9305                 {
9306                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9307
9308                         try {
9309                                 tb.DefineGenericParameters ((string []) null);
9310                                 Assert.Fail ("#A1");
9311                         } catch (ArgumentNullException ex) {
9312                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9313                                 Assert.IsNull (ex.InnerException, "#A3");
9314                                 Assert.IsNotNull (ex.Message, "#A4");
9315                                 Assert.AreEqual ("names", ex.ParamName, "#A5");
9316                         }
9317
9318                         try {
9319                                 tb.DefineGenericParameters ("K", null, "V");
9320                                 Assert.Fail ("#B1");
9321                         } catch (ArgumentNullException ex) {
9322                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9323                                 Assert.IsNull (ex.InnerException, "#B3");
9324                                 Assert.IsNotNull (ex.Message, "#B4");
9325                                 Assert.AreEqual ("names", ex.ParamName, "#B5");
9326                         }
9327                 }
9328
9329                 [Test]
9330                 public void GenericType ()
9331                 {
9332                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9333                         tb.DefineGenericParameters ("T");
9334
9335                         Assert.IsTrue (tb.IsGenericType, "#A1");
9336                         Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9337                         Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9338                         Assert.IsFalse (tb.IsGenericParameter, "#A4");
9339
9340                         Type[] args = tb.GetGenericArguments ();
9341                         Assert.IsFalse (args [0].IsGenericType, "#B1");
9342                         Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9343                         Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9344                         Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9345                 }
9346
9347                 [Test]
9348                 public void MakeGenericType ()
9349                 {
9350                         TypeBuilder tb;
9351                         Type generic_type;
9352                 
9353                         tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9354                         tb.DefineGenericParameters ("T");
9355
9356                         generic_type = tb.MakeGenericType (typeof (int));
9357                         Assert.IsTrue (generic_type.IsGenericType, "#A1");
9358                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9359                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9360                         Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9361
9362                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9363                         Assert.IsTrue (generic_type.IsGenericType, "#B1");
9364                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9365                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9366                         Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9367
9368                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9369                                 | TypeAttributes.Abstract | TypeAttributes.Public);
9370                         tb.DefineGenericParameters ("T");
9371
9372                         generic_type = tb.MakeGenericType (typeof (int));
9373                         Assert.IsTrue (generic_type.IsGenericType, "#C1");
9374                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9375                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9376                         Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9377
9378                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9379                         Assert.IsTrue (generic_type.IsGenericType, "#D1");
9380                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9381                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9382                         Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9383                 }
9384
9385                 [Test]
9386                 public void MakeGenericType_NoGenericTypeDefinition ()
9387                 {
9388                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9389                         try {
9390                                 tb.MakeGenericType (typeof (int));
9391                                 Assert.Fail ("#1");
9392                         } catch (InvalidOperationException ex) {
9393                                 // Operation is not valid due to the current
9394                                 // state of the object
9395                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9396                                 Assert.IsNull (ex.InnerException, "#3");
9397                                 Assert.IsNotNull (ex.Message, "#4");
9398                         }
9399                 }
9400
9401                 [Test]
9402                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9403                 public void MakeGenericType_TypeArguments_Null_Mono ()
9404                 {
9405                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9406                         tb.DefineGenericParameters ("K", "V");
9407
9408                         try {
9409                                 tb.MakeGenericType ((Type []) null);
9410                                 Assert.Fail ("#A1");
9411                         } catch (ArgumentNullException ex) {
9412                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9413                                 Assert.IsNull (ex.InnerException, "#A3");
9414                                 Assert.IsNotNull (ex.Message, "#A4");
9415                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9416                         }
9417
9418                         try {
9419                                 tb.MakeGenericType (typeof (string), (Type) null);
9420                                 Assert.Fail ("#B1");
9421                         } catch (ArgumentNullException ex) {
9422                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9423                                 Assert.IsNull (ex.InnerException, "#B3");
9424                                 Assert.IsNotNull (ex.Message, "#B4");
9425                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9426                         }
9427                 }
9428
9429                 [Test]
9430                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9431                 public void MakeGenericType_TypeArguments_Null_MS ()
9432                 {
9433                         Type generic_type;
9434                         Type [] type_args;
9435
9436                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9437                         tb.DefineGenericParameters ("K", "V");
9438
9439                         generic_type = tb.MakeGenericType ((Type []) null);
9440                         Assert.IsNotNull (generic_type, "#A1");
9441                         Assert.IsTrue (generic_type.IsGenericType, "#A2");
9442                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9443                         type_args = generic_type.GetGenericArguments ();
9444                         Assert.IsNull (type_args, "#A4");
9445
9446                         generic_type  = tb.MakeGenericType (typeof (string), (Type) null);
9447                         Assert.IsNotNull (generic_type, "#B1");
9448                         Assert.IsTrue (generic_type.IsGenericType, "#B2");
9449                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9450                         type_args = generic_type.GetGenericArguments ();
9451                         Assert.IsNotNull (type_args, "#B4");
9452                         Assert.AreEqual (2, type_args.Length, "#B5");
9453                         Assert.AreEqual (typeof (string), type_args [0], "#B6");
9454                         Assert.IsNull (type_args [1], "#B7");
9455                 }
9456
9457                 [Test]
9458                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9459                 public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9460                 {
9461                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9462                         tb.DefineGenericParameters ("K", "V");
9463                         try {
9464                                 tb.MakeGenericType (typeof (int));
9465                                 Assert.Fail ("#1");
9466                         } catch (ArgumentException ex) {
9467                                 // The type or method has 2 generic prarameter(s)
9468                                 // but 1 generic argument(s) were provided. A
9469                                 // generic argument must be provided for each
9470                                 // generic parameter
9471                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9472                                 Assert.IsNull (ex.InnerException, "#3");
9473                                 Assert.IsNotNull (ex.Message, "#4");
9474                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9475                         }
9476                 }
9477
9478                 [Test]
9479                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9480                 public void MakeGenericType_TypeArguments_Mismatch_MS ()
9481                 {
9482                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9483                         tb.DefineGenericParameters ("K", "V");
9484                         
9485                         Type generic_type = tb.MakeGenericType (typeof (int));
9486                         Assert.IsTrue (generic_type.IsGenericType, "#1");
9487                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9488                         Type [] type_args = generic_type.GetGenericArguments ();
9489                         Assert.IsNotNull (type_args, "#3");
9490                         Assert.AreEqual (1, type_args.Length, "#4");
9491                         Assert.AreEqual (typeof (int), type_args [0], "#5");
9492                 }
9493
9494                 [Test]
9495                 public void MakeArrayType_Complete ()
9496                 {
9497                         // reference type
9498                         TypeBuilder tb = module.DefineType (genTypeName (),
9499                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9500                                 typeof (ContextBoundObject));
9501                         Type emittedType = tb.CreateType ();
9502                         Type arrayType = tb.MakeArrayType ();
9503                         Assert.IsTrue (arrayType.IsArray, "#A1");
9504                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9505                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9506                         Assert.IsFalse (tb.HasElementType, "#A4");
9507                         Assert.IsTrue (tb.IsCreated (), "#A5");
9508
9509                         // value type
9510                         tb = module.DefineType (genTypeName (),
9511                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9512                                 typeof (ValueType));
9513                         emittedType = tb.CreateType ();
9514                         arrayType = tb.MakeArrayType ();
9515                         Assert.IsTrue (arrayType.IsArray, "#B1");
9516                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9517                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9518                         Assert.IsFalse (tb.HasElementType, "#B4");
9519                         Assert.IsTrue (tb.IsCreated (), "#B5");
9520
9521                         tb = module.DefineType (genTypeName (),
9522                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9523                                 typeof (Enum));
9524                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9525                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
9526                         emittedType = tb.CreateType ();
9527                         arrayType = tb.MakeArrayType ();
9528                         Assert.IsTrue (arrayType.IsArray, "#C1");
9529                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9530                         Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9531                         Assert.IsFalse (tb.HasElementType, "#C4");
9532                         Assert.IsTrue (tb.IsCreated (), "#C5");
9533                 }
9534
9535                 [Test] // bug #82015
9536                 public void MakeArrayType_Incomplete ()
9537                 {
9538                         // reference type
9539                         TypeBuilder tb = module.DefineType (genTypeName (),
9540                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9541                                 typeof (ContextBoundObject));
9542                         Type arrayType = tb.MakeArrayType ();
9543                         Assert.IsTrue (arrayType.IsArray, "#A1");
9544                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9545                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9546                         Assert.IsFalse (tb.HasElementType, "#A4");
9547                         Assert.IsFalse (tb.IsCreated (), "#A5");
9548
9549                         // value type
9550                         tb = module.DefineType (genTypeName (),
9551                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9552                                 typeof (ValueType));
9553                         arrayType = tb.MakeArrayType ();
9554                         Assert.IsTrue (arrayType.IsArray, "#B1");
9555                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9556                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9557                         Assert.IsFalse (tb.HasElementType, "#B4");
9558                         Assert.IsFalse (tb.IsCreated (), "#B5");
9559
9560                         // enum
9561                         tb = module.DefineType (genTypeName (),
9562                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9563                                 typeof (Enum));
9564                         arrayType = tb.MakeArrayType ();
9565                         Assert.IsTrue (arrayType.IsArray, "#C1");
9566                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9567                         Assert.IsFalse (tb.HasElementType, "#C3");
9568                         Assert.IsFalse (tb.IsCreated (), "#C4");
9569                 }
9570
9571                 [Test]
9572                 public void GetCustomAttributes_InflatedType ()
9573                 {
9574                         TypeBuilder tb = module.DefineType (genTypeName ());
9575                         tb.DefineGenericParameters (new string[] { "FOO" });
9576
9577                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9578                                 new Type [] { typeof (string) });
9579
9580                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9581                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9582
9583                         tb.SetCustomAttribute (caBuilder);
9584                         Type t = tb.CreateType ();
9585
9586                         Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9587
9588                         Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9589                 }
9590
9591                 [Test]
9592                 public void GetField ()
9593                 {
9594                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9595                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9596
9597                         ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9598
9599                         FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9600
9601                         Type t = tb.MakeGenericType (typeof (int));
9602
9603                         // Chect that calling MakeArrayType () does not initialize the class
9604                         // (bug #351172)
9605                         t.MakeArrayType ();
9606
9607                         // Check that the instantiation of a type builder contains live data
9608                         TypeBuilder.GetField (t, fb1);
9609                         FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9610                         FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9611
9612                         MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9613                         ILGenerator ilgen = mb.GetILGenerator ();
9614                         ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9615                         ilgen.Emit (OpCodes.Dup);
9616                         ilgen.Emit (OpCodes.Ldc_I4, 42);
9617                         ilgen.Emit (OpCodes.Stfld, fi2);
9618                         ilgen.Emit (OpCodes.Ldfld, fi2);
9619                         ilgen.Emit (OpCodes.Ret);
9620
9621                         // Check GetField on a type instantiated with type parameters
9622                         Type t3 = tb.MakeGenericType (typeParams [0]);
9623                         FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9624                         FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9625
9626                         MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9627                         ILGenerator ilgen3 = mb3.GetILGenerator ();
9628                         ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9629                         ilgen3.Emit (OpCodes.Ldfld, fi3);
9630                         ilgen3.Emit (OpCodes.Ret);
9631
9632                         Type created = tb.CreateType ();
9633
9634                         Type inst = created.MakeGenericType (typeof (object));
9635
9636                         Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9637
9638                         Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9639                 }
9640                 
9641                 [Test] //bug #354047
9642                 public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9643                 {
9644                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9645                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9646                         Type t = tb.CreateType ();
9647
9648                         Type inst = tb.MakeGenericType (typeParams [0]);
9649                         Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9650                 }
9651
9652                 [Test] //bug #354047
9653                 public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9654                 {
9655                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9656                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9657                         Type t = tb.CreateType ();
9658
9659                         Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9660                         Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9661                 }
9662
9663                 [Test] //bug #354047
9664                 public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9665                 {
9666                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9667                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9668                         Type t = tb.CreateType ();
9669
9670                         Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9671                 }
9672
9673                 [Test] //bug #399047
9674                 public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9675                                 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9676
9677                                 module = assembly.DefineDynamicModule ("Instance.exe");
9678   
9679                 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9680                 Type T = G.DefineGenericParameters ("T") [0];
9681                                 ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9682                 Type GObj = G.MakeGenericType (new Type [] { T });
9683
9684                 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9685
9686                 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9687
9688                 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9689                 Type TATest = Test.DefineGenericParameters ("TA") [0];
9690                 {
9691                         Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9692
9693                         ILGenerator il = Test.GetILGenerator ();
9694
9695                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9696                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9697                         il.Emit (OpCodes.Pop);
9698
9699                         il.Emit (OpCodes.Ret);
9700                 }
9701
9702                                 MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9703                                 {
9704                                         ILGenerator il = main.GetILGenerator ();
9705                                         il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9706                                         il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9707                                         il.Emit (OpCodes.Ret);
9708                                 }
9709
9710                                 assembly.SetEntryPoint (main);
9711                 G.CreateType ();
9712                 P.CreateType ();
9713
9714                 assembly.Save ("Instance.exe");
9715                                 Thread.GetDomain ().ExecuteAssembly(Path.GetTempPath () + Path.DirectorySeparatorChar + "Instance.exe");
9716                 }
9717
9718                 [Test]
9719                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9720                 {
9721                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9722                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9723                         tb.CreateType ();
9724
9725                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9726                         module = assembly.DefineDynamicModule ("Instance.exe");
9727
9728                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9729                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9730                         ILGenerator il = mb.GetILGenerator ();
9731
9732                         il.Emit (OpCodes.Ldc_I4_1);
9733                         il.Emit (OpCodes.Newarr, typeof (int));
9734                         il.Emit (OpCodes.Dup);
9735                         il.Emit (OpCodes.Ldtoken, fb);
9736                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9737                         il.Emit (OpCodes.Ret);
9738
9739                         Type t = tb2.CreateType ();
9740                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9741                         //Console.WriteLine (res[0]);
9742                 }
9743
9744                 public interface IDelegateFactory
9745                 {
9746                         Delegate Create (Delegate del);
9747                 }
9748
9749                 [Test]
9750                 public void CreateType_Ctor_NoBody ()
9751                 {
9752                         TypeBuilder tb = module.DefineType (genTypeName ());
9753                         tb.DefineConstructor (MethodAttributes.Public,
9754                                 CallingConventions.Standard,
9755                                 new Type [] { typeof (string) });
9756                         try {
9757                                 tb.CreateType ();
9758                                 Assert.Fail ("#1");
9759                         } catch (InvalidOperationException ex) {
9760                                 // Method '.ctor' does not have a method body
9761                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9762                                 Assert.IsNull (ex.InnerException, "#3");
9763                                 Assert.IsNotNull (ex.Message, "#4");
9764                                 Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9765                         }
9766                 }
9767
9768                 [Test] //bug #361689
9769                 public void CreateTypeFailsWithInvalidMethodOverride ()
9770                 {
9771                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9772
9773                         MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
9774                         ILGenerator gen = mc.GetILGenerator ();
9775                         gen.Emit (OpCodes.Ldarg_0);
9776                         gen.Emit (OpCodes.Ret);
9777                         tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
9778                         try {
9779                                 tb.CreateType ();
9780                                 Assert.Fail ("#1 create type did not throw TypeLoadException");
9781                         } catch (TypeLoadException) {
9782                         
9783                         }
9784                 }
9785
9786                 [Test] //bug #349194
9787                 public void IsAssignableToWorksWithInterfacesOnParent ()
9788                 {
9789             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9790                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
9791
9792                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9793                         Type t = tb.CreateType ();
9794                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9795                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
9796                         
9797                         
9798                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9799                         Type t2 = tb2.CreateType ();
9800                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9801                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
9802                 }
9803
9804
9805                 [Test] //bug #430508
9806                 public void MakeGenericTypeRespectBaseType ()
9807                 {
9808             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9809                         EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
9810
9811                         MethodBuilder mb = tb.DefineMethod ("Test",
9812                                                                                                 MethodAttributes.Public,
9813                                                                                                 typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
9814                                                                                                 new Type [0]);
9815                         ILGenerator il = mb.GetILGenerator();
9816                         il.Emit (OpCodes.Ldnull);
9817                         il.Emit (OpCodes.Ret);
9818         
9819                         Type e = eb.CreateType ();
9820                         Type c = tb.CreateType ();
9821                 
9822                         Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
9823                 }
9824
9825                 [Test]
9826                 public void GetCustomAttrOnFieldOfInflatedType ()
9827                 {
9828                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9829                         tb.DefineGenericParameters ("T");
9830
9831                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9832                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9833                                 new object [0]);
9834
9835                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9836                         field.SetCustomAttribute (caBuilder);
9837
9838                         Type t = tb.CreateType ();
9839
9840                         FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9841                         object[] cattrs = fi.GetCustomAttributes (false);
9842                         Assert.AreEqual (1, cattrs.Length);
9843
9844                         fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9845                         cattrs = fi.GetCustomAttributes (false);
9846                         Assert.AreEqual (1, cattrs.Length);
9847                 }
9848
9849                 [Test]
9850                 public void GetCustomAttrOnPropertyOfInflatedType ()
9851                 {
9852                         TypeBuilder tb = module.DefineType (genTypeName ());
9853                         tb.DefineGenericParameters ("T");
9854
9855                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9856                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9857                                 new object [0]);
9858
9859                         PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
9860                         property.SetCustomAttribute (caBuilder);
9861
9862                         Type t = tb.CreateType ();
9863
9864                         PropertyInfo pi = t.GetProperties ()[0];
9865                         object[] cattrs = pi.GetCustomAttributes (false);
9866                         Assert.AreEqual (1, cattrs.Length);
9867
9868                         pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
9869                         cattrs = pi.GetCustomAttributes (false);
9870                         Assert.AreEqual (1, cattrs.Length);
9871                 }
9872
9873                 [Test]
9874                 public void GetCustomAttrOnEventOfInflatedType ()
9875                 {
9876                         TypeBuilder tb = module.DefineType (genTypeName ());
9877                         tb.DefineGenericParameters ("T");
9878
9879                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9880                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9881                                 new object [0]);
9882
9883                         EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
9884                         evt.SetCustomAttribute (caBuilder);
9885
9886                         Type t = tb.CreateType ();
9887
9888                         EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9889                         object[] cattrs = ei.GetCustomAttributes (false);
9890                         Assert.AreEqual (1, cattrs.Length);
9891
9892                         ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9893                         cattrs = ei.GetCustomAttributes (false);
9894                         Assert.AreEqual (1, cattrs.Length);
9895                 }
9896
9897                 public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
9898                 {
9899                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9900                         tb.DefineGenericParameters ("T");
9901  
9902                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9903                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9904                                 new object [0]);
9905
9906                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9907                         field.SetCustomAttribute (caBuilder);
9908
9909
9910                         tb.MakeGenericType (typeof (int)).GetMethods ();
9911                         tb.MakeGenericType (typeof (double)).GetMethods ();
9912                         
9913                         Type t = tb.CreateType ();
9914                         
9915                         t.MakeGenericType (typeof (int)).GetMethods ();
9916                         t.MakeGenericType (typeof (double)).GetMethods ();
9917                 }
9918
9919                 [Test]
9920                 public void TestGenericFieldAccess () // bug #467415
9921                 {
9922                         AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
9923                         AppDomain domain = AppDomain.CurrentDomain;
9924                         AssemblyBuilder demoAssembly =
9925                                 domain.DefineDynamicAssembly(asmName,
9926                                                 AssemblyBuilderAccess.RunAndSave);
9927
9928                         // Define the module that contains the code. For an
9929                         // assembly with one module, the module name is the
9930                         // assembly name plus a file extension.
9931                         ModuleBuilder demoModule =
9932                                 demoAssembly.DefineDynamicModule(asmName.Name,
9933                                                 asmName.Name+".dll");
9934
9935                         TypeBuilder demoType =
9936                                 demoModule.DefineType("DemoType", TypeAttributes.Public);
9937
9938                         MethodBuilder factory =
9939                                 demoType.DefineMethod("Factory",
9940                                                 MethodAttributes.Public | MethodAttributes.Static);
9941
9942                         string[] typeParameterNames = {"T"};
9943                         GenericTypeParameterBuilder[] typeParameters =
9944                                 factory.DefineGenericParameters(typeParameterNames);
9945
9946                         GenericTypeParameterBuilder T = typeParameters[0];
9947
9948                         Type[] parms = {};
9949                         factory.SetParameters(parms);
9950
9951                         factory.SetReturnType(T);
9952
9953                         ILGenerator ilgen = factory.GetILGenerator();
9954
9955                         Type G = typeof(Gen<>);
9956                         Type GT = G.MakeGenericType (T);
9957                         FieldInfo GF = G.GetField("field");
9958                         FieldInfo GTF = TypeBuilder.GetField(GT, GF);
9959
9960                         ilgen.Emit(OpCodes.Ldsfld, GTF);
9961                         ilgen.Emit(OpCodes.Ret);
9962
9963                         // Complete the type.
9964                         Type dt = demoType.CreateType();
9965                         // Save the assembly, so it can be examined with Ildasm.exe.
9966                         //demoAssembly.Save(asmName.Name+".dll");
9967
9968                         MethodInfo m = dt.GetMethod("Factory");
9969                         MethodInfo bound = m.MakeGenericMethod(typeof(int));
9970
9971                         // Display a string representing the bound method.
9972                         //Console.WriteLine(bound);
9973
9974                         object[] parameters = {};
9975                         int result = (int)(bound.Invoke(null, parameters));
9976
9977                         Assert.AreEqual (0, result, "#1");
9978                 }
9979
9980                 static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
9981                 {
9982                         foreach (MethodInfo mi in methods)
9983                                 if (mi.Name == name)
9984                                         return mi;
9985                         return null;
9986                 }
9987
9988                 void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
9989                 {
9990                         ConstructorBuilder cb;
9991                         MethodBuilder mb;
9992                         PropertyBuilder pb;
9993                         EventBuilder eb;
9994                         ILGenerator ilgen;
9995
9996                         if (defineCtors) {
9997                                 //
9998                                 // instance constructors
9999                                 //
10000                                 cb = tb.DefineConstructor (MethodAttributes.Private,
10001                                         CallingConventions.Standard,
10002                                         new Type [] { typeof (int), typeof (int) });
10003                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10004
10005                                 cb = tb.DefineConstructor (MethodAttributes.Family,
10006                                         CallingConventions.Standard,
10007                                         new Type [] { typeof (string) });
10008                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10009
10010                                 cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10011                                         CallingConventions.Standard,
10012                                         new Type [] { typeof (string), typeof (string) });
10013                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10014
10015                                 cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10016                                         CallingConventions.Standard,
10017                                         new Type [] { typeof (int) });
10018                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10019
10020                                 cb = tb.DefineConstructor (MethodAttributes.Public,
10021                                         CallingConventions.Standard,
10022                                         new Type [] { typeof (int), typeof (bool) });
10023                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10024
10025                                 cb = tb.DefineConstructor (MethodAttributes.Assembly,
10026                                         CallingConventions.Standard,
10027                                         new Type [] { typeof (string), typeof (int) });
10028                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10029
10030                                 //
10031                                 // static constructors
10032                                 //
10033
10034                                 cb = tb.DefineConstructor (MethodAttributes.Private |
10035                                         MethodAttributes.Static,
10036                                         CallingConventions.Standard,
10037                                         Type.EmptyTypes);
10038                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10039                         }
10040
10041                         //
10042                         // instance methods
10043                         //
10044
10045                         mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10046                                 MethodAttributes.Private, typeof (void),
10047                                 Type.EmptyTypes);
10048                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10049
10050                         mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10051                                 MethodAttributes.Family, typeof (void),
10052                                 Type.EmptyTypes);
10053                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10054
10055                         mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10056                                 MethodAttributes.FamANDAssem, typeof (void),
10057                                 Type.EmptyTypes);
10058                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10059
10060                         mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10061                                 MethodAttributes.FamORAssem, typeof (void),
10062                                 Type.EmptyTypes);
10063                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10064
10065                         mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10066                                 MethodAttributes.Public, typeof (void),
10067                                 Type.EmptyTypes);
10068                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10069
10070                         mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10071                                 MethodAttributes.Assembly, typeof (void),
10072                                 Type.EmptyTypes);
10073                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10074
10075                         //
10076                         // static methods
10077                         //
10078
10079                         mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10080                                 MethodAttributes.Private | MethodAttributes.Static,
10081                                 typeof (void), Type.EmptyTypes);
10082                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10083
10084                         mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10085                                 MethodAttributes.Family | MethodAttributes.Static,
10086                                 typeof (void), Type.EmptyTypes);
10087                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10088
10089                         mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10090                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10091                                 typeof (void), Type.EmptyTypes);
10092                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10093
10094                         mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10095                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10096                                 typeof (void), Type.EmptyTypes);
10097                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10098
10099                         mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10100                                 MethodAttributes.Public | MethodAttributes.Static,
10101                                 typeof (void), Type.EmptyTypes);
10102                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10103
10104                         mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10105                                 MethodAttributes.Assembly | MethodAttributes.Static,
10106                                 typeof (void), Type.EmptyTypes);
10107                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10108
10109                         //
10110                         // instance fields
10111                         //
10112
10113                         tb.DefineField ("privateInstance" + suffix,
10114                                 typeof (string), FieldAttributes.Private);
10115                         tb.DefineField ("familyInstance" + suffix,
10116                                 typeof (string), FieldAttributes.Family);
10117                         tb.DefineField ("famANDAssemInstance" + suffix,
10118                                 typeof (string), FieldAttributes.FamANDAssem);
10119                         tb.DefineField ("famORAssemInstance" + suffix,
10120                                 typeof (string), FieldAttributes.FamORAssem);
10121                         tb.DefineField ("publicInstance" + suffix,
10122                                 typeof (string), FieldAttributes.Public);
10123                         tb.DefineField ("assemblyInstance" + suffix,
10124                                 typeof (string), FieldAttributes.Assembly);
10125
10126                         //
10127                         // static fields
10128                         //
10129
10130                         tb.DefineField ("privateStatic" + suffix,
10131                                 typeof (string), FieldAttributes.Private |
10132                                 FieldAttributes.Static);
10133                         tb.DefineField ("familyStatic" + suffix,
10134                                 typeof (string), FieldAttributes.Family |
10135                                 FieldAttributes.Static);
10136                         tb.DefineField ("famANDAssemStatic" + suffix,
10137                                 typeof (string), FieldAttributes.FamANDAssem |
10138                                 FieldAttributes.Static);
10139                         tb.DefineField ("famORAssemStatic" + suffix,
10140                                 typeof (string), FieldAttributes.FamORAssem |
10141                                 FieldAttributes.Static);
10142                         tb.DefineField ("publicStatic" + suffix,
10143                                 typeof (string), FieldAttributes.Public |
10144                                 FieldAttributes.Static);
10145                         tb.DefineField ("assemblyStatic" + suffix,
10146                                 typeof (string), FieldAttributes.Assembly |
10147                                 FieldAttributes.Static);
10148
10149                         //
10150                         // instance properties
10151                         //
10152
10153                         pb = tb.DefineProperty ("PrivateInstance" + suffix,
10154                                 PropertyAttributes.None, typeof (string),
10155                                 Type.EmptyTypes);
10156                         mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10157                                 MethodAttributes.Private, typeof (string),
10158                                 Type.EmptyTypes);
10159                         ilgen = mb.GetILGenerator ();
10160                         ilgen.Emit (OpCodes.Ldnull);
10161                         ilgen.Emit (OpCodes.Ret);
10162                         pb.SetGetMethod (mb);
10163
10164                         pb = tb.DefineProperty ("FamilyInstance" + suffix,
10165                                 PropertyAttributes.None, typeof (string),
10166                                 Type.EmptyTypes);
10167                         mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10168                                 MethodAttributes.Family, typeof (string),
10169                                 Type.EmptyTypes);
10170                         ilgen = mb.GetILGenerator ();
10171                         ilgen.Emit (OpCodes.Ldnull);
10172                         ilgen.Emit (OpCodes.Ret);
10173                         pb.SetGetMethod (mb);
10174
10175                         pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10176                                 PropertyAttributes.None, typeof (string),
10177                                 Type.EmptyTypes);
10178                         mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10179                                 MethodAttributes.FamANDAssem, typeof (string),
10180                                 Type.EmptyTypes);
10181                         ilgen = mb.GetILGenerator ();
10182                         ilgen.Emit (OpCodes.Ldnull);
10183                         ilgen.Emit (OpCodes.Ret);
10184                         pb.SetGetMethod (mb);
10185
10186                         pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10187                                 PropertyAttributes.None, typeof (string),
10188                                 Type.EmptyTypes);
10189                         mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10190                                 MethodAttributes.FamORAssem, typeof (string),
10191                                 Type.EmptyTypes);
10192                         ilgen = mb.GetILGenerator ();
10193                         ilgen.Emit (OpCodes.Ldnull);
10194                         ilgen.Emit (OpCodes.Ret);
10195                         pb.SetGetMethod (mb);
10196
10197                         pb = tb.DefineProperty ("PublicInstance" + suffix,
10198                                 PropertyAttributes.None, typeof (string),
10199                                 Type.EmptyTypes);
10200                         mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10201                                 MethodAttributes.Public, typeof (string),
10202                                 Type.EmptyTypes);
10203                         ilgen = mb.GetILGenerator ();
10204                         ilgen.Emit (OpCodes.Ldnull);
10205                         ilgen.Emit (OpCodes.Ret);
10206                         pb.SetGetMethod (mb);
10207
10208                         pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10209                                 PropertyAttributes.None, typeof (string),
10210                                 Type.EmptyTypes);
10211                         mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10212                                 MethodAttributes.Assembly, typeof (string),
10213                                 Type.EmptyTypes);
10214                         ilgen = mb.GetILGenerator ();
10215                         ilgen.Emit (OpCodes.Ldnull);
10216                         ilgen.Emit (OpCodes.Ret);
10217                         pb.SetGetMethod (mb);
10218
10219                         //
10220                         // static properties
10221                         //
10222
10223                         pb = tb.DefineProperty ("PrivateStatic" + suffix,
10224                                 PropertyAttributes.None, typeof (string),
10225                                 Type.EmptyTypes);
10226                         mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10227                                 MethodAttributes.Private | MethodAttributes.Static,
10228                                 typeof (string), Type.EmptyTypes);
10229                         ilgen = mb.GetILGenerator ();
10230                         ilgen.Emit (OpCodes.Ldnull);
10231                         ilgen.Emit (OpCodes.Ret);
10232                         pb.SetGetMethod (mb);
10233
10234                         pb = tb.DefineProperty ("FamilyStatic" + suffix,
10235                                 PropertyAttributes.None, typeof (string),
10236                                 Type.EmptyTypes);
10237                         mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10238                                 MethodAttributes.Family | MethodAttributes.Static,
10239                                 typeof (string), Type.EmptyTypes);
10240                         ilgen = mb.GetILGenerator ();
10241                         ilgen.Emit (OpCodes.Ldnull);
10242                         ilgen.Emit (OpCodes.Ret);
10243                         pb.SetGetMethod (mb);
10244
10245                         pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10246                                 PropertyAttributes.None, typeof (string),
10247                                 Type.EmptyTypes);
10248                         mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10249                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10250                                 typeof (string), Type.EmptyTypes);
10251                         ilgen = mb.GetILGenerator ();
10252                         ilgen.Emit (OpCodes.Ldnull);
10253                         ilgen.Emit (OpCodes.Ret);
10254                         pb.SetGetMethod (mb);
10255
10256                         pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10257                                 PropertyAttributes.None, typeof (string),
10258                                 Type.EmptyTypes);
10259                         mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10260                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10261                                 typeof (string), Type.EmptyTypes);
10262                         ilgen = mb.GetILGenerator ();
10263                         ilgen.Emit (OpCodes.Ldnull);
10264                         ilgen.Emit (OpCodes.Ret);
10265                         pb.SetGetMethod (mb);
10266
10267                         pb = tb.DefineProperty ("PublicStatic" + suffix,
10268                                 PropertyAttributes.None, typeof (string),
10269                                 Type.EmptyTypes);
10270                         mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10271                                 MethodAttributes.Public | MethodAttributes.Static,
10272                                 typeof (string), Type.EmptyTypes);
10273                         ilgen = mb.GetILGenerator ();
10274                         ilgen.Emit (OpCodes.Ldnull);
10275                         ilgen.Emit (OpCodes.Ret);
10276                         pb.SetGetMethod (mb);
10277
10278                         pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10279                                 PropertyAttributes.None, typeof (string),
10280                                 Type.EmptyTypes);
10281                         mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10282                                 MethodAttributes.Assembly | MethodAttributes.Static,
10283                                 typeof (string), Type.EmptyTypes);
10284                         ilgen = mb.GetILGenerator ();
10285                         ilgen.Emit (OpCodes.Ldnull);
10286                         ilgen.Emit (OpCodes.Ret);
10287                         pb.SetGetMethod (mb);
10288
10289                         //
10290                         // instance events
10291                         //
10292
10293                         eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10294                                 EventAttributes.None, typeof (EventHandler));
10295                         mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10296                                 MethodAttributes.Private, typeof (void),
10297                                 Type.EmptyTypes);
10298                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10299                         eb.SetAddOnMethod (mb);
10300
10301                         eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10302                                 EventAttributes.None, typeof (EventHandler));
10303                         mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10304                                 MethodAttributes.Family, typeof (void),
10305                                 Type.EmptyTypes);
10306                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10307                         eb.SetAddOnMethod (mb);
10308
10309                         eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10310                                 EventAttributes.None, typeof (EventHandler));
10311                         mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10312                                 MethodAttributes.FamANDAssem, typeof (void),
10313                                 Type.EmptyTypes);
10314                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10315                         eb.SetAddOnMethod (mb);
10316
10317                         eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10318                                 EventAttributes.None, typeof (EventHandler));
10319                         mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10320                                 MethodAttributes.FamORAssem, typeof (void),
10321                                 Type.EmptyTypes);
10322                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10323                         eb.SetAddOnMethod (mb);
10324
10325                         eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10326                                 EventAttributes.None, typeof (EventHandler));
10327                         mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10328                                 MethodAttributes.Public, typeof (void),
10329                                 Type.EmptyTypes);
10330                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10331                         eb.SetAddOnMethod (mb);
10332
10333                         eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10334                                 EventAttributes.None, typeof (EventHandler));
10335                         mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10336                                 MethodAttributes.Family, typeof (void),
10337                                 Type.EmptyTypes);
10338                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10339                         eb.SetAddOnMethod (mb);
10340
10341                         //
10342                         // static events
10343                         //
10344
10345                         eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10346                                 EventAttributes.None, typeof (EventHandler));
10347                         mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10348                                 MethodAttributes.Private | MethodAttributes.Static,
10349                                 typeof (void), Type.EmptyTypes);
10350                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10351                         eb.SetAddOnMethod (mb);
10352
10353                         eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10354                                 EventAttributes.None, typeof (EventHandler));
10355                         mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10356                                 MethodAttributes.Family | MethodAttributes.Static,
10357                                 typeof (void), Type.EmptyTypes);
10358                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10359                         eb.SetAddOnMethod (mb);
10360
10361                         eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10362                                 EventAttributes.None, typeof (EventHandler));
10363                         mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10364                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10365                                 typeof (void), Type.EmptyTypes);
10366                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10367                         eb.SetAddOnMethod (mb);
10368
10369                         eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10370                                 EventAttributes.None, typeof (EventHandler));
10371                         mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10372                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10373                                 typeof (void), Type.EmptyTypes);
10374                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10375                         eb.SetAddOnMethod (mb);
10376
10377                         eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10378                                 EventAttributes.None, typeof (EventHandler));
10379                         mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10380                                 MethodAttributes.Public | MethodAttributes.Static,
10381                                 typeof (void), Type.EmptyTypes);
10382                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10383                         eb.SetAddOnMethod (mb);
10384
10385                         eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10386                                 EventAttributes.None, typeof (EventHandler));
10387                         mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10388                                 MethodAttributes.Family | MethodAttributes.Static,
10389                                 typeof (void), Type.EmptyTypes);
10390                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10391                         eb.SetAddOnMethod (mb);
10392                 }
10393
10394                 static TypeBuilder Resolve1_Tb;
10395                 static bool Resolve1_Called;
10396
10397                 public class Lookup<T>
10398                 {
10399                         public static Type t = typeof(T);
10400                 }
10401
10402                 Assembly Resolve1 (object sender, ResolveEventArgs args) {
10403                         Resolve1_Called = true;
10404                         Resolve1_Tb.CreateType ();
10405                         return Resolve1_Tb.Assembly;
10406                 }
10407
10408                 [Test]
10409                 public void TypeResolveGenericInstances () {
10410                         // Test that TypeResolve is called for generic instances (#483852)
10411                         TypeBuilder tb1 = null;
10412
10413                         AppDomain.CurrentDomain.TypeResolve += Resolve1;
10414
10415                         tb1 = module.DefineType("Foo");
10416                         Resolve1_Tb = tb1;
10417                         FieldInfo field = TypeBuilder.GetField(typeof(Lookup<>).MakeGenericType(tb1), typeof(Lookup<>).GetField("t"));
10418                         TypeBuilder tb2 = module.DefineType("Bar");
10419                         ConstructorBuilder cb = tb2.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
10420                         ILGenerator ilgen = cb.GetILGenerator();
10421                         
10422                         ilgen.Emit(OpCodes.Ldarg_0);
10423                         ilgen.Emit(OpCodes.Call, tb2.BaseType.GetConstructor(Type.EmptyTypes));
10424
10425                         ilgen.Emit(OpCodes.Ldsfld, field);
10426                         ilgen.Emit(OpCodes.Pop);
10427                         ilgen.Emit(OpCodes.Ret);
10428                         Activator.CreateInstance(tb2.CreateType());
10429
10430                         Assert.IsTrue (Resolve1_Called);
10431                 }
10432
10433                 [Test]
10434                 public void CreateConcreteTypeWithAbstractMethod ()
10435                 {
10436                         TypeBuilder tb = module.DefineType (genTypeName ());
10437                         tb.DefineMethod("method", MethodAttributes.Abstract | MethodAttributes.Public, typeof (void), Type.EmptyTypes);
10438                         try {
10439                                 tb.CreateType ();
10440                                 Assert.Fail ("#1");
10441                         } catch (InvalidOperationException) {}
10442                 }
10443
10444                 [Test]
10445                 public void ConcreteTypeDontLeakGenericParamFromItSelf ()
10446                 {
10447             var tb = module.DefineType (genTypeName ());
10448                         var gps = tb.DefineGenericParameters ("T");
10449             var mb = tb.DefineMethod ("m", MethodAttributes.Public | MethodAttributes.Static);
10450             mb.SetParameters (gps);
10451             mb.GetILGenerator ().Emit (OpCodes.Ret);
10452
10453             var ti = tb.CreateType ();
10454             var mi = ti.GetMethod ("m");
10455                         var arg0 = mi.GetParameters () [0].ParameterType;
10456
10457                         Assert.AreNotSame (arg0, gps [0], "#1");
10458                 }
10459
10460                 [Test]
10461                 public void ConcreteTypeDontLeakGenericParamFromMethods ()
10462                 {
10463             var tb = module.DefineType (genTypeName ());
10464             var mb = tb.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Static);
10465             var gps = mb.DefineGenericParameters ("T");
10466             mb.SetParameters (gps);
10467             mb.GetILGenerator ().Emit (OpCodes.Ret);
10468
10469             var ti = tb.CreateType ();
10470             var mi = ti.GetMethod ("m");
10471                         var arg0 = mi.GetParameters () [0].ParameterType;
10472
10473                         Assert.AreNotSame (arg0, gps [0], "#1");
10474                 }
10475
10476                 [Test]
10477                 public void DeclaringMethodReturnsNull ()
10478                 {
10479                         TypeBuilder tb = module.DefineType (genTypeName ());
10480                         Assert.IsNull (tb.DeclaringMethod, null, "#1");
10481                 }
10482
10483                 [Test]
10484                 public void GenericParameterPositionReturns0 ()
10485                 {
10486                         TypeBuilder tb = module.DefineType (genTypeName ());
10487                         Assert.AreEqual (0, tb.GenericParameterPosition, "#1");
10488                 }
10489
10490                 [Test]
10491                 public void GetGenericTypeDefinitionBehavior ()
10492                 {
10493                         TypeBuilder tb = module.DefineType (genTypeName ());
10494                         try {
10495                                 tb.GetGenericTypeDefinition ();
10496                                 Assert.Fail ("#1");
10497                         } catch (InvalidOperationException) {}
10498
10499                         tb.DefineGenericParameters ("T");
10500                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#2");
10501
10502                         tb.CreateType ();
10503                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#3");
10504                 }
10505
10506                 [Test]
10507                 public void GetElementTypeNotSupported ()
10508                 {
10509                         TypeBuilder tb = module.DefineType (genTypeName ());
10510                         try {
10511                                 tb.GetElementType ();
10512                                 Assert.Fail ("#1");
10513                         } catch (NotSupportedException) {}
10514                 }
10515
10516                 [Test]
10517                 public void GenericParameterAttributesReturnsNone ()
10518                 {
10519                         TypeBuilder tb = module.DefineType (genTypeName ());
10520                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#1");
10521
10522                         tb.DefineGenericParameters ("T");
10523                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#2");
10524
10525                         tb.CreateType ();
10526                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#3");
10527                 }
10528
10529                 [Test]
10530                 public void GetGenericArgumentsReturnsNullForNonGenericTypeBuilder ()
10531                 {
10532                         TypeBuilder tb = module.DefineType (genTypeName ());
10533                         Assert.IsNull (tb.GetGenericArguments (), "#1");
10534                 }
10535
10536                 public interface IFaceA {}
10537                 public interface IFaceB : IFaceA {}
10538                 [Test]
10539                 public void GetInterfacesAfterCreate ()
10540                 {
10541                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type[] { typeof (IFaceB) });
10542
10543                         Type[] ifaces = tb.GetInterfaces ();
10544                         Assert.AreEqual (1, ifaces.Length, "#1");
10545                         Assert.AreEqual (typeof (IFaceB), ifaces [0], "#2");
10546
10547                         tb.CreateType ();
10548                         ifaces = tb.GetInterfaces ();
10549                         Assert.AreEqual (2, ifaces.Length, "#3");
10550                         //Interfaces can come in any particular order
10551                         if (ifaces [0] == typeof (IFaceB)) {
10552                                 Assert.AreEqual (typeof (IFaceB), ifaces [0], "#4");
10553                                 Assert.AreEqual (typeof (IFaceA), ifaces [1], "#5");
10554                         } else {
10555                                 Assert.AreEqual (typeof (IFaceB), ifaces [1], "#4");
10556                                 Assert.AreEqual (typeof (IFaceA), ifaces [0], "#5");
10557                         }
10558                 }
10559
10560                 public interface MB_Iface
10561                 {
10562                     int Test ();
10563                 }
10564
10565                 public class MB_Impl : MB_Iface
10566                 {
10567                     public virtual int Test () { return 1; }
10568                 }
10569                 [Test]
10570                 public void MethodOverrideBodyMustBelongToTypeBuilder ()
10571                 {
10572                         TypeBuilder tb = module.DefineType (genTypeName ());
10573                         MethodInfo md = typeof (MB_Iface).GetMethod("Test");
10574             MethodInfo md2 = typeof (MB_Impl).GetMethod("Test");
10575                         try {
10576                 tb.DefineMethodOverride (md, md2);
10577                 Assert.Fail ("#1");
10578                         } catch (ArgumentException) {}
10579                 }
10580
10581                 [Test]
10582                 public void GetConstructorsThrowWhenIncomplete ()
10583                 {
10584                         TypeBuilder tb = module.DefineType (genTypeName ());
10585                         try {
10586                                 tb.GetConstructors (BindingFlags.Instance);
10587                                 Assert.Fail ("#1");
10588                         } catch (NotSupportedException) { }
10589
10590                         tb.CreateType ();
10591                         Assert.IsNotNull (tb.GetConstructors (BindingFlags.Instance), "#2");
10592                 }
10593
10594                 [Test]
10595                 public void GetEventsThrowWhenIncomplete ()
10596                 {
10597                         TypeBuilder tb = module.DefineType (genTypeName ());
10598                         try {
10599                                 tb.GetEvents (BindingFlags.Instance);
10600                                 Assert.Fail ("#1");
10601                         } catch (NotSupportedException) { }
10602
10603                         tb.CreateType ();
10604                         Assert.IsNotNull (tb.GetEvents (BindingFlags.Instance), "#2");
10605                 }
10606
10607                 [Test]
10608                 public void GetNestedTypeCreatedAfterTypeIsCreated ()
10609                 {
10610                         TypeBuilder tb = module.DefineType (genTypeName ());
10611                         TypeBuilder nested = tb.DefineNestedType ("Bar", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10612                         tb.CreateType ();
10613                         Assert.IsNull (tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#1");
10614                         Type res = nested.CreateType ();
10615                         Assert.AreEqual (res, tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#2");
10616
10617                         TypeBuilder nested2 = tb.DefineNestedType ("Bar2", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10618                         Assert.IsNull (tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#3");
10619                         res = nested2.CreateType ();
10620                         Assert.AreEqual (res, tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#4");
10621                 }
10622
10623
10624                 [Test]
10625                 public void IsDefinedThrowWhenIncomplete ()
10626                 {
10627                         TypeBuilder tb = module.DefineType (genTypeName ());
10628                         try {
10629                                 tb.IsDefined (typeof (string), true);
10630                                 Assert.Fail ("#1");
10631                         } catch (NotSupportedException) { }
10632
10633                         tb.CreateType ();
10634                         Assert.IsNotNull (tb.IsDefined (typeof (string), true), "#2");
10635                 }
10636
10637                 [Test] //Bug #594728
10638                 public void IsSubclassOfWorksIfSetParentIsCalledOnParent ()
10639                 {
10640                         var tb_a = module.DefineType ("A", TypeAttributes.Public);
10641                         var tb_b = module.DefineType ("B", TypeAttributes.Public);
10642         
10643                         tb_b.SetParent (tb_a);
10644                         tb_a.SetParent (typeof (Attribute));
10645         
10646                         Assert.IsTrue (tb_b.IsSubclassOf (tb_a), "#1");
10647                         Assert.IsTrue (tb_b.IsSubclassOf (typeof (Attribute)), "#2");
10648                         Assert.IsFalse (tb_a.IsSubclassOf (tb_b), "#3");
10649         
10650         
10651                         var a = tb_a.CreateType ();
10652                         var b = tb_b.CreateType ();
10653         
10654                         Assert.IsTrue (b.IsSubclassOf (a), "#4");
10655                         Assert.IsTrue (b.IsSubclassOf (typeof (Attribute)), "#5");
10656                         Assert.IsFalse (a.IsSubclassOf (b), "#6");
10657                 }
10658
10659                 [Test]
10660                 public void DefinedDefaultConstructorWorksWithGenericBaseType ()
10661                 {
10662                         AssemblyName assemblyName = new AssemblyName ("a");
10663                         AssemblyBuilder ass = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.RunAndSave);
10664                         var mb = ass.DefineDynamicModule ("a.dll");
10665
10666                         var tb = mb.DefineType ("Base");
10667                         tb.DefineGenericParameters ("F");
10668
10669                         var inst = tb.MakeGenericType (typeof (int));
10670                         var tb2 = mb.DefineType ("Child", TypeAttributes.Public, inst);
10671
10672                         tb.CreateType ();
10673                         var res = tb2.CreateType ();
10674
10675                         Assert.IsNotNull (res, "#1");
10676                         Assert.AreEqual (1, res.GetConstructors ().Length, "#2");
10677                 }
10678
10679                 /* 
10680                  * Tests for passing user types to Ref.Emit. Currently these only test
10681                  * whenever the runtime code can handle them without crashing, since we
10682                  * don't support user types yet.
10683                  * These tests are disabled for windows since the MS runtime trips on them.
10684                  */
10685                 [Test]
10686                 [Category ("NotDotNet")] //Proper UT handling is a mono extension to SRE bugginess
10687                 public void UserTypes () {
10688                         TypeDelegator t = new TypeDelegator (typeof (int));
10689
10690                         try {
10691                                 /* Parent */
10692                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10693                         } catch {
10694                         }
10695
10696                         try {
10697                                 /* Interfaces */
10698                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10699                                 tb.CreateType ();
10700                         } catch {
10701                         }
10702
10703                         try {
10704                                 /* Fields */
10705                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10706                                 tb.DefineField ("Foo", t, FieldAttributes.Public);
10707                                 tb.CreateType ();
10708                         } catch {
10709                         }
10710
10711                         try {
10712                                 /* Custom modifiers on fields */
10713                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10714                                 tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10715                                 tb.CreateType ();
10716                         } catch {
10717                         }
10718 /* this is mono only
10719                         try {
10720                                 UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10721                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10722                                 FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10723                                 fb.SetMarshal (m);
10724                                 tb.CreateType ();
10725                         } catch {
10726                         }
10727 */
10728                         try {
10729                                 /* Properties */
10730                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10731                                 tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10732                                 tb.CreateType ();
10733                         } catch {
10734                         }
10735
10736                         try {
10737                                 /* Custom modifiers on properties */
10738                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10739                                 // FIXME: These seems to be ignored
10740                                 tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10741                                 tb.CreateType ();
10742                         } catch {
10743                         }
10744
10745                         try {
10746                                 /* Method return types */
10747                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10748                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10749                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10750                                 tb.CreateType ();
10751                         } catch {
10752                         }
10753
10754                         try {
10755                                 /* Custom modifiers on method return types */
10756                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10757                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10758                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10759                                 tb.CreateType ();
10760                         } catch {
10761                         }
10762
10763                         try {
10764                                 /* Method parameters */
10765                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10766                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10767                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10768                                 tb.CreateType ();
10769                         } catch {
10770                         }
10771
10772                         try {
10773                                 /* Custom modifiers on method parameters */
10774                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10775                                 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 }});
10776                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10777                                 tb.CreateType ();
10778                         } catch {
10779                         }
10780
10781                         try {
10782                                 /* Ctor parameters */
10783                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10784                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10785                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10786                                 tb.CreateType ();
10787                         } catch {
10788                         }
10789                         
10790                         try {
10791                                 /* Custom modifiers on ctor parameters */
10792                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10793                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10794                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10795                                 tb.CreateType ();
10796                         } catch {
10797                         }
10798
10799                         try {
10800                                 /* SignatureHelper arguments */
10801                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10802                                 sighelper.AddArgument (t, false);
10803                                 byte[] arr = sighelper.GetSignature ();
10804                         } catch {
10805                         }
10806
10807                         try {
10808                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10809                                 sighelper.AddArgument (t, false);
10810                                 byte[] arr = sighelper.GetSignature ();
10811                         } catch {
10812                         }
10813
10814                         try {
10815                                 /* Custom modifiers on SignatureHelper arguments */
10816                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10817                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10818                                 byte[] arr = sighelper.GetSignature ();
10819                         } catch {
10820                         }
10821
10822                         try {
10823                                 /* Custom modifiers on SignatureHelper arguments */
10824                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10825                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10826                                 byte[] arr = sighelper.GetSignature ();
10827                         } catch {
10828                         }
10829
10830                         /* Arguments to ILGenerator methods */
10831                         try {
10832                                 /* Emit () */
10833                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10834                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10835                                 ILGenerator ig = mb.GetILGenerator ();
10836                                 ig.Emit (OpCodes.Ldnull);
10837                                 ig.Emit (OpCodes.Castclass, t);
10838                                 ig.Emit (OpCodes.Pop);
10839                                 ig.Emit (OpCodes.Ret);
10840                                 tb.CreateType ();
10841                         } catch {
10842                         }
10843
10844                         try {
10845                                 /* DeclareLocal () */
10846                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10847                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10848                                 ILGenerator ig = mb.GetILGenerator ();
10849                                 ig.DeclareLocal (t);
10850                                 ig.Emit (OpCodes.Ret);
10851                                 tb.CreateType ();
10852                         } catch {
10853                         }
10854
10855                         try {
10856                                 /* BeginExceptionCatchBlock () */
10857                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10858                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10859                                 ILGenerator ig = mb.GetILGenerator ();
10860                                 ig.BeginExceptionBlock ();
10861                                 ig.BeginCatchBlock (t);
10862                                 ig.Emit (OpCodes.Ret);
10863                                 tb.CreateType ();
10864                         } catch {
10865                         }
10866
10867                         try {
10868                                 /* EmitCalli () */
10869                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10870                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10871                                 ILGenerator ig = mb.GetILGenerator ();
10872                                 ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
10873                                 ig.Emit (OpCodes.Ret);
10874                                 tb.CreateType ();
10875                         } catch {
10876                         }
10877                 }
10878
10879                 //Test for #572660
10880         [Test]
10881         public void CircularArrayType()
10882         {
10883                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndSave);
10884                         var moduleBuilder = assemblyBuilder.DefineDynamicModule("Test", "Test.dll", true);
10885                         var typeBuilder = moduleBuilder.DefineType("Foo", TypeAttributes.Public);
10886                         var fieldBuilder = typeBuilder.DefineField("Foos", typeBuilder.MakeArrayType(), FieldAttributes.Public);
10887
10888                         var fooType = typeBuilder.CreateType();
10889                         Assert.AreSame(fooType.MakeArrayType(), fooType.GetField("Foos").FieldType);
10890         }
10891
10892
10893                 [Test] //Test for #422113
10894                 [ExpectedException (typeof (TypeLoadException))]
10895                 public void CreateInstanceOfIncompleteType ()
10896                 {
10897                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class, null, new Type[] { typeof (IComparable) });
10898                         Type proxyType = tb.CreateType();
10899                         Activator.CreateInstance(proxyType);
10900                 }
10901
10902                 [Test] //Test for #640780
10903                 public void StaticMethodNotUsedInIfaceVtable ()
10904                 {
10905                         TypeBuilder tb1 = module.DefineType("Interface", TypeAttributes.Interface | TypeAttributes.Abstract);
10906                         tb1.DefineTypeInitializer().GetILGenerator().Emit(OpCodes.Ret);
10907                         tb1.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract);
10908                         tb1.CreateType();
10909                         
10910                         TypeBuilder tb2 = module.DefineType("Class", TypeAttributes.Sealed);
10911                         tb2.AddInterfaceImplementation(tb1);
10912                         tb2.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual)
10913                             .GetILGenerator().Emit(OpCodes.Ret);
10914                         tb2.DefineDefaultConstructor(MethodAttributes.Public);
10915                         
10916                         Activator.CreateInstance(tb2.CreateType());
10917                 }
10918
10919                 [Test] //Test for #648391
10920                 public void GetConstructorCheckCtorDeclaringType ()
10921                 {
10922                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10923                         string[] typeParamNames = { "TFirst" };
10924                         GenericTypeParameterBuilder[] typeParams = myType.DefineGenericParameters (typeParamNames);
10925                         var ctor = myType.DefineDefaultConstructor (MethodAttributes.Public);
10926                         var ctori = TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (int)), ctor);
10927                         try {
10928                                 TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (bool)), ctori);
10929                                 Assert.Fail ("#1");
10930                         } catch (ArgumentException) {
10931                                 //OK
10932                         }
10933                 }
10934
10935                 [Test] //Test for #649237
10936                 public void GetFieldCheckFieldDeclaringType () {
10937                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10938                         myType.DefineGenericParameters ( "TFirst");
10939                         TypeBuilder otherType = module.DefineType ("Sample2", TypeAttributes.Public);
10940                         otherType.DefineGenericParameters ( "TFirst");
10941
10942                         var field = myType.DefineField ("field", typeof (object), FieldAttributes.Public);
10943
10944                         try {
10945                                 TypeBuilder.GetField (otherType.MakeGenericType (typeof (int)), field);
10946                                 Assert.Fail ("#1");
10947                         } catch (ArgumentException) {
10948                                 //OK
10949                         }
10950                 }
10951
10952                 [Test]
10953                 public void TypeWithFieldRVAWorksUnderSgen () {
10954                 AssemblyName an = new AssemblyName("MAIN");
10955                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an,
10956                     AssemblyBuilderAccess.Run, ".");
10957                 ModuleBuilder mob = ab.DefineDynamicModule("MAIN");
10958                 TypeBuilder tb = mob.DefineType("MAIN", TypeAttributes.Public |
10959                     TypeAttributes.Sealed | TypeAttributes.Abstract |
10960                     TypeAttributes.Class | TypeAttributes.BeforeFieldInit);
10961
10962                 byte[] source = new byte[] { 42 };
10963                 FieldBuilder fb = tb.DefineInitializedData("A0", source, 0);
10964
10965                 MethodBuilder mb = tb.DefineMethod("EVAL", MethodAttributes.Static |
10966                     MethodAttributes.Public, typeof(byte[]), new Type[] { });
10967                 ILGenerator il = mb.GetILGenerator();
10968
10969                 il.Emit(OpCodes.Ldc_I4_1);
10970                 il.Emit(OpCodes.Newarr, typeof(byte));
10971                 il.Emit(OpCodes.Dup);
10972                 il.Emit(OpCodes.Ldtoken, fb);
10973                 il.Emit(OpCodes.Call, typeof(RuntimeHelpers).GetMethod("InitializeArray"));
10974                 il.Emit(OpCodes.Ret);
10975
10976                 Type t = tb.CreateType();
10977
10978                 GC.Collect();
10979
10980                 byte[] res = (byte[]) t.InvokeMember("EVAL", BindingFlags.Public |
10981                     BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
10982                     new object[] { });
10983
10984                 Assert.AreEqual (42, res[0]);
10985             }
10986
10987
10988                 [Test]
10989                 public void Ldfld_Regress_9531 () {
10990                         Build<Example<int>> ();
10991                 }
10992
10993                 void Build<T> () {
10994             var base_class = typeof(T);
10995
10996             var builder = module.DefineType(genTypeName (),
10997                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
10998                 base_class);
10999
11000             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11001             
11002             var cb = builder.DefineConstructor(
11003                 MethodAttributes.Public | MethodAttributes.SpecialName,
11004                 CallingConventions.HasThis,
11005                 new[] { typeof(string) });
11006             
11007             var il = cb.GetILGenerator();
11008             
11009             if (field == null)
11010             {
11011                 throw new InvalidOperationException("wtf");
11012             }
11013             
11014             il.Emit(OpCodes.Ldarg_0);
11015             il.Emit(OpCodes.Ldarg_1);
11016             il.Emit(OpCodes.Stfld, field);
11017             il.Emit(OpCodes.Ret);
11018             
11019             builder.CreateType();
11020                 }
11021
11022                 public class Example<T> {
11023                         public string Field;
11024                         public T Field2;
11025                 }
11026
11027                 [Test]
11028                 public void Ldfld_Encoding_10122 () {
11029                         Build2<Example<int>> ();
11030                 }
11031
11032                 void Build2<T> () {
11033                         var base_class = typeof(T);
11034
11035                 string AssemblyName = genTypeName ();
11036                 string AssemblyFileName = AssemblyName + ".dll";
11037
11038                         var assemblyBuilderAccess = AssemblyBuilderAccess.Save;
11039                         var assemblyName = new AssemblyName(AssemblyName);
11040                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
11041                         var moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName, AssemblyFileName);
11042
11043
11044                         var builder = moduleBuilder.DefineType("Wrapped",
11045                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11046                 base_class);
11047
11048             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11049             
11050             var cb = builder.DefineConstructor(
11051                 MethodAttributes.Public | MethodAttributes.SpecialName,
11052                 CallingConventions.HasThis,
11053                 new[] { typeof(string) });
11054             
11055             var il = cb.GetILGenerator();
11056             
11057             if (field == null)
11058             {
11059                 throw new InvalidOperationException("wtf");
11060             }
11061             
11062             il.Emit(OpCodes.Ldarg_0);
11063             il.Emit(OpCodes.Ldarg_1);
11064             il.Emit(OpCodes.Stfld, field);
11065             il.Emit(OpCodes.Ret);
11066             
11067             builder.CreateType();
11068
11069                         assemblyBuilder.Save (AssemblyFileName);
11070
11071                         var fromDisk = Assembly.Load (AssemblyName);
11072                         Console.WriteLine (fromDisk);
11073                         var t = fromDisk.GetType ("Wrapped");
11074                         Activator.CreateInstance (t, new object[] { "string"});
11075                 }
11076
11077                 public interface IFace16096 {
11078                         object Bar ();
11079                 }
11080
11081                 [Test]
11082                 public void MemberRef_Caching_16096 () {
11083                         var outer_class = module.DefineType(
11084                                 "container",
11085                                 TypeAttributes.Class | TypeAttributes.Public,
11086                                 typeof(object));
11087
11088                         var builder = outer_class.DefineNestedType(
11089                                 "bind@32-1",
11090                                 TypeAttributes.Class | TypeAttributes.Public,
11091                                 typeof(object));
11092
11093                         builder.AddInterfaceImplementation (typeof (IFace16096));
11094
11095                         var ctor = builder.DefineDefaultConstructor (MethodAttributes.Public);
11096                         var field = builder.DefineField ("Field", typeof (object), FieldAttributes.Public);
11097                         var g_args = builder.DefineGenericParameters("b","a");
11098                         var method = builder.DefineMethod ("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof (object), new Type [0]);
11099
11100                         var il = method.GetILGenerator();
11101                         il.Emit (OpCodes.Ldarg_0);
11102                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (builder.MakeGenericType (g_args), field));
11103                         il.Emit (OpCodes.Pop);
11104                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (builder.MakeGenericType (g_args), ctor));
11105                         il.Emit (OpCodes.Ret);
11106
11107                         var type = builder.CreateType ();
11108
11109                         /*Build a gshared instance. */
11110                         var ginst = type.MakeGenericType (typeof (List<char>), typeof (object));
11111                         var ins = (IFace16096)Activator.CreateInstance (ginst);
11112
11113                         /* This will trigger the runtime to cache the MEMBER_REF to the .ctor as it won't have a context. */
11114                         var ins2 = ins.Bar ();
11115                         Assert.IsNotNull (ins2);
11116
11117                         /* Build an unsharable version. */
11118                         var ginst2 = type.MakeGenericType (typeof (List<char>), typeof (char));
11119                         var ins3 = (IFace16096)Activator.CreateInstance (ginst2);
11120
11121                         /* This will trigger the runtime to use the cached version, which is wrong as it's an open type. */
11122                         var ins4 = ins3.Bar ();
11123                         Assert.IsNotNull (ins4);
11124                 }
11125
11126                 // #22059
11127                 [Test]
11128                 [ExpectedException (typeof (TypeLoadException))]
11129                 public void PrivateIface ()
11130                 {
11131                         TypeBuilder tb = module.DefineType ("Sample", TypeAttributes.Public, typeof (object), new[] { typeof (IFoo) });
11132             tb.CreateType();
11133                 }
11134
11135                 interface IFoo {
11136                 }
11137         }
11138 }