Ensure the System.Web.UI.WebControls.RepeatInfo_Autogen test runs under en-US
[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 (ASSEMBLY_NAME, ASSEMBLY_NAME + ".dll");
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                 [Category ("AndroidNotWorking")] // Fails with System.MethodAccessException : Method `t17:.ctor ()' is inaccessible from method `t18:.ctor ()'
1186                 public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1187                 {
1188                         TypeBuilder tb;
1189                         
1190                         tb = module.DefineType (genTypeName ());
1191                         tb.DefineDefaultConstructor (MethodAttributes.Private);
1192                         Type parent_type = tb.CreateType ();
1193
1194                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1195                                 parent_type);
1196                         tb.DefineDefaultConstructor (MethodAttributes.Public);
1197                         Type emitted_type = tb.CreateType ();
1198                         try {
1199                                 Activator.CreateInstance (emitted_type);
1200                                 Assert.Fail ("#1");
1201                         } catch (TargetInvocationException ex) {
1202                                 Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1203                                 Assert.IsNotNull (ex.InnerException, "#3");
1204                                 Assert.IsNotNull (ex.Message, "#4");
1205
1206                                 MethodAccessException mae = ex.InnerException as MethodAccessException;
1207                                 Assert.IsNotNull (mae, "#5");
1208                                 Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1209                                 Assert.IsNull (mae.InnerException, "#7");
1210                                 Assert.IsNotNull (mae.Message, "#8");
1211                                 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1212                                 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1213                         }
1214                 }
1215
1216                 [Test]
1217                 public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1218                 {
1219                         TypeBuilder tb;
1220
1221                         tb = module.DefineType (genTypeName ());
1222                         ConstructorBuilder cb = tb.DefineConstructor (
1223                                 MethodAttributes.Public,
1224                                 CallingConventions.Standard,
1225                                 new Type [] { typeof (string) });
1226                         cb.GetILGenerator ().Emit (OpCodes.Ret);
1227                         Type parent_type = tb.CreateType ();
1228
1229                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1230                                 parent_type);
1231                         try {
1232                                 tb.DefineDefaultConstructor (MethodAttributes.Public);
1233                                 Assert.Fail ("#1");
1234                         } catch (NotSupportedException ex) {
1235                                 // Parent does not have a default constructor.
1236                                 // The default constructor must be explicitly defined
1237                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1238                                 Assert.IsNull (ex.InnerException, "#3");
1239                                 Assert.IsNotNull (ex.Message, "#4");
1240                         }
1241                 }
1242
1243                 [Test]
1244                 public void DefineEvent_Name_NullChar ()
1245                 {
1246                         TypeBuilder tb = module.DefineType (genTypeName ());
1247
1248                         try {
1249                                 tb.DefineEvent ("\0test", EventAttributes.None,
1250                                         typeof (int));
1251                                 Assert.Fail ("#A1");
1252                         } catch (ArgumentException ex) {
1253                                 // Illegal name
1254                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1255                                 Assert.IsNull (ex.InnerException, "#A3");
1256                                 Assert.IsNotNull (ex.Message, "#A4");
1257                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1258                         }
1259
1260                         EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1261                                 typeof (int));
1262                         Assert.IsNotNull (eb, "#B1");
1263                 }
1264
1265                 [Test]
1266                 public void TestDefineEvent ()
1267                 {
1268                         TypeBuilder tb = module.DefineType (genTypeName ());
1269
1270                         // Test invalid arguments
1271                         try {
1272                                 tb.DefineEvent (null, 0, typeof (int));
1273                                 Assert.Fail ("#A1");
1274                         } catch (ArgumentNullException ex) {
1275                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1276                                 Assert.IsNull (ex.InnerException, "#A3");
1277                                 Assert.IsNotNull (ex.Message, "#A4");
1278                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1279                         }
1280
1281                         try {
1282                                 tb.DefineEvent ("FOO", 0, null);
1283                                 Assert.Fail ("#B1");
1284                         } catch (ArgumentNullException ex) {
1285                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1286                                 Assert.IsNull (ex.InnerException, "#B3");
1287                                 Assert.IsNotNull (ex.Message, "#B4");
1288                                 Assert.AreEqual ("type", ex.ParamName, "#B5");
1289                         }
1290
1291                         try {
1292                                 tb.DefineEvent (string.Empty, 0, typeof (int));
1293                                 Assert.Fail ("#C1");
1294                         } catch (ArgumentException ex) {
1295                                 // Empty name is not legal
1296                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1297                                 Assert.IsNull (ex.InnerException, "#C3");
1298                                 Assert.IsNotNull (ex.Message, "#C4");
1299                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1300                         }
1301
1302                         tb.CreateType ();
1303
1304                         // Can not be called on a created type
1305                         try {
1306                                 tb.DefineEvent ("BAR", 0, typeof (int));
1307                                 Assert.Fail ("#D1");
1308                         } catch (InvalidOperationException ex) {
1309                                 // Unable to change after type has been created
1310                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1311                                 Assert.IsNull (ex.InnerException, "#D3");
1312                                 Assert.IsNotNull (ex.Message, "#D4");
1313                         }
1314                 }
1315
1316                 [Test] // DefineField (String, Type, FieldAttributes)
1317                 public void DefineField1 ()
1318                 {
1319                         TypeBuilder tb = module.DefineType (genTypeName ());
1320
1321                         // Check invalid arguments
1322                         try {
1323                                 tb.DefineField (null, typeof (int), 0);
1324                                 Assert.Fail ("#A1");
1325                         } catch (ArgumentNullException ex) {
1326                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1327                                 Assert.IsNull (ex.InnerException, "#A3");
1328                                 Assert.IsNotNull (ex.Message, "#A4");
1329                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1330                         }
1331
1332                         try {
1333                                 tb.DefineField (string.Empty, typeof (int), 0);
1334                                 Assert.Fail ("#B1");
1335                         } catch (ArgumentException ex) {
1336                                 // Empty name is not legal
1337                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1338                                 Assert.IsNull (ex.InnerException, "#B3");
1339                                 Assert.IsNotNull (ex.Message, "#B4");
1340                                 Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1341                         }
1342
1343                         try {
1344                                 // Strangely, 'A<NULL>' is accepted...
1345                                 string name = String.Format ("{0}", (char) 0);
1346                                 tb.DefineField (name, typeof (int), 0);
1347                                 Assert.Fail ("#C1");
1348                         } catch (ArgumentException ex) {
1349                                 // Illegal name
1350                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1351                                 Assert.IsNull (ex.InnerException, "#C3");
1352                                 Assert.IsNotNull (ex.Message, "#C4");
1353                                 Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1354                         }
1355
1356                         try {
1357                                 tb.DefineField ("A", typeof (void), 0);
1358                                 Assert.Fail ("#D1");
1359                         } catch (ArgumentException ex) {
1360                                 // Bad field type in defining field
1361                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1362                                 Assert.IsNull (ex.InnerException, "#D3");
1363                                 Assert.IsNotNull (ex.Message, "#D4");
1364                                 Assert.IsNull (ex.ParamName, "#D5");
1365                         }
1366
1367                         tb.CreateType ();
1368
1369                         // Can not be called on a created type
1370                         try {
1371                                 tb.DefineField ("B", typeof (int), 0);
1372                                 Assert.Fail ("#E1");
1373                         } catch (InvalidOperationException ex) {
1374                                 // Unable to change after type has been created
1375                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1376                                 Assert.IsNull (ex.InnerException, "#E3");
1377                                 Assert.IsNotNull (ex.Message, "#E4");
1378                         }
1379                 }
1380
1381                 [Test] // DefineField (String, Type, FieldAttributes)
1382                 public void DefineField1_Name_NullChar ()
1383                 {
1384                         TypeBuilder tb = module.DefineType (genTypeName ());
1385
1386                         try {
1387                                 tb.DefineField ("\0test", typeof (int),
1388                                         FieldAttributes.Private);
1389                                 Assert.Fail ("#A1");
1390                         } catch (ArgumentException ex) {
1391                                 // Illegal name
1392                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1393                                 Assert.IsNull (ex.InnerException, "#A3");
1394                                 Assert.IsNotNull (ex.Message, "#A4");
1395                                 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1396                         }
1397
1398                         FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1399                                 FieldAttributes.Private);
1400                         Assert.IsNotNull (fb, "#B1");
1401                         Assert.AreEqual ("te\0st", fb.Name, "#B2");
1402                 }
1403
1404                 [Test] // DefineField (String, Type, FieldAttributes)
1405                 public void DefineField1_Type_Null ()
1406                 {
1407                         TypeBuilder tb = module.DefineType (genTypeName ());
1408
1409                         try {
1410                                 tb.DefineField ("test", (Type) null,
1411                                         FieldAttributes.Private);
1412                                 Assert.Fail ("#1");
1413                         } catch (ArgumentNullException ex) {
1414                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1415                                 Assert.IsNull (ex.InnerException, "#3");
1416                                 Assert.IsNotNull (ex.Message, "#4");
1417                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1418                         }
1419                 }
1420
1421                 [Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
1422                 public void DefineField2_Type_Null ()
1423                 {
1424                         TypeBuilder tb = module.DefineType (genTypeName ());
1425
1426                         try {
1427                                 tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1428                                         Type.EmptyTypes, FieldAttributes.Private);
1429                                 Assert.Fail ("#1");
1430                         } catch (ArgumentNullException ex) {
1431                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1432                                 Assert.IsNull (ex.InnerException, "#3");
1433                                 Assert.IsNotNull (ex.Message, "#4");
1434                                 Assert.AreEqual ("type", ex.ParamName, "#5");
1435                         }
1436                 }
1437
1438                 [Test]
1439                 public void TestDefineInitializedData ()
1440                 {
1441                         TypeBuilder tb = module.DefineType (genTypeName ());
1442
1443                         // Check invalid arguments
1444                         try {
1445                                 tb.DefineInitializedData (null, new byte [1], 0);
1446                                 Assert.Fail ("#A1");
1447                         } catch (ArgumentNullException ex) {
1448                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1449                                 Assert.IsNull (ex.InnerException, "#A3");
1450                                 Assert.IsNotNull (ex.Message, "#A4");
1451                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1452                         }
1453
1454                         try {
1455                                 tb.DefineInitializedData ("FOO", null, 0);
1456                                 Assert.Fail ("#B1");
1457                         } catch (ArgumentNullException ex) {
1458                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1459                                 Assert.IsNull (ex.InnerException, "#B3");
1460                                 Assert.IsNotNull (ex.Message, "#B4");
1461                                 Assert.AreEqual ("data", ex.ParamName, "#B5");
1462                         }
1463
1464                         try {
1465                                 tb.DefineInitializedData (string.Empty, new byte [1], 0);
1466                                 Assert.Fail ("#C1");
1467                         } catch (ArgumentException ex) {
1468                                 // Empty name is not legal
1469                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1470                                 Assert.IsNull (ex.InnerException, "#C3");
1471                                 Assert.IsNotNull (ex.Message, "#C4");
1472                                 Assert.AreEqual ("name", ex.ParamName, "#C5");
1473                         }
1474
1475                         // The size of the data is less than or equal to zero ???
1476                         try {
1477                                 tb.DefineInitializedData ("BAR", new byte [0], 0);
1478                                 Assert.Fail ("#D1");
1479                         } catch (ArgumentException ex) {
1480                                 // Data size must be > 0 and < 0x3f0000
1481                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1482                                 Assert.IsNull (ex.InnerException, "#D3");
1483                                 Assert.IsNotNull (ex.Message, "#D4");
1484                                 Assert.IsNull (ex.ParamName, "#D5");
1485                         }
1486
1487                         try {
1488                                 string name = String.Format ("{0}", (char) 0);
1489                                 tb.DefineInitializedData (name, new byte [1], 0);
1490                                 Assert.Fail ("#E1");
1491                         } catch (ArgumentException ex) {
1492                                 // Illegal name
1493                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1494                                 Assert.IsNull (ex.InnerException, "#E3");
1495                                 Assert.IsNotNull (ex.Message, "#E4");
1496                                 Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1497                         }
1498
1499                         tb.CreateType ();
1500
1501                         // Can not be called on a created type, altough the MSDN docs does not mention this
1502                         try {
1503                                 tb.DefineInitializedData ("BAR2", new byte [1], 0);
1504                                 Assert.Fail ("#F1");
1505                         } catch (InvalidOperationException ex) {
1506                                 // Unable to change after type has been created
1507                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1508                                 Assert.IsNull (ex.InnerException, "#F3");
1509                                 Assert.IsNotNull (ex.Message, "#F4");
1510                         }
1511                 }
1512
1513                 [Test]
1514                 public void DefineUninitializedDataInvalidArgs ()
1515                 {
1516                         TypeBuilder tb = module.DefineType (genTypeName ());
1517
1518                         try {
1519                                 tb.DefineUninitializedData (null, 1, 0);
1520                                 Assert.Fail ("#A1");
1521                         } catch (ArgumentNullException ex) {
1522                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1523                                 Assert.IsNull (ex.InnerException, "#A3");
1524                                 Assert.IsNotNull (ex.Message, "#A4");
1525                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1526                         }
1527
1528                         try {
1529                                 tb.DefineUninitializedData (string.Empty, 1, 0);
1530                                 Assert.Fail ("#B1");
1531                         } catch (ArgumentException ex) {
1532                                 // Empty name is not legal
1533                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1534                                 Assert.IsNull (ex.InnerException, "#B3");
1535                                 Assert.IsNotNull (ex.Message, "#B4");
1536                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1537                         }
1538
1539                         // The size of the data is less than or equal to zero ???
1540                         try {
1541                                 tb.DefineUninitializedData ("BAR", 0, 0);
1542                                 Assert.Fail ("#C1");
1543                         } catch (ArgumentException ex) {
1544                                 // Data size must be > 0 and < 0x3f0000
1545                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1546                                 Assert.IsNull (ex.InnerException, "#C3");
1547                                 Assert.IsNotNull (ex.Message, "#C4");
1548                                 Assert.IsNull (ex.ParamName, "#C5");
1549                         }
1550
1551                         try {
1552                                 string name = String.Format ("{0}", (char) 0);
1553                                 tb.DefineUninitializedData (name, 1, 0);
1554                                 Assert.Fail ("#D1");
1555                         } catch (ArgumentException ex) {
1556                                 // Illegal name
1557                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1558                                 Assert.IsNull (ex.InnerException, "#D3");
1559                                 Assert.IsNotNull (ex.Message, "#D4");
1560                                 Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1561                         }
1562                 }
1563
1564                 [Test]
1565                 public void DefineUninitializedDataAlreadyCreated ()
1566                 {
1567                         TypeBuilder tb = module.DefineType (genTypeName ());
1568                         tb.CreateType ();
1569                         try {
1570                                 tb.DefineUninitializedData ("BAR2", 1, 0);
1571                                 Assert.Fail ("#1");
1572                         } catch (InvalidOperationException ex) {
1573                                 // Unable to change after type has been created
1574                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1575                                 Assert.IsNull (ex.InnerException, "#3");
1576                                 Assert.IsNotNull (ex.Message, "#4");
1577                         }
1578                 }
1579
1580                 [Test]
1581                 public void DefineUninitializedData ()
1582                 {
1583                         TypeBuilder tb = module.DefineType (genTypeName ());
1584
1585                         tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1586
1587                         Type t = tb.CreateType ();
1588
1589                         object o = Activator.CreateInstance (t);
1590
1591                         FieldInfo fi = t.GetField ("foo");
1592
1593                         object fieldVal = fi.GetValue (o);
1594
1595                         IntPtr ptr = Marshal.AllocHGlobal (4);
1596                         Marshal.StructureToPtr (fieldVal, ptr, true);
1597                         Marshal.FreeHGlobal (ptr);
1598                 }
1599
1600                 [Test]
1601                 public void DefineMethod_Name_NullChar ()
1602                 {
1603                         TypeBuilder tb = module.DefineType (genTypeName ());
1604                         try {
1605                                 tb.DefineMethod ("\0test", MethodAttributes.Private,
1606                                         typeof (string), Type.EmptyTypes);
1607                                 Assert.Fail ("#A1");
1608                         } catch (ArgumentException ex) {
1609                                 // Illegal name
1610                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1611                                 Assert.IsNull (ex.InnerException, "#A3");
1612                                 Assert.IsNotNull (ex.Message, "#A4");
1613                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1614                         }
1615
1616                         MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1617                                 typeof (string), Type.EmptyTypes);
1618                         Assert.IsNotNull (mb, "#B1");
1619                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1620                 }
1621
1622                 [Test]
1623                 public void TestDefineMethod ()
1624                 {
1625                         TypeBuilder tb = module.DefineType (genTypeName ());
1626
1627                         // Check invalid arguments
1628                         try {
1629                                 tb.DefineMethod (null, 0, null, null);
1630                                 Assert.Fail ("#A1");
1631                         } catch (ArgumentNullException ex) {
1632                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1633                                 Assert.IsNull (ex.InnerException, "#A3");
1634                                 Assert.IsNotNull (ex.Message, "#A4");
1635                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1636                         }
1637
1638                         try {
1639                                 tb.DefineMethod (string.Empty, 0, null, null);
1640                                 Assert.Fail ("#B1");
1641                         } catch (ArgumentException ex) {
1642                                 // Empty name is not legal
1643                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1644                                 Assert.IsNull (ex.InnerException, "#B3");
1645                                 Assert.IsNotNull (ex.Message, "#B4");
1646                                 Assert.AreEqual ("name", ex.ParamName, "#B5");
1647                         }
1648
1649                         // Check non-virtual methods on an interface
1650                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1651                         try {
1652                                 tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1653                                 Assert.Fail ("#C1");
1654                         } catch (ArgumentException ex) {
1655                                 // Interface method must be abstract and virtual
1656                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1657                                 Assert.IsNull (ex.InnerException, "#C3");
1658                                 Assert.IsNotNull (ex.Message, "#C4");
1659                                 Assert.IsNull (ex.ParamName, "#C5");
1660                         }
1661
1662                         // Check static methods on an interface
1663                         tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1664                                                           typeof (void),
1665                                                           Type.EmptyTypes);
1666
1667                         tb.CreateType ();
1668                         // Can not be called on a created type
1669                         try {
1670                                 tb.DefineMethod ("bar", 0, null, null);
1671                                 Assert.Fail ("#D1");
1672                         } catch (InvalidOperationException ex) {
1673                                 // Unable to change after type has been created
1674                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1675                                 Assert.IsNull (ex.InnerException, "#D3");
1676                                 Assert.IsNotNull (ex.Message, "#D4");
1677                         }
1678                 }
1679
1680                 [Test] // bug #327484
1681                 [Category ("NotWorking")]
1682                 public void TestDefineMethod_Abstract ()
1683                 {
1684                         TypeBuilder tb = module.DefineType (genTypeName ());
1685                         tb.DefineMethod ("Run", MethodAttributes.Public |
1686                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1687                                 typeof (void), Type.EmptyTypes);
1688
1689                         try {
1690                                 tb.CreateType ();
1691                                 Assert.Fail ("#A1");
1692                         } catch (InvalidOperationException ex) {
1693                                 // Type must be declared abstract if any of its
1694                                 // methods are abstract
1695                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1696                                 Assert.IsNull (ex.InnerException, "#A3");
1697                                 Assert.IsNotNull (ex.Message, "#A4");
1698                         }
1699
1700                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1701                         tb.DefineMethod ("Run", MethodAttributes.Public |
1702                                 MethodAttributes.Abstract, typeof (void),
1703                                 Type.EmptyTypes);
1704
1705                         try {
1706                                 tb.CreateType ();
1707                                 Assert.Fail ("#B1");
1708                         } catch (TypeLoadException ex) {
1709                                 // Non-virtual abstract method
1710                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1711                                 Assert.IsNull (ex.InnerException, "#B3");
1712                                 Assert.IsNotNull (ex.Message, "#B4");
1713                         }
1714
1715                         tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1716                                 TypeAttributes.Public);
1717                         tb.DefineMethod ("Run", MethodAttributes.Public |
1718                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
1719                                 typeof (void), Type.EmptyTypes);
1720                         Type emittedType = tb.CreateType ();
1721
1722                         MethodInfo mi1 = emittedType.GetMethod ("Run");
1723                         Assert.IsNotNull (mi1, "#C1");
1724                         Assert.IsTrue (mi1.IsAbstract, "#C2");
1725
1726                         MethodInfo mi2 = tb.GetMethod ("Run");
1727                         Assert.IsNotNull (mi2, "#D1");
1728                         Assert.IsTrue (mi2.IsAbstract, "#D2");
1729                 }
1730
1731                 // TODO: DefineMethodOverride
1732
1733                 [Test]
1734                 public void TestDefineNestedType ()
1735                 {
1736                         TypeBuilder tb = module.DefineType (genTypeName ());
1737
1738                         // Check invalid arguments
1739                         try {
1740                                 tb.DefineNestedType (null);
1741                                 Assert.Fail ("#A1");
1742                         } catch (ArgumentNullException ex) {
1743                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1744                                 Assert.IsNull (ex.InnerException, "#A3");
1745                                 Assert.IsNotNull (ex.Message, "#A4");
1746                                 Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1747                         }
1748
1749                         try {
1750                                 tb.DefineNestedType (string.Empty);
1751                                 Assert.Fail ("#B1");
1752                         } catch (ArgumentException ex) {
1753                                 // Empty name is not legal
1754                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1755                                 Assert.IsNull (ex.InnerException, "#B3");
1756                                 Assert.IsNotNull (ex.Message, "#B4");
1757                                 Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1758                         }
1759
1760                         try {
1761                                 tb.DefineNestedType (nullName ());
1762                                 Assert.Fail ("#C1");
1763                         } catch (ArgumentException ex) {
1764                                 // Illegal name
1765                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1766                                 Assert.IsNull (ex.InnerException, "#C3");
1767                                 Assert.IsNotNull (ex.Message, "#C4");
1768                                 Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1769                         }
1770
1771                         // If I fix the code so this works then mcs breaks -> how can mcs
1772                         // works under MS .NET in the first place ???
1773                         /*
1774                         try {
1775                                 tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1776                                 Fail ("Nested visibility must be specified.");
1777                         }
1778                         catch (ArgumentException) {
1779                         }
1780                         */
1781
1782                         try {
1783                                 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1784                                                                          new Type [1]);
1785                                 Assert.Fail ("#D1");
1786                         } catch (ArgumentNullException ex) {
1787                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1788                                 Assert.IsNull (ex.InnerException, "#D3");
1789                                 Assert.IsNotNull (ex.Message, "#D4");
1790                                 Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1791                         }
1792
1793                         // I think this should reject non-interfaces, but it does not
1794                         tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1795                                                                  new Type [1] { typeof (object) });
1796
1797                         // Normal invocation
1798                         tb.DefineNestedType ("Nest");
1799
1800                         tb.CreateType ();
1801
1802                         // According to the MSDN docs, this cannnot be called after the type
1803                         // is created, but it works.
1804                         tb.DefineNestedType ("Nest2");
1805
1806                         // According to the MSDN docs, a Sealed class can't contain nested 
1807                         // types, but this is not true
1808                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1809                         tb2.DefineNestedType ("AA");
1810
1811                         // According to the MSDN docs, interfaces can only contain interfaces,
1812                         // but this is not true
1813                         TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1814
1815                         tb3.DefineNestedType ("AA");
1816
1817                         // Check shorter versions
1818                         {
1819                                 TypeBuilder nested = tb.DefineNestedType ("N1");
1820
1821                                 Assert.AreEqual ("N1", nested.Name, "#E1");
1822                                 Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1823                                 Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1824                                 Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1825                         }
1826
1827                         // TODO:
1828                 }
1829
1830                 [Test]
1831                 public void NestedTypeSave () {
1832                         var tb = module.DefineType (genTypeName ());
1833
1834                         var tbuilder = tb.DefineNestedType ("Test.CodeGen", TypeAttributes.Public | TypeAttributes.Class);
1835                         var entryp = tbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), null);
1836                         var ilg = entryp.GetILGenerator (128);
1837                         ilg.Emit (OpCodes.Ldtoken, tb);
1838                         ilg.Emit (OpCodes.Pop);
1839                         ilg.Emit (OpCodes.Ret);
1840
1841                         tbuilder.CreateType ();
1842                         tb.CreateType ();
1843
1844                         assembly.Save (ASSEMBLY_NAME + ".dll");
1845                 }
1846
1847                 [Test]
1848                 public void DefinePInvokeMethod_Name_NullChar ()
1849                 {
1850                         TypeBuilder tb = module.DefineType (genTypeName ());
1851                         try {
1852                                 tb.DefinePInvokeMethod ("\0test", "B", "C",
1853                                         MethodAttributes.Private, CallingConventions.Standard,
1854                                         typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1855                                         CharSet.Unicode);
1856                                 Assert.Fail ("#A1");
1857                         } catch (ArgumentException ex) {
1858                                 // Illegal name
1859                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1860                                 Assert.IsNull (ex.InnerException, "#A3");
1861                                 Assert.IsNotNull (ex.Message, "#A4");
1862                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1863                         }
1864
1865                         MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1866                                 MethodAttributes.Private, CallingConventions.Standard,
1867                                 typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1868                                 CharSet.Unicode);
1869                         Assert.IsNotNull (mb, "#B1");
1870                         Assert.AreEqual ("te\0st", mb.Name, "#B2");
1871                 }
1872
1873                 [Test]
1874                 public void TestDefinePInvokeMethod ()
1875                 {
1876                         TypeBuilder tb = module.DefineType (genTypeName ());
1877
1878                         tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1879
1880                         // Try invalid parameters
1881                         try {
1882                                 tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1883                                 Assert.Fail ("#A1");
1884                         } catch (ArgumentNullException ex) {
1885                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1886                                 Assert.IsNull (ex.InnerException, "#A3");
1887                                 Assert.IsNotNull (ex.Message, "#A4");
1888                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1889                         }
1890                         // etc...
1891
1892                         // Try invalid attributes
1893                         try {
1894                                 tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1895                                 Assert.Fail ("#B1");
1896                         } catch (ArgumentException ex) {
1897                                 // PInvoke methods must be static and native and
1898                                 // cannot be abstract
1899                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1900                                 Assert.IsNull (ex.InnerException, "#B3");
1901                                 Assert.IsNotNull (ex.Message, "#B4");
1902                                 Assert.IsNull (ex.ParamName, "#B5");
1903                         }
1904
1905                         // Try an interface parent
1906                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1907
1908                         try {
1909                                 tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1910                                 Assert.Fail ("#C1");
1911                         } catch (ArgumentException ex) {
1912                                 // PInvoke methods cannot exist on interfaces
1913                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1914                                 Assert.IsNull (ex.InnerException, "#B3");
1915                                 Assert.IsNotNull (ex.Message, "#B4");
1916                                 Assert.IsNull (ex.ParamName, "#B5");
1917                         }
1918                 }
1919
1920                 [Test]
1921                 public void DefineProperty_Name_NullChar ()
1922                 {
1923                         TypeBuilder tb = module.DefineType (genTypeName ());
1924
1925                         try {
1926                                 tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
1927                                 Assert.Fail ("#A1");
1928                         } catch (ArgumentException ex) {
1929                                 // Illegal name
1930                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1931                                 Assert.IsNull (ex.InnerException, "#A3");
1932                                 Assert.IsNotNull (ex.Message, "#A4");
1933                                 Assert.AreEqual ("name", ex.ParamName, "#A5");
1934                         }
1935
1936                         PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
1937                                 typeof (string), Type.EmptyTypes); 
1938                         Assert.IsNotNull (pb, "#B1");
1939                         Assert.AreEqual ("te\0st", pb.Name, "#B2");
1940                 }
1941
1942                 [Test]
1943                 public void DefineProperty_ParameterTypes_ItemNull ()
1944                 {
1945                         TypeBuilder tb = module.DefineType (genTypeName ());
1946
1947                         try {
1948                                 tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
1949                                 Assert.Fail ("#1");
1950                         } catch (ArgumentNullException ex) {
1951                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1952                                 Assert.IsNull (ex.InnerException, "#3");
1953                                 Assert.IsNotNull (ex.Message, "#4");
1954                         }
1955                 }
1956
1957                 [Test]
1958                 public void DefineProperty_ReturnType_Null ()
1959                 {
1960                         TypeBuilder tb = module.DefineType (genTypeName ());
1961                         tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
1962                 }
1963
1964                 [Test]
1965                 public void GetMethod_WorksWithTypeBuilderParameter () {
1966                         TypeBuilder tb = module.DefineType (genTypeName ());
1967                         var garg = tb.DefineGenericParameters ("T") [0];
1968                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
1969                 
1970                         var mi = TypeBuilder.GetMethod (tb, mb);
1971                         var decl = mi.DeclaringType;
1972
1973                         Assert.IsTrue (decl.IsGenericType, "#1");
1974                         Assert.IsFalse (decl.IsGenericTypeDefinition, "#2");
1975                         Assert.AreEqual (tb, decl.GetGenericTypeDefinition (), "#3");
1976                         Assert.AreEqual (garg, decl.GetGenericArguments () [0], "#4");
1977                 }
1978
1979                 [Test]
1980                 public void GetConstructor_FailWithTypeBuilderParameter () {
1981                         TypeBuilder tb = module.DefineType (genTypeName ());
1982                         var garg = tb.DefineGenericParameters ("T") [0];
1983                         var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
1984
1985                         try {
1986                                 TypeBuilder.GetConstructor (tb, cb);
1987                                 Assert.Fail ("#1");
1988                         } catch (ArgumentException ex) {
1989                                 Assert.AreEqual ("type", ex.ParamName, "#2");
1990                         }
1991                 }
1992
1993                 [Test]
1994                 public void GetField_FailWithTypeBuilderParameter () {
1995                         TypeBuilder tb = module.DefineType (genTypeName ());
1996                         var garg = tb.DefineGenericParameters ("T") [0];
1997                         var fb = tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
1998
1999                         try {
2000                                 TypeBuilder.GetField (tb, fb);
2001                                 Assert.Fail ("#1");
2002                         } catch (ArgumentException ex) {
2003                                 Assert.AreEqual ("type", ex.ParamName, "#2");
2004                         }
2005                 }
2006
2007                 [Test]
2008                 public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
2009                         TypeBuilder tb = module.DefineType (genTypeName ());
2010                         tb.DefineGenericParameters ("T");
2011                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2012
2013                         Type ginst = tb.MakeGenericType (typeof (int));
2014                         
2015                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2016                         try {
2017                                 TypeBuilder.GetMethod (ginst, mi);
2018                                 Assert.Fail ("#1");
2019                         } catch (ArgumentException ex) {
2020                                 Assert.AreEqual ("method", ex.ParamName, "#5");
2021                         }
2022                 }
2023
2024                 [Test]
2025                 public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2026                         TypeBuilder tb = module.DefineType (genTypeName ());
2027                         tb.DefineGenericParameters ("T");
2028                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2029                         ILGenerator ig = mb.GetILGenerator ();
2030                         ig.Emit (OpCodes.Ret);
2031                         
2032                         tb.CreateType ();
2033                         
2034                         MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2035                         Assert.IsNotNull (mi);
2036                 }
2037
2038                 [Test]
2039                 [Category ("NotDotNet")]
2040                 [Category ("NotWorking")]
2041                 public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2042                         AssemblyName assemblyName = new AssemblyName ();
2043                         assemblyName.Name = ASSEMBLY_NAME;
2044
2045                         assembly =
2046                                 Thread.GetDomain ().DefineDynamicAssembly (
2047                                         assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, Path.GetTempPath ());
2048
2049                         module = assembly.DefineDynamicModule ("module1");
2050                         
2051                         TypeBuilder tb = module.DefineType (genTypeName ());
2052                         tb.DefineGenericParameters ("T");
2053                         MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2054
2055                         Type ginst = tb.MakeGenericType (typeof (int));
2056                         
2057                         MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2058
2059                         try {
2060                                 TypeBuilder.GetMethod (ginst, mi);
2061                         } catch (ArgumentException ex) {
2062                                 Assert.Fail ("#1");
2063                         }
2064                 }
2065
2066
2067                 [Test]
2068                 // Test that changes made to the method builder after a call to GetMethod ()
2069                 // are visible
2070                 public void TestGetMethod ()
2071                 {
2072                         TypeBuilder tb = module.DefineType (genTypeName ());
2073                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2074
2075                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2076                         ILGenerator ig;
2077                         ig = cb.GetILGenerator ();
2078                         ig.Emit (OpCodes.Ret);
2079
2080                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2081
2082                         // Create a method builder but do not emit IL yet
2083                         MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2084
2085                         Type t = tb.MakeGenericType (typeof (int));
2086
2087                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2088
2089                         ig = mb.GetILGenerator ();
2090                         ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2091                         ig.Emit (OpCodes.Ret);
2092
2093                         // Finish the method
2094                         ig = mb1.GetILGenerator ();
2095                         ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2096                         ig.Emit (OpCodes.Ret);
2097
2098                         Type t2 = tb.CreateType ();
2099
2100                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2101                 }
2102
2103                 [Test]
2104                 public void TestGetConstructor ()
2105                 {
2106                         TypeBuilder tb = module.DefineType (genTypeName ());
2107                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2108
2109                         ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2110                         ILGenerator ig;
2111
2112                         Type t = tb.MakeGenericType (typeof (int));
2113
2114                         MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2115
2116                         ig = mb.GetILGenerator ();
2117
2118                         ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2119                         
2120                         ig.Emit (OpCodes.Newobj, ci);
2121                         ig.Emit (OpCodes.Ret);
2122
2123                         // Finish the ctorbuilder
2124                         ig = cb.GetILGenerator ();
2125                         ig.Emit(OpCodes.Ldarg_0);
2126                         ig.Emit(OpCodes.Call, tb.BaseType.GetConstructor(Type.EmptyTypes));             
2127                         ig.Emit (OpCodes.Ret);
2128
2129                         Type t2 = tb.CreateType ();
2130
2131                         Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2132                 }
2133
2134                 [Test]
2135                 [ExpectedException (typeof (ArgumentException))]
2136                 public void Static_GetConstructor_TypeNull ()
2137                 {
2138                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2139                         // null is non-generic (from exception message)
2140                         TypeBuilder.GetConstructor (null, ci);
2141                 }
2142
2143                 [Test]
2144                 [ExpectedException (typeof (ArgumentException))]
2145                 public void Static_GetConstructor_TypeGeneric ()
2146                 {
2147                         Type t = typeof (List<>).MakeGenericType (typeof (int));
2148                         ConstructorInfo ci = typeof (object).GetConstructor (Type.EmptyTypes);
2149                         // type is not 'TypeBuilder' (from exception message)
2150                         TypeBuilder.GetConstructor (t, ci);
2151                 }
2152
2153                 [Test]
2154                 public void Static_GetConstructor_TypeBuilderGeneric_ConstructorInfoNull ()
2155                 {
2156                         TypeBuilder tb = module.DefineType ("XXX");
2157                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2158                         Type fooOfT = tb.MakeGenericType (typeParams [0]);
2159                         try {
2160                                 TypeBuilder.GetConstructor (fooOfT, null);
2161                                 Assert.Fail ("Expected NullReferenceException");
2162                         }
2163                         catch (NullReferenceException) {
2164                         }
2165                 }
2166
2167                 [Test] //#536243
2168                 public void CreateTypeThrowsForMethodsWithBadLabels ()
2169                 {
2170                         TypeBuilder tb = module.DefineType (genTypeName ());
2171
2172                         MethodBuilder mb = tb.DefineMethod("F", MethodAttributes.Public, typeof(string), null);
2173                         ILGenerator il_gen = mb.GetILGenerator ();
2174                         il_gen.DefineLabel ();
2175                         il_gen.Emit (OpCodes.Leave, new Label ());
2176                         try {
2177                                 tb.CreateType ();
2178                                 Assert.Fail ();
2179                         } catch (ArgumentException) {}
2180                 }
2181
2182                 [Test]
2183                 [Category ("NotWorking")]
2184                 public void TestIsDefinedIncomplete ()
2185                 {
2186                         TypeBuilder tb = module.DefineType (genTypeName ());
2187                         try {
2188                                 tb.IsDefined (typeof (int), true);
2189                                 Assert.Fail ("#1");
2190                         } catch (NotSupportedException ex) {
2191                                 // The invoked member is not supported in a
2192                                 // dynamic module
2193                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2194                                 Assert.IsNull (ex.InnerException, "#3");
2195                                 Assert.IsNotNull (ex.Message, "#4");
2196                         }
2197                 }
2198
2199                 [Test]
2200                 public void TestIsDefinedComplete ()
2201                 {
2202                         TypeBuilder tb = module.DefineType (genTypeName ());
2203
2204                         ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2205                                 new Type [] { typeof (string) });
2206
2207                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2208                                 new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2209
2210                         tb.SetCustomAttribute (caBuilder);
2211                         tb.CreateType ();
2212                         Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2213                 }
2214
2215                 [Test]
2216                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
2217                 public void IsDefined_AttributeType_Null ()
2218                 {
2219                         TypeBuilder tb = module.DefineType (genTypeName ());
2220                         tb.CreateType ();
2221
2222                         try {
2223                                 tb.IsDefined ((Type) null, false);
2224                                 Assert.Fail ("#1");
2225                         } catch (ArgumentNullException ex) {
2226                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2227                                 Assert.IsNull (ex.InnerException, "#3");
2228                                 Assert.IsNotNull (ex.Message, "#4");
2229                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2230                         }
2231                 }
2232
2233                 [Test] // GetConstructor (Type [])
2234                 public void GetConstructor1_Incomplete ()
2235                 {
2236                         TypeBuilder tb = module.DefineType (genTypeName ());
2237                         ConstructorBuilder cb = tb.DefineConstructor (
2238                                 MethodAttributes.Public,
2239                                 CallingConventions.Standard,
2240                                 Type.EmptyTypes);
2241                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2242
2243                         try {
2244                                 tb.GetConstructor (Type.EmptyTypes);
2245                                 Assert.Fail ("#1");
2246                         } catch (NotSupportedException ex) {
2247                                 // The invoked member is not supported in a
2248                                 // dynamic module
2249                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2250                                 Assert.IsNull (ex.InnerException, "#3");
2251                                 Assert.IsNotNull (ex.Message, "#4");
2252                         }
2253                 }
2254
2255                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2256                 public void GetConstructor2_Complete ()
2257                 {
2258                         BindingFlags flags;
2259                         ConstructorInfo ctor;
2260
2261                         TypeBuilder redType = module.DefineType (genTypeName (),
2262                                 TypeAttributes.Public);
2263                         CreateMembers (redType, "Red", true);
2264
2265                         TypeBuilder greenType = module.DefineType (genTypeName (),
2266                                 TypeAttributes.Public, redType);
2267                         CreateMembers (greenType, "Green", false);
2268                         ConstructorBuilder cb = greenType.DefineConstructor (
2269                                 MethodAttributes.Public,
2270                                 CallingConventions.Standard,
2271                                 Type.EmptyTypes);
2272                         cb.GetILGenerator ().Emit (OpCodes.Ret);
2273
2274                         redType.CreateType ();
2275                         greenType.CreateType ();
2276
2277                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
2278
2279                         ctor = greenType.GetConstructor (flags, null,
2280                                 new Type [] { typeof (int), typeof (int) },
2281                                 new ParameterModifier [0]);
2282                         Assert.IsNull (ctor, "#A1");
2283
2284                         ctor = greenType.GetConstructor (flags, null,
2285                                 new Type [] { typeof (string) },
2286                                 new ParameterModifier [0]);
2287                         Assert.IsNull (ctor, "#A2");
2288
2289                         ctor = greenType.GetConstructor (flags, null,
2290                                 new Type [] { typeof (string), typeof (string) },
2291                                 new ParameterModifier [0]);
2292                         Assert.IsNull (ctor, "#A3");
2293
2294                         ctor = greenType.GetConstructor (flags, null,
2295                                 new Type [] { typeof (int) },
2296                                 new ParameterModifier [0]);
2297                         Assert.IsNull (ctor, "#A4");
2298
2299                         ctor = greenType.GetConstructor (flags, null,
2300                                 new Type [] { typeof (int), typeof (bool) },
2301                                 new ParameterModifier [0]);
2302                         Assert.IsNull (ctor, "#A5");
2303
2304                         ctor = greenType.GetConstructor (flags, null,
2305                                 new Type [] { typeof (string), typeof (int) },
2306                                 new ParameterModifier [0]);
2307                         Assert.IsNull (ctor, "#A6");
2308
2309                         ctor = greenType.GetConstructor (flags, null,
2310                                 Type.EmptyTypes,
2311                                 new ParameterModifier [0]);
2312                         Assert.IsNull (ctor, "#A7");
2313
2314                         ctor = redType.GetConstructor (flags, null,
2315                                 new Type [] { typeof (int), typeof (int) },
2316                                 new ParameterModifier [0]);
2317                         Assert.IsNotNull (ctor, "#A8a");
2318                         Assert.IsTrue (ctor.IsPrivate, "#A8b");
2319                         Assert.IsFalse (ctor.IsStatic, "#A8c");
2320                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2321                         Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2322
2323                         ctor = redType.GetConstructor (flags, null,
2324                                 new Type [] { typeof (string) },
2325                                 new ParameterModifier [0]);
2326                         Assert.IsNotNull (ctor, "#A9a");
2327                         Assert.IsTrue (ctor.IsFamily, "#A9b");
2328                         Assert.IsFalse (ctor.IsStatic, "#A9c");
2329                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2330                         Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2331
2332                         ctor = redType.GetConstructor (flags, null,
2333                                 new Type [] { typeof (string), typeof (string) },
2334                                 new ParameterModifier [0]);
2335                         Assert.IsNotNull (ctor, "#A10a");
2336                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2337                         Assert.IsFalse (ctor.IsStatic, "#A10c");
2338                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2339                         Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2340
2341                         ctor = redType.GetConstructor (flags, null,
2342                                 new Type [] { typeof (int) },
2343                                 new ParameterModifier [0]);
2344                         Assert.IsNotNull (ctor, "#A11a");
2345                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2346                         Assert.IsFalse (ctor.IsStatic, "#A11c");
2347                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2348                         Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2349
2350                         ctor = redType.GetConstructor (flags, null,
2351                                 new Type [] { typeof (int), typeof (bool) },
2352                                 new ParameterModifier [0]);
2353                         Assert.IsNull (ctor, "#A12");
2354
2355                         ctor = redType.GetConstructor (flags, null,
2356                                 new Type [] { typeof (string), typeof (int) },
2357                                 new ParameterModifier [0]);
2358                         Assert.IsNotNull (ctor, "#A13a");
2359                         Assert.IsTrue (ctor.IsAssembly, "#A13b");
2360                         Assert.IsFalse (ctor.IsStatic, "#A13c");
2361                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2362                         Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2363
2364                         ctor = redType.GetConstructor (flags, null,
2365                                 Type.EmptyTypes,
2366                                 new ParameterModifier [0]);
2367                         Assert.IsNull (ctor, "#A14");
2368
2369                         flags = BindingFlags.Instance | BindingFlags.Public;
2370
2371                         ctor = greenType.GetConstructor (flags, null,
2372                                 new Type [] { typeof (int), typeof (int) },
2373                                 new ParameterModifier [0]);
2374                         Assert.IsNull (ctor, "#B1");
2375
2376                         ctor = greenType.GetConstructor (flags, null,
2377                                 new Type [] { typeof (string) },
2378                                 new ParameterModifier [0]);
2379                         Assert.IsNull (ctor, "#B2");
2380
2381                         ctor = greenType.GetConstructor (flags, null,
2382                                 new Type [] { typeof (string), typeof (string) },
2383                                 new ParameterModifier [0]);
2384                         Assert.IsNull (ctor, "#B3");
2385
2386                         ctor = greenType.GetConstructor (flags, null,
2387                                 new Type [] { typeof (int) },
2388                                 new ParameterModifier [0]);
2389                         Assert.IsNull (ctor, "#B4");
2390
2391                         ctor = greenType.GetConstructor (flags, null,
2392                                 new Type [] { typeof (int), typeof (bool) },
2393                                 new ParameterModifier [0]);
2394                         Assert.IsNull (ctor, "#B5");
2395
2396                         ctor = greenType.GetConstructor (flags, null,
2397                                 new Type [] { typeof (string), typeof (int) },
2398                                 new ParameterModifier [0]);
2399                         Assert.IsNull (ctor, "#B6");
2400
2401                         ctor = greenType.GetConstructor (flags, null,
2402                                 Type.EmptyTypes,
2403                                 new ParameterModifier [0]);
2404                         Assert.IsNotNull (ctor, "#B7a");
2405                         Assert.IsTrue (ctor.IsPublic, "#B7b");
2406                         Assert.IsFalse (ctor.IsStatic, "#B7c");
2407                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2408                         Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2409
2410                         ctor = redType.GetConstructor (flags, null,
2411                                 new Type [] { typeof (int), typeof (int) },
2412                                 new ParameterModifier [0]);
2413                         Assert.IsNull (ctor, "#B8");
2414
2415                         ctor = redType.GetConstructor (flags, null,
2416                                 new Type [] { typeof (string) },
2417                                 new ParameterModifier [0]);
2418                         Assert.IsNull (ctor, "#B9");
2419
2420                         ctor = redType.GetConstructor (flags, null,
2421                                 new Type [] { typeof (string), typeof (string) },
2422                                 new ParameterModifier [0]);
2423                         Assert.IsNull (ctor, "#B10");
2424
2425                         ctor = redType.GetConstructor (flags, null,
2426                                 new Type [] { typeof (int) },
2427                                 new ParameterModifier [0]);
2428                         Assert.IsNull (ctor, "#B11");
2429
2430                         ctor = redType.GetConstructor (flags, null,
2431                                 new Type [] { typeof (int), typeof (bool) },
2432                                 new ParameterModifier [0]);
2433                         Assert.IsNotNull (ctor, "#B12a");
2434                         Assert.IsTrue (ctor.IsPublic, "#B12b");
2435                         Assert.IsFalse (ctor.IsStatic, "#B12c");
2436                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2437                         Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2438
2439                         ctor = redType.GetConstructor (flags, null,
2440                                 new Type [] { typeof (string), typeof (int) },
2441                                 new ParameterModifier [0]);
2442                         Assert.IsNull (ctor, "#B13");
2443
2444                         ctor = redType.GetConstructor (flags, null,
2445                                 Type.EmptyTypes,
2446                                 new ParameterModifier [0]);
2447                         Assert.IsNull (ctor, "#B14");
2448
2449                         flags = BindingFlags.Static | BindingFlags.Public;
2450
2451                         ctor = greenType.GetConstructor (flags, null,
2452                                 new Type [] { typeof (int), typeof (int) },
2453                                 new ParameterModifier [0]);
2454                         Assert.IsNull (ctor, "#C1");
2455
2456                         ctor = greenType.GetConstructor (flags, null,
2457                                 new Type [] { typeof (string) },
2458                                 new ParameterModifier [0]);
2459                         Assert.IsNull (ctor, "#C2");
2460
2461                         ctor = greenType.GetConstructor (flags, null,
2462                                 new Type [] { typeof (string), typeof (string) },
2463                                 new ParameterModifier [0]);
2464                         Assert.IsNull (ctor, "#C3");
2465
2466                         ctor = greenType.GetConstructor (flags, null,
2467                                 new Type [] { typeof (int) },
2468                                 new ParameterModifier [0]);
2469                         Assert.IsNull (ctor, "#C4");
2470
2471                         ctor = greenType.GetConstructor (flags, null,
2472                                 new Type [] { typeof (int), typeof (bool) },
2473                                 new ParameterModifier [0]);
2474                         Assert.IsNull (ctor, "#C5");
2475
2476                         ctor = greenType.GetConstructor (flags, null,
2477                                 new Type [] { typeof (string), typeof (int) },
2478                                 new ParameterModifier [0]);
2479                         Assert.IsNull (ctor, "#C6");
2480
2481                         ctor = greenType.GetConstructor (flags, null,
2482                                 Type.EmptyTypes,
2483                                 new ParameterModifier [0]);
2484                         Assert.IsNull (ctor, "#C7");
2485
2486                         ctor = redType.GetConstructor (flags, null,
2487                                 new Type [] { typeof (int), typeof (int) },
2488                                 new ParameterModifier [0]);
2489                         Assert.IsNull (ctor, "#C8");
2490
2491                         ctor = redType.GetConstructor (flags, null,
2492                                 new Type [] { typeof (string) },
2493                                 new ParameterModifier [0]);
2494                         Assert.IsNull (ctor, "#C9");
2495
2496                         ctor = redType.GetConstructor (flags, null,
2497                                 new Type [] { typeof (string), typeof (string) },
2498                                 new ParameterModifier [0]);
2499                         Assert.IsNull (ctor, "#C10");
2500
2501                         ctor = redType.GetConstructor (flags, null,
2502                                 new Type [] { typeof (int) },
2503                                 new ParameterModifier [0]);
2504                         Assert.IsNull (ctor, "#C11a");
2505
2506                         ctor = redType.GetConstructor (flags, null,
2507                                 new Type [] { typeof (int), typeof (bool) },
2508                                 new ParameterModifier [0]);
2509                         Assert.IsNull (ctor, "#C12");
2510
2511                         ctor = redType.GetConstructor (flags, null,
2512                                 new Type [] { typeof (string), typeof (int) },
2513                                 new ParameterModifier [0]);
2514                         Assert.IsNull (ctor, "#C13");
2515
2516                         ctor = redType.GetConstructor (flags, null,
2517                                 Type.EmptyTypes,
2518                                 new ParameterModifier [0]);
2519                         Assert.IsNull (ctor, "#C14");
2520
2521                         flags = BindingFlags.Static | BindingFlags.NonPublic;
2522
2523                         ctor = greenType.GetConstructor (flags, null,
2524                                 new Type [] { typeof (int), typeof (int) },
2525                                 new ParameterModifier [0]);
2526                         Assert.IsNull (ctor, "#D1");
2527
2528                         ctor = greenType.GetConstructor (flags, null,
2529                                 new Type [] { typeof (string) },
2530                                 new ParameterModifier [0]);
2531                         Assert.IsNull (ctor, "#D2");
2532
2533                         ctor = greenType.GetConstructor (flags, null,
2534                                 new Type [] { typeof (string), typeof (string) },
2535                                 new ParameterModifier [0]);
2536                         Assert.IsNull (ctor, "#D3");
2537
2538                         ctor = greenType.GetConstructor (flags, null,
2539                                 new Type [] { typeof (int) },
2540                                 new ParameterModifier [0]);
2541                         Assert.IsNull (ctor, "#D4");
2542
2543                         ctor = greenType.GetConstructor (flags, null,
2544                                 new Type [] { typeof (int), typeof (bool) },
2545                                 new ParameterModifier [0]);
2546                         Assert.IsNull (ctor, "#D5");
2547
2548                         ctor = greenType.GetConstructor (flags, null,
2549                                 new Type [] { typeof (string), typeof (int) },
2550                                 new ParameterModifier [0]);
2551                         Assert.IsNull (ctor, "#D6");
2552
2553                         ctor = greenType.GetConstructor (flags, null,
2554                                 Type.EmptyTypes,
2555                                 new ParameterModifier [0]);
2556                         Assert.IsNull (ctor, "#D7");
2557
2558                         ctor = redType.GetConstructor (flags, null,
2559                                 new Type [] { typeof (int), typeof (int) },
2560                                 new ParameterModifier [0]);
2561                         Assert.IsNull (ctor, "#D8");
2562
2563                         ctor = redType.GetConstructor (flags, null,
2564                                 new Type [] { typeof (string) },
2565                                 new ParameterModifier [0]);
2566                         Assert.IsNull (ctor, "#D9");
2567
2568                         ctor = redType.GetConstructor (flags, null,
2569                                 new Type [] { typeof (string), typeof (string) },
2570                                 new ParameterModifier [0]);
2571                         Assert.IsNull (ctor, "#D10");
2572
2573                         ctor = redType.GetConstructor (flags, null,
2574                                 new Type [] { typeof (int) },
2575                                 new ParameterModifier [0]);
2576                         Assert.IsNull (ctor, "#D11");
2577
2578                         ctor = redType.GetConstructor (flags, null,
2579                                 new Type [] { typeof (int), typeof (bool) },
2580                                 new ParameterModifier [0]);
2581                         Assert.IsNull (ctor, "#D12");
2582
2583                         ctor = redType.GetConstructor (flags, null,
2584                                 new Type [] { typeof (string), typeof (int) },
2585                                 new ParameterModifier [0]);
2586                         Assert.IsNull (ctor, "#D13");
2587
2588                         ctor = redType.GetConstructor (flags, null,
2589                                 Type.EmptyTypes,
2590                                 new ParameterModifier [0]);
2591                         Assert.IsNotNull (ctor, "#D14a");
2592                         Assert.IsTrue (ctor.IsPrivate, "#D14b");
2593                         Assert.IsTrue (ctor.IsStatic, "#B14c");
2594                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2595                         Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2596
2597                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2598                                 BindingFlags.FlattenHierarchy;
2599
2600                         ctor = greenType.GetConstructor (flags, null,
2601                                 new Type [] { typeof (int), typeof (int) },
2602                                 new ParameterModifier [0]);
2603                         Assert.IsNull (ctor, "#E1");
2604
2605                         ctor = greenType.GetConstructor (flags, null,
2606                                 new Type [] { typeof (string) },
2607                                 new ParameterModifier [0]);
2608                         Assert.IsNull (ctor, "#E2");
2609
2610                         ctor = greenType.GetConstructor (flags, null,
2611                                 new Type [] { typeof (string), typeof (string) },
2612                                 new ParameterModifier [0]);
2613                         Assert.IsNull (ctor, "#E3");
2614
2615                         ctor = greenType.GetConstructor (flags, null,
2616                                 new Type [] { typeof (int) },
2617                                 new ParameterModifier [0]);
2618                         Assert.IsNull (ctor, "#E4");
2619
2620                         ctor = greenType.GetConstructor (flags, null,
2621                                 new Type [] { typeof (int), typeof (bool) },
2622                                 new ParameterModifier [0]);
2623                         Assert.IsNull (ctor, "#E5");
2624
2625                         ctor = greenType.GetConstructor (flags, null,
2626                                 new Type [] { typeof (string), typeof (int) },
2627                                 new ParameterModifier [0]);
2628                         Assert.IsNull (ctor, "#E6");
2629
2630                         ctor = greenType.GetConstructor (flags, null,
2631                                 Type.EmptyTypes,
2632                                 new ParameterModifier [0]);
2633                         Assert.IsNull (ctor, "#E7");
2634
2635                         ctor = redType.GetConstructor (flags, null,
2636                                 new Type [] { typeof (int), typeof (int) },
2637                                 new ParameterModifier [0]);
2638                         Assert.IsNotNull (ctor, "#E8a");
2639                         Assert.IsTrue (ctor.IsPrivate, "#E8b");
2640                         Assert.IsFalse (ctor.IsStatic, "#E8c");
2641                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2642                         Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2643
2644                         ctor = redType.GetConstructor (flags, null,
2645                                 new Type [] { typeof (string) },
2646                                 new ParameterModifier [0]);
2647                         Assert.IsNotNull (ctor, "#E9a");
2648                         Assert.IsTrue (ctor.IsFamily, "#E9b");
2649                         Assert.IsFalse (ctor.IsStatic, "#E9c");
2650                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2651                         Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2652
2653                         ctor = redType.GetConstructor (flags, null,
2654                                 new Type [] { typeof (string), typeof (string) },
2655                                 new ParameterModifier [0]);
2656                         Assert.IsNotNull (ctor, "#E10a");
2657                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2658                         Assert.IsFalse (ctor.IsStatic, "#E10c");
2659                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2660                         Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2661
2662                         ctor = redType.GetConstructor (flags, null,
2663                                 new Type [] { typeof (int) },
2664                                 new ParameterModifier [0]);
2665                         Assert.IsNotNull (ctor, "#E11a");
2666                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2667                         Assert.IsFalse (ctor.IsStatic, "#E11c");
2668                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2669                         Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2670
2671                         ctor = redType.GetConstructor (flags, null,
2672                                 new Type [] { typeof (int), typeof (bool) },
2673                                 new ParameterModifier [0]);
2674                         Assert.IsNull (ctor, "#E12");
2675
2676                         ctor = redType.GetConstructor (flags, null,
2677                                 new Type [] { typeof (string), typeof (int) },
2678                                 new ParameterModifier [0]);
2679                         Assert.IsNotNull (ctor, "#E13a");
2680                         Assert.IsTrue (ctor.IsAssembly, "#E13b");
2681                         Assert.IsFalse (ctor.IsStatic, "#E13c");
2682                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2683                         Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2684
2685                         ctor = redType.GetConstructor (flags, null,
2686                                 Type.EmptyTypes,
2687                                 new ParameterModifier [0]);
2688                         Assert.IsNull (ctor, "#E14");
2689
2690                         flags = BindingFlags.Instance | BindingFlags.Public |
2691                                 BindingFlags.FlattenHierarchy;
2692
2693                         ctor = greenType.GetConstructor (flags, null,
2694                                 new Type [] { typeof (int), typeof (int) },
2695                                 new ParameterModifier [0]);
2696                         Assert.IsNull (ctor, "#F1");
2697
2698                         ctor = greenType.GetConstructor (flags, null,
2699                                 new Type [] { typeof (string) },
2700                                 new ParameterModifier [0]);
2701                         Assert.IsNull (ctor, "#F2");
2702
2703                         ctor = greenType.GetConstructor (flags, null,
2704                                 new Type [] { typeof (string), typeof (string) },
2705                                 new ParameterModifier [0]);
2706                         Assert.IsNull (ctor, "#F3");
2707
2708                         ctor = greenType.GetConstructor (flags, null,
2709                                 new Type [] { typeof (int) },
2710                                 new ParameterModifier [0]);
2711                         Assert.IsNull (ctor, "#F4");
2712
2713                         ctor = greenType.GetConstructor (flags, null,
2714                                 new Type [] { typeof (int), typeof (bool) },
2715                                 new ParameterModifier [0]);
2716                         Assert.IsNull (ctor, "#F5");
2717
2718                         ctor = greenType.GetConstructor (flags, null,
2719                                 new Type [] { typeof (string), typeof (int) },
2720                                 new ParameterModifier [0]);
2721                         Assert.IsNull (ctor, "#F6");
2722
2723                         ctor = greenType.GetConstructor (flags, null,
2724                                 Type.EmptyTypes,
2725                                 new ParameterModifier [0]);
2726                         Assert.IsNotNull (ctor, "#F7a");
2727                         Assert.IsTrue (ctor.IsPublic, "#F7b");
2728                         Assert.IsFalse (ctor.IsStatic, "#F7c");
2729                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2730                         Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2731
2732                         ctor = redType.GetConstructor (flags, null,
2733                                 new Type [] { typeof (int), typeof (int) },
2734                                 new ParameterModifier [0]);
2735                         Assert.IsNull (ctor, "#F8");
2736
2737                         ctor = redType.GetConstructor (flags, null,
2738                                 new Type [] { typeof (string) },
2739                                 new ParameterModifier [0]);
2740                         Assert.IsNull (ctor, "#F9");
2741
2742                         ctor = redType.GetConstructor (flags, null,
2743                                 new Type [] { typeof (string), typeof (string) },
2744                                 new ParameterModifier [0]);
2745                         Assert.IsNull (ctor, "#F10");
2746
2747                         ctor = redType.GetConstructor (flags, null,
2748                                 new Type [] { typeof (int) },
2749                                 new ParameterModifier [0]);
2750                         Assert.IsNull (ctor, "#F11");
2751
2752                         ctor = redType.GetConstructor (flags, null,
2753                                 new Type [] { typeof (int), typeof (bool) },
2754                                 new ParameterModifier [0]);
2755                         Assert.IsNotNull (ctor, "#F12a");
2756                         Assert.IsTrue (ctor.IsPublic, "#F12b");
2757                         Assert.IsFalse (ctor.IsStatic, "#F12c");
2758                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2759                         Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2760
2761                         ctor = redType.GetConstructor (flags, null,
2762                                 new Type [] { typeof (string), typeof (int) },
2763                                 new ParameterModifier [0]);
2764                         Assert.IsNull (ctor, "#F13");
2765
2766                         ctor = redType.GetConstructor (flags, null,
2767                                 Type.EmptyTypes,
2768                                 new ParameterModifier [0]);
2769                         Assert.IsNull (ctor, "#F14");
2770
2771                         flags = BindingFlags.Static | BindingFlags.Public |
2772                                 BindingFlags.FlattenHierarchy;
2773
2774                         ctor = greenType.GetConstructor (flags, null,
2775                                 new Type [] { typeof (int), typeof (int) },
2776                                 new ParameterModifier [0]);
2777                         Assert.IsNull (ctor, "#G1");
2778
2779                         ctor = greenType.GetConstructor (flags, null,
2780                                 new Type [] { typeof (string) },
2781                                 new ParameterModifier [0]);
2782                         Assert.IsNull (ctor, "#G2");
2783
2784                         ctor = greenType.GetConstructor (flags, null,
2785                                 new Type [] { typeof (string), typeof (string) },
2786                                 new ParameterModifier [0]);
2787                         Assert.IsNull (ctor, "#G3");
2788
2789                         ctor = greenType.GetConstructor (flags, null,
2790                                 new Type [] { typeof (int) },
2791                                 new ParameterModifier [0]);
2792                         Assert.IsNull (ctor, "#G4");
2793
2794                         ctor = greenType.GetConstructor (flags, null,
2795                                 new Type [] { typeof (int), typeof (bool) },
2796                                 new ParameterModifier [0]);
2797                         Assert.IsNull (ctor, "#G5");
2798
2799                         ctor = greenType.GetConstructor (flags, null,
2800                                 new Type [] { typeof (string), typeof (int) },
2801                                 new ParameterModifier [0]);
2802                         Assert.IsNull (ctor, "#G6");
2803
2804                         ctor = greenType.GetConstructor (flags, null,
2805                                 Type.EmptyTypes,
2806                                 new ParameterModifier [0]);
2807                         Assert.IsNull (ctor, "#G7");
2808
2809                         ctor = redType.GetConstructor (flags, null,
2810                                 new Type [] { typeof (int), typeof (int) },
2811                                 new ParameterModifier [0]);
2812                         Assert.IsNull (ctor, "#G8");
2813
2814                         ctor = redType.GetConstructor (flags, null,
2815                                 new Type [] { typeof (string) },
2816                                 new ParameterModifier [0]);
2817                         Assert.IsNull (ctor, "#G9");
2818
2819                         ctor = redType.GetConstructor (flags, null,
2820                                 new Type [] { typeof (string), typeof (string) },
2821                                 new ParameterModifier [0]);
2822                         Assert.IsNull (ctor, "#G10");
2823
2824                         ctor = redType.GetConstructor (flags, null,
2825                                 new Type [] { typeof (int) },
2826                                 new ParameterModifier [0]);
2827                         Assert.IsNull (ctor, "#G11");
2828
2829                         ctor = redType.GetConstructor (flags, null,
2830                                 new Type [] { typeof (int), typeof (bool) },
2831                                 new ParameterModifier [0]);
2832                         Assert.IsNull (ctor, "#G12");
2833
2834                         ctor = redType.GetConstructor (flags, null,
2835                                 new Type [] { typeof (string), typeof (int) },
2836                                 new ParameterModifier [0]);
2837                         Assert.IsNull (ctor, "#G13");
2838
2839                         ctor = redType.GetConstructor (flags, null,
2840                                 Type.EmptyTypes,
2841                                 new ParameterModifier [0]);
2842                         Assert.IsNull (ctor, "#G14");
2843
2844                         flags = BindingFlags.Static | BindingFlags.NonPublic |
2845                                 BindingFlags.FlattenHierarchy;
2846
2847                         ctor = greenType.GetConstructor (flags, null,
2848                                 new Type [] { typeof (int), typeof (int) },
2849                                 new ParameterModifier [0]);
2850                         Assert.IsNull (ctor, "#H1");
2851
2852                         ctor = greenType.GetConstructor (flags, null,
2853                                 new Type [] { typeof (string) },
2854                                 new ParameterModifier [0]);
2855                         Assert.IsNull (ctor, "#H2");
2856
2857                         ctor = greenType.GetConstructor (flags, null,
2858                                 new Type [] { typeof (string), typeof (string) },
2859                                 new ParameterModifier [0]);
2860                         Assert.IsNull (ctor, "#H3");
2861
2862                         ctor = greenType.GetConstructor (flags, null,
2863                                 new Type [] { typeof (int) },
2864                                 new ParameterModifier [0]);
2865                         Assert.IsNull (ctor, "#H4");
2866
2867                         ctor = greenType.GetConstructor (flags, null,
2868                                 new Type [] { typeof (int), typeof (bool) },
2869                                 new ParameterModifier [0]);
2870                         Assert.IsNull (ctor, "#H5");
2871
2872                         ctor = greenType.GetConstructor (flags, null,
2873                                 new Type [] { typeof (string), typeof (int) },
2874                                 new ParameterModifier [0]);
2875                         Assert.IsNull (ctor, "#H6");
2876
2877                         ctor = greenType.GetConstructor (flags, null,
2878                                 Type.EmptyTypes,
2879                                 new ParameterModifier [0]);
2880                         Assert.IsNull (ctor, "#H7");
2881
2882                         ctor = redType.GetConstructor (flags, null,
2883                                 new Type [] { typeof (int), typeof (int) },
2884                                 new ParameterModifier [0]);
2885                         Assert.IsNull (ctor, "#H8");
2886
2887                         ctor = redType.GetConstructor (flags, null,
2888                                 new Type [] { typeof (string) },
2889                                 new ParameterModifier [0]);
2890                         Assert.IsNull (ctor, "#H9");
2891
2892                         ctor = redType.GetConstructor (flags, null,
2893                                 new Type [] { typeof (string), typeof (string) },
2894                                 new ParameterModifier [0]);
2895                         Assert.IsNull (ctor, "#H10");
2896
2897                         ctor = redType.GetConstructor (flags, null,
2898                                 new Type [] { typeof (int) },
2899                                 new ParameterModifier [0]);
2900                         Assert.IsNull (ctor, "#H11");
2901
2902                         ctor = redType.GetConstructor (flags, null,
2903                                 new Type [] { typeof (int), typeof (bool) },
2904                                 new ParameterModifier [0]);
2905                         Assert.IsNull (ctor, "#H12");
2906
2907                         ctor = redType.GetConstructor (flags, null,
2908                                 new Type [] { typeof (string), typeof (int) },
2909                                 new ParameterModifier [0]);
2910                         Assert.IsNull (ctor, "#H13");
2911
2912                         ctor = redType.GetConstructor (flags, null,
2913                                 Type.EmptyTypes,
2914                                 new ParameterModifier [0]);
2915                         Assert.IsNotNull (ctor, "#H14");
2916                         Assert.IsTrue (ctor.IsPrivate, "#H14b");
2917                         Assert.IsTrue (ctor.IsStatic, "#H14c");
2918                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2919                         Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2920
2921                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
2922                                 BindingFlags.DeclaredOnly;
2923
2924                         ctor = greenType.GetConstructor (flags, null,
2925                                 new Type [] { typeof (int), typeof (int) },
2926                                 new ParameterModifier [0]);
2927                         Assert.IsNull (ctor, "#I1");
2928
2929                         ctor = greenType.GetConstructor (flags, null,
2930                                 new Type [] { typeof (string) },
2931                                 new ParameterModifier [0]);
2932                         Assert.IsNull (ctor, "#I2");
2933
2934                         ctor = greenType.GetConstructor (flags, null,
2935                                 new Type [] { typeof (string), typeof (string) },
2936                                 new ParameterModifier [0]);
2937                         Assert.IsNull (ctor, "#I3");
2938
2939                         ctor = greenType.GetConstructor (flags, null,
2940                                 new Type [] { typeof (int) },
2941                                 new ParameterModifier [0]);
2942                         Assert.IsNull (ctor, "#I4");
2943
2944                         ctor = greenType.GetConstructor (flags, null,
2945                                 new Type [] { typeof (int), typeof (bool) },
2946                                 new ParameterModifier [0]);
2947                         Assert.IsNull (ctor, "#I5");
2948
2949                         ctor = greenType.GetConstructor (flags, null,
2950                                 new Type [] { typeof (string), typeof (int) },
2951                                 new ParameterModifier [0]);
2952                         Assert.IsNull (ctor, "#I6");
2953
2954                         ctor = greenType.GetConstructor (flags, null,
2955                                 Type.EmptyTypes,
2956                                 new ParameterModifier [0]);
2957                         Assert.IsNull (ctor, "#I7");
2958
2959                         ctor = redType.GetConstructor (flags, null,
2960                                 new Type [] { typeof (int), typeof (int) },
2961                                 new ParameterModifier [0]);
2962                         Assert.IsNotNull (ctor, "#I8a");
2963                         Assert.IsTrue (ctor.IsPrivate, "#I8b");
2964                         Assert.IsFalse (ctor.IsStatic, "#I8c");
2965                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
2966                         Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
2967
2968                         ctor = redType.GetConstructor (flags, null,
2969                                 new Type [] { typeof (string) },
2970                                 new ParameterModifier [0]);
2971                         Assert.IsNotNull (ctor, "#I9a");
2972                         Assert.IsTrue (ctor.IsFamily, "#I9b");
2973                         Assert.IsFalse (ctor.IsStatic, "#I9c");
2974                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
2975                         Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
2976
2977                         ctor = redType.GetConstructor (flags, null,
2978                                 new Type [] { typeof (string), typeof (string) },
2979                                 new ParameterModifier [0]);
2980                         Assert.IsNotNull (ctor, "#I10a");
2981                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
2982                         Assert.IsFalse (ctor.IsStatic, "#I10c");
2983                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
2984                         Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
2985
2986                         ctor = redType.GetConstructor (flags, null,
2987                                 new Type [] { typeof (int) },
2988                                 new ParameterModifier [0]);
2989                         Assert.IsNotNull (ctor, "#I11a");
2990                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
2991                         Assert.IsFalse (ctor.IsStatic, "#I11c");
2992                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
2993                         Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
2994
2995                         ctor = redType.GetConstructor (flags, null,
2996                                 new Type [] { typeof (int), typeof (bool) },
2997                                 new ParameterModifier [0]);
2998                         Assert.IsNull (ctor, "#I12");
2999
3000                         ctor = redType.GetConstructor (flags, null,
3001                                 new Type [] { typeof (string), typeof (int) },
3002                                 new ParameterModifier [0]);
3003                         Assert.IsNotNull (ctor, "#I13a");
3004                         Assert.IsTrue (ctor.IsAssembly, "#I13b");
3005                         Assert.IsFalse (ctor.IsStatic, "#I13c");
3006                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
3007                         Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
3008
3009                         ctor = redType.GetConstructor (flags, null,
3010                                 Type.EmptyTypes,
3011                                 new ParameterModifier [0]);
3012                         Assert.IsNull (ctor, "#I14");
3013
3014                         flags = BindingFlags.Instance | BindingFlags.Public |
3015                                 BindingFlags.DeclaredOnly;
3016
3017                         ctor = greenType.GetConstructor (flags, null,
3018                                 new Type [] { typeof (int), typeof (int) },
3019                                 new ParameterModifier [0]);
3020                         Assert.IsNull (ctor, "#J1");
3021
3022                         ctor = greenType.GetConstructor (flags, null,
3023                                 new Type [] { typeof (string) },
3024                                 new ParameterModifier [0]);
3025                         Assert.IsNull (ctor, "#J2");
3026
3027                         ctor = greenType.GetConstructor (flags, null,
3028                                 new Type [] { typeof (string), typeof (string) },
3029                                 new ParameterModifier [0]);
3030                         Assert.IsNull (ctor, "#J3");
3031
3032                         ctor = greenType.GetConstructor (flags, null,
3033                                 new Type [] { typeof (int) },
3034                                 new ParameterModifier [0]);
3035                         Assert.IsNull (ctor, "#J4");
3036
3037                         ctor = greenType.GetConstructor (flags, null,
3038                                 new Type [] { typeof (int), typeof (bool) },
3039                                 new ParameterModifier [0]);
3040                         Assert.IsNull (ctor, "#J5");
3041
3042                         ctor = greenType.GetConstructor (flags, null,
3043                                 new Type [] { typeof (string), typeof (int) },
3044                                 new ParameterModifier [0]);
3045                         Assert.IsNull (ctor, "#J6");
3046
3047                         ctor = greenType.GetConstructor (flags, null,
3048                                 Type.EmptyTypes,
3049                                 new ParameterModifier [0]);
3050                         Assert.IsNotNull (ctor, "#J7a");
3051                         Assert.IsTrue (ctor.IsPublic, "#J7b");
3052                         Assert.IsFalse (ctor.IsStatic, "#J7c");
3053                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3054                         Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3055
3056                         ctor = redType.GetConstructor (flags, null,
3057                                 new Type [] { typeof (int), typeof (int) },
3058                                 new ParameterModifier [0]);
3059                         Assert.IsNull (ctor, "#J8");
3060
3061                         ctor = redType.GetConstructor (flags, null,
3062                                 new Type [] { typeof (string) },
3063                                 new ParameterModifier [0]);
3064                         Assert.IsNull (ctor, "#J9");
3065
3066                         ctor = redType.GetConstructor (flags, null,
3067                                 new Type [] { typeof (string), typeof (string) },
3068                                 new ParameterModifier [0]);
3069                         Assert.IsNull (ctor, "#J10");
3070
3071                         ctor = redType.GetConstructor (flags, null,
3072                                 new Type [] { typeof (int) },
3073                                 new ParameterModifier [0]);
3074                         Assert.IsNull (ctor, "#J11");
3075
3076                         ctor = redType.GetConstructor (flags, null,
3077                                 new Type [] { typeof (int), typeof (bool) },
3078                                 new ParameterModifier [0]);
3079                         Assert.IsNotNull (ctor, "#J12a");
3080                         Assert.IsTrue (ctor.IsPublic, "#J12b");
3081                         Assert.IsFalse (ctor.IsStatic, "#J12c");
3082                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3083                         Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3084
3085                         ctor = redType.GetConstructor (flags, null,
3086                                 new Type [] { typeof (string), typeof (int) },
3087                                 new ParameterModifier [0]);
3088                         Assert.IsNull (ctor, "#J13");
3089
3090                         ctor = redType.GetConstructor (flags, null,
3091                                 Type.EmptyTypes,
3092                                 new ParameterModifier [0]);
3093                         Assert.IsNull (ctor, "#J14");
3094
3095                         flags = BindingFlags.Static | BindingFlags.Public |
3096                                 BindingFlags.DeclaredOnly;
3097
3098                         ctor = greenType.GetConstructor (flags, null,
3099                                 new Type [] { typeof (int), typeof (int) },
3100                                 new ParameterModifier [0]);
3101                         Assert.IsNull (ctor, "#K1");
3102
3103                         ctor = greenType.GetConstructor (flags, null,
3104                                 new Type [] { typeof (string) },
3105                                 new ParameterModifier [0]);
3106                         Assert.IsNull (ctor, "#K2");
3107
3108                         ctor = greenType.GetConstructor (flags, null,
3109                                 new Type [] { typeof (string), typeof (string) },
3110                                 new ParameterModifier [0]);
3111                         Assert.IsNull (ctor, "#K3");
3112
3113                         ctor = greenType.GetConstructor (flags, null,
3114                                 new Type [] { typeof (int) },
3115                                 new ParameterModifier [0]);
3116                         Assert.IsNull (ctor, "#K4");
3117
3118                         ctor = greenType.GetConstructor (flags, null,
3119                                 new Type [] { typeof (int), typeof (bool) },
3120                                 new ParameterModifier [0]);
3121                         Assert.IsNull (ctor, "#K5");
3122
3123                         ctor = greenType.GetConstructor (flags, null,
3124                                 new Type [] { typeof (string), typeof (int) },
3125                                 new ParameterModifier [0]);
3126                         Assert.IsNull (ctor, "#K6");
3127
3128                         ctor = greenType.GetConstructor (flags, null,
3129                                 Type.EmptyTypes,
3130                                 new ParameterModifier [0]);
3131                         Assert.IsNull (ctor, "#K7");
3132
3133                         ctor = redType.GetConstructor (flags, null,
3134                                 new Type [] { typeof (int), typeof (int) },
3135                                 new ParameterModifier [0]);
3136                         Assert.IsNull (ctor, "#K8");
3137
3138                         ctor = redType.GetConstructor (flags, null,
3139                                 new Type [] { typeof (string) },
3140                                 new ParameterModifier [0]);
3141                         Assert.IsNull (ctor, "#K9");
3142
3143                         ctor = redType.GetConstructor (flags, null,
3144                                 new Type [] { typeof (string), typeof (string) },
3145                                 new ParameterModifier [0]);
3146                         Assert.IsNull (ctor, "#K10");
3147
3148                         ctor = redType.GetConstructor (flags, null,
3149                                 new Type [] { typeof (int) },
3150                                 new ParameterModifier [0]);
3151                         Assert.IsNull (ctor, "#K11");
3152
3153                         ctor = redType.GetConstructor (flags, null,
3154                                 new Type [] { typeof (int), typeof (bool) },
3155                                 new ParameterModifier [0]);
3156                         Assert.IsNull (ctor, "#K12");
3157
3158                         ctor = redType.GetConstructor (flags, null,
3159                                 new Type [] { typeof (string), typeof (int) },
3160                                 new ParameterModifier [0]);
3161                         Assert.IsNull (ctor, "#K13");
3162
3163                         ctor = redType.GetConstructor (flags, null,
3164                                 Type.EmptyTypes,
3165                                 new ParameterModifier [0]);
3166                         Assert.IsNull (ctor, "#K14");
3167
3168                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3169                                 BindingFlags.DeclaredOnly;
3170
3171                         ctor = greenType.GetConstructor (flags, null,
3172                                 new Type [] { typeof (int), typeof (int) },
3173                                 new ParameterModifier [0]);
3174                         Assert.IsNull (ctor, "#L1");
3175
3176                         ctor = greenType.GetConstructor (flags, null,
3177                                 new Type [] { typeof (string) },
3178                                 new ParameterModifier [0]);
3179                         Assert.IsNull (ctor, "#L2");
3180
3181                         ctor = greenType.GetConstructor (flags, null,
3182                                 new Type [] { typeof (string), typeof (string) },
3183                                 new ParameterModifier [0]);
3184                         Assert.IsNull (ctor, "#L3");
3185
3186                         ctor = greenType.GetConstructor (flags, null,
3187                                 new Type [] { typeof (int) },
3188                                 new ParameterModifier [0]);
3189                         Assert.IsNull (ctor, "#L4");
3190
3191                         ctor = greenType.GetConstructor (flags, null,
3192                                 new Type [] { typeof (int), typeof (bool) },
3193                                 new ParameterModifier [0]);
3194                         Assert.IsNull (ctor, "#L5");
3195
3196                         ctor = greenType.GetConstructor (flags, null,
3197                                 new Type [] { typeof (string), typeof (int) },
3198                                 new ParameterModifier [0]);
3199                         Assert.IsNull (ctor, "#L6");
3200
3201                         ctor = greenType.GetConstructor (flags, null,
3202                                 Type.EmptyTypes,
3203                                 new ParameterModifier [0]);
3204                         Assert.IsNull (ctor, "#L7");
3205
3206                         ctor = redType.GetConstructor (flags, null,
3207                                 new Type [] { typeof (int), typeof (int) },
3208                                 new ParameterModifier [0]);
3209                         Assert.IsNull (ctor, "#L8");
3210
3211                         ctor = redType.GetConstructor (flags, null,
3212                                 new Type [] { typeof (string) },
3213                                 new ParameterModifier [0]);
3214                         Assert.IsNull (ctor, "#L9");
3215
3216                         ctor = redType.GetConstructor (flags, null,
3217                                 new Type [] { typeof (string), typeof (string) },
3218                                 new ParameterModifier [0]);
3219                         Assert.IsNull (ctor, "#L10");
3220
3221                         ctor = redType.GetConstructor (flags, null,
3222                                 new Type [] { typeof (int) },
3223                                 new ParameterModifier [0]);
3224                         Assert.IsNull (ctor, "#L11");
3225
3226                         ctor = redType.GetConstructor (flags, null,
3227                                 new Type [] { typeof (int), typeof (bool) },
3228                                 new ParameterModifier [0]);
3229                         Assert.IsNull (ctor, "#L12");
3230
3231                         ctor = redType.GetConstructor (flags, null,
3232                                 new Type [] { typeof (string), typeof (int) },
3233                                 new ParameterModifier [0]);
3234                         Assert.IsNull (ctor, "#L13");
3235
3236                         ctor = redType.GetConstructor (flags, null,
3237                                 Type.EmptyTypes,
3238                                 new ParameterModifier [0]);
3239                         Assert.IsNotNull (ctor, "#L14a");
3240                         Assert.IsTrue (ctor.IsPrivate, "#L14b");
3241                         Assert.IsTrue (ctor.IsStatic, "#L14c");
3242                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3243                         Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3244
3245                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3246                                 BindingFlags.Public;
3247
3248                         ctor = greenType.GetConstructor (flags, null,
3249                                 new Type [] { typeof (int), typeof (int) },
3250                                 new ParameterModifier [0]);
3251                         Assert.IsNull (ctor, "#M1");
3252
3253                         ctor = greenType.GetConstructor (flags, null,
3254                                 new Type [] { typeof (string) },
3255                                 new ParameterModifier [0]);
3256                         Assert.IsNull (ctor, "#M2");
3257
3258                         ctor = greenType.GetConstructor (flags, null,
3259                                 new Type [] { typeof (string), typeof (string) },
3260                                 new ParameterModifier [0]);
3261                         Assert.IsNull (ctor, "#M3");
3262
3263                         ctor = greenType.GetConstructor (flags, null,
3264                                 new Type [] { typeof (int) },
3265                                 new ParameterModifier [0]);
3266                         Assert.IsNull (ctor, "#M4");
3267
3268                         ctor = greenType.GetConstructor (flags, null,
3269                                 new Type [] { typeof (int), typeof (bool) },
3270                                 new ParameterModifier [0]);
3271                         Assert.IsNull (ctor, "#M5");
3272
3273                         ctor = greenType.GetConstructor (flags, null,
3274                                 new Type [] { typeof (string), typeof (int) },
3275                                 new ParameterModifier [0]);
3276                         Assert.IsNull (ctor, "#M6");
3277
3278                         ctor = greenType.GetConstructor (flags, null,
3279                                 Type.EmptyTypes,
3280                                 new ParameterModifier [0]);
3281                         Assert.IsNotNull (ctor, "#M7a");
3282                         Assert.IsTrue (ctor.IsPublic, "#M7b");
3283                         Assert.IsFalse (ctor.IsStatic, "#M7c");
3284                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3285                         Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3286
3287                         ctor = redType.GetConstructor (flags, null,
3288                                 new Type [] { typeof (int), typeof (int) },
3289                                 new ParameterModifier [0]);
3290                         Assert.IsNotNull (ctor, "#M8a");
3291                         Assert.IsTrue (ctor.IsPrivate, "#M8b");
3292                         Assert.IsFalse (ctor.IsStatic, "#M8c");
3293                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3294                         Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3295
3296                         ctor = redType.GetConstructor (flags, null,
3297                                 new Type [] { typeof (string) },
3298                                 new ParameterModifier [0]);
3299                         Assert.IsNotNull (ctor, "#M9a");
3300                         Assert.IsTrue (ctor.IsFamily, "#M9b");
3301                         Assert.IsFalse (ctor.IsStatic, "#M9c");
3302                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3303                         Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3304
3305                         ctor = redType.GetConstructor (flags, null,
3306                                 new Type [] { typeof (string), typeof (string) },
3307                                 new ParameterModifier [0]);
3308                         Assert.IsNotNull (ctor, "#M10a");
3309                         Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3310                         Assert.IsFalse (ctor.IsStatic, "#M10c");
3311                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3312                         Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3313
3314                         ctor = redType.GetConstructor (flags, null,
3315                                 new Type [] { typeof (int) },
3316                                 new ParameterModifier [0]);
3317                         Assert.IsNotNull (ctor, "#M11a");
3318                         Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3319                         Assert.IsFalse (ctor.IsStatic, "#M11c");
3320                         Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3321                         Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3322
3323                         ctor = redType.GetConstructor (flags, null,
3324                                 new Type [] { typeof (int), typeof (bool) },
3325                                 new ParameterModifier [0]);
3326                         Assert.IsNotNull (ctor, "#M12a");
3327                         Assert.IsTrue (ctor.IsPublic, "#M12b");
3328                         Assert.IsFalse (ctor.IsStatic, "#M12c");
3329                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3330                         Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3331
3332                         ctor = redType.GetConstructor (flags, null,
3333                                 new Type [] { typeof (string), typeof (int) },
3334                                 new ParameterModifier [0]);
3335                         Assert.IsNotNull (ctor, "#M13a");
3336                         Assert.IsTrue (ctor.IsAssembly, "#M13b");
3337                         Assert.IsFalse (ctor.IsStatic, "#M13c");
3338                         Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3339                         Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3340
3341                         ctor = redType.GetConstructor (flags, null,
3342                                 Type.EmptyTypes,
3343                                 new ParameterModifier [0]);
3344                         Assert.IsNull (ctor, "#M14");
3345
3346                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3347                                 BindingFlags.Public;
3348
3349                         ctor = greenType.GetConstructor (flags, null,
3350                                 new Type [] { typeof (int), typeof (int) },
3351                                 new ParameterModifier [0]);
3352                         Assert.IsNull (ctor, "#N1");
3353
3354                         ctor = greenType.GetConstructor (flags, null,
3355                                 new Type [] { typeof (string) },
3356                                 new ParameterModifier [0]);
3357                         Assert.IsNull (ctor, "#N2");
3358
3359                         ctor = greenType.GetConstructor (flags, null,
3360                                 new Type [] { typeof (string), typeof (string) },
3361                                 new ParameterModifier [0]);
3362                         Assert.IsNull (ctor, "#N3");
3363
3364                         ctor = greenType.GetConstructor (flags, null,
3365                                 new Type [] { typeof (int) },
3366                                 new ParameterModifier [0]);
3367                         Assert.IsNull (ctor, "#N4");
3368
3369                         ctor = greenType.GetConstructor (flags, null,
3370                                 new Type [] { typeof (int), typeof (bool) },
3371                                 new ParameterModifier [0]);
3372                         Assert.IsNull (ctor, "#N5");
3373
3374                         ctor = greenType.GetConstructor (flags, null,
3375                                 new Type [] { typeof (string), typeof (int) },
3376                                 new ParameterModifier [0]);
3377                         Assert.IsNull (ctor, "#N6");
3378
3379                         ctor = greenType.GetConstructor (flags, null,
3380                                 Type.EmptyTypes,
3381                                 new ParameterModifier [0]);
3382                         Assert.IsNull (ctor, "#N7");
3383
3384                         ctor = redType.GetConstructor (flags, null,
3385                                 new Type [] { typeof (int), typeof (int) },
3386                                 new ParameterModifier [0]);
3387                         Assert.IsNull (ctor, "#N8");
3388
3389                         ctor = redType.GetConstructor (flags, null,
3390                                 new Type [] { typeof (string) },
3391                                 new ParameterModifier [0]);
3392                         Assert.IsNull (ctor, "#N9");
3393
3394                         ctor = redType.GetConstructor (flags, null,
3395                                 new Type [] { typeof (string), typeof (string) },
3396                                 new ParameterModifier [0]);
3397                         Assert.IsNull (ctor, "#N10");
3398
3399                         ctor = redType.GetConstructor (flags, null,
3400                                 new Type [] { typeof (int) },
3401                                 new ParameterModifier [0]);
3402                         Assert.IsNull (ctor, "#N11");
3403
3404                         ctor = redType.GetConstructor (flags, null,
3405                                 new Type [] { typeof (int), typeof (bool) },
3406                                 new ParameterModifier [0]);
3407                         Assert.IsNull (ctor, "#N12");
3408
3409                         ctor = redType.GetConstructor (flags, null,
3410                                 new Type [] { typeof (string), typeof (int) },
3411                                 new ParameterModifier [0]);
3412                         Assert.IsNull (ctor, "#N13");
3413
3414                         ctor = redType.GetConstructor (flags, null,
3415                                 Type.EmptyTypes,
3416                                 new ParameterModifier [0]);
3417                         Assert.IsNotNull (ctor, "#N14a");
3418                         Assert.IsTrue (ctor.IsPrivate, "#N14b");
3419                         Assert.IsTrue (ctor.IsStatic, "#N14c");
3420                         Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3421                         Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3422                 }
3423
3424                 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
3425                 public void GetConstructor2_Incomplete ()
3426                 {
3427                         TypeBuilder tb = module.DefineType (genTypeName ());
3428                         ConstructorBuilder cb = tb.DefineConstructor (
3429                                 MethodAttributes.Public,
3430                                 CallingConventions.Standard,
3431                                 Type.EmptyTypes);
3432                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3433
3434                         try {
3435                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3436                                         null, Type.EmptyTypes, new ParameterModifier [0]);
3437                                 Assert.Fail ("#1");
3438                         } catch (NotSupportedException ex) {
3439                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3440                                 Assert.IsNull (ex.InnerException, "#3");
3441                                 Assert.IsNotNull (ex.Message, "#4");
3442                         }
3443                 }
3444
3445                 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
3446                 public void GetConstructor3_Incomplete ()
3447                 {
3448                         TypeBuilder tb = module.DefineType (genTypeName ());
3449                         ConstructorBuilder cb = tb.DefineConstructor (
3450                                 MethodAttributes.Public,
3451                                 CallingConventions.Standard,
3452                                 Type.EmptyTypes);
3453                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3454
3455                         try {
3456                                 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3457                                         null, CallingConventions.Standard, Type.EmptyTypes,
3458                                         new ParameterModifier [0]);
3459                                 Assert.Fail ("#1");
3460                         } catch (NotSupportedException ex) {
3461                                 // The invoked member is not supported in a
3462                                 // dynamic module
3463                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3464                                 Assert.IsNull (ex.InnerException, "#3");
3465                                 Assert.IsNotNull (ex.Message, "#4");
3466                         }
3467                 }
3468
3469                 [Test] // GetConstructors ()
3470                 [Category ("NotWorking")] // mcs depends on this
3471                 public void GetConstructors1_Incomplete ()
3472                 {
3473                         TypeBuilder tb = module.DefineType (genTypeName ());
3474                         ConstructorBuilder cb = tb.DefineConstructor (
3475                                 MethodAttributes.Public,
3476                                 CallingConventions.Standard,
3477                                 Type.EmptyTypes);
3478                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3479
3480                         try {
3481                                 tb.GetConstructors ();
3482                                 Assert.Fail ("#1");
3483                         } catch (NotSupportedException ex) {
3484                                 // The invoked member is not supported in a
3485                                 // dynamic module
3486                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3487                                 Assert.IsNull (ex.InnerException, "#3");
3488                                 Assert.IsNotNull (ex.Message, "#4");
3489                         }
3490                 }
3491
3492                 [Test] // GetConstructors (BindingFlags)
3493                 public void GetConstructors2_Complete ()
3494                 {
3495                         BindingFlags flags;
3496                         ConstructorInfo [] ctors;
3497
3498                         TypeBuilder redType = module.DefineType (genTypeName (),
3499                                 TypeAttributes.Public);
3500                         CreateMembers (redType, "Red", true);
3501
3502                         TypeBuilder greenType = module.DefineType (genTypeName (),
3503                                 TypeAttributes.Public, redType);
3504                         CreateMembers (greenType, "Green", false);
3505                         ConstructorBuilder cb = greenType.DefineConstructor (
3506                                 MethodAttributes.Public,
3507                                 CallingConventions.Standard,
3508                                 Type.EmptyTypes);
3509                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3510
3511                         redType.CreateType ();
3512                         greenType.CreateType ();
3513
3514                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3515
3516                         ctors = greenType.GetConstructors (flags);
3517                         Assert.AreEqual (0, ctors.Length, "#A1");
3518
3519                         ctors = redType.GetConstructors (flags);
3520                         Assert.AreEqual (5, ctors.Length, "#A2");
3521                         Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3522                         Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3523                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3524                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3525                         Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3526                         Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3527                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3528                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3529                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3530                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3531                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3532                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3533                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3534                         Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3535                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3536                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3537                         Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3538                         Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3539                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3540                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3541
3542                         flags = BindingFlags.Instance | BindingFlags.Public;
3543
3544                         ctors = greenType.GetConstructors (flags);
3545                         Assert.AreEqual (1, ctors.Length, "#B1");
3546                         Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3547                         Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3548                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3549                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3550
3551                         ctors = redType.GetConstructors (flags);
3552                         Assert.AreEqual (1, ctors.Length, "#B3");
3553                         Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3554                         Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3555                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3556                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3557
3558                         flags = BindingFlags.Static | BindingFlags.Public;
3559
3560                         ctors = greenType.GetConstructors (flags);
3561                         Assert.AreEqual (0, ctors.Length, "#C1");
3562
3563                         ctors = redType.GetConstructors (flags);
3564                         Assert.AreEqual (0, ctors.Length, "#C2");
3565
3566                         flags = BindingFlags.Static | BindingFlags.NonPublic;
3567
3568                         ctors = greenType.GetConstructors (flags);
3569                         Assert.AreEqual (0, ctors.Length, "#D1");
3570
3571                         ctors = redType.GetConstructors (flags);
3572                         Assert.AreEqual (1, ctors.Length, "#D2");
3573                         Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3574                         Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3575                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3576                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3577
3578                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3579                                 BindingFlags.FlattenHierarchy;
3580
3581                         ctors = greenType.GetConstructors (flags);
3582                         Assert.AreEqual (0, ctors.Length, "#E1");
3583
3584                         ctors = redType.GetConstructors (flags);
3585                         Assert.AreEqual (5, ctors.Length, "#E2");
3586                         Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3587                         Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3588                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3589                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3590                         Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3591                         Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3592                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3593                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3594                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3595                         Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3596                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3597                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3598                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3599                         Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3600                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3601                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3602                         Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3603                         Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3604                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3605                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3606
3607                         flags = BindingFlags.Instance | BindingFlags.Public |
3608                                 BindingFlags.FlattenHierarchy;
3609
3610                         ctors = greenType.GetConstructors (flags);
3611                         Assert.AreEqual (1, ctors.Length, "#F1");
3612                         Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3613                         Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3614                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3615                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3616
3617                         ctors = redType.GetConstructors (flags);
3618                         Assert.AreEqual (1, ctors.Length, "#F3");
3619                         Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3620                         Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3621                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3622                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3623
3624                         flags = BindingFlags.Static | BindingFlags.Public |
3625                                 BindingFlags.FlattenHierarchy;
3626
3627                         ctors = greenType.GetConstructors (flags);
3628                         Assert.AreEqual (0, ctors.Length, "#G1");
3629
3630                         ctors = redType.GetConstructors (flags);
3631                         Assert.AreEqual (0, ctors.Length, "#G2");
3632
3633                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3634                                 BindingFlags.FlattenHierarchy;
3635
3636                         ctors = greenType.GetConstructors (flags);
3637                         Assert.AreEqual (0, ctors.Length, "#H1");
3638
3639                         ctors = redType.GetConstructors (flags);
3640                         Assert.AreEqual (1, ctors.Length, "#H2");
3641                         Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3642                         Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3643                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3644                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3645
3646                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3647                                 BindingFlags.DeclaredOnly;
3648
3649                         ctors = greenType.GetConstructors (flags);
3650                         Assert.AreEqual (0, ctors.Length, "#I1");
3651
3652                         ctors = redType.GetConstructors (flags);
3653                         Assert.AreEqual (5, ctors.Length, "#I2");
3654                         Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3655                         Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3656                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3657                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3658                         Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3659                         Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3660                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3661                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3662                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3663                         Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3664                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3665                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3666                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3667                         Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3668                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3669                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3670                         Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3671                         Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3672                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3673                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3674
3675                         flags = BindingFlags.Instance | BindingFlags.Public |
3676                                 BindingFlags.DeclaredOnly;
3677
3678                         ctors = greenType.GetConstructors (flags);
3679                         Assert.AreEqual (1, ctors.Length, "#J1");
3680                         Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3681                         Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3682                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3683                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3684
3685                         ctors = redType.GetConstructors (flags);
3686                         Assert.AreEqual (1, ctors.Length, "#J3");
3687                         Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3688                         Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3689                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3690                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3691
3692                         flags = BindingFlags.Static | BindingFlags.Public |
3693                                 BindingFlags.DeclaredOnly;
3694
3695                         ctors = greenType.GetConstructors (flags);
3696                         Assert.AreEqual (0, ctors.Length, "#K1");
3697
3698                         ctors = redType.GetConstructors (flags);
3699                         Assert.AreEqual (0, ctors.Length, "#K2");
3700
3701                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3702                                 BindingFlags.DeclaredOnly;
3703
3704                         ctors = greenType.GetConstructors (flags);
3705                         Assert.AreEqual (0, ctors.Length, "#L1");
3706
3707                         ctors = redType.GetConstructors (flags);
3708                         Assert.AreEqual (1, ctors.Length, "#L2");
3709                         Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3710                         Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3711                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3712                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3713
3714                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
3715                                 BindingFlags.Public;
3716
3717                         ctors = greenType.GetConstructors (flags);
3718                         Assert.AreEqual (1, ctors.Length, "#M1");
3719                         Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3720                         Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3721                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3722                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3723
3724                         ctors = redType.GetConstructors (flags);
3725                         Assert.AreEqual (6, ctors.Length, "#M3");
3726                         Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3727                         Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3728                         Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3729                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3730                         Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3731                         Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3732                         Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3733                         Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3734                         Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3735                         Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3736                         Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3737                         Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3738                         Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3739                         Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3740                         Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3741                         Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3742                         Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3743                         Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3744                         Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3745                         Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3746                         Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3747                         Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3748                         Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3749                         Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3750
3751                         flags = BindingFlags.Static | BindingFlags.NonPublic |
3752                                 BindingFlags.Public;
3753
3754                         ctors = greenType.GetConstructors (flags);
3755                         Assert.AreEqual (0, ctors.Length, "#N1");
3756
3757                         ctors = redType.GetConstructors (flags);
3758                         Assert.AreEqual (1, ctors.Length, "#N2");
3759                         Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3760                         Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3761                         Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3762                         Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3763                 }
3764
3765                 [Test] // GetConstructors (BindingFlags)
3766                 [Category ("NotWorking")] // mcs depends on this
3767                 public void GetConstructors2_Incomplete ()
3768                 {
3769                         TypeBuilder tb = module.DefineType (genTypeName ());
3770                         ConstructorBuilder cb = tb.DefineConstructor (
3771                                 MethodAttributes.Public,
3772                                 CallingConventions.Standard,
3773                                 Type.EmptyTypes);
3774                         cb.GetILGenerator ().Emit (OpCodes.Ret);
3775
3776                         try {
3777                                 tb.GetConstructors (BindingFlags.Public |
3778                                         BindingFlags.Instance);
3779                                 Assert.Fail ("#1");
3780                         } catch (NotSupportedException ex) {
3781                                 // The invoked member is not supported in a
3782                                 // dynamic module
3783                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3784                                 Assert.IsNull (ex.InnerException, "#3");
3785                                 Assert.IsNotNull (ex.Message, "#4");
3786                         }
3787                 }
3788
3789                 [Test]
3790                 public void TestGetCustomAttributesIncomplete ()
3791                 {
3792                         TypeBuilder tb = module.DefineType (genTypeName ());
3793                         try {
3794                                 tb.GetCustomAttributes (false);
3795                                 Assert.Fail ("#1");
3796                         } catch (NotSupportedException ex) {
3797                                 // The invoked member is not supported in a
3798                                 // dynamic module
3799                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3800                                 Assert.IsNull (ex.InnerException, "#3");
3801                                 Assert.IsNotNull (ex.Message, "#4");
3802                         }
3803                 }
3804
3805                 [Test]
3806                 public void TestGetCustomAttributesComplete ()
3807                 {
3808                         TypeBuilder tb = module.DefineType (genTypeName ());
3809
3810                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3811                                 new Type [] { typeof (string) });
3812
3813                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3814                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3815
3816                         tb.SetCustomAttribute (caBuilder);
3817                         tb.CreateType ();
3818
3819                         Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3820                 }
3821
3822                 [Test]
3823                 public void TestGetCustomAttributesOfTypeIncomplete ()
3824                 {
3825                         TypeBuilder tb = module.DefineType (genTypeName ());
3826                         try {
3827                                 tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3828                                 Assert.Fail ("#1");
3829                         } catch (NotSupportedException ex) {
3830                                 // The invoked member is not supported in a
3831                                 // dynamic module
3832                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3833                                 Assert.IsNull (ex.InnerException, "#3");
3834                                 Assert.IsNotNull (ex.Message, "#4");
3835                         }
3836                 }
3837
3838                 [Test]
3839                 public void TestGetCustomAttributesOfTypeComplete ()
3840                 {
3841                         TypeBuilder tb = module.DefineType (genTypeName ());
3842
3843                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3844                                 new Type [] { typeof (string) });
3845
3846                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3847                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3848
3849                         tb.SetCustomAttribute (caBuilder);
3850                         tb.CreateType ();
3851
3852                         Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3853                         Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3854                 }
3855
3856                 [Test]
3857                 public void TestGetCustomAttributesOfNullTypeComplete ()
3858                 {
3859                         TypeBuilder tb = module.DefineType (genTypeName ());
3860                         tb.CreateType ();
3861                         try {
3862                                 tb.GetCustomAttributes (null, false);
3863                                 Assert.Fail ("#1");
3864                         } catch (ArgumentNullException ex) {
3865                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3866                                 Assert.IsNull (ex.InnerException, "#3");
3867                                 Assert.IsNotNull (ex.Message, "#4");
3868                                 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3869                         }
3870                 }
3871
3872                 [Test]
3873                 [Ignore ("mcs depends on this")]
3874                 public void TestGetEventsIncomplete ()
3875                 {
3876                         TypeBuilder tb = module.DefineType (genTypeName ());
3877                         try {
3878                                 tb.GetEvents ();
3879                                 Assert.Fail ("#1");
3880                         } catch (NotSupportedException ex) {
3881                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3882                                 Assert.IsNull (ex.InnerException, "#3");
3883                                 Assert.IsNotNull (ex.Message, "#4");
3884                                 throw;
3885                         }
3886                 }
3887
3888                 [Test]
3889                 public void TestGetEventsComplete ()
3890                 {
3891                         TypeBuilder tb = module.DefineType (genTypeName ());
3892
3893                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3894                                 typeof (void), new Type [] { typeof (Object) });
3895                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3896
3897                         // create public event
3898                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3899                                 typeof (ResolveEventHandler));
3900                         eventbuilder.SetRaiseMethod (onclickMethod);
3901
3902                         Type emittedType = tb.CreateType ();
3903
3904                         Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3905                         Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3906                 }
3907
3908
3909                 [Test]
3910                 [Ignore ("mcs depends on this")]
3911                 public void TestGetEventsFlagsIncomplete ()
3912                 {
3913                         TypeBuilder tb = module.DefineType (genTypeName ());
3914                         try {
3915                                 tb.GetEvents (BindingFlags.Public);
3916                                 Assert.Fail ("#1");
3917                         } catch (NotSupportedException ex) {
3918                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3919                                 Assert.IsNull (ex.InnerException, "#3");
3920                                 Assert.IsNotNull (ex.Message, "#4");
3921                                 throw;
3922                         }
3923                 }
3924
3925                 [Test]
3926                 public void TestGetEventsFlagsComplete ()
3927                 {
3928                         TypeBuilder tb = module.DefineType (genTypeName ());
3929
3930                         MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3931                                 typeof (void), new Type [] { typeof (Object) });
3932                         onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3933
3934                         // create public event
3935                         EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3936                                 typeof (ResolveEventHandler));
3937                         changeEvent.SetRaiseMethod (onchangeMethod);
3938
3939                         // create non-public event
3940                         EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3941                                 typeof (ResolveEventHandler));
3942
3943                         Type emittedType = tb.CreateType ();
3944
3945                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3946                         Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3947                         Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3948                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
3949                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3950                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
3951                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3952                         Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
3953                                 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3954                 }
3955
3956                 [Test]
3957                 public void TestGetEventsFlagsComplete_Inheritance ()
3958                 {
3959                         EventInfo [] events;
3960                         BindingFlags flags;
3961
3962                         TypeBuilder blueType = module.DefineType (genTypeName (),
3963                                 TypeAttributes.Public);
3964                         CreateMembers (blueType, "Blue", false);
3965
3966                         TypeBuilder redType = module.DefineType (genTypeName (),
3967                                 TypeAttributes.Public, blueType);
3968                         CreateMembers (redType, "Red", false);
3969
3970                         TypeBuilder greenType = module.DefineType (genTypeName (),
3971                                 TypeAttributes.Public, redType);
3972                         CreateMembers (greenType, "Green", false);
3973
3974                         blueType.CreateType ();
3975                         redType.CreateType ();
3976                         greenType.CreateType ();
3977
3978                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
3979                         events = greenType.GetEvents (flags);
3980
3981                         Assert.AreEqual (13, events.Length, "#A1");
3982                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
3983                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
3984                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
3985                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
3986                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
3987                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
3988                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
3989                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
3990                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
3991                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
3992                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
3993                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
3994                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
3995
3996                         flags = BindingFlags.Instance | BindingFlags.Public;
3997                         events = greenType.GetEvents (flags);
3998
3999                         Assert.AreEqual (3, events.Length, "#B1");
4000                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
4001                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
4002                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
4003
4004                         flags = BindingFlags.Static | BindingFlags.Public;
4005                         events = greenType.GetEvents (flags);
4006
4007                         Assert.AreEqual (1, events.Length, "#C1");
4008                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
4009
4010                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4011                         events = greenType.GetEvents (flags);
4012
4013                         Assert.AreEqual (5, events.Length, "#D1");
4014                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
4015                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
4016                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
4017                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4018                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4019
4020                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4021                                 BindingFlags.FlattenHierarchy;
4022                         events = greenType.GetEvents (flags);
4023
4024                         Assert.AreEqual (13, events.Length, "#E1");
4025                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4026                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4027                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4028                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4029                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4030                         Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4031                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4032                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4033                         Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4034                         Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4035                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4036                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4037                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4038
4039                         flags = BindingFlags.Instance | BindingFlags.Public |
4040                                 BindingFlags.FlattenHierarchy;
4041                         events = greenType.GetEvents (flags);
4042
4043                         Assert.AreEqual (3, events.Length, "#F1");
4044                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4045                         Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4046                         Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4047
4048                         flags = BindingFlags.Static | BindingFlags.Public |
4049                                 BindingFlags.FlattenHierarchy;
4050                         events = greenType.GetEvents (flags);
4051
4052                         Assert.AreEqual (3, events.Length, "#G1");
4053                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4054                         Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4055                         Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4056
4057                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4058                                 BindingFlags.FlattenHierarchy;
4059                         events = greenType.GetEvents (flags);
4060
4061                         Assert.AreEqual (13, events.Length, "#H1");
4062                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4063                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4064                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4065                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4066                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4067                         Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4068                         Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4069                         Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4070                         Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4071                         Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4072                         Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4073                         Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4074                         Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4075
4076                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4077                                 BindingFlags.DeclaredOnly;
4078                         events = greenType.GetEvents (flags);
4079
4080                         Assert.AreEqual (5, events.Length, "#I1");
4081                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4082                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4083                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4084                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4085                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4086
4087                         flags = BindingFlags.Instance | BindingFlags.Public |
4088                                 BindingFlags.DeclaredOnly;
4089                         events = greenType.GetEvents (flags);
4090
4091                         Assert.AreEqual (1, events.Length, "#J1");
4092                         Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4093
4094                         flags = BindingFlags.Static | BindingFlags.Public |
4095                                 BindingFlags.DeclaredOnly;
4096                         events = greenType.GetEvents (flags);
4097
4098                         Assert.AreEqual (1, events.Length, "#K1");
4099                         Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4100
4101                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4102                                 BindingFlags.DeclaredOnly;
4103                         events = greenType.GetEvents (flags);
4104
4105                         Assert.AreEqual (5, events.Length, "#L1");
4106                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4107                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4108                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4109                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4110                         Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4111
4112                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4113                                 BindingFlags.Public;
4114                         events = greenType.GetEvents (flags);
4115
4116                         Assert.AreEqual (16, events.Length, "#M1");
4117                         Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4118                         Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4119                         Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4120                         Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4121                         Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4122                         Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4123                         Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4124                         Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4125                         Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4126                         Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4127                         Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4128                         Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4129                         Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4130                         Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4131                         Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4132                         Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4133
4134                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4135                                 BindingFlags.Public;
4136                         events = greenType.GetEvents (flags);
4137
4138                         Assert.AreEqual (6, events.Length, "#N1");
4139                         Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4140                         Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4141                         Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4142                         Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4143                         Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4144                         Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4145                 }
4146
4147                 [Test]
4148                 [Ignore ("mcs depends on this")]
4149                 public void TestGetEventIncomplete ()
4150                 {
4151                         TypeBuilder tb = module.DefineType (genTypeName ());
4152                         try {
4153                                 tb.GetEvent ("FOO");
4154                                 Assert.Fail ("#1");
4155                         } catch (NotSupportedException ex) {
4156                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4157                                 Assert.IsNull (ex.InnerException, "#3");
4158                                 Assert.IsNotNull (ex.Message, "#4");
4159                                 throw;
4160                         }
4161                 }
4162
4163                 [Test]
4164                 public void TestGetEventComplete ()
4165                 {
4166                         TypeBuilder tb = module.DefineType (genTypeName ());
4167
4168                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4169                                 typeof (void), new Type [] { typeof (Object) });
4170                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4171
4172                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4173                                 typeof (ResolveEventHandler));
4174                         eventbuilder.SetRaiseMethod (onclickMethod);
4175
4176                         Type emittedType = tb.CreateType ();
4177
4178                         Assert.IsNotNull (tb.GetEvent ("Change"));
4179                         Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4180                         Assert.IsNull (tb.GetEvent ("NotChange"));
4181                         Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4182                 }
4183
4184                 [Test]
4185                 [Ignore ("mcs depends on this")]
4186                 public void TestGetEventFlagsIncomplete ()
4187                 {
4188                         TypeBuilder tb = module.DefineType (genTypeName ());
4189                         try {
4190                                 tb.GetEvent ("FOO", BindingFlags.Public);
4191                                 Assert.Fail ("#1");
4192                         } catch (NotSupportedException ex) {
4193                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4194                                 Assert.IsNull (ex.InnerException, "#3");
4195                                 Assert.IsNotNull (ex.Message, "#4");
4196                                 throw;
4197                         }
4198                 }
4199
4200                 [Test]
4201                 public void TestGetEventFlagsComplete ()
4202                 {
4203                         TypeBuilder tb = module.DefineType (genTypeName ());
4204
4205                         MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4206                                 typeof (void), new Type [] { typeof (Object) });
4207                         onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4208
4209                         EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4210                                 typeof (ResolveEventHandler));
4211                         eventbuilder.SetRaiseMethod (onclickMethod);
4212
4213                         Type emittedType = tb.CreateType ();
4214
4215                         Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4216                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4217                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4218                         Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4219                         Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4220                                 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4221                 }
4222
4223                 [Test]
4224                 public void TestGetEventFlagsComplete_Inheritance ()
4225                 {
4226                         BindingFlags flags;
4227
4228                         TypeBuilder blueType = module.DefineType (genTypeName (),
4229                                 TypeAttributes.Public);
4230                         CreateMembers (blueType, "Blue", false);
4231
4232                         TypeBuilder redType = module.DefineType (genTypeName (),
4233                                 TypeAttributes.Public, blueType);
4234                         CreateMembers (redType, "Red", false);
4235
4236                         TypeBuilder greenType = module.DefineType (genTypeName (),
4237                                 TypeAttributes.Public, redType);
4238                         CreateMembers (greenType, "Green", false);
4239
4240                         blueType.CreateType ();
4241                         redType.CreateType ();
4242                         greenType.CreateType ();
4243
4244                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
4245
4246                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4247                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4248                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4249                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4250                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4251                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4252                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4253                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4254                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4255                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4256                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4257                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4258                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4259                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4260                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4261                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4262                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4263                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4264                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4265                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4266                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4267                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4268                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4269                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4270                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4271                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4272                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4273                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4274                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4275                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4276                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4277                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4278                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4279                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4280                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4281                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4282
4283                         flags = BindingFlags.Instance | BindingFlags.Public;
4284
4285                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4286                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4287                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4288                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4289                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4290                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4291                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4292                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4293                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4294                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4295                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4296                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4297                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4298                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4299                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4300                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4301                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4302                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4303                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4304                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4305                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4306                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4307                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4308                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4309                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4310                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4311                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4312                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4313                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4314                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4315                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4316                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4317                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4318                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4319                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4320                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4321
4322                         flags = BindingFlags.Static | BindingFlags.Public;
4323
4324                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4325                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4326                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4327                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4328                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4329                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4330                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4331                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4332                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4333                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4334                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4335                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4336                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4337                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4338                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4339                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4340                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4341                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4342                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4343                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4344                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4345                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4346                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4347                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4348                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4349                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4350                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4351                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4352                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4353                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4354                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4355                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4356                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4357                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4358                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4359                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4360
4361                         flags = BindingFlags.Static | BindingFlags.NonPublic;
4362
4363                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4364                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4365                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4366                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4367                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4368                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4369                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4370                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4371                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4372                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4373                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4374                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4375                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4376                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4377                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4378                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4379                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4380                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4381                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4382                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4383                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4384                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4385                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4386                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4387                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4388                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4389                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4390                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4391                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4392                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4393                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4394                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4395                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4396                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4397                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4398                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4399
4400                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4401                                 BindingFlags.FlattenHierarchy;
4402
4403                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4404                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4405                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4406                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4407                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4408                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4409                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4410                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4411                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4412                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4413                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4414                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4415                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4416                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4417                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4418                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4419                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4420                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4421                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4422                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4423                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4424                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4425                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4426                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4427                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4428                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4429                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4430                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4431                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4432                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4433                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4434                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4435                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4436                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4437                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4438                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4439
4440                         flags = BindingFlags.Instance | BindingFlags.Public |
4441                                 BindingFlags.FlattenHierarchy;
4442
4443                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4444                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4445                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4446                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4447                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4448                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4449                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4450                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4451                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4452                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4453                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4454                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4455                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4456                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4457                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4458                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4459                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4460                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4461                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4462                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4463                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4464                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4465                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4466                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4467                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4468                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4469                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4470                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4471                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4472                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4473                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4474                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4475                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4476                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4477                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4478                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4479
4480                         flags = BindingFlags.Static | BindingFlags.Public |
4481                                 BindingFlags.FlattenHierarchy;
4482
4483                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4484                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4485                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4486                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4487                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4488                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4489                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4490                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4491                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4492                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4493                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4494                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4495                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4496                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4497                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4498                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4499                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4500                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4501                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4502                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4503                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4504                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4505                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4506                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4507                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4508                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4509                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4510                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4511                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4512                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4513                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4514                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4515                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4516                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4517                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4518                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4519
4520                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4521                                 BindingFlags.FlattenHierarchy;
4522
4523                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4524                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4525                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4526                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4527                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4528                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4529                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4530                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4531                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4532                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4533                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4534                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4535                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4536                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4537                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4538                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4539                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4540                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4541                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4542                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4543                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4544                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4545                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4546                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4547                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4548                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4549                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4550                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4551                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4552                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4553                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4554                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4555                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4556                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4557                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4558                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4559
4560                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4561                                 BindingFlags.DeclaredOnly;
4562
4563                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4564                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4565                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4566                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4567                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4568                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4569                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4570                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4571                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4572                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4573                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4574                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4575                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4576                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4577                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4578                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4579                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4580                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4581                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4582                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4583                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4584                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4585                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4586                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4587                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4588                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4589                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4590                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4591                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4592                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4593                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4594                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4595                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4596                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4597                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4598                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4599
4600                         flags = BindingFlags.Instance | BindingFlags.Public |
4601                                 BindingFlags.DeclaredOnly;
4602
4603                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4604                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4605                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4606                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4607                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4608                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4609                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4610                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4611                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4612                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4613                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4614                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4615                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4616                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4617                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4618                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4619                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4620                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4621                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4622                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4623                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4624                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4625                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4626                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4627                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4628                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4629                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4630                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4631                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4632                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4633                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4634                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4635                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4636                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4637                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4638                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4639
4640                         flags = BindingFlags.Static | BindingFlags.Public |
4641                                 BindingFlags.DeclaredOnly;
4642
4643                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4644                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4645                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4646                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4647                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4648                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4649                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4650                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4651                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4652                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4653                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4654                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4655                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4656                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4657                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4658                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4659                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4660                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4661                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4662                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4663                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4664                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4665                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4666                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4667                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4668                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4669                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4670                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4671                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4672                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4673                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4674                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4675                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4676                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4677                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4678                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4679
4680                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4681                                 BindingFlags.DeclaredOnly;
4682
4683                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4684                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4685                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4686                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4687                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4688                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4689                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4690                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4691                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4692                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4693                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4694                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4695                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4696                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4697                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4698                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4699                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4700                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4701                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4702                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4703                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4704                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4705                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4706                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4707                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4708                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4709                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4710                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4711                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4712                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4713                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4714                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4715                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4716                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4717                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4718                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4719
4720                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
4721                                 BindingFlags.Public;
4722
4723                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4724                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4725                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4726                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4727                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4728                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4729                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4730                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4731                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4732                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4733                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4734                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4735                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4736                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4737                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4738                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4739                         Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4740                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4741                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4742                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4743                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4744                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4745                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4746                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4747                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4748                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4749                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4750                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4751                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4752                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4753                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4754                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4755                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4756                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4757                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4758                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4759
4760                         flags = BindingFlags.Static | BindingFlags.NonPublic |
4761                                 BindingFlags.Public;
4762
4763                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4764                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4765                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4766                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4767                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4768                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4769                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4770                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4771                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4772                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4773                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4774                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4775                         Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4776                         Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4777                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4778                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4779                         Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4780                         Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4781                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4782                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4783                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4784                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4785                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4786                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4787                         Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4788                         Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4789                         Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4790                         Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4791                         Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4792                         Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4793                         Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4794                         Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4795                         Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4796                         Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4797                         Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4798                         Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4799                 }
4800
4801                 [Test]
4802                 [Category ("NotWorking")] // mcs depends on this
4803                 public void TestGetFieldsIncomplete_MS ()
4804                 {
4805                         TypeBuilder tb = module.DefineType (genTypeName ());
4806                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4807                         try {
4808                                 tb.GetFields ();
4809                                 Assert.Fail ("#1");
4810                         } catch (NotSupportedException ex) {
4811                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4812                                 Assert.IsNull (ex.InnerException, "#3");
4813                                 Assert.IsNotNull (ex.Message, "#4");
4814                         }
4815                 }
4816
4817                 [Test]
4818                 [Category ("NotDotNet")] // mcs depends on this
4819                 public void TestGetFieldsIncomplete_Mono ()
4820                 {
4821                         TypeBuilder tb = module.DefineType (genTypeName ());
4822                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4823                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4824                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4825                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4826
4827                         FieldInfo [] fields = tb.GetFields ();
4828                         Assert.AreEqual (2, fields.Length, "#A1");
4829                         Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4830                         Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4831
4832                         tb = module.DefineType (genTypeName ());
4833                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4834                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4835                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4836                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4837                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4838                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4839
4840                         fields = tb.GetFields ();
4841                         Assert.AreEqual (4, fields.Length, "#B1");
4842                         Assert.AreEqual ("First", fields [0].Name, "#B2");
4843                         Assert.AreEqual ("Second", fields [1].Name, "#B3");
4844                         Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4845                         Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4846                 }
4847
4848                 [Test]
4849                 public void TestGetFieldsComplete ()
4850                 {
4851                         TypeBuilder tb = module.DefineType (genTypeName ());
4852                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4853
4854                         Type emittedType = tb.CreateType ();
4855                         FieldInfo [] dynamicFields = tb.GetFields ();
4856                         FieldInfo [] emittedFields = emittedType.GetFields ();
4857
4858                         Assert.AreEqual (1, dynamicFields.Length, "#A1");
4859                         Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4860                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4861                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4862
4863                         // bug #81638
4864                         object value = Activator.CreateInstance (emittedType);
4865                         emittedFields [0].SetValue (value, 5);
4866                         Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4867                         Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4868                         dynamicFields [0].SetValue (value, 4);
4869                         Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4870                         Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4871                 }
4872
4873                 [Test] // bug #82625 / 325292
4874                 public void TestGetFieldsComplete_Generic ()
4875                 {
4876                         // FIXME: merge this with TestGetFieldsComplete when
4877                         // bug #82625 is fixed
4878
4879                         TypeBuilder tb;
4880                         Type emittedType;
4881                         FieldInfo [] dynamicFields;
4882                         FieldInfo [] emittedFields;
4883
4884                         tb = module.DefineType (genTypeName ());
4885                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4886                         tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4887                         tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4888                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4889                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4890                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4891
4892                         emittedType = tb.CreateType ();
4893                         dynamicFields = tb.GetFields ();
4894                         emittedFields = emittedType.GetFields ();
4895
4896                         Assert.AreEqual (4, dynamicFields.Length, "#C1");
4897                         Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4898                         Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4899                         Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4900                         Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4901                         Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4902                         Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4903                         Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4904                         Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4905
4906                         Assert.AreEqual (4, emittedFields.Length, "#D1");
4907                         Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4908                         Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4909                         Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4910                         Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4911                         Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4912                         Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4913                         Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4914                         Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4915                 }
4916
4917                 [Test]
4918                 [Category ("NotWorking")] // mcs depends on this
4919                 public void TestGetFieldsFlagsIncomplete_MS ()
4920                 {
4921                         TypeBuilder tb = module.DefineType (genTypeName ());
4922                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4923                         try {
4924                                 tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4925                                 Assert.Fail ("#1");
4926                         } catch (NotSupportedException ex) {
4927                                 // The invoked member is not supported in a
4928                                 // dynamic module
4929                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4930                                 Assert.IsNull (ex.InnerException, "#3");
4931                                 Assert.IsNotNull (ex.Message, "#4");
4932                         }
4933                 }
4934
4935                 [Test]
4936                 [Category ("NotDotNet")] // mcs depends on this
4937                 public void TestGetFieldsFlagsIncomplete_Mono ()
4938                 {
4939                         FieldInfo [] fields;
4940
4941                         TypeBuilder tb = module.DefineType (genTypeName ());
4942                         tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4943                         tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4944                         tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4945                         tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4946
4947                         fields = tb.GetFields (BindingFlags.Public |
4948                                 BindingFlags.NonPublic | BindingFlags.Instance);
4949                         Assert.AreEqual (2, fields.Length, "#A1");
4950                         Assert.AreEqual ("name", fields [0].Name, "#A2");
4951                         Assert.AreEqual ("Sex", fields [1].Name, "#A3");
4952
4953                         fields = tb.GetFields (BindingFlags.Public |
4954                                 BindingFlags.Instance | BindingFlags.Static);
4955                         Assert.AreEqual (2, fields.Length, "#B1");
4956                         Assert.AreEqual ("Sex", fields [0].Name, "#B2");
4957                         Assert.AreEqual ("MALE", fields [1].Name, "#B3");
4958
4959                         fields = tb.GetFields (BindingFlags.Public |
4960                                 BindingFlags.NonPublic | BindingFlags.Instance |
4961                                 BindingFlags.Static);
4962                         Assert.AreEqual (4, fields.Length, "#C1");
4963                         Assert.AreEqual ("name", fields [0].Name, "#C2");
4964                         Assert.AreEqual ("Sex", fields [1].Name, "#C3");
4965                         Assert.AreEqual ("MALE", fields [2].Name, "#C4");
4966                         Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
4967                 }
4968
4969                 [Test]
4970                 public void TestGetFieldsFlagsComplete ()
4971                 {
4972                         TypeBuilder tb = module.DefineType (genTypeName ());
4973                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4974
4975                         Type emittedType = tb.CreateType ();
4976
4977                         Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4978                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
4979                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4980                         Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4981                         Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
4982                                 emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4983                 }
4984
4985                 [Test]
4986                 public void TestGetFieldsFlagsComplete_Inheritance ()
4987                 {
4988                         FieldInfo [] fields;
4989                         BindingFlags flags;
4990
4991                         TypeBuilder blueType = module.DefineType (genTypeName (),
4992                                 TypeAttributes.Public);
4993                         CreateMembers (blueType, "Blue", false);
4994
4995                         TypeBuilder redType = module.DefineType (genTypeName (),
4996                                 TypeAttributes.Public, blueType);
4997                         CreateMembers (redType, "Red", false);
4998
4999                         TypeBuilder greenType = module.DefineType (genTypeName (),
5000                                 TypeAttributes.Public, redType);
5001                         CreateMembers (greenType, "Green", false);
5002
5003                         blueType.CreateType ();
5004                         redType.CreateType ();
5005                         greenType.CreateType ();
5006
5007                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5008                         fields = greenType.GetFields (flags);
5009
5010                         Assert.AreEqual (13, fields.Length, "#A1");
5011                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
5012                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
5013                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
5014                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
5015                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
5016                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
5017                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5018                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5019                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5020                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5021                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5022                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5023                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5024
5025                         flags = BindingFlags.Instance | BindingFlags.Public;
5026                         fields = greenType.GetFields (flags);
5027
5028                         Assert.AreEqual (3, fields.Length, "#B1");
5029                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5030                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5031                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5032
5033                         flags = BindingFlags.Static | BindingFlags.Public;
5034                         fields = greenType.GetFields (flags);
5035
5036                         Assert.AreEqual (1, fields.Length, "#C1");
5037                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5038
5039                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5040                         fields = greenType.GetFields (flags);
5041
5042                         Assert.AreEqual (5, fields.Length, "#D1");
5043                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5044                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5045                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5046                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5047                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5048
5049                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5050                                 BindingFlags.FlattenHierarchy;
5051                         fields = greenType.GetFields (flags);
5052
5053                         Assert.AreEqual (13, fields.Length, "#E1");
5054                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5055                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5056                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5057                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5058                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5059                         Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5060                         Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5061                         Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5062                         Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5063                         Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5064                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5065                         Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5066                         Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5067
5068                         flags = BindingFlags.Instance | BindingFlags.Public |
5069                                 BindingFlags.FlattenHierarchy;
5070                         fields = greenType.GetFields (flags);
5071
5072                         Assert.AreEqual (3, fields.Length, "#F1");
5073                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5074                         Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5075                         Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5076
5077                         flags = BindingFlags.Static | BindingFlags.Public |
5078                                 BindingFlags.FlattenHierarchy;
5079                         fields = greenType.GetFields (flags);
5080
5081                         Assert.AreEqual (3, fields.Length, "#G1");
5082                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5083                         Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5084                         Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5085
5086                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5087                                 BindingFlags.FlattenHierarchy;
5088                         fields = greenType.GetFields (flags);
5089
5090                         Assert.AreEqual (13, fields.Length, "#H1");
5091                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5092                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5093                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5094                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5095                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5096                         Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5097                         Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5098                         Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5099                         Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5100                         Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5101                         Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5102                         Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5103                         Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5104
5105                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5106                                 BindingFlags.DeclaredOnly;
5107                         fields = greenType.GetFields (flags);
5108
5109                         Assert.AreEqual (5, fields.Length, "#I1");
5110                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5111                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5112                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5113                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5114                         Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5115
5116                         flags = BindingFlags.Instance | BindingFlags.Public |
5117                                 BindingFlags.DeclaredOnly;
5118                         fields = greenType.GetFields (flags);
5119
5120                         Assert.AreEqual (1, fields.Length, "#J1");
5121                         Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5122
5123                         flags = BindingFlags.Static | BindingFlags.Public |
5124                                 BindingFlags.DeclaredOnly;
5125                         fields = greenType.GetFields (flags);
5126
5127                         Assert.AreEqual (1, fields.Length, "#K1");
5128                         Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5129
5130                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5131                                 BindingFlags.DeclaredOnly;
5132                         fields = greenType.GetFields (flags);
5133
5134                         Assert.AreEqual (5, fields.Length, "#L1");
5135                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5136                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5137                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5138                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5139                         Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5140
5141                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5142                                 BindingFlags.Public;
5143                         fields = greenType.GetFields (flags);
5144
5145                         Assert.AreEqual (16, fields.Length, "#M1");
5146                         Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5147                         Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5148                         Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5149                         Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5150                         Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5151                         Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5152                         Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5153                         Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5154                         Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5155                         Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5156                         Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5157                         Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5158                         Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5159                         Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5160                         Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5161                         Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5162
5163                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5164                                 BindingFlags.Public;
5165                         fields = greenType.GetFields (flags);
5166
5167                         Assert.AreEqual (6, fields.Length, "#N1");
5168                         Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5169                         Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5170                         Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5171                         Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5172                         Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5173                         Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5174                 }
5175
5176                 [Test]
5177                 [Category ("NotWorking")] // mcs depends on this
5178                 public void TestGetFieldIncomplete_MS ()
5179                 {
5180                         TypeBuilder tb = module.DefineType (genTypeName ());
5181                         tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5182                         try {
5183                                 tb.GetField ("test");
5184                                 Assert.Fail ("#1");
5185                         } catch (NotSupportedException ex) {
5186                                 // The invoked member is not supported in a
5187                                 // dynamic module
5188                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5189                                 Assert.IsNull (ex.InnerException, "#3");
5190                                 Assert.IsNotNull (ex.Message, "#4");
5191                         }
5192                 }
5193
5194                 [Test]
5195                 [Category ("NotDotNet")] // mcs depends on this
5196                 public void TestGetFieldIncomplete_Mono ()
5197                 {
5198                         TypeBuilder tb = module.DefineType (genTypeName ());
5199                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5200                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5201
5202                         FieldInfo field = tb.GetField ("TestField");
5203                         Assert.IsNotNull (field, "#A1");
5204                         Assert.AreEqual ("TestField", field.Name, "#A2");
5205                         Assert.IsTrue (field is FieldBuilder, "#A3");
5206
5207                         Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5208                         Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5209                 }
5210
5211                 [Test]
5212                 public void TestGetFieldComplete ()
5213                 {
5214                         TypeBuilder tb = module.DefineType (genTypeName ());
5215                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5216
5217                         Type emittedType = tb.CreateType ();
5218
5219                         FieldInfo dynamicField = tb.GetField ("TestField");
5220                         FieldInfo emittedField = emittedType.GetField ("TestField");
5221                         Assert.IsNotNull (dynamicField, "#A1");
5222                         Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5223                         Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5224                         Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5225                         Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5226
5227                         // bug #81638
5228                         object value = Activator.CreateInstance (emittedType);
5229                         emittedField.SetValue (value, 5);
5230                         Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5231                         Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5232                         dynamicField.SetValue (value, 4);
5233                         Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5234                         Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5235                 }
5236
5237                 [Test] // bug #81640
5238                 public void TestGetFieldComplete_Type ()
5239                 {
5240                         TypeBuilder tb = module.DefineType (genTypeName ());
5241                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5242                         Type emittedType = tb.CreateType ();
5243                         FieldInfo dynamicField = tb.GetField ("TestField");
5244                         Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5245
5246                         object value = Activator.CreateInstance (emittedType);
5247                         Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5248                 }
5249
5250                 [Test]
5251                 [Category ("NotWorking")] // mcs depends on this
5252                 public void TestGetFieldFlagsIncomplete_MS ()
5253                 {
5254                         TypeBuilder tb = module.DefineType (genTypeName ());
5255                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5256                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5257                         try {
5258                                 tb.GetField ("test", BindingFlags.Public);
5259                                 Assert.Fail ("#1");
5260                         } catch (NotSupportedException ex) {
5261                                 // The invoked member is not supported in a
5262                                 // dynamic module
5263                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5264                                 Assert.IsNull (ex.InnerException, "#3");
5265                                 Assert.IsNotNull (ex.Message, "#4");
5266                         }
5267                 }
5268
5269                 [Test]
5270                 [Category ("NotDotNet")] // mcs depends on this
5271                 public void TestGetFieldFlagsIncomplete_Mono ()
5272                 {
5273                         TypeBuilder tb = module.DefineType (genTypeName ());
5274                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5275                         tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5276
5277                         FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5278                                 | BindingFlags.Instance);
5279                         Assert.IsNotNull (field, "#A1");
5280                         Assert.AreEqual ("TestField", field.Name, "#A2");
5281                         Assert.IsTrue (field is FieldBuilder, "#A3");
5282
5283                         field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5284                                 BindingFlags.Instance);
5285                         Assert.IsNotNull (field, "#B1");
5286                         Assert.AreEqual ("OtherField", field.Name, "#B2");
5287                         Assert.IsTrue (field is FieldBuilder, "#B3");
5288
5289                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5290                                 BindingFlags.Instance), "#C1");
5291                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5292                                 BindingFlags.Static), "#C2");
5293                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5294                                 BindingFlags.Instance), "#C3");
5295                         Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5296                                 BindingFlags.Static), "#C4");
5297                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5298                                 BindingFlags.Instance), "#C5");
5299                         Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5300                                 BindingFlags.Instance), "#C6");
5301                 }
5302
5303                 [Test]
5304                 public void TestGetFieldFlagsComplete ()
5305                 {
5306                         TypeBuilder tb = module.DefineType (genTypeName ());
5307                         tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5308
5309                         Type emittedType = tb.CreateType ();
5310
5311                         Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5312                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5313                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5314                         Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5315                         Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5316                                 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5317                 }
5318
5319                 [Test]
5320                 public void TestGetFieldFlagsComplete_Inheritance ()
5321                 {
5322                         BindingFlags flags;
5323
5324                         TypeBuilder blueType = module.DefineType (genTypeName (),
5325                                 TypeAttributes.Public);
5326                         CreateMembers (blueType, "Blue", false);
5327
5328                         TypeBuilder redType = module.DefineType (genTypeName (),
5329                                 TypeAttributes.Public, blueType);
5330                         CreateMembers (redType, "Red", false);
5331
5332                         TypeBuilder greenType = module.DefineType (genTypeName (),
5333                                 TypeAttributes.Public, redType);
5334                         CreateMembers (greenType, "Green", false);
5335
5336                         blueType.CreateType ();
5337                         redType.CreateType ();
5338                         greenType.CreateType ();
5339
5340                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
5341
5342                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5343                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5344                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5345                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5346                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5347                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5348                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5349                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5350                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5351                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5352                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5353                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5354                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5355                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5356                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5357                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5358                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5359                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5360                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5361                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5362                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5363                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5364                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5365                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5366                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5367                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5368                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5369                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5370                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5371                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5372                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5373                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5374                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5375                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5376                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5377                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5378
5379                         flags = BindingFlags.Instance | BindingFlags.Public;
5380
5381                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5382                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5383                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5384                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5385                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5386                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5387                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5388                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5389                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5390                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5391                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5392                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5393                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5394                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5395                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5396                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5397                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5398                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5399                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5400                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5401                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5402                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5403                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5404                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5405                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5406                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5407                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5408                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5409                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5410                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5411                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5412                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5413                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5414                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5415                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5416                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5417
5418                         flags = BindingFlags.Static | BindingFlags.Public;
5419
5420                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5421                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5422                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5423                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5424                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5425                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5426                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5427                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5428                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5429                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5430                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5431                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5432                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5433                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5434                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5435                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5436                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5437                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5438                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5439                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5440                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5441                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5442                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5443                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5444                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5445                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5446                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5447                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5448                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5449                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5450                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5451                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5452                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5453                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5454                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5455                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5456
5457                         flags = BindingFlags.Static | BindingFlags.NonPublic;
5458
5459                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5460                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5461                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5462                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5463                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5464                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5465                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5466                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5467                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5468                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5469                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5470                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5471                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5472                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5473                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5474                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5475                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5476                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5477                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5478                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5479                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5480                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5481                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5482                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5483                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5484                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5485                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5486                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5487                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5488                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5489                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5490                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5491                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5492                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5493                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5494                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5495
5496                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5497                                 BindingFlags.FlattenHierarchy;
5498
5499                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5500                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5501                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5502                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5503                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5504                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5505                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5506                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5507                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5508                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5509                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5510                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5511                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5512                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5513                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5514                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5515                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5516                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5517                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5518                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5519                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5520                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5521                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5522                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5523                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5524                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5525                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5526                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5527                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5528                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5529                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5530                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5531                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5532                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5533                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5534                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5535
5536                         flags = BindingFlags.Instance | BindingFlags.Public |
5537                                 BindingFlags.FlattenHierarchy;
5538
5539                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5540                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5541                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5542                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5543                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5544                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5545                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5546                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5547                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5548                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5549                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5550                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5551                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5552                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5553                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5554                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5555                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5556                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5557                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5558                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5559                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5560                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5561                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5562                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5563                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5564                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5565                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5566                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5567                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5568                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5569                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5570                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5571                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5572                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5573                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5574                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5575
5576                         flags = BindingFlags.Static | BindingFlags.Public |
5577                                 BindingFlags.FlattenHierarchy;
5578
5579                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5580                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5581                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5582                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5583                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5584                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5585                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5586                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5587                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5588                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5589                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5590                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5591                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5592                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5593                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5594                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5595                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5596                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5597                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5598                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5599                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5600                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5601                         Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5602                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5603                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5604                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5605                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5606                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5607                         Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5608                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5609                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5610                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5611                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5612                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5613                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5614                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5615
5616                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5617                                 BindingFlags.FlattenHierarchy;
5618
5619                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5620                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5621                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5622                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5623                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5624                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5625                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5626                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5627                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5628                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5629                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5630                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5631                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5632                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5633                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5634                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5635                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5636                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5637                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5638                         Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5639                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5640                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5641                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5642                         Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5643                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5644                         Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5645                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5646                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5647                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5648                         Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5649                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5650                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5651                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5652                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5653                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5654                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5655
5656                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5657                                 BindingFlags.DeclaredOnly;
5658
5659                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5660                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5661                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5662                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5663                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5664                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5665                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5666                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5667                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5668                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5669                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5670                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5671                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5672                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5673                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5674                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5675                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5676                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5677                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5678                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5679                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5680                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5681                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5682                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5683                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5684                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5685                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5686                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5687                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5688                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5689                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5690                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5691                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5692                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5693                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5694                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5695
5696                         flags = BindingFlags.Instance | BindingFlags.Public |
5697                                 BindingFlags.DeclaredOnly;
5698
5699                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5700                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5701                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5702                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5703                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5704                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5705                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5706                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5707                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5708                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5709                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5710                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5711                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5712                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5713                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5714                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5715                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5716                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5717                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5718                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5719                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5720                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5721                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5722                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5723                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5724                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5725                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5726                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5727                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5728                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5729                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5730                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5731                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5732                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5733                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5734                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5735
5736                         flags = BindingFlags.Static | BindingFlags.Public |
5737                                 BindingFlags.DeclaredOnly;
5738
5739                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5740                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5741                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5742                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5743                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5744                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5745                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5746                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5747                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5748                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5749                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5750                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5751                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5752                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5753                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5754                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5755                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5756                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5757                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5758                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5759                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5760                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5761                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5762                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5763                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5764                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5765                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5766                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5767                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5768                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5769                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5770                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5771                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5772                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5773                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5774                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5775
5776                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5777                                 BindingFlags.DeclaredOnly;
5778
5779                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5780                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5781                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5782                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5783                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5784                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5785                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5786                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5787                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5788                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5789                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5790                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5791                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5792                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5793                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5794                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5795                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5796                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5797                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5798                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5799                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5800                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5801                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5802                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5803                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5804                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5805                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5806                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5807                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5808                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5809                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5810                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5811                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5812                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5813                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5814                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5815
5816                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
5817                                 BindingFlags.Public;
5818
5819                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5820                         Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5821                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5822                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5823                         Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5824                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5825                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5826                         Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5827                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5828                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5829                         Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5830                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5831                         Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5832                         Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5833                         Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5834                         Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5835                         Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5836                         Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5837                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5838                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5839                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5840                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5841                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5842                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5843                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5844                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5845                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5846                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5847                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5848                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5849                         Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5850                         Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5851                         Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5852                         Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5853                         Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5854                         Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5855
5856                         flags = BindingFlags.Static | BindingFlags.NonPublic |
5857                                 BindingFlags.Public;
5858
5859                         Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5860                         Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5861                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5862                         Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5863                         Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5864                         Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5865                         Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5866                         Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5867                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5868                         Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5869                         Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5870                         Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5871                         Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5872                         Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5873                         Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5874                         Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5875                         Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5876                         Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5877                         Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5878                         Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5879                         Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5880                         Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5881                         Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5882                         Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5883                         Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5884                         Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5885                         Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5886                         Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5887                         Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5888                         Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5889                         Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5890                         Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5891                         Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5892                         Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5893                         Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5894                         Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5895                 }
5896
5897                 [Test]
5898                 [Category ("NotDotNet")] // mcs depends on this
5899                 public void TestGetPropertiesIncomplete_Mono ()
5900                 {
5901                         TypeBuilder tb = module.DefineType (genTypeName ());
5902                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5903                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5904                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5905
5906                         PropertyInfo [] properties = tb.GetProperties ();
5907                         Assert.AreEqual (2, properties.Length, "#1");
5908                         Assert.AreEqual ("Name", properties [0].Name, "#2");
5909                         Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5910                 }
5911
5912                 [Test]
5913                 [Category ("NotWorking")] // mcs depends on this
5914                 public void TestGetPropertiesIncomplete_MS ()
5915                 {
5916                         TypeBuilder tb = module.DefineType (genTypeName ());
5917                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5918                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5919                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5920
5921                         try {
5922                                 tb.GetProperties ();
5923                                 Assert.Fail ("#1");
5924                         } catch (NotSupportedException ex) {
5925                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5926                                 Assert.IsNull (ex.InnerException, "#3");
5927                                 Assert.IsNotNull (ex.Message, "#4");
5928                         }
5929                 }
5930
5931                 [Test]
5932                 public void TestGetPropertiesComplete ()
5933                 {
5934                         TypeBuilder tb = module.DefineType (genTypeName ());
5935                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5936
5937                         Type emittedType = tb.CreateType ();
5938
5939                         Assert.AreEqual (1, tb.GetProperties ().Length);
5940                         Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
5941                 }
5942
5943                 [Test]
5944                 [Category ("NotDotNet")] // mcs depends on this
5945                 public void TestGetPropertiesFlagsIncomplete_Mono ()
5946                 {
5947                         PropertyInfo [] properties;
5948
5949                         TypeBuilder tb = module.DefineType (genTypeName ());
5950                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5951                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5952                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5953
5954                         properties = tb.GetProperties (BindingFlags.Public | 
5955                                 BindingFlags.NonPublic | BindingFlags.Instance);
5956                         Assert.AreEqual (3, properties.Length, "#A1");
5957                         Assert.AreEqual ("Name", properties [0].Name, "#A2");
5958                         Assert.AreEqual ("Income", properties [1].Name, "#A3");
5959                         Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
5960
5961                         properties = tb.GetProperties (BindingFlags.Public |
5962                                 BindingFlags.Instance);
5963                         Assert.AreEqual (2, properties.Length, "#B1");
5964                         Assert.AreEqual ("Name", properties [0].Name, "#B2");
5965                         Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
5966
5967                         properties = tb.GetProperties (BindingFlags.NonPublic |
5968                                 BindingFlags.Instance);
5969                         Assert.AreEqual (1, properties.Length, "#C1");
5970                         Assert.AreEqual ("Income", properties [0].Name, "#C2");
5971                 }
5972
5973                 [Test]
5974                 [Category ("NotWorking")] // mcs depends on this
5975                 public void TestGetPropertiesFlagsIncomplete_MS ()
5976                 {
5977                         TypeBuilder tb = module.DefineType (genTypeName ());
5978                         DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5979                         DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5980                         DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5981
5982                         try {
5983                                 tb.GetProperties (BindingFlags.Public);
5984                                 Assert.Fail ("#1");
5985                         } catch (NotSupportedException ex) {
5986                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5987                                 Assert.IsNull (ex.InnerException, "#3");
5988                                 Assert.IsNotNull (ex.Message, "#4");
5989                         }
5990                 }
5991
5992                 [Test]
5993                 public void TestGetPropertiesFlagsComplete ()
5994                 {
5995                         TypeBuilder tb = module.DefineType (genTypeName ());
5996                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5997
5998                         Type emittedType = tb.CreateType ();
5999
6000                         Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6001                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
6002                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6003                         Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6004                         Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
6005                                 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6006                 }
6007
6008                 [Test]
6009                 public void TestGetPropertiesFlagsComplete_Inheritance ()
6010                 {
6011                         PropertyInfo [] props;
6012                         BindingFlags flags;
6013
6014                         TypeBuilder blueType = module.DefineType (genTypeName (),
6015                                 TypeAttributes.Public);
6016                         CreateMembers (blueType, "Blue", false);
6017
6018                         TypeBuilder redType = module.DefineType (genTypeName (),
6019                                 TypeAttributes.Public, blueType);
6020                         CreateMembers (redType, "Red", false);
6021
6022                         TypeBuilder greenType = module.DefineType (genTypeName (),
6023                                 TypeAttributes.Public, redType);
6024                         CreateMembers (greenType, "Green", false);
6025
6026                         blueType.CreateType ();
6027                         redType.CreateType ();
6028                         greenType.CreateType ();
6029
6030                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6031                         props = greenType.GetProperties (flags);
6032
6033                         Assert.AreEqual (13, props.Length, "#A1");
6034                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6035                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6036                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6037                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6038                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6039                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6040                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6041                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6042                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6043                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6044                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6045                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6046                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6047
6048                         flags = BindingFlags.Instance | BindingFlags.Public;
6049                         props = greenType.GetProperties (flags);
6050
6051                         Assert.AreEqual (3, props.Length, "#B1");
6052                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6053                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6054                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6055
6056                         flags = BindingFlags.Static | BindingFlags.Public;
6057                         props = greenType.GetProperties (flags);
6058
6059                         Assert.AreEqual (1, props.Length, "#C1");
6060                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6061
6062                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6063                         props = greenType.GetProperties (flags);
6064
6065                         Assert.AreEqual (5, props.Length, "#D1");
6066                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6067                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6068                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6069                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6070                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6071
6072                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6073                                 BindingFlags.FlattenHierarchy;
6074                         props = greenType.GetProperties (flags);
6075
6076                         Assert.AreEqual (13, props.Length, "#E1");
6077                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6078                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6079                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6080                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6081                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6082                         Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6083                         Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6084                         Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6085                         Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6086                         Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6087                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6088                         Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6089                         Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6090
6091                         flags = BindingFlags.Instance | BindingFlags.Public |
6092                                 BindingFlags.FlattenHierarchy;
6093                         props = greenType.GetProperties (flags);
6094
6095                         Assert.AreEqual (3, props.Length, "#F1");
6096                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6097                         Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6098                         Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6099
6100                         flags = BindingFlags.Static | BindingFlags.Public |
6101                                 BindingFlags.FlattenHierarchy;
6102                         props = greenType.GetProperties (flags);
6103
6104                         Assert.AreEqual (3, props.Length, "#G1");
6105                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6106                         Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6107                         Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6108
6109                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6110                                 BindingFlags.FlattenHierarchy;
6111                         props = greenType.GetProperties (flags);
6112
6113                         Assert.AreEqual (13, props.Length, "#H1");
6114                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6115                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6116                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6117                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6118                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6119                         Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6120                         Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6121                         Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6122                         Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6123                         Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6124                         Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6125                         Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6126                         Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6127
6128                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6129                                 BindingFlags.DeclaredOnly;
6130                         props = greenType.GetProperties (flags);
6131
6132                         Assert.AreEqual (5, props.Length, "#I1");
6133                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6134                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6135                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6136                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6137                         Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6138
6139                         flags = BindingFlags.Instance | BindingFlags.Public |
6140                                 BindingFlags.DeclaredOnly;
6141                         props = greenType.GetProperties (flags);
6142
6143                         Assert.AreEqual (1, props.Length, "#J1");
6144                         Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6145
6146                         flags = BindingFlags.Static | BindingFlags.Public |
6147                                 BindingFlags.DeclaredOnly;
6148                         props = greenType.GetProperties (flags);
6149
6150                         Assert.AreEqual (1, props.Length, "#K1");
6151                         Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6152
6153                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6154                                 BindingFlags.DeclaredOnly;
6155                         props = greenType.GetProperties (flags);
6156
6157                         Assert.AreEqual (5, props.Length, "#L1");
6158                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6159                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6160                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6161                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6162                         Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6163
6164                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6165                                 BindingFlags.Public;
6166                         props = greenType.GetProperties (flags);
6167
6168                         Assert.AreEqual (16, props.Length, "#M1");
6169                         Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6170                         Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6171                         Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6172                         Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6173                         Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6174                         Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6175                         Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6176                         Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6177                         Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6178                         Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6179                         Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6180                         Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6181                         Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6182                         Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6183                         Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6184                         Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6185
6186                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6187                                 BindingFlags.Public;
6188                         props = greenType.GetProperties (flags);
6189
6190                         Assert.AreEqual (6, props.Length, "#N1");
6191                         Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6192                         Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6193                         Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6194                         Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6195                         Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6196                         Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6197                 }
6198
6199                 [Test]
6200                 public void TestGetPropertyIncomplete ()
6201                 {
6202                         TypeBuilder tb = module.DefineType (genTypeName ());
6203                         try {
6204                                 tb.GetProperty ("test");
6205                                 Assert.Fail ("#1");
6206                         } catch (NotSupportedException ex) {
6207                                 // The invoked member is not supported in a
6208                                 // dynamic module
6209                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6210                                 Assert.IsNull (ex.InnerException, "#3");
6211                                 Assert.IsNotNull (ex.Message, "#4");
6212                         }
6213                 }
6214
6215                 [Test]
6216                 public void TestGetPropertyComplete ()
6217                 {
6218                         TypeBuilder tb = module.DefineType (genTypeName ());
6219                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6220
6221                         Type emittedType = tb.CreateType ();
6222
6223                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6224                         Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6225
6226                         try {
6227                                 tb.GetProperty ("CustomerName");
6228                                 Assert.Fail ("#1");
6229                         } catch (NotSupportedException ex) {
6230                                 // The invoked member is not supported in a
6231                                 // dynamic module
6232                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6233                                 Assert.IsNull (ex.InnerException, "#3");
6234                                 Assert.IsNotNull (ex.Message, "#4");
6235                         }
6236                 }
6237
6238                 [Test]
6239                 public void TestGetPropertyFlagsIncomplete ()
6240                 {
6241                         TypeBuilder tb = module.DefineType (genTypeName ());
6242                         try {
6243                                 tb.GetProperty ("test", BindingFlags.Public);
6244                                 Assert.Fail ("#1");
6245                         } catch (NotSupportedException ex) {
6246                                 // The invoked member is not supported in a
6247                                 // dynamic module
6248                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6249                                 Assert.IsNull (ex.InnerException, "#3");
6250                                 Assert.IsNotNull (ex.Message, "#4");
6251                         }
6252                 }
6253
6254                 [Test]
6255                 public void TestGetPropertyFlagsComplete ()
6256                 {
6257                         TypeBuilder tb = module.DefineType (genTypeName ());
6258                         DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6259
6260                         Type emittedType = tb.CreateType ();
6261
6262                         Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6263                                 BindingFlags.Public));
6264                         Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6265                                 BindingFlags.NonPublic));
6266
6267                         try {
6268                                 tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6269                                 Assert.Fail ("#1");
6270                         } catch (NotSupportedException ex) {
6271                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6272                                 Assert.IsNull (ex.InnerException, "#3");
6273                                 Assert.IsNotNull (ex.Message, "#4");
6274                         }
6275                 }
6276
6277                 [Test]
6278                 public void TestGetMethodFlagsComplete ()
6279                 {
6280                         BindingFlags flags;
6281
6282                         TypeBuilder blueType = module.DefineType (genTypeName (),
6283                                 TypeAttributes.Public);
6284                         CreateMembers (blueType, "Blue", false);
6285
6286                         TypeBuilder redType = module.DefineType (genTypeName (),
6287                                 TypeAttributes.Public, blueType);
6288                         CreateMembers (redType, "Red", false);
6289
6290                         TypeBuilder greenType = module.DefineType (genTypeName (),
6291                                 TypeAttributes.Public, redType);
6292                         CreateMembers (greenType, "Green", false);
6293
6294                         blueType.CreateType ();
6295                         redType.CreateType ();
6296                         greenType.CreateType ();
6297
6298                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
6299
6300                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6301                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6302                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6303                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6304                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6305                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6306                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6307                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6308                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6309                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6310                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6311                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6312                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6313                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6314                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6315                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6316                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6317                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6318                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6319                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6320                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6321                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6322                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6323                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6324                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6325                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6326                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6327                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6328                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6329                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6330                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6331                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6332                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6333                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6334                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6335                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6336
6337                         flags = BindingFlags.Instance | BindingFlags.Public;
6338
6339                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6340                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6341                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6342                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6343                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6344                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6345                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6346                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6347                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6348                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6349                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6350                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6351                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6352                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6353                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6354                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6355                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6356                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6357                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6358                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6359                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6360                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6361                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6362                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6363                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6364                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6365                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6366                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6367                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6368                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6369                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6370                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6371                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6372                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6373                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6374                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6375
6376                         flags = BindingFlags.Static | BindingFlags.Public;
6377
6378                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6379                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6380                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6381                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6382                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6383                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6384                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6385                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6386                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6387                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6388                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6389                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6390                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6391                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6392                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6393                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6394                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6395                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6396                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6397                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6398                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6399                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6400                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6401                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6402                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6403                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6404                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6405                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6406                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6407                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6408                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6409                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6410                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6411                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6412                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6413                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6414
6415                         flags = BindingFlags.Static | BindingFlags.NonPublic;
6416
6417                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6418                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6419                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6420                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6421                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6422                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6423                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6424                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6425                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6426                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6427                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6428                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6429                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6430                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6431                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6432                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6433                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6434                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6435                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6436                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6437                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6438                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6439                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6440                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6441                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6442                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6443                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6444                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6445                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6446                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6447                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6448                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6449                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6450                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6451                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6452                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6453
6454                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6455                                 BindingFlags.FlattenHierarchy;
6456
6457                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6458                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6459                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6460                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6461                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6462                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6463                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6464                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6465                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6466                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6467                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6468                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6469                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6470                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6471                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6472                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6473                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6474                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6475                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6476                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6477                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6478                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6479                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6480                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6481                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6482                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6483                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6484                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6485                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6486                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6487                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6488                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6489                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6490                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6491                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6492                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6493
6494                         flags = BindingFlags.Instance | BindingFlags.Public |
6495                                 BindingFlags.FlattenHierarchy;
6496
6497                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6498                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6499                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6500                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6501                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6502                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6503                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6504                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6505                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6506                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6507                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6508                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6509                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6510                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6511                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6512                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6513                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6514                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6515                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6516                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6517                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6518                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6519                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6520                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6521                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6522                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6523                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6524                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6525                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6526                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6527                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6528                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6529                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6530                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6531                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6532                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6533
6534                         flags = BindingFlags.Static | BindingFlags.Public |
6535                                 BindingFlags.FlattenHierarchy;
6536
6537                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6538                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6539                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6540                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6541                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6542                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6543                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6544                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6545                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6546                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6547                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6548                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6549                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6550                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6551                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6552                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6553                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6554                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6555                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6556                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6557                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6558                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6559                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6560                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6561                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6562                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6563                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6564                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6565                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6566                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6567                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6568                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6569                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6570                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6571                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6572                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6573
6574                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6575                                 BindingFlags.FlattenHierarchy;
6576
6577                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6578                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6579                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6580                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6581                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6582                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6583                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6584                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6585                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6586                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6587                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6588                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6589                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6590                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6591                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6592                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6593                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6594                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6595                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6596                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6597                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6598                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6599                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6600                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6601                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6602                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6603                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6604                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6605                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6606                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6607                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6608                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6609                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6610                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6611                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6612                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6613
6614                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6615                                 BindingFlags.DeclaredOnly;
6616
6617                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6618                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6619                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6620                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6621                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6622                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6623                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6624                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6625                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6626                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6627                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6628                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6629                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6630                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6631                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6632                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6633                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6634                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6635                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6636                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6637                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6638                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6639                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6640                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6641                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6642                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6643                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6644                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6645                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6646                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6647                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6648                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6649                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6650                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6651                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6652                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6653
6654                         flags = BindingFlags.Instance | BindingFlags.Public |
6655                                 BindingFlags.DeclaredOnly;
6656
6657                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6658                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6659                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6660                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6661                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6662                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6663                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6664                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6665                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6666                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6667                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6668                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6669                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6670                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6671                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6672                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6673                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6674                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6675                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6676                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6677                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6678                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6679                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6680                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6681                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6682                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6683                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6684                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6685                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6686                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6687                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6688                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6689                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6690                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6691                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6692                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6693
6694                         flags = BindingFlags.Static | BindingFlags.Public |
6695                                 BindingFlags.DeclaredOnly;
6696
6697                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6698                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6699                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6700                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6701                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6702                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6703                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6704                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6705                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6706                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6707                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6708                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6709                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6710                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6711                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6712                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6713                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6714                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6715                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6716                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6717                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6718                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6719                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6720                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6721                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6722                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6723                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6724                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6725                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6726                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6727                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6728                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6729                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6730                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6731                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6732                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6733
6734                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6735                                 BindingFlags.DeclaredOnly;
6736
6737                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6738                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6739                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6740                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6741                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6742                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6743                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6744                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6745                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6746                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6747                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6748                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6749                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6750                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6751                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6752                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6753                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6754                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6755                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6756                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6757                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6758                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6759                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6760                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6761                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6762                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6763                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6764                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6765                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6766                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6767                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6768                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6769                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6770                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6771                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6772                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6773
6774                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
6775                                 BindingFlags.Public;
6776
6777                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6778                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6779                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6780                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6781                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6782                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6783                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6784                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6785                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6786                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6787                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6788                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6789                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6790                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6791                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6792                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6793                         Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6794                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6795                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6796                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6797                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6798                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6799                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6800                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6801                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6802                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6803                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6804                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6805                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6806                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6807                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6808                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6809                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6810                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6811                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6812                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6813
6814                         flags = BindingFlags.Static | BindingFlags.NonPublic |
6815                                 BindingFlags.Public;
6816
6817                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6818                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6819                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6820                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6821                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6822                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6823                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6824                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6825                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6826                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6827                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6828                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6829                         Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6830                         Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6831                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6832                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6833                         Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6834                         Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6835                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6836                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6837                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6838                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6839                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6840                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6841                         Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6842                         Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6843                         Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6844                         Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6845                         Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6846                         Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6847                         Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6848                         Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6849                         Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6850                         Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6851                         Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6852                         Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6853                 }
6854
6855                 [Test]
6856                 [Category ("NotDotNet")] // mcs depends on this
6857                 public void TestGetMethodsIncomplete_Mono ()
6858                 {
6859                         MethodBuilder mb;
6860                         ILGenerator ilgen;
6861
6862                         TypeBuilder tb = module.DefineType (genTypeName (),
6863                                 TypeAttributes.Abstract);
6864                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6865                                 typeof (void), Type.EmptyTypes);
6866                         ilgen = mb.GetILGenerator ();
6867                         ilgen.Emit (OpCodes.Ret);
6868
6869                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6870                                 typeof (void), Type.EmptyTypes);
6871                         ilgen = mb.GetILGenerator ();
6872                         ilgen.Emit (OpCodes.Ret);
6873
6874                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6875                                 MethodAttributes.Static,
6876                                 typeof (void), Type.EmptyTypes);
6877                         ilgen = mb.GetILGenerator ();
6878                         ilgen.Emit (OpCodes.Ret);
6879
6880                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6881                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6882                                 typeof (void), Type.EmptyTypes);
6883
6884                         MethodInfo [] methods = tb.GetMethods ();
6885                         Assert.AreEqual (7, methods.Length, "#A");
6886
6887                         Assert.AreEqual ("Equals", methods [0].Name, "#B1");
6888                         Assert.IsFalse (methods [0].IsStatic, "#B2");
6889                         Assert.IsFalse (methods [0].IsAbstract, "#B3");
6890
6891                         Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
6892                         Assert.IsFalse (methods [1].IsStatic, "#C2");
6893                         Assert.IsFalse (methods [1].IsAbstract, "#C3");
6894
6895                         Assert.AreEqual ("GetType", methods [2].Name, "#D1");
6896                         Assert.IsFalse (methods [2].IsStatic, "#D2");
6897                         Assert.IsFalse (methods [2].IsAbstract, "#D3");
6898
6899                         Assert.AreEqual ("ToString", methods [3].Name, "#E1");
6900                         Assert.IsFalse (methods [3].IsStatic, "#E2");
6901                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
6902
6903                         Assert.AreEqual ("Hello", methods [4].Name, "#F1");
6904                         Assert.IsFalse (methods [4].IsStatic, "#F2");
6905                         Assert.IsFalse (methods [4].IsAbstract, "#F3");
6906
6907                         Assert.AreEqual ("Execute", methods [5].Name, "#G1");
6908                         Assert.IsTrue (methods [5].IsStatic, "#G2");
6909                         Assert.IsFalse (methods [5].IsAbstract, "#G3");
6910
6911                         Assert.AreEqual ("Init", methods [6].Name, "#H1");
6912                         Assert.IsFalse (methods [6].IsStatic, "#H2");
6913                         Assert.IsTrue (methods [6].IsAbstract, "#H3");
6914                 }
6915
6916                 [Test]
6917                 [Category ("NotWorking")] // mcs depends on this
6918                 public void TestGetMethodsIncomplete_MS ()
6919                 {
6920                         MethodBuilder mb;
6921                         ILGenerator ilgen;
6922
6923                         TypeBuilder tb = module.DefineType (genTypeName (),
6924                                 TypeAttributes.Abstract);
6925                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6926                                 typeof (void), Type.EmptyTypes);
6927                         ilgen = mb.GetILGenerator ();
6928                         ilgen.Emit (OpCodes.Ret);
6929
6930                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6931                                 typeof (void), Type.EmptyTypes);
6932                         ilgen = mb.GetILGenerator ();
6933                         ilgen.Emit (OpCodes.Ret);
6934
6935                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6936                                 MethodAttributes.Static,
6937                                 typeof (void), Type.EmptyTypes);
6938                         ilgen = mb.GetILGenerator ();
6939                         ilgen.Emit (OpCodes.Ret);
6940
6941                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6942                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6943                                 typeof (void), Type.EmptyTypes);
6944
6945                         try {
6946                                 tb.GetMethods ();
6947                                 Assert.Fail ("#1");
6948                         } catch (NotSupportedException ex) {
6949                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6950                                 Assert.IsNull (ex.InnerException, "#3");
6951                                 Assert.IsNotNull (ex.Message, "#4");
6952                         }
6953                 }
6954
6955                 [Test]
6956                 public void TestGetMethodsComplete ()
6957                 {
6958                         MethodBuilder mb;
6959                         ILGenerator ilgen;
6960                         MethodInfo mi;
6961
6962                         TypeBuilder tb = module.DefineType (genTypeName (),
6963                                 TypeAttributes.Abstract);
6964                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6965                                 typeof (string), Type.EmptyTypes);
6966                         ilgen = mb.GetILGenerator ();
6967                         ilgen.Emit (OpCodes.Ldstr, "Hi! ");
6968                         ilgen.Emit (OpCodes.Ldarg_1);
6969                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
6970                                 new Type [] { typeof (string), typeof (string) });
6971                         ilgen.Emit (OpCodes.Call, infoMethod);
6972                         ilgen.Emit (OpCodes.Ret);
6973
6974                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6975                                 typeof (void), Type.EmptyTypes);
6976                         ilgen = mb.GetILGenerator ();
6977                         ilgen.Emit (OpCodes.Ret);
6978
6979                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6980                                 MethodAttributes.Static,
6981                                 typeof (void), Type.EmptyTypes);
6982                         ilgen = mb.GetILGenerator ();
6983                         ilgen.Emit (OpCodes.Ret);
6984
6985                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6986                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
6987                                 typeof (void), Type.EmptyTypes);
6988
6989                         Type emittedType = tb.CreateType ();
6990
6991                         MethodInfo [] methods = emittedType.GetMethods ();
6992                         Assert.AreEqual (7, methods.Length, "#A1");
6993                         Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
6994
6995                         mi = GetMethodByName (methods, "Hello");
6996                         Assert.IsNotNull (mi, "#B1");
6997                         Assert.IsFalse (mi.IsStatic, "#B2");
6998                         Assert.IsFalse (mi.IsAbstract, "#B3");
6999
7000                         mi = GetMethodByName (methods, "Execute");
7001                         Assert.IsNotNull (mi, "#C1");
7002                         Assert.IsTrue (mi.IsStatic, "#C2");
7003                         Assert.IsFalse (mi.IsAbstract, "#C3");
7004
7005                         mi = GetMethodByName (methods, "Init");
7006                         Assert.IsNotNull (mi, "#D1");
7007                         Assert.IsFalse (mi.IsStatic, "#D2");
7008                         Assert.IsTrue (mi.IsAbstract, "#D3");
7009
7010                         mi = GetMethodByName (methods, "GetType");
7011                         Assert.IsNotNull (mi, "#E1");
7012                         Assert.IsFalse (methods [3].IsStatic, "#E2");
7013                         Assert.IsFalse (methods [3].IsAbstract, "#E3");
7014
7015                         mi = GetMethodByName (methods, "ToString");
7016                         Assert.IsNotNull (mi, "#F1");
7017                         Assert.IsFalse (mi.IsStatic, "#F2");
7018                         Assert.IsFalse (mi.IsAbstract, "#F3");
7019
7020                         mi = GetMethodByName (methods, "Equals");
7021                         Assert.IsNotNull (mi, "#G1");
7022                         Assert.IsFalse (mi.IsStatic, "#G2");
7023                         Assert.IsFalse (mi.IsAbstract, "#G3");
7024
7025                         mi = GetMethodByName (methods, "GetHashCode");
7026                         Assert.IsNotNull (mi, "#H1");
7027                         Assert.IsFalse (mi.IsStatic, "#H2");
7028                         Assert.IsFalse (mi.IsAbstract, "#H3");
7029                 }
7030
7031                 [Test]
7032                 [Category ("NotDotNet")] // mcs depends on this
7033                 public void TestGetMethodsFlagsIncomplete_Inheritance ()
7034                 {
7035                         MethodInfo [] methods;
7036                         BindingFlags flags;
7037
7038                         TypeBuilder blueType = module.DefineType (genTypeName (),
7039                                 TypeAttributes.Public);
7040                         CreateMembers (blueType, "Blue", false);
7041
7042                         TypeBuilder redType = module.DefineType (genTypeName (),
7043                                 TypeAttributes.Public, blueType);
7044                         CreateMembers (redType, "Red", false);
7045
7046                         TypeBuilder greenType = module.DefineType (genTypeName (),
7047                                 TypeAttributes.Public, redType);
7048                         CreateMembers (greenType, "Green", false);
7049
7050                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7051                         methods = greenType.GetMethods (flags);
7052
7053                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7054                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7055                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7056                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7057                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7058                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7059                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7060                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7061                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7062                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7063                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7064                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7065                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7066                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7067                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7068                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7069                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7070                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7071                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7072                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7073                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7074                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7075                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7076                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7077                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7078                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7079                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7080                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7081                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7082                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7083                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7084                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7085                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7086                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7087                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7088                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7089
7090                         flags = BindingFlags.Instance | BindingFlags.Public;
7091                         methods = greenType.GetMethods (flags);
7092
7093                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7094                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7095                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7096                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7097                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7098                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7099                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7100                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7101                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7102                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7103                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7104                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7105                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7106                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7107                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7108                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7109                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7110                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7111                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7112                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7113                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7114                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7115                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7116                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7117                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7118                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7119                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7120                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7121                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7122                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7123                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7124                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7125                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7126                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7127                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7128                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7129
7130                         flags = BindingFlags.Static | BindingFlags.Public;
7131                         methods = greenType.GetMethods (flags);
7132
7133                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7134                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7135                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7136                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7137                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7138                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7139                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7140                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7141                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7142                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7143                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7144                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7145                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7146                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7147                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7148                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7149                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7150                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7151                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7152                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7153                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7154                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7155                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7156                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7157                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7158                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7159                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7160                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7161                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7162                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7163                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7164                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7165                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7166                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7167                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7168                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7169
7170                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7171                         methods = greenType.GetMethods (flags);
7172
7173                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7174                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7175                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7176                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7177                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7178                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7179                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7180                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7181                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7182                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7183                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7184                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7185                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7186                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7187                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7188                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7189                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7190                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7191                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7192                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7193                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7194                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7195                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7196                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7197                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7198                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7199                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7200                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7201                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7202                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7203                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7204                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7205                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7206                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7207                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7208                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7209
7210                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7211                                 BindingFlags.FlattenHierarchy;
7212                         methods = greenType.GetMethods (flags);
7213
7214                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7215                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7216                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7217                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7218                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7219                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7220                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7221                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7222                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7223                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7224                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7225                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7226                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7227                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7228                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7229                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7230                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7231                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7232                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7233                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7234                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7235                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7236                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7237                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7238                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7239                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7240                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7241                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7242                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7243                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7244                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7245                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7246                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7247                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7248                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7249                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7250
7251                         flags = BindingFlags.Instance | BindingFlags.Public |
7252                                 BindingFlags.FlattenHierarchy;
7253                         methods = greenType.GetMethods (flags);
7254
7255                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7256                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7257                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7258                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7259                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7260                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7261                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7262                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7263                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7264                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7265                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7266                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7267                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7268                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7269                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7270                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7271                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7272                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7273                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7274                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7275                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7276                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7277                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7278                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7279                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7280                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7281                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7282                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7283                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7284                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7285                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7286                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7287                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7288                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7289                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7290                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7291
7292                         flags = BindingFlags.Static | BindingFlags.Public |
7293                                 BindingFlags.FlattenHierarchy;
7294                         methods = greenType.GetMethods (flags);
7295
7296                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7297                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7298                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7299                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7300                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7301                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7302                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7303                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7304                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7305                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7306                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7307                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7308                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7309                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7310                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7311                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7312                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7313                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7314                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7315                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7316                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7317                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7318                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7319                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7320                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7321                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7322                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7323                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7324                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7325                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7326                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7327                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7328                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7329                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7330                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7331                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7332
7333                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7334                                 BindingFlags.FlattenHierarchy;
7335                         methods = greenType.GetMethods (flags);
7336
7337                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7338                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7339                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7340                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7341                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7342                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7343                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7344                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7345                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7346                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7347                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7348                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7349                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7350                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7351                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7352                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7353                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7354                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7355                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7356                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7357                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7358                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7359                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7360                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7361                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7362                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7363                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7364                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7365                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7366                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7367                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7368                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7369                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7370                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7371                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7372                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7373
7374                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7375                                 BindingFlags.DeclaredOnly;
7376                         methods = greenType.GetMethods (flags);
7377
7378                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7379                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7380                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7381                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7382                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7383                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7384                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7385                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7386                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7387                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7388                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7389                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7390                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7391                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7392                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7393                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7394                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7395                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7396                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7397                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7398                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7399                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7400                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7401                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7402                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7403                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7404                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7405                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7406                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7407                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7408                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7409                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7410                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7411                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7412                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7413                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7414
7415                         flags = BindingFlags.Instance | BindingFlags.Public |
7416                                 BindingFlags.DeclaredOnly;
7417                         methods = greenType.GetMethods (flags);
7418
7419                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7420                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7421                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7422                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7423                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7424                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7425                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7426                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7427                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7428                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7429                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7430                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7431                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7432                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7433                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7434                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7435                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7436                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7437                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7438                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7439                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7440                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7441                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7442                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7443                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7444                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7445                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7446                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7447                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7448                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7449                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7450                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7451                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7452                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7453                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7454                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7455
7456                         flags = BindingFlags.Static | BindingFlags.Public |
7457                                 BindingFlags.DeclaredOnly;
7458                         methods = greenType.GetMethods (flags);
7459
7460                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7461                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7462                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7463                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7464                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7465                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7466                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7467                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7468                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7469                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7470                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7471                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7472                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7473                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7474                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7475                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7476                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7477                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7478                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7479                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7480                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7481                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7482                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7483                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7484                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7485                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7486                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7487                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7488                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7489                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7490                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7491                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7492                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7493                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7494                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7495                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7496
7497                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7498                                 BindingFlags.DeclaredOnly;
7499                         methods = greenType.GetMethods (flags);
7500
7501                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7502                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7503                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7504                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7505                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7506                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7507                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7508                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7509                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7510                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7511                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7512                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7513                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7514                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7515                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7516                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7517                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7518                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7519                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7520                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7521                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7522                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7523                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7524                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7525                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7526                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7527                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7528                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7529                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7530                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7531                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7532                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7533                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7534                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7535                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7536                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7537
7538                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7539                                 BindingFlags.Public;
7540                         methods = greenType.GetMethods (flags);
7541
7542                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7543                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7544                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7545                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7546                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7547                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7548                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7549                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7550                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7551                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7552                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7553                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7554                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7555                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7556                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7557                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7558                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7559                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7560                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7561                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7562                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7563                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7564                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7565                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7566                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7567                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7568                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7569                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7570                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7571                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7572                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7573                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7574                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7575                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7576                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7577                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7578
7579                         flags = BindingFlags.Static | BindingFlags.NonPublic |
7580                                 BindingFlags.Public;
7581                         methods = greenType.GetMethods (flags);
7582
7583                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7584                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7585                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7586                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7587                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7588                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7589                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7590                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7591                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7592                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7593                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7594                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7595                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7596                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7597                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7598                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7599                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7600                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7601                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7602                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7603                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7604                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7605                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7606                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7607                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7608                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7609                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7610                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7611                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7612                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7613                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7614                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7615                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7616                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7617                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7618                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7619                 }
7620
7621                 [Test]
7622                 [Category ("NotDotNet")] // mcs depends on this
7623                 public void TestGetMethodsFlagsIncomplete_Mono ()
7624                 {
7625                         MethodBuilder mb;
7626                         ILGenerator ilgen;
7627                         MethodInfo [] methods;
7628
7629                         TypeBuilder tb = module.DefineType (genTypeName (),
7630                                 TypeAttributes.Abstract);
7631                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7632                                 typeof (void), Type.EmptyTypes);
7633                         ilgen = mb.GetILGenerator ();
7634                         ilgen.Emit (OpCodes.Ret);
7635
7636                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7637                                 typeof (void), Type.EmptyTypes);
7638                         ilgen = mb.GetILGenerator ();
7639                         ilgen.Emit (OpCodes.Ret);
7640
7641                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7642                                 MethodAttributes.Static,
7643                                 typeof (void), Type.EmptyTypes);
7644                         ilgen = mb.GetILGenerator ();
7645                         ilgen.Emit (OpCodes.Ret);
7646
7647                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7648                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7649                                 typeof (void), Type.EmptyTypes);
7650
7651                         methods = tb.GetMethods (BindingFlags.Public |
7652                                 BindingFlags.Instance);
7653                         Assert.AreEqual (6, methods.Length, "#A1");
7654                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7655                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7656                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7657                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7658                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7659
7660                         methods = tb.GetMethods (BindingFlags.Public |
7661                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7662                         Assert.AreEqual (2, methods.Length, "#B1");
7663                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7664                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7665
7666                         methods = tb.GetMethods (BindingFlags.Public |
7667                                 BindingFlags.Instance | BindingFlags.Static);
7668                         Assert.AreEqual (7, methods.Length, "#C1");
7669                         Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7670                         Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7671                         Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7672                         Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7673                         Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7674                         Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7675
7676                         methods = tb.GetMethods (BindingFlags.NonPublic |
7677                                 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7678                         Assert.AreEqual (1, methods.Length, "#D1");
7679                         Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7680                 }
7681
7682
7683                 [Test]
7684                 [Category ("NotWorking")] // mcs depends on this
7685                 public void TestGetMethodsFlagsIncomplete_MS ()
7686                 {
7687                         MethodBuilder mb;
7688                         ILGenerator ilgen;
7689
7690                         TypeBuilder tb = module.DefineType (genTypeName (),
7691                                 TypeAttributes.Abstract);
7692                         mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7693                                 typeof (void), Type.EmptyTypes);
7694                         ilgen = mb.GetILGenerator ();
7695                         ilgen.Emit (OpCodes.Ret);
7696
7697                         mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7698                                 typeof (void), Type.EmptyTypes);
7699                         ilgen = mb.GetILGenerator ();
7700                         ilgen.Emit (OpCodes.Ret);
7701
7702                         mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7703                                 MethodAttributes.Static,
7704                                 typeof (void), Type.EmptyTypes);
7705                         ilgen = mb.GetILGenerator ();
7706                         ilgen.Emit (OpCodes.Ret);
7707
7708                         mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7709                                 MethodAttributes.Abstract | MethodAttributes.Virtual,
7710                                 typeof (void), Type.EmptyTypes);
7711
7712                         try {
7713                                 tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7714                                 Assert.Fail ("#1");
7715                         } catch (NotSupportedException ex) {
7716                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7717                                 Assert.IsNull (ex.InnerException, "#3");
7718                                 Assert.IsNotNull (ex.Message, "#4");
7719                         }
7720                 }
7721
7722                 [Test]
7723                 public void TestGetMethodsFlagsComplete ()
7724                 {
7725                         TypeBuilder tb = module.DefineType (genTypeName ());
7726                         MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7727                                 MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7728                         ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7729                         helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7730                         helloMethodIL.Emit (OpCodes.Ldarg_1);
7731                         MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7732                                 new Type [] { typeof (string), typeof (string) });
7733                         helloMethodIL.Emit (OpCodes.Call, infoMethod);
7734                         helloMethodIL.Emit (OpCodes.Ret);
7735
7736                         Type emittedType = tb.CreateType ();
7737
7738                         Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7739                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7740                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7741                         Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7742                         Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7743                                 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7744                 }
7745
7746                 [Test]
7747                 public void TestGetMethodsFlagsComplete_Inheritance ()
7748                 {
7749                         MethodInfo [] methods;
7750                         BindingFlags flags;
7751
7752                         TypeBuilder blueType = module.DefineType (genTypeName (),
7753                                 TypeAttributes.Public);
7754                         CreateMembers (blueType, "Blue", false);
7755
7756                         TypeBuilder redType = module.DefineType (genTypeName (),
7757                                 TypeAttributes.Public, blueType);
7758                         CreateMembers (redType, "Red", false);
7759
7760                         TypeBuilder greenType = module.DefineType (genTypeName (),
7761                                 TypeAttributes.Public, redType);
7762                         CreateMembers (greenType, "Green", false);
7763
7764                         blueType.CreateType ();
7765                         redType.CreateType ();
7766                         greenType.CreateType ();
7767
7768                         flags = BindingFlags.Instance | BindingFlags.NonPublic;
7769                         methods = greenType.GetMethods (flags);
7770
7771                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7772                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7773                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7774                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7775                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7776                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7777                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7778                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7779                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7780                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7781                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7782                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7783                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7784                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7785                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7786                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7787                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7788                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7789                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7790                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7791                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7792                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7793                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7794                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7795                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7796                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7797                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7798                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7799                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7800                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7801                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7802                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7803                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7804                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7805                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7806                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7807
7808                         flags = BindingFlags.Instance | BindingFlags.Public;
7809                         methods = greenType.GetMethods (flags);
7810
7811                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7812                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7813                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7814                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7815                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7816                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7817                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7818                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7819                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7820                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7821                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7822                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7823                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7824                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7825                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7826                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7827                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7828                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7829                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7830                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7831                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7832                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7833                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7834                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7835                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7836                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7837                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7838                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7839                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7840                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7841                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7842                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7843                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7844                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7845                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7846                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7847
7848                         flags = BindingFlags.Static | BindingFlags.Public;
7849                         methods = greenType.GetMethods (flags);
7850
7851                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7852                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7853                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7854                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7855                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7856                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7857                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7858                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7859                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7860                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7861                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7862                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7863                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7864                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7865                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7866                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7867                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7868                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7869                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7870                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7871                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7872                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7873                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7874                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7875                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7876                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7877                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7878                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7879                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7880                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7881                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7882                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7883                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7884                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7885                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7886                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7887
7888                         flags = BindingFlags.Static | BindingFlags.NonPublic;
7889                         methods = greenType.GetMethods (flags);
7890
7891                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7892                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7893                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7894                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7895                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7896                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7897                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7898                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7899                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7900                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7901                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7902                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7903                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7904                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7905                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7906                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7907                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7908                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7909                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7910                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7911                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7912                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7913                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7914                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7915                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7916                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7917                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7918                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7919                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7920                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7921                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7922                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7923                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7924                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7925                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7926                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7927
7928                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
7929                                 BindingFlags.FlattenHierarchy;
7930                         methods = greenType.GetMethods (flags);
7931
7932                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7933                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7934                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7935                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7936                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7937                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7938                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7939                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7940                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7941                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7942                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7943                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7944                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7945                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7946                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7947                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7948                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7949                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7950                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7951                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7952                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7953                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7954                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7955                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7956                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7957                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7958                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7959                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7960                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7961                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7962                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7963                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7964                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7965                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7966                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7967                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7968
7969                         flags = BindingFlags.Instance | BindingFlags.Public |
7970                                 BindingFlags.FlattenHierarchy;
7971                         methods = greenType.GetMethods (flags);
7972
7973                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7974                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7975                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7976                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7977                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7978                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7979                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7980                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7981                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7982                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7983                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7984                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7985                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7986                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7987                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7988                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7989                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7990                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7991                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7992                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7993                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7994                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7995                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7996                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7997                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7998                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7999                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
8000                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
8001                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
8002                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
8003                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
8004                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
8005                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
8006                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
8007                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
8008                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
8009
8010                         flags = BindingFlags.Static | BindingFlags.Public |
8011                                 BindingFlags.FlattenHierarchy;
8012                         methods = greenType.GetMethods (flags);
8013
8014                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
8015                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
8016                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
8017                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8018                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8019                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8020                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8021                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8022                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8023                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8024                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8025                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8026                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8027                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8028                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8029                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8030                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8031                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8032                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8033                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8034                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8035                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8036                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8037                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8038                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8039                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8040                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8041                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8042                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8043                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8044                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8045                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8046                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8047                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8048                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8049                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8050
8051                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8052                                 BindingFlags.FlattenHierarchy;
8053                         methods = greenType.GetMethods (flags);
8054
8055                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8056                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8057                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8058                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8059                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8060                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8061                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8062                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8063                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8064                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8065                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8066                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8067                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8068                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8069                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8070                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8071                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8072                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8073                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8074                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8075                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8076                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8077                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8078                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8079                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8080                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8081                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8082                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8083                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8084                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8085                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8086                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8087                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8088                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8089                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8090                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8091
8092                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8093                                 BindingFlags.DeclaredOnly;
8094                         methods = greenType.GetMethods (flags);
8095
8096                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8097                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8098                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8099                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8100                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8101                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8102                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8103                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8104                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8105                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8106                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8107                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8108                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8109                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8110                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8111                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8112                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8113                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8114                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8115                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8116                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8117                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8118                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8119                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8120                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8121                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8122                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8123                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8124                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8125                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8126                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8127                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8128                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8129                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8130                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8131                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8132
8133                         flags = BindingFlags.Instance | BindingFlags.Public |
8134                                 BindingFlags.DeclaredOnly;
8135                         methods = greenType.GetMethods (flags);
8136
8137                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8138                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8139                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8140                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8141                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8142                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8143                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8144                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8145                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8146                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8147                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8148                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8149                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8150                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8151                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8152                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8153                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8154                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8155                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8156                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8157                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8158                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8159                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8160                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8161                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8162                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8163                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8164                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8165                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8166                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8167                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8168                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8169                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8170                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8171                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8172                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8173
8174                         flags = BindingFlags.Static | BindingFlags.Public |
8175                                 BindingFlags.DeclaredOnly;
8176                         methods = greenType.GetMethods (flags);
8177
8178                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8179                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8180                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8181                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8182                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8183                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8184                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8185                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8186                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8187                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8188                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8189                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8190                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8191                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8192                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8193                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8194                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8195                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8196                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8197                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8198                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8199                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8200                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8201                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8202                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8203                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8204                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8205                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8206                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8207                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8208                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8209                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8210                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8211                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8212                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8213                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8214
8215                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8216                                 BindingFlags.DeclaredOnly;
8217                         methods = greenType.GetMethods (flags);
8218
8219                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8220                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8221                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8222                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8223                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8224                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8225                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8226                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8227                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8228                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8229                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8230                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8231                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8232                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8233                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8234                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8235                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8236                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8237                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8238                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8239                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8240                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8241                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8242                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8243                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8244                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8245                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8246                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8247                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8248                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8249                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8250                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8251                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8252                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8253                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8254                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8255
8256                         flags = BindingFlags.Instance | BindingFlags.NonPublic |
8257                                 BindingFlags.Public;
8258                         methods = greenType.GetMethods (flags);
8259
8260                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8261                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8262                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8263                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8264                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8265                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8266                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8267                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8268                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8269                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8270                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8271                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8272                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8273                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8274                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8275                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8276                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8277                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8278                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8279                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8280                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8281                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8282                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8283                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8284                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8285                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8286                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8287                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8288                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8289                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8290                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8291                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8292                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8293                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8294                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8295                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8296
8297                         flags = BindingFlags.Static | BindingFlags.NonPublic |
8298                                 BindingFlags.Public;
8299                         methods = greenType.GetMethods (flags);
8300
8301                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8302                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8303                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8304                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8305                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8306                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8307                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8308                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8309                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8310                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8311                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8312                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8313                         Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8314                         Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8315                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8316                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8317                         Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8318                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8319                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8320                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8321                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8322                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8323                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8324                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8325                         Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8326                         Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8327                         Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8328                         Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8329                         Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8330                         Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8331                         Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8332                         Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8333                         Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8334                         Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8335                         Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8336                         Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8337                 }
8338
8339                 [Test]
8340                 public void TestGetMemberIncomplete ()
8341                 {
8342                         TypeBuilder tb = module.DefineType (genTypeName ());
8343                         try {
8344                                 tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8345                                 Assert.Fail ("#1");
8346                         } catch (NotSupportedException ex) {
8347                                 // The invoked member is not supported in a
8348                                 // dynamic module
8349                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8350                                 Assert.IsNull (ex.InnerException, "#3");
8351                                 Assert.IsNotNull (ex.Message, "#4");
8352                         }
8353                 }
8354
8355                 [Test]
8356                 public void TestGetMemberComplete ()
8357                 {
8358                         TypeBuilder tb = module.DefineType (genTypeName ());
8359                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8360
8361                         Type emittedType = tb.CreateType ();
8362
8363                         Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8364                         Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8365                 }
8366
8367                 [Test]
8368                 public void TestGetMembersIncomplete ()
8369                 {
8370                         TypeBuilder tb = module.DefineType (genTypeName ());
8371                         try {
8372                                 tb.GetMembers ();
8373                                 Assert.Fail ("#1");
8374                         } catch (NotSupportedException ex) {
8375                                 // The invoked member is not supported in a
8376                                 // dynamic module
8377                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8378                                 Assert.IsNull (ex.InnerException, "#3");
8379                                 Assert.IsNotNull (ex.Message, "#4");
8380                         }
8381                 }
8382
8383                 [Test]
8384                 public void TestGetMembersComplete ()
8385                 {
8386                         TypeBuilder tb = module.DefineType (genTypeName ());
8387                         Type emittedType = tb.CreateType ();
8388
8389                         Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8390                 }
8391
8392                 [Test]
8393                 public void TestGetMembersFlagsIncomplete ()
8394                 {
8395                         TypeBuilder tb = module.DefineType (genTypeName ());
8396                         try {
8397                                 tb.GetMembers (BindingFlags.Public);
8398                                 Assert.Fail ("#1");
8399                         } catch (NotSupportedException ex) {
8400                                 // The invoked member is not supported in a
8401                                 // dynamic module
8402                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8403                                 Assert.IsNull (ex.InnerException, "#3");
8404                                 Assert.IsNotNull (ex.Message, "#4");
8405                         }
8406                 }
8407
8408                 [Test]
8409                 public void TestGetMembersFlagsComplete ()
8410                 {
8411                         TypeBuilder tb = module.DefineType (genTypeName ());
8412                         tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8413
8414                         Type emittedType = tb.CreateType ();
8415
8416                         Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8417                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8418                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8419                         Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8420                                 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8421                 }
8422
8423                 [Test]
8424                 public void TestGetInterfaceIncomplete ()
8425                 {
8426                         TypeBuilder tb = module.DefineType (genTypeName ());
8427                         try {
8428                                 tb.GetInterface ("FOO", true);
8429                                 Assert.Fail ("#1");
8430                         } catch (NotSupportedException ex) {
8431                                 // The invoked member is not supported in a
8432                                 // dynamic module
8433                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8434                                 Assert.IsNull (ex.InnerException, "#3");
8435                                 Assert.IsNotNull (ex.Message, "#4");
8436                         }
8437                 }
8438
8439                 [Test]
8440                 public void TestGetInterfaces ()
8441                 {
8442                         TypeBuilder tb = module.DefineType (genTypeName ());
8443                         Type [] interfaces = tb.GetInterfaces ();
8444                         Assert.AreEqual (0, interfaces.Length);
8445
8446                         TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8447                         Type emittedInterface = tbInterface.CreateType ();
8448
8449                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8450                         interfaces = tb.GetInterfaces ();
8451                         Assert.AreEqual (1, interfaces.Length);
8452                 }
8453
8454                 [Test]
8455                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8456                 public void TestAddDeclarativeSecurityAlreadyCreated ()
8457                 {
8458                         TypeBuilder tb = module.DefineType (genTypeName ());
8459                         tb.CreateType ();
8460
8461                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8462                         try {
8463                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8464                                 Assert.Fail ("#1");
8465                         } catch (InvalidOperationException ex) {
8466                                 // Unable to change after type has been created
8467                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8468                                 Assert.IsNull (ex.InnerException, "#3");
8469                                 Assert.IsNotNull (ex.Message, "#4");
8470                         }
8471                 }
8472
8473                 [Test]
8474                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8475                 public void TestAddDeclarativeSecurityNullPermissionSet ()
8476                 {
8477                         TypeBuilder tb = module.DefineType (genTypeName ());
8478                         try {
8479                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8480                                 Assert.Fail ("#1");
8481                         } catch (ArgumentNullException ex) {
8482                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8483                                 Assert.IsNull (ex.InnerException, "#3");
8484                                 Assert.IsNotNull (ex.Message, "#4");
8485                                 Assert.AreEqual ("pset", ex.ParamName, "#5");
8486                         }
8487
8488                 }
8489
8490                 [Test]
8491                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8492                 public void TestAddDeclarativeSecurityInvalidAction ()
8493                 {
8494                         TypeBuilder tb = module.DefineType (genTypeName ());
8495
8496                         SecurityAction [] actions = new SecurityAction [] { 
8497                         SecurityAction.RequestMinimum,
8498                         SecurityAction.RequestOptional,
8499                         SecurityAction.RequestRefuse };
8500                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8501
8502                         foreach (SecurityAction action in actions) {
8503                                 try {
8504                                         tb.AddDeclarativeSecurity (action, set);
8505                                         Assert.Fail ();
8506                                 } catch (ArgumentOutOfRangeException) {
8507                                 }
8508                         }
8509                 }
8510
8511                 [Test]
8512                 [Category ("MobileNotWorking")] // Not available in the 2.1 profile
8513                 public void TestAddDeclarativeSecurityDuplicateAction ()
8514                 {
8515                         TypeBuilder tb = module.DefineType (genTypeName ());
8516
8517                         PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8518                         tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8519                         try {
8520                                 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8521                                 Assert.Fail ("#1");
8522                         } catch (InvalidOperationException ex) {
8523                                 // Multiple permission sets specified with the
8524                                 // same SecurityAction
8525                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8526                                 Assert.IsNull (ex.InnerException, "#3");
8527                                 Assert.IsNotNull (ex.Message, "#4");
8528                         }
8529                 }
8530
8531                 [Test]
8532                 public void TestEnums ()
8533                 {
8534                         TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8535                         TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8536                                                                                                                  typeof (Enum));
8537                         enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8538                         // add value__ field, see DefineEnum method of ModuleBuilder
8539                         enumToCreate.DefineField ("value__", typeof (Int32),
8540                                 FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8541
8542                         // add enum entries
8543                         FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8544                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8545                         fb.SetConstant ((Int32) 0);
8546
8547                         fb = enumToCreate.DefineField ("B", enumToCreate,
8548                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8549                         fb.SetConstant ((Int32) 1);
8550
8551                         fb = enumToCreate.DefineField ("C", enumToCreate,
8552                                 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8553                         fb.SetConstant ((Int32) 2);
8554
8555                         Type enumType = enumToCreate.CreateType ();
8556
8557                         object enumVal = Enum.ToObject (enumType, (Int32) 3);
8558
8559                         Assert.AreEqual ("B, C", enumVal.ToString ());
8560                         Assert.AreEqual (3, (Int32) enumVal);
8561                 }
8562
8563                 [Test]
8564                 public void DefineEnum ()
8565                 {
8566                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8567                                                                                                                  TypeAttributes.Public);
8568                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8569                                                                                                                  TypeAttributes.Public, typeof (int));
8570                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8571                         enumBuilder.CreateType ();
8572                         typeBuilder.CreateType ();
8573                 }
8574
8575                 [Test]
8576                 [Category ("NotWorking")]
8577                 public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8578                 {
8579                         TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8580                                                                                                                  TypeAttributes.Public);
8581                         EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8582                                                                                                                  TypeAttributes.Public, typeof (int));
8583                         typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8584                         try {
8585                                 typeBuilder.CreateType ();
8586                                 Assert.Fail ("#1");
8587                         } catch (TypeLoadException) {
8588                                 // Could not load type '...' from assembly
8589                                 // 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8590                         }
8591                         Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8592                         Assert.IsNull (typeBuilder.CreateType (), "#3");
8593                 }
8594
8595                 [Test]
8596                 public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8597                 {
8598                         TypeBuilder tb = module.DefineType (genTypeName ());
8599                         ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8600                                 GetConstructor (Type.EmptyTypes);
8601                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8602                                 attrCtor, new object [0]);
8603                         Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8604                         tb.SetCustomAttribute (caBuilder);
8605                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8606                         Type emittedType = tb.CreateType ();
8607                         Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8608                         //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8609                         object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8610                         Assert.AreEqual (1, emittedAttrs.Length, "#5");
8611                 }
8612
8613                 private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8614                 {
8615                         // define the field holding the property value
8616                         FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8617                                 typeof (string), FieldAttributes.Private);
8618
8619                         PropertyBuilder propertyBuilder = tb.DefineProperty (
8620                                 propertyName, PropertyAttributes.HasDefault, typeof (string),
8621                                 new Type [] { typeof (string) });
8622
8623                         // First, we'll define the behavior of the "get" property for CustomerName as a method.
8624                         MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8625                                                                         methodAttribs,
8626                                                                         typeof (string),
8627                                                                         new Type [] { });
8628
8629                         ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8630
8631                         getIL.Emit (OpCodes.Ldarg_0);
8632                         getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8633                         getIL.Emit (OpCodes.Ret);
8634
8635                         // Now, we'll define the behavior of the "set" property for CustomerName.
8636                         MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8637                                                                         methodAttribs,
8638                                                                         null,
8639                                                                         new Type [] { typeof (string) });
8640
8641                         ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8642
8643                         setIL.Emit (OpCodes.Ldarg_0);
8644                         setIL.Emit (OpCodes.Ldarg_1);
8645                         setIL.Emit (OpCodes.Stfld, fieldBuilder);
8646                         setIL.Emit (OpCodes.Ret);
8647
8648                         // Last, we must map the two methods created above to our PropertyBuilder to 
8649                         // their corresponding behaviors, "get" and "set" respectively. 
8650                         propertyBuilder.SetGetMethod (getMethodBuilder);
8651                         propertyBuilder.SetSetMethod (setMethodBuilder);
8652                         return propertyBuilder;
8653                 }
8654
8655                 static int handler_called = 0;
8656
8657                 [Test]
8658                 public void TestTypeResolve ()
8659                 {
8660                         string typeName = genTypeName ();
8661
8662                         ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8663                         AppDomain.CurrentDomain.TypeResolve += handler;
8664                         handler_called = 0;
8665                         Type t = Type.GetType (typeName);
8666                         Assert.AreEqual (typeName, t.Name);
8667                         Assert.AreEqual (1, handler_called);
8668                         AppDomain.CurrentDomain.TypeResolve -= handler;
8669                 }
8670
8671                 Assembly TypeResolve (object sender, ResolveEventArgs args)
8672                 {
8673                         TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8674                         tb.CreateType ();
8675                         handler_called++;
8676                         return tb.Assembly;
8677                 }
8678
8679                 [Test]
8680                 public void IsAssignableFrom_Created ()
8681                 {
8682                         TypeBuilder tb = module.DefineType (genTypeName (),
8683                                 TypeAttributes.Public, typeof (MemoryStream),
8684                                 new Type [] { typeof (IThrowable), typeof (Bar) });
8685                         tb.AddInterfaceImplementation (typeof (IDestroyable));
8686                         Type emitted_type = tb.CreateType ();
8687
8688                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8689                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8690                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8691                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8692                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8693                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8694                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8695                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8696                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8697                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8698                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8699                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8700                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8701                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8702                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8703                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8704                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8705                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8706
8707                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8708                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8709                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8710                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8711                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8712                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8713                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8714                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8715                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8716                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8717
8718                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8719                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8720                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8721                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8722                         Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8723
8724                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8725                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8726                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8727                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8728                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8729                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8730                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8731                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8732                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8733                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8734                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8735                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8736                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8737                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8738                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8739                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8740                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8741                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8742
8743                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8744                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8745                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8746                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8747                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8748                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8749                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8750                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8751                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8752                         Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8753
8754                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8755                                 tb.FullName + "[]")), "#F1");
8756                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8757                                 tb.FullName + "[]")), "#F2");
8758                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8759                                 tb.FullName + "[]")), "#F3");
8760
8761                         TypeBuilder tb2 = module.DefineType (genTypeName (),
8762                                 TypeAttributes.Public, tb,
8763                                 new Type [] { typeof (IAir) });
8764                         Type emitted_type2 = tb2.CreateType ();
8765
8766                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8767                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8768                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8769                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8770                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8771                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8772                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8773                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8774                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8775                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8776                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8777                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8778                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8779                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8780                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8781                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8782                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8783                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8784
8785                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8786                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8787                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8788                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8789                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8790                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8791                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8792                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8793                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8794                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8795
8796                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
8797                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
8798                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
8799                         Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
8800                         Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
8801                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
8802                         Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
8803                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
8804                         Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
8805                         Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
8806                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
8807                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
8808                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
8809                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
8810
8811                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
8812                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
8813                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
8814                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
8815                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
8816                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
8817                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
8818                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
8819                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
8820                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
8821                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
8822                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
8823                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
8824                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
8825                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
8826                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
8827                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
8828                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
8829
8830                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
8831                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
8832                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
8833                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
8834                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
8835                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
8836                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
8837                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
8838                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
8839                         Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
8840
8841                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8842                                 tb2.FullName + "[]")), "#L1");
8843                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8844                                 tb2.FullName + "[]")), "#L2");
8845                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8846                                 tb2.FullName + "[]")), "#L3");
8847
8848                         TypeBuilder tb3 = module.DefineType (genTypeName (),
8849                                 TypeAttributes.Public, tb2,
8850                                 new Type [] { typeof (IWater) });
8851                         Type emitted_type3 = tb3.CreateType ();
8852
8853                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
8854                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
8855                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
8856                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
8857                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
8858                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
8859                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
8860                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
8861                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
8862                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
8863                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
8864                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
8865                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
8866                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
8867                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
8868                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
8869                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
8870                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
8871
8872                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
8873                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
8874                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
8875                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
8876                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
8877                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
8878                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
8879                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
8880                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
8881                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
8882
8883                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
8884                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
8885                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
8886                         Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
8887                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
8888                         Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
8889                         Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
8890                         Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
8891                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
8892                         Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
8893                         Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
8894                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
8895                         Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
8896                         Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
8897                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
8898                         Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
8899                         Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
8900                         Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
8901                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
8902                         Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
8903                         Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
8904                         Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
8905
8906                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
8907                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
8908                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
8909                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
8910                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
8911                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
8912                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
8913                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
8914                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
8915                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
8916                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
8917                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
8918                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
8919                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
8920                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
8921                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
8922                         Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
8923                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
8924
8925                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
8926                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
8927                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
8928                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
8929                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
8930                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
8931                         Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
8932                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
8933                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
8934                         Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
8935
8936                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8937                                 tb3.FullName + "[]")), "#R1");
8938                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8939                                 tb3.FullName + "[]")), "#R2");
8940                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8941                                 tb3.FullName + "[]")), "#R3");
8942
8943                         TypeBuilder tb4 = module.DefineType (genTypeName (),
8944                                 TypeAttributes.Public, null,
8945                                 new Type [] { typeof (IWater) });
8946                         tb4.DefineGenericParameters ("T");
8947
8948                         Type inst = tb4.MakeGenericType (typeof (int));
8949                         Type emitted_type4 = tb4.CreateType ();
8950                         Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
8951                         // This returns True if CreateType () is called _before_ MakeGenericType...
8952                         //Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
8953                 }
8954
8955                 [Test]
8956                 public void IsAssignableFrom_NotCreated ()
8957                 {
8958                         TypeBuilder tb = module.DefineType (genTypeName (),
8959                                 TypeAttributes.Public, typeof (MemoryStream),
8960                                 new Type [] {
8961                                         typeof (IThrowable), typeof (Bar),
8962                                         typeof (IComparable)
8963                                         });
8964
8965                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8966                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8967                         //Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8968                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8969                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
8970                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
8971                         Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
8972                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
8973                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
8974                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
8975                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
8976                         Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
8977
8978                         //Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
8979                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
8980                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
8981                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
8982                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
8983                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
8984
8985                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
8986                         Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
8987                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
8988                         Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
8989                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
8990                         Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
8991                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
8992                         Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
8993                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
8994                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
8995
8996                         Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
8997                         Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
8998
8999                         TypeBuilder tb2 = module.DefineType (genTypeName (),
9000                                 TypeAttributes.Public, tb,
9001                                 new Type[] { typeof (IAir) });
9002
9003                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
9004                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
9005                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
9006                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
9007                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
9008                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
9009                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
9010                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
9011                         Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
9012                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
9013                         Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
9014                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
9015
9016                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#F1");
9017                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
9018                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#F3");
9019                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
9020                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
9021                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9022
9023                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9024                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9025                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9026                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9027                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9028                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9029                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9030                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9031                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9032                         Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9033
9034                         Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9035                         Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9036                         Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9037
9038                         TypeBuilder tb3 = module.DefineType (genTypeName (),
9039                                 TypeAttributes.Public, tb2,
9040                                 new Type[] { typeof (IWater) });
9041
9042                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9043                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9044                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9045                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9046                         Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9047                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9048                         Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9049                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9050                         Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9051                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9052                         //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9053                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9054
9055                         Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9056                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9057                         Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9058                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9059                         Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9060                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9061
9062                         Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9063                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9064                         Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9065                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9066                         Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9067                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9068                         Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9069                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9070                         Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9071                         Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9072
9073                         Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9074                         Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9075                         Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9076                         Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9077                         Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9078                 }
9079
9080                 [Test]
9081                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9082                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9083                 {
9084                         TypeBuilder tb = module.DefineType (genTypeName (),
9085                                 TypeAttributes.Public, typeof (FormatException),
9086                                 new Type [] { typeof (IThrowable) });
9087                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9088
9089                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9090                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9091
9092                         Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9093                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9094                 }
9095
9096                 [Test]
9097                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9098                 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9099                 {
9100                         TypeBuilder tb = module.DefineType (genTypeName (),
9101                                 TypeAttributes.Public, typeof (FormatException),
9102                                 new Type [] { typeof (IThrowable) });
9103                         tb.AddInterfaceImplementation (typeof (IDestroyable));
9104
9105                         Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9106                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9107
9108                         Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9109                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9110                 }
9111
9112
9113                 [Test]
9114                 // Casts don't work with unfinished types
9115                 [Category ("NotWorking")]
9116                 [Category ("NotDotNet")]
9117                 public void IsAssignableFrom_NotCreated_Array ()
9118                 {
9119                         TypeBuilder tb = module.DefineType (genTypeName (),
9120                                 TypeAttributes.Public, typeof (FormatException),
9121                                 new Type [] {
9122                                         typeof (IThrowable), typeof (Bar),
9123                                         typeof (IComparable)
9124                                         });
9125
9126                         Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9127                                 tb.FullName + "[]")), "#1");
9128                         Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9129                                 tb.FullName + "[]")), "#2");
9130                         Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9131                                 tb.FullName + "[]")), "#3");
9132                 }
9133
9134                 [Test]
9135                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9136                 public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9137                 {
9138                         TypeBuilder tb = module.DefineType (genTypeName (),
9139                                 TypeAttributes.Public, typeof (FormatException),
9140                                 new Type [] {
9141                                         typeof (IThrowable), typeof (Bar),
9142                                         typeof (IComparable)
9143                                         });
9144
9145                         Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9146                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9147                 }
9148
9149                 [Test]
9150                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9151                 public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9152                 {
9153                         TypeBuilder tb = module.DefineType (genTypeName (),
9154                                 TypeAttributes.Public, typeof (FormatException),
9155                                 new Type [] {
9156                                         typeof (IThrowable), typeof (Bar),
9157                                         typeof (IComparable)
9158                                         });
9159
9160                         Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9161                         Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9162                 }
9163
9164                 [Test]
9165                 public void CreateType_EmptyMethodBody ()
9166                 {
9167                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9168
9169                         tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9170                         try {
9171                                 tb.CreateType ();
9172                                 Assert.Fail ("#1");
9173                         } catch (InvalidOperationException ex) {
9174                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9175                                 Assert.IsNull (ex.InnerException, "#3");
9176                                 Assert.IsNotNull (ex.Message, "#4");
9177                         }
9178                 }
9179
9180                 [Test]
9181                 public void CreateType_EmptyCtorBody ()
9182                 {
9183                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9184
9185                         tb.DefineConstructor (0, CallingConventions.Standard, null);
9186                         try {
9187                                 tb.CreateType ();
9188                                 Assert.Fail ("#1");
9189                         } catch (InvalidOperationException ex) {
9190                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9191                                 Assert.IsNull (ex.InnerException, "#3");
9192                                 Assert.IsNotNull (ex.Message, "#4");
9193                         }
9194                 }
9195
9196                 [Test]
9197                 [Category ("NotWorking")]
9198                 public void CreateType_Interface_ParentInvalid ()
9199                 {
9200                         TypeBuilder tb;
9201
9202                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9203                                 typeof (Exception));
9204                         Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9205                         try {
9206                                 tb.CreateType ();
9207                                 Assert.Fail ("#A2");
9208                         } catch (TypeLoadException ex) {
9209                                 // Could not load interface 't5' from assembly '...'
9210                                 // because it must extend from Object
9211                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9212                                 Assert.IsNull (ex.InnerException, "#A4");
9213                                 Assert.IsNotNull (ex.Message, "#A5");
9214                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9215                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9216                         }
9217
9218                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9219                                 typeof (object));
9220                         Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9221                         try {
9222                                 tb.CreateType ();
9223                                 Assert.Fail ("#B2");
9224                         } catch (TypeLoadException ex) {
9225                                 // Failure has occurred while loading a type
9226                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9227                                 Assert.IsNull (ex.InnerException, "#B4");
9228                                 Assert.IsNotNull (ex.Message, "#B5");
9229                         }
9230
9231                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9232                                 typeof (EmptyInterface));
9233                         Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9234                         try {
9235                                 tb.CreateType ();
9236                                 Assert.Fail ("#C2");
9237                         } catch (TypeLoadException ex) {
9238                                 // Could not load interface 't5' from assembly '...'
9239                                 // because the parent type is an interface
9240                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9241                                 Assert.IsNull (ex.InnerException, "#C4");
9242                                 Assert.IsNotNull (ex.Message, "#C5");
9243                                 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9244                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9245                         }
9246                 }
9247
9248                 [Test]
9249                 public void CreateType_Parent_DefaultCtorMissing ()
9250                 {
9251                         TypeBuilder tb;
9252
9253                         tb = module.DefineType (genTypeName ());
9254                         ConstructorBuilder cb = tb.DefineConstructor (
9255                                 MethodAttributes.Public,
9256                                 CallingConventions.Standard,
9257                                 new Type [] { typeof (string) });
9258                         cb.GetILGenerator ().Emit (OpCodes.Ret);
9259                         Type parent_type = tb.CreateType ();
9260
9261                         tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9262                                 parent_type);
9263                         try {
9264                                 tb.CreateType ();
9265                                 Assert.Fail ("#1");
9266                         } catch (NotSupportedException ex) {
9267                                 // Parent does not have a default constructor.
9268                                 // The default constructor must be explicitly defined
9269                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9270                                 Assert.IsNull (ex.InnerException, "#3");
9271                                 Assert.IsNotNull (ex.Message, "#4");
9272                         }
9273                 }
9274
9275                 [Test]
9276                 public void CreateType_Parent_Null ()
9277                 {
9278                         TypeBuilder tb;
9279                         Type emitted_type;
9280                         
9281                         tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9282                         Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9283                         emitted_type = tb.CreateType ();
9284                         Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9285
9286                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9287                         Assert.IsNull (tb.BaseType, "#B1");
9288                         emitted_type = tb.CreateType ();
9289                         Assert.IsNull (emitted_type.BaseType, "#B2");
9290                 }
9291
9292                 [Test]
9293                 [Category ("NotWorking")]
9294                 public void DefineGenericParameters_AlreadyDefined ()
9295                 {
9296                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9297                         tb.DefineGenericParameters ("K");
9298                         try {
9299                                 tb.DefineGenericParameters ("V");
9300                                 Assert.Fail ("#1");
9301                         } catch (InvalidOperationException ex) {
9302                                 // Operation is not valid due to the current
9303                                 // state of the object
9304                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9305                                 Assert.IsNull (ex.InnerException, "#3");
9306                                 Assert.IsNotNull (ex.Message, "#4");
9307                         }
9308                 }
9309
9310                 [Test]
9311                 public void DefineGenericParameters_Names_Empty ()
9312                 {
9313                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9314
9315                         try {
9316                                 tb.DefineGenericParameters (new string [0]);
9317                                 Assert.Fail ("#1");
9318                         } catch (ArgumentException ex) {
9319                                 // Value does not fall within the expected range
9320                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9321                                 Assert.IsNull (ex.InnerException, "#3");
9322                                 Assert.IsNotNull (ex.Message, "#4");
9323                                 Assert.IsNull (ex.ParamName, "#5");
9324                         }
9325                 }
9326
9327                 [Test]
9328                 public void DefineGenericParameters_Names_Null ()
9329                 {
9330                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9331
9332                         try {
9333                                 tb.DefineGenericParameters ((string []) null);
9334                                 Assert.Fail ("#A1");
9335                         } catch (ArgumentNullException ex) {
9336                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9337                                 Assert.IsNull (ex.InnerException, "#A3");
9338                                 Assert.IsNotNull (ex.Message, "#A4");
9339                                 Assert.AreEqual ("names", ex.ParamName, "#A5");
9340                         }
9341
9342                         try {
9343                                 tb.DefineGenericParameters ("K", null, "V");
9344                                 Assert.Fail ("#B1");
9345                         } catch (ArgumentNullException ex) {
9346                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9347                                 Assert.IsNull (ex.InnerException, "#B3");
9348                                 Assert.IsNotNull (ex.Message, "#B4");
9349                                 Assert.AreEqual ("names", ex.ParamName, "#B5");
9350                         }
9351                 }
9352
9353                 [Test]
9354                 public void GenericType ()
9355                 {
9356                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9357                         tb.DefineGenericParameters ("T");
9358
9359                         Assert.IsTrue (tb.IsGenericType, "#A1");
9360                         Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9361                         Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9362                         Assert.IsFalse (tb.IsGenericParameter, "#A4");
9363
9364                         Type[] args = tb.GetGenericArguments ();
9365                         Assert.IsFalse (args [0].IsGenericType, "#B1");
9366                         Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9367                         Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9368                         Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9369                 }
9370
9371                 [Test]
9372                 public void MakeGenericType ()
9373                 {
9374                         TypeBuilder tb;
9375                         Type generic_type;
9376                 
9377                         tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9378                         tb.DefineGenericParameters ("T");
9379
9380                         generic_type = tb.MakeGenericType (typeof (int));
9381                         Assert.IsTrue (generic_type.IsGenericType, "#A1");
9382                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9383                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9384                         Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9385
9386                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9387                         Assert.IsTrue (generic_type.IsGenericType, "#B1");
9388                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9389                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9390                         Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9391
9392                         tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9393                                 | TypeAttributes.Abstract | TypeAttributes.Public);
9394                         tb.DefineGenericParameters ("T");
9395
9396                         generic_type = tb.MakeGenericType (typeof (int));
9397                         Assert.IsTrue (generic_type.IsGenericType, "#C1");
9398                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9399                         Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9400                         Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9401
9402                         generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9403                         Assert.IsTrue (generic_type.IsGenericType, "#D1");
9404                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9405                         Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9406                         Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9407                 }
9408
9409                 [Test]
9410                 public void MakeGenericType_NoGenericTypeDefinition ()
9411                 {
9412                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9413                         try {
9414                                 tb.MakeGenericType (typeof (int));
9415                                 Assert.Fail ("#1");
9416                         } catch (InvalidOperationException ex) {
9417                                 // Operation is not valid due to the current
9418                                 // state of the object
9419                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9420                                 Assert.IsNull (ex.InnerException, "#3");
9421                                 Assert.IsNotNull (ex.Message, "#4");
9422                         }
9423                 }
9424
9425                 [Test]
9426                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9427                 public void MakeGenericType_TypeArguments_Null_Mono ()
9428                 {
9429                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9430                         tb.DefineGenericParameters ("K", "V");
9431
9432                         try {
9433                                 tb.MakeGenericType ((Type []) null);
9434                                 Assert.Fail ("#A1");
9435                         } catch (ArgumentNullException ex) {
9436                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9437                                 Assert.IsNull (ex.InnerException, "#A3");
9438                                 Assert.IsNotNull (ex.Message, "#A4");
9439                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9440                         }
9441
9442                         try {
9443                                 tb.MakeGenericType (typeof (string), (Type) null);
9444                                 Assert.Fail ("#B1");
9445                         } catch (ArgumentNullException ex) {
9446                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9447                                 Assert.IsNull (ex.InnerException, "#B3");
9448                                 Assert.IsNotNull (ex.Message, "#B4");
9449                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9450                         }
9451                 }
9452
9453                 [Test]
9454                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9455                 public void MakeGenericType_TypeArguments_Null_MS ()
9456                 {
9457                         Type generic_type;
9458                         Type [] type_args;
9459
9460                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9461                         tb.DefineGenericParameters ("K", "V");
9462
9463                         generic_type = tb.MakeGenericType ((Type []) null);
9464                         Assert.IsNotNull (generic_type, "#A1");
9465                         Assert.IsTrue (generic_type.IsGenericType, "#A2");
9466                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9467                         type_args = generic_type.GetGenericArguments ();
9468                         Assert.IsNull (type_args, "#A4");
9469
9470                         generic_type  = tb.MakeGenericType (typeof (string), (Type) null);
9471                         Assert.IsNotNull (generic_type, "#B1");
9472                         Assert.IsTrue (generic_type.IsGenericType, "#B2");
9473                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9474                         type_args = generic_type.GetGenericArguments ();
9475                         Assert.IsNotNull (type_args, "#B4");
9476                         Assert.AreEqual (2, type_args.Length, "#B5");
9477                         Assert.AreEqual (typeof (string), type_args [0], "#B6");
9478                         Assert.IsNull (type_args [1], "#B7");
9479                 }
9480
9481                 [Test]
9482                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9483                 public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9484                 {
9485                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9486                         tb.DefineGenericParameters ("K", "V");
9487                         try {
9488                                 tb.MakeGenericType (typeof (int));
9489                                 Assert.Fail ("#1");
9490                         } catch (ArgumentException ex) {
9491                                 // The type or method has 2 generic prarameter(s)
9492                                 // but 1 generic argument(s) were provided. A
9493                                 // generic argument must be provided for each
9494                                 // generic parameter
9495                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9496                                 Assert.IsNull (ex.InnerException, "#3");
9497                                 Assert.IsNotNull (ex.Message, "#4");
9498                                 Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9499                         }
9500                 }
9501
9502                 [Test]
9503                 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9504                 public void MakeGenericType_TypeArguments_Mismatch_MS ()
9505                 {
9506                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9507                         tb.DefineGenericParameters ("K", "V");
9508                         
9509                         Type generic_type = tb.MakeGenericType (typeof (int));
9510                         Assert.IsTrue (generic_type.IsGenericType, "#1");
9511                         Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9512                         Type [] type_args = generic_type.GetGenericArguments ();
9513                         Assert.IsNotNull (type_args, "#3");
9514                         Assert.AreEqual (1, type_args.Length, "#4");
9515                         Assert.AreEqual (typeof (int), type_args [0], "#5");
9516                 }
9517
9518                 [Test]
9519                 public void MakeArrayType_Complete ()
9520                 {
9521                         // reference type
9522                         TypeBuilder tb = module.DefineType (genTypeName (),
9523                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9524                                 typeof (ContextBoundObject));
9525                         Type emittedType = tb.CreateType ();
9526                         Type arrayType = tb.MakeArrayType ();
9527                         Assert.IsTrue (arrayType.IsArray, "#A1");
9528                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9529                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9530                         Assert.IsFalse (tb.HasElementType, "#A4");
9531                         Assert.IsTrue (tb.IsCreated (), "#A5");
9532
9533                         // value type
9534                         tb = module.DefineType (genTypeName (),
9535                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9536                                 typeof (ValueType));
9537                         emittedType = tb.CreateType ();
9538                         arrayType = tb.MakeArrayType ();
9539                         Assert.IsTrue (arrayType.IsArray, "#B1");
9540                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9541                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9542                         Assert.IsFalse (tb.HasElementType, "#B4");
9543                         Assert.IsTrue (tb.IsCreated (), "#B5");
9544
9545                         tb = module.DefineType (genTypeName (),
9546                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9547                                 typeof (Enum));
9548                         tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9549                                 FieldAttributes.Private | FieldAttributes.RTSpecialName);
9550                         emittedType = tb.CreateType ();
9551                         arrayType = tb.MakeArrayType ();
9552                         Assert.IsTrue (arrayType.IsArray, "#C1");
9553                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9554                         Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9555                         Assert.IsFalse (tb.HasElementType, "#C4");
9556                         Assert.IsTrue (tb.IsCreated (), "#C5");
9557                 }
9558
9559                 [Test] // bug #82015
9560                 public void MakeArrayType_Incomplete ()
9561                 {
9562                         // reference type
9563                         TypeBuilder tb = module.DefineType (genTypeName (),
9564                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9565                                 typeof (ContextBoundObject));
9566                         Type arrayType = tb.MakeArrayType ();
9567                         Assert.IsTrue (arrayType.IsArray, "#A1");
9568                         Assert.IsTrue (arrayType.HasElementType, "#A2");
9569                         Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9570                         Assert.IsFalse (tb.HasElementType, "#A4");
9571                         Assert.IsFalse (tb.IsCreated (), "#A5");
9572
9573                         // value type
9574                         tb = module.DefineType (genTypeName (),
9575                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9576                                 typeof (ValueType));
9577                         arrayType = tb.MakeArrayType ();
9578                         Assert.IsTrue (arrayType.IsArray, "#B1");
9579                         Assert.IsTrue (arrayType.HasElementType, "#B2");
9580                         Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9581                         Assert.IsFalse (tb.HasElementType, "#B4");
9582                         Assert.IsFalse (tb.IsCreated (), "#B5");
9583
9584                         // enum
9585                         tb = module.DefineType (genTypeName (),
9586                                 TypeAttributes.Sealed | TypeAttributes.Serializable,
9587                                 typeof (Enum));
9588                         arrayType = tb.MakeArrayType ();
9589                         Assert.IsTrue (arrayType.IsArray, "#C1");
9590                         Assert.IsTrue (arrayType.HasElementType, "#C2");
9591                         Assert.IsFalse (tb.HasElementType, "#C3");
9592                         Assert.IsFalse (tb.IsCreated (), "#C4");
9593                 }
9594
9595                 [Test]
9596                 public void GetCustomAttributes_InflatedType ()
9597                 {
9598                         TypeBuilder tb = module.DefineType (genTypeName ());
9599                         tb.DefineGenericParameters (new string[] { "FOO" });
9600
9601                         ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9602                                 new Type [] { typeof (string) });
9603
9604                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9605                                 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9606
9607                         tb.SetCustomAttribute (caBuilder);
9608                         Type t = tb.CreateType ();
9609
9610                         Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9611
9612                         Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9613                 }
9614
9615                 [Test]
9616                 public void GetField ()
9617                 {
9618                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9619                         GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9620
9621                         ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9622
9623                         FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9624
9625                         Type t = tb.MakeGenericType (typeof (int));
9626
9627                         // Chect that calling MakeArrayType () does not initialize the class
9628                         // (bug #351172)
9629                         t.MakeArrayType ();
9630
9631                         // Check that the instantiation of a type builder contains live data
9632                         TypeBuilder.GetField (t, fb1);
9633                         FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9634                         FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9635
9636                         MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9637                         ILGenerator ilgen = mb.GetILGenerator ();
9638                         ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9639                         ilgen.Emit (OpCodes.Dup);
9640                         ilgen.Emit (OpCodes.Ldc_I4, 42);
9641                         ilgen.Emit (OpCodes.Stfld, fi2);
9642                         ilgen.Emit (OpCodes.Ldfld, fi2);
9643                         ilgen.Emit (OpCodes.Ret);
9644
9645                         // Check GetField on a type instantiated with type parameters
9646                         Type t3 = tb.MakeGenericType (typeParams [0]);
9647                         FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9648                         FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9649
9650                         MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9651                         ILGenerator ilgen3 = mb3.GetILGenerator ();
9652                         ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9653                         ilgen3.Emit (OpCodes.Ldfld, fi3);
9654                         ilgen3.Emit (OpCodes.Ret);
9655
9656                         Type created = tb.CreateType ();
9657
9658                         Type inst = created.MakeGenericType (typeof (object));
9659
9660                         Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9661
9662                         Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9663                 }
9664                 
9665                 [Test] //bug #354047
9666                 public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9667                 {
9668                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9669                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9670                         Type t = tb.CreateType ();
9671
9672                         Type inst = tb.MakeGenericType (typeParams [0]);
9673                         Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9674                 }
9675
9676                 [Test] //bug #354047
9677                 public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9678                 {
9679                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9680                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9681                         Type t = tb.CreateType ();
9682
9683                         Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9684                         Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9685                 }
9686
9687                 [Test] //bug #354047
9688                 public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9689                 {
9690                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9691                         GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9692                         Type t = tb.CreateType ();
9693
9694                         Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9695                 }
9696
9697                 [Test] //bug #399047
9698                 public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9699                                 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9700
9701                                 module = assembly.DefineDynamicModule ("Instance.exe");
9702   
9703                 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9704                 Type T = G.DefineGenericParameters ("T") [0];
9705                                 ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9706                 Type GObj = G.MakeGenericType (new Type [] { T });
9707
9708                 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9709
9710                 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9711
9712                 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9713                 Type TATest = Test.DefineGenericParameters ("TA") [0];
9714                 {
9715                         Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9716
9717                         ILGenerator il = Test.GetILGenerator ();
9718
9719                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9720                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9721                         il.Emit (OpCodes.Pop);
9722
9723                         il.Emit (OpCodes.Ret);
9724                 }
9725
9726                                 MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9727                                 {
9728                                         ILGenerator il = main.GetILGenerator ();
9729                                         il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9730                                         il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9731                                         il.Emit (OpCodes.Ret);
9732                                 }
9733
9734                                 assembly.SetEntryPoint (main);
9735                 G.CreateType ();
9736                 P.CreateType ();
9737
9738                 assembly.Save ("Instance.exe");
9739                                 Thread.GetDomain ().ExecuteAssembly(Path.GetTempPath () + Path.DirectorySeparatorChar + "Instance.exe");
9740                 }
9741
9742                 [Test]
9743                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9744                 {
9745                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9746                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9747                         tb.CreateType ();
9748
9749                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9750                         module = assembly.DefineDynamicModule ("Instance.exe");
9751
9752                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9753                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9754                         ILGenerator il = mb.GetILGenerator ();
9755
9756                         il.Emit (OpCodes.Ldc_I4_1);
9757                         il.Emit (OpCodes.Newarr, typeof (int));
9758                         il.Emit (OpCodes.Dup);
9759                         il.Emit (OpCodes.Ldtoken, fb);
9760                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9761                         il.Emit (OpCodes.Ret);
9762
9763                         Type t = tb2.CreateType ();
9764                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9765                         //Console.WriteLine (res[0]);
9766                 }
9767
9768                 [Test]
9769                 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers2 ()
9770                 {
9771                         TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9772                         var garg = tb.DefineGenericParameters ("T") [0];
9773                         FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9774                         tb.CreateType ();
9775
9776                         assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9777                         module = assembly.DefineDynamicModule ("Instance.exe");
9778
9779                         TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9780                         MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9781                         ILGenerator il = mb.GetILGenerator ();
9782
9783                         il.Emit (OpCodes.Ldc_I4_1);
9784                         il.Emit (OpCodes.Newarr, typeof (int));
9785                         il.Emit (OpCodes.Dup);
9786                         il.Emit (OpCodes.Ldtoken, fb);
9787                         il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9788                         il.Emit (OpCodes.Ret);
9789
9790                         Type t = tb2.CreateType ();
9791                         int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9792                         //Console.WriteLine (res[0]);
9793                 }
9794
9795                 public interface IDelegateFactory
9796                 {
9797                         Delegate Create (Delegate del);
9798                 }
9799
9800                 [Test]
9801                 public void CreateType_Ctor_NoBody ()
9802                 {
9803                         TypeBuilder tb = module.DefineType (genTypeName ());
9804                         tb.DefineConstructor (MethodAttributes.Public,
9805                                 CallingConventions.Standard,
9806                                 new Type [] { typeof (string) });
9807                         try {
9808                                 tb.CreateType ();
9809                                 Assert.Fail ("#1");
9810                         } catch (InvalidOperationException ex) {
9811                                 // Method '.ctor' does not have a method body
9812                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9813                                 Assert.IsNull (ex.InnerException, "#3");
9814                                 Assert.IsNotNull (ex.Message, "#4");
9815                                 Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9816                         }
9817                 }
9818
9819                 [Test] //bug #361689
9820                 public void CreateTypeFailsWithInvalidMethodOverride ()
9821                 {
9822                         TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9823
9824                         MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
9825                         ILGenerator gen = mc.GetILGenerator ();
9826                         gen.Emit (OpCodes.Ldarg_0);
9827                         gen.Emit (OpCodes.Ret);
9828                         tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
9829                         try {
9830                                 tb.CreateType ();
9831                                 Assert.Fail ("#1 create type did not throw TypeLoadException");
9832                         } catch (TypeLoadException) {
9833                         
9834                         }
9835                 }
9836
9837                 [Test] //bug #349194
9838                 public void IsAssignableToWorksWithInterfacesOnParent ()
9839                 {
9840             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9841                         TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
9842
9843                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9844                         Type t = tb.CreateType ();
9845                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9846                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
9847                         
9848                         
9849                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9850                         Type t2 = tb2.CreateType ();
9851                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9852                         Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
9853                 }
9854
9855
9856                 [Test] //bug #430508
9857                 public void MakeGenericTypeRespectBaseType ()
9858                 {
9859             TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9860                         EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
9861
9862                         MethodBuilder mb = tb.DefineMethod ("Test",
9863                                                                                                 MethodAttributes.Public,
9864                                                                                                 typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
9865                                                                                                 new Type [0]);
9866                         ILGenerator il = mb.GetILGenerator();
9867                         il.Emit (OpCodes.Ldnull);
9868                         il.Emit (OpCodes.Ret);
9869         
9870                         Type e = eb.CreateType ();
9871                         Type c = tb.CreateType ();
9872                 
9873                         Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
9874                 }
9875
9876                 [Test]
9877                 public void GetCustomAttrOnFieldOfInflatedType ()
9878                 {
9879                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9880                         tb.DefineGenericParameters ("T");
9881
9882                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9883                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9884                                 new object [0]);
9885
9886                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9887                         field.SetCustomAttribute (caBuilder);
9888
9889                         Type t = tb.CreateType ();
9890
9891                         FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9892                         object[] cattrs = fi.GetCustomAttributes (false);
9893                         Assert.AreEqual (1, cattrs.Length);
9894
9895                         fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9896                         cattrs = fi.GetCustomAttributes (false);
9897                         Assert.AreEqual (1, cattrs.Length);
9898                 }
9899
9900                 [Test]
9901                 public void GetCustomAttrOnPropertyOfInflatedType ()
9902                 {
9903                         TypeBuilder tb = module.DefineType (genTypeName ());
9904                         tb.DefineGenericParameters ("T");
9905
9906                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9907                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9908                                 new object [0]);
9909
9910                         PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
9911                         property.SetCustomAttribute (caBuilder);
9912
9913                         Type t = tb.CreateType ();
9914
9915                         PropertyInfo pi = t.GetProperties ()[0];
9916                         object[] cattrs = pi.GetCustomAttributes (false);
9917                         Assert.AreEqual (1, cattrs.Length);
9918
9919                         pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
9920                         cattrs = pi.GetCustomAttributes (false);
9921                         Assert.AreEqual (1, cattrs.Length);
9922                 }
9923
9924                 [Test]
9925                 public void GetCustomAttrOnEventOfInflatedType ()
9926                 {
9927                         TypeBuilder tb = module.DefineType (genTypeName ());
9928                         tb.DefineGenericParameters ("T");
9929
9930                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9931                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9932                                 new object [0]);
9933
9934                         EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
9935                         evt.SetCustomAttribute (caBuilder);
9936
9937                         Type t = tb.CreateType ();
9938
9939                         EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9940                         object[] cattrs = ei.GetCustomAttributes (false);
9941                         Assert.AreEqual (1, cattrs.Length);
9942
9943                         ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
9944                         cattrs = ei.GetCustomAttributes (false);
9945                         Assert.AreEqual (1, cattrs.Length);
9946                 }
9947
9948                 public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
9949                 {
9950                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9951                         tb.DefineGenericParameters ("T");
9952  
9953                         CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
9954                                 typeof (SimpleTestAttribute).GetConstructors ()[0],
9955                                 new object [0]);
9956
9957                         FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
9958                         field.SetCustomAttribute (caBuilder);
9959
9960
9961                         tb.MakeGenericType (typeof (int)).GetMethods ();
9962                         tb.MakeGenericType (typeof (double)).GetMethods ();
9963                         
9964                         Type t = tb.CreateType ();
9965                         
9966                         t.MakeGenericType (typeof (int)).GetMethods ();
9967                         t.MakeGenericType (typeof (double)).GetMethods ();
9968                 }
9969
9970                 [Test]
9971                 public void TestGenericFieldAccess () // bug #467415
9972                 {
9973                         AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
9974                         AppDomain domain = AppDomain.CurrentDomain;
9975                         AssemblyBuilder demoAssembly =
9976                                 domain.DefineDynamicAssembly(asmName,
9977                                                 AssemblyBuilderAccess.RunAndSave);
9978
9979                         // Define the module that contains the code. For an
9980                         // assembly with one module, the module name is the
9981                         // assembly name plus a file extension.
9982                         ModuleBuilder demoModule =
9983                                 demoAssembly.DefineDynamicModule(asmName.Name,
9984                                                 asmName.Name+".dll");
9985
9986                         TypeBuilder demoType =
9987                                 demoModule.DefineType("DemoType", TypeAttributes.Public);
9988
9989                         MethodBuilder factory =
9990                                 demoType.DefineMethod("Factory",
9991                                                 MethodAttributes.Public | MethodAttributes.Static);
9992
9993                         string[] typeParameterNames = {"T"};
9994                         GenericTypeParameterBuilder[] typeParameters =
9995                                 factory.DefineGenericParameters(typeParameterNames);
9996
9997                         GenericTypeParameterBuilder T = typeParameters[0];
9998
9999                         Type[] parms = {};
10000                         factory.SetParameters(parms);
10001
10002                         factory.SetReturnType(T);
10003
10004                         ILGenerator ilgen = factory.GetILGenerator();
10005
10006                         Type G = typeof(Gen<>);
10007                         Type GT = G.MakeGenericType (T);
10008                         FieldInfo GF = G.GetField("field");
10009                         FieldInfo GTF = TypeBuilder.GetField(GT, GF);
10010
10011                         ilgen.Emit(OpCodes.Ldsfld, GTF);
10012                         ilgen.Emit(OpCodes.Ret);
10013
10014                         // Complete the type.
10015                         Type dt = demoType.CreateType();
10016                         // Save the assembly, so it can be examined with Ildasm.exe.
10017                         //demoAssembly.Save(asmName.Name+".dll");
10018
10019                         MethodInfo m = dt.GetMethod("Factory");
10020                         MethodInfo bound = m.MakeGenericMethod(typeof(int));
10021
10022                         // Display a string representing the bound method.
10023                         //Console.WriteLine(bound);
10024
10025                         object[] parameters = {};
10026                         int result = (int)(bound.Invoke(null, parameters));
10027
10028                         Assert.AreEqual (0, result, "#1");
10029                 }
10030
10031                 static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
10032                 {
10033                         foreach (MethodInfo mi in methods)
10034                                 if (mi.Name == name)
10035                                         return mi;
10036                         return null;
10037                 }
10038
10039                 void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
10040                 {
10041                         ConstructorBuilder cb;
10042                         MethodBuilder mb;
10043                         PropertyBuilder pb;
10044                         EventBuilder eb;
10045                         ILGenerator ilgen;
10046
10047                         if (defineCtors) {
10048                                 //
10049                                 // instance constructors
10050                                 //
10051                                 cb = tb.DefineConstructor (MethodAttributes.Private,
10052                                         CallingConventions.Standard,
10053                                         new Type [] { typeof (int), typeof (int) });
10054                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10055
10056                                 cb = tb.DefineConstructor (MethodAttributes.Family,
10057                                         CallingConventions.Standard,
10058                                         new Type [] { typeof (string) });
10059                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10060
10061                                 cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10062                                         CallingConventions.Standard,
10063                                         new Type [] { typeof (string), typeof (string) });
10064                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10065
10066                                 cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10067                                         CallingConventions.Standard,
10068                                         new Type [] { typeof (int) });
10069                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10070
10071                                 cb = tb.DefineConstructor (MethodAttributes.Public,
10072                                         CallingConventions.Standard,
10073                                         new Type [] { typeof (int), typeof (bool) });
10074                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10075
10076                                 cb = tb.DefineConstructor (MethodAttributes.Assembly,
10077                                         CallingConventions.Standard,
10078                                         new Type [] { typeof (string), typeof (int) });
10079                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10080
10081                                 //
10082                                 // static constructors
10083                                 //
10084
10085                                 cb = tb.DefineConstructor (MethodAttributes.Private |
10086                                         MethodAttributes.Static,
10087                                         CallingConventions.Standard,
10088                                         Type.EmptyTypes);
10089                                 cb.GetILGenerator ().Emit (OpCodes.Ret);
10090                         }
10091
10092                         //
10093                         // instance methods
10094                         //
10095
10096                         mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10097                                 MethodAttributes.Private, typeof (void),
10098                                 Type.EmptyTypes);
10099                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10100
10101                         mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10102                                 MethodAttributes.Family, typeof (void),
10103                                 Type.EmptyTypes);
10104                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10105
10106                         mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10107                                 MethodAttributes.FamANDAssem, typeof (void),
10108                                 Type.EmptyTypes);
10109                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10110
10111                         mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10112                                 MethodAttributes.FamORAssem, typeof (void),
10113                                 Type.EmptyTypes);
10114                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10115
10116                         mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10117                                 MethodAttributes.Public, typeof (void),
10118                                 Type.EmptyTypes);
10119                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10120
10121                         mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10122                                 MethodAttributes.Assembly, typeof (void),
10123                                 Type.EmptyTypes);
10124                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10125
10126                         //
10127                         // static methods
10128                         //
10129
10130                         mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10131                                 MethodAttributes.Private | MethodAttributes.Static,
10132                                 typeof (void), Type.EmptyTypes);
10133                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10134
10135                         mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10136                                 MethodAttributes.Family | MethodAttributes.Static,
10137                                 typeof (void), Type.EmptyTypes);
10138                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10139
10140                         mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10141                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10142                                 typeof (void), Type.EmptyTypes);
10143                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10144
10145                         mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10146                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10147                                 typeof (void), Type.EmptyTypes);
10148                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10149
10150                         mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10151                                 MethodAttributes.Public | MethodAttributes.Static,
10152                                 typeof (void), Type.EmptyTypes);
10153                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10154
10155                         mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10156                                 MethodAttributes.Assembly | MethodAttributes.Static,
10157                                 typeof (void), Type.EmptyTypes);
10158                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10159
10160                         //
10161                         // instance fields
10162                         //
10163
10164                         tb.DefineField ("privateInstance" + suffix,
10165                                 typeof (string), FieldAttributes.Private);
10166                         tb.DefineField ("familyInstance" + suffix,
10167                                 typeof (string), FieldAttributes.Family);
10168                         tb.DefineField ("famANDAssemInstance" + suffix,
10169                                 typeof (string), FieldAttributes.FamANDAssem);
10170                         tb.DefineField ("famORAssemInstance" + suffix,
10171                                 typeof (string), FieldAttributes.FamORAssem);
10172                         tb.DefineField ("publicInstance" + suffix,
10173                                 typeof (string), FieldAttributes.Public);
10174                         tb.DefineField ("assemblyInstance" + suffix,
10175                                 typeof (string), FieldAttributes.Assembly);
10176
10177                         //
10178                         // static fields
10179                         //
10180
10181                         tb.DefineField ("privateStatic" + suffix,
10182                                 typeof (string), FieldAttributes.Private |
10183                                 FieldAttributes.Static);
10184                         tb.DefineField ("familyStatic" + suffix,
10185                                 typeof (string), FieldAttributes.Family |
10186                                 FieldAttributes.Static);
10187                         tb.DefineField ("famANDAssemStatic" + suffix,
10188                                 typeof (string), FieldAttributes.FamANDAssem |
10189                                 FieldAttributes.Static);
10190                         tb.DefineField ("famORAssemStatic" + suffix,
10191                                 typeof (string), FieldAttributes.FamORAssem |
10192                                 FieldAttributes.Static);
10193                         tb.DefineField ("publicStatic" + suffix,
10194                                 typeof (string), FieldAttributes.Public |
10195                                 FieldAttributes.Static);
10196                         tb.DefineField ("assemblyStatic" + suffix,
10197                                 typeof (string), FieldAttributes.Assembly |
10198                                 FieldAttributes.Static);
10199
10200                         //
10201                         // instance properties
10202                         //
10203
10204                         pb = tb.DefineProperty ("PrivateInstance" + suffix,
10205                                 PropertyAttributes.None, typeof (string),
10206                                 Type.EmptyTypes);
10207                         mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10208                                 MethodAttributes.Private, typeof (string),
10209                                 Type.EmptyTypes);
10210                         ilgen = mb.GetILGenerator ();
10211                         ilgen.Emit (OpCodes.Ldnull);
10212                         ilgen.Emit (OpCodes.Ret);
10213                         pb.SetGetMethod (mb);
10214
10215                         pb = tb.DefineProperty ("FamilyInstance" + suffix,
10216                                 PropertyAttributes.None, typeof (string),
10217                                 Type.EmptyTypes);
10218                         mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10219                                 MethodAttributes.Family, typeof (string),
10220                                 Type.EmptyTypes);
10221                         ilgen = mb.GetILGenerator ();
10222                         ilgen.Emit (OpCodes.Ldnull);
10223                         ilgen.Emit (OpCodes.Ret);
10224                         pb.SetGetMethod (mb);
10225
10226                         pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10227                                 PropertyAttributes.None, typeof (string),
10228                                 Type.EmptyTypes);
10229                         mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10230                                 MethodAttributes.FamANDAssem, typeof (string),
10231                                 Type.EmptyTypes);
10232                         ilgen = mb.GetILGenerator ();
10233                         ilgen.Emit (OpCodes.Ldnull);
10234                         ilgen.Emit (OpCodes.Ret);
10235                         pb.SetGetMethod (mb);
10236
10237                         pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10238                                 PropertyAttributes.None, typeof (string),
10239                                 Type.EmptyTypes);
10240                         mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10241                                 MethodAttributes.FamORAssem, typeof (string),
10242                                 Type.EmptyTypes);
10243                         ilgen = mb.GetILGenerator ();
10244                         ilgen.Emit (OpCodes.Ldnull);
10245                         ilgen.Emit (OpCodes.Ret);
10246                         pb.SetGetMethod (mb);
10247
10248                         pb = tb.DefineProperty ("PublicInstance" + suffix,
10249                                 PropertyAttributes.None, typeof (string),
10250                                 Type.EmptyTypes);
10251                         mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10252                                 MethodAttributes.Public, typeof (string),
10253                                 Type.EmptyTypes);
10254                         ilgen = mb.GetILGenerator ();
10255                         ilgen.Emit (OpCodes.Ldnull);
10256                         ilgen.Emit (OpCodes.Ret);
10257                         pb.SetGetMethod (mb);
10258
10259                         pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10260                                 PropertyAttributes.None, typeof (string),
10261                                 Type.EmptyTypes);
10262                         mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10263                                 MethodAttributes.Assembly, typeof (string),
10264                                 Type.EmptyTypes);
10265                         ilgen = mb.GetILGenerator ();
10266                         ilgen.Emit (OpCodes.Ldnull);
10267                         ilgen.Emit (OpCodes.Ret);
10268                         pb.SetGetMethod (mb);
10269
10270                         //
10271                         // static properties
10272                         //
10273
10274                         pb = tb.DefineProperty ("PrivateStatic" + suffix,
10275                                 PropertyAttributes.None, typeof (string),
10276                                 Type.EmptyTypes);
10277                         mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10278                                 MethodAttributes.Private | MethodAttributes.Static,
10279                                 typeof (string), Type.EmptyTypes);
10280                         ilgen = mb.GetILGenerator ();
10281                         ilgen.Emit (OpCodes.Ldnull);
10282                         ilgen.Emit (OpCodes.Ret);
10283                         pb.SetGetMethod (mb);
10284
10285                         pb = tb.DefineProperty ("FamilyStatic" + suffix,
10286                                 PropertyAttributes.None, typeof (string),
10287                                 Type.EmptyTypes);
10288                         mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10289                                 MethodAttributes.Family | MethodAttributes.Static,
10290                                 typeof (string), Type.EmptyTypes);
10291                         ilgen = mb.GetILGenerator ();
10292                         ilgen.Emit (OpCodes.Ldnull);
10293                         ilgen.Emit (OpCodes.Ret);
10294                         pb.SetGetMethod (mb);
10295
10296                         pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10297                                 PropertyAttributes.None, typeof (string),
10298                                 Type.EmptyTypes);
10299                         mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10300                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10301                                 typeof (string), Type.EmptyTypes);
10302                         ilgen = mb.GetILGenerator ();
10303                         ilgen.Emit (OpCodes.Ldnull);
10304                         ilgen.Emit (OpCodes.Ret);
10305                         pb.SetGetMethod (mb);
10306
10307                         pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10308                                 PropertyAttributes.None, typeof (string),
10309                                 Type.EmptyTypes);
10310                         mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10311                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10312                                 typeof (string), Type.EmptyTypes);
10313                         ilgen = mb.GetILGenerator ();
10314                         ilgen.Emit (OpCodes.Ldnull);
10315                         ilgen.Emit (OpCodes.Ret);
10316                         pb.SetGetMethod (mb);
10317
10318                         pb = tb.DefineProperty ("PublicStatic" + suffix,
10319                                 PropertyAttributes.None, typeof (string),
10320                                 Type.EmptyTypes);
10321                         mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10322                                 MethodAttributes.Public | MethodAttributes.Static,
10323                                 typeof (string), Type.EmptyTypes);
10324                         ilgen = mb.GetILGenerator ();
10325                         ilgen.Emit (OpCodes.Ldnull);
10326                         ilgen.Emit (OpCodes.Ret);
10327                         pb.SetGetMethod (mb);
10328
10329                         pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10330                                 PropertyAttributes.None, typeof (string),
10331                                 Type.EmptyTypes);
10332                         mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10333                                 MethodAttributes.Assembly | MethodAttributes.Static,
10334                                 typeof (string), Type.EmptyTypes);
10335                         ilgen = mb.GetILGenerator ();
10336                         ilgen.Emit (OpCodes.Ldnull);
10337                         ilgen.Emit (OpCodes.Ret);
10338                         pb.SetGetMethod (mb);
10339
10340                         //
10341                         // instance events
10342                         //
10343
10344                         eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10345                                 EventAttributes.None, typeof (EventHandler));
10346                         mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10347                                 MethodAttributes.Private, typeof (void),
10348                                 Type.EmptyTypes);
10349                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10350                         eb.SetAddOnMethod (mb);
10351
10352                         eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10353                                 EventAttributes.None, typeof (EventHandler));
10354                         mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10355                                 MethodAttributes.Family, typeof (void),
10356                                 Type.EmptyTypes);
10357                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10358                         eb.SetAddOnMethod (mb);
10359
10360                         eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10361                                 EventAttributes.None, typeof (EventHandler));
10362                         mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10363                                 MethodAttributes.FamANDAssem, typeof (void),
10364                                 Type.EmptyTypes);
10365                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10366                         eb.SetAddOnMethod (mb);
10367
10368                         eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10369                                 EventAttributes.None, typeof (EventHandler));
10370                         mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10371                                 MethodAttributes.FamORAssem, typeof (void),
10372                                 Type.EmptyTypes);
10373                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10374                         eb.SetAddOnMethod (mb);
10375
10376                         eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10377                                 EventAttributes.None, typeof (EventHandler));
10378                         mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10379                                 MethodAttributes.Public, typeof (void),
10380                                 Type.EmptyTypes);
10381                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10382                         eb.SetAddOnMethod (mb);
10383
10384                         eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10385                                 EventAttributes.None, typeof (EventHandler));
10386                         mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10387                                 MethodAttributes.Family, typeof (void),
10388                                 Type.EmptyTypes);
10389                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10390                         eb.SetAddOnMethod (mb);
10391
10392                         //
10393                         // static events
10394                         //
10395
10396                         eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10397                                 EventAttributes.None, typeof (EventHandler));
10398                         mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10399                                 MethodAttributes.Private | MethodAttributes.Static,
10400                                 typeof (void), Type.EmptyTypes);
10401                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10402                         eb.SetAddOnMethod (mb);
10403
10404                         eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10405                                 EventAttributes.None, typeof (EventHandler));
10406                         mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10407                                 MethodAttributes.Family | MethodAttributes.Static,
10408                                 typeof (void), Type.EmptyTypes);
10409                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10410                         eb.SetAddOnMethod (mb);
10411
10412                         eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10413                                 EventAttributes.None, typeof (EventHandler));
10414                         mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10415                                 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10416                                 typeof (void), Type.EmptyTypes);
10417                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10418                         eb.SetAddOnMethod (mb);
10419
10420                         eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10421                                 EventAttributes.None, typeof (EventHandler));
10422                         mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10423                                 MethodAttributes.FamORAssem | MethodAttributes.Static,
10424                                 typeof (void), Type.EmptyTypes);
10425                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10426                         eb.SetAddOnMethod (mb);
10427
10428                         eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10429                                 EventAttributes.None, typeof (EventHandler));
10430                         mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10431                                 MethodAttributes.Public | MethodAttributes.Static,
10432                                 typeof (void), Type.EmptyTypes);
10433                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10434                         eb.SetAddOnMethod (mb);
10435
10436                         eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10437                                 EventAttributes.None, typeof (EventHandler));
10438                         mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10439                                 MethodAttributes.Family | MethodAttributes.Static,
10440                                 typeof (void), Type.EmptyTypes);
10441                         mb.GetILGenerator ().Emit (OpCodes.Ret);
10442                         eb.SetAddOnMethod (mb);
10443                 }
10444
10445                 static TypeBuilder Resolve1_Tb;
10446                 static bool Resolve1_Called;
10447
10448                 public class Lookup<T>
10449                 {
10450                         public static Type t = typeof(T);
10451                 }
10452
10453                 Assembly Resolve1 (object sender, ResolveEventArgs args) {
10454                         Resolve1_Called = true;
10455                         Resolve1_Tb.CreateType ();
10456                         return Resolve1_Tb.Assembly;
10457                 }
10458
10459                 [Test]
10460                 public void TypeResolveGenericInstances () {
10461                         // Test that TypeResolve is called for generic instances (#483852)
10462                         TypeBuilder tb1 = null;
10463
10464                         AppDomain.CurrentDomain.TypeResolve += Resolve1;
10465
10466                         tb1 = module.DefineType("Foo");
10467                         Resolve1_Tb = tb1;
10468                         FieldInfo field = TypeBuilder.GetField(typeof(Lookup<>).MakeGenericType(tb1), typeof(Lookup<>).GetField("t"));
10469                         TypeBuilder tb2 = module.DefineType("Bar");
10470                         ConstructorBuilder cb = tb2.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
10471                         ILGenerator ilgen = cb.GetILGenerator();
10472                         
10473                         ilgen.Emit(OpCodes.Ldarg_0);
10474                         ilgen.Emit(OpCodes.Call, tb2.BaseType.GetConstructor(Type.EmptyTypes));
10475
10476                         ilgen.Emit(OpCodes.Ldsfld, field);
10477                         ilgen.Emit(OpCodes.Pop);
10478                         ilgen.Emit(OpCodes.Ret);
10479                         Activator.CreateInstance(tb2.CreateType());
10480
10481                         Assert.IsTrue (Resolve1_Called);
10482                 }
10483
10484                 [Test]
10485                 public void CreateConcreteTypeWithAbstractMethod ()
10486                 {
10487                         TypeBuilder tb = module.DefineType (genTypeName ());
10488                         tb.DefineMethod("method", MethodAttributes.Abstract | MethodAttributes.Public, typeof (void), Type.EmptyTypes);
10489                         try {
10490                                 tb.CreateType ();
10491                                 Assert.Fail ("#1");
10492                         } catch (InvalidOperationException) {}
10493                 }
10494
10495                 [Test]
10496                 public void ConcreteTypeDontLeakGenericParamFromItSelf ()
10497                 {
10498             var tb = module.DefineType (genTypeName ());
10499                         var gps = tb.DefineGenericParameters ("T");
10500             var mb = tb.DefineMethod ("m", MethodAttributes.Public | MethodAttributes.Static);
10501             mb.SetParameters (gps);
10502             mb.GetILGenerator ().Emit (OpCodes.Ret);
10503
10504             var ti = tb.CreateType ();
10505             var mi = ti.GetMethod ("m");
10506                         var arg0 = mi.GetParameters () [0].ParameterType;
10507
10508                         Assert.AreNotSame (arg0, gps [0], "#1");
10509                 }
10510
10511                 [Test]
10512                 public void ConcreteTypeDontLeakGenericParamFromMethods ()
10513                 {
10514             var tb = module.DefineType (genTypeName ());
10515             var mb = tb.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Static);
10516             var gps = mb.DefineGenericParameters ("T");
10517             mb.SetParameters (gps);
10518             mb.GetILGenerator ().Emit (OpCodes.Ret);
10519
10520             var ti = tb.CreateType ();
10521             var mi = ti.GetMethod ("m");
10522                         var arg0 = mi.GetParameters () [0].ParameterType;
10523
10524                         Assert.AreNotSame (arg0, gps [0], "#1");
10525                 }
10526
10527                 [Test]
10528                 public void DeclaringMethodReturnsNull ()
10529                 {
10530                         TypeBuilder tb = module.DefineType (genTypeName ());
10531                         Assert.IsNull (tb.DeclaringMethod, null, "#1");
10532                 }
10533
10534                 [Test]
10535                 public void GenericParameterPositionReturns0 ()
10536                 {
10537                         TypeBuilder tb = module.DefineType (genTypeName ());
10538                         Assert.AreEqual (0, tb.GenericParameterPosition, "#1");
10539                 }
10540
10541                 [Test]
10542                 public void GetGenericTypeDefinitionBehavior ()
10543                 {
10544                         TypeBuilder tb = module.DefineType (genTypeName ());
10545                         try {
10546                                 tb.GetGenericTypeDefinition ();
10547                                 Assert.Fail ("#1");
10548                         } catch (InvalidOperationException) {}
10549
10550                         tb.DefineGenericParameters ("T");
10551                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#2");
10552
10553                         tb.CreateType ();
10554                         Assert.AreEqual (tb, tb.GetGenericTypeDefinition (), "#3");
10555                 }
10556
10557                 [Test]
10558                 public void GetElementTypeNotSupported ()
10559                 {
10560                         TypeBuilder tb = module.DefineType (genTypeName ());
10561                         try {
10562                                 tb.GetElementType ();
10563                                 Assert.Fail ("#1");
10564                         } catch (NotSupportedException) {}
10565                 }
10566
10567                 [Test]
10568                 public void GenericParameterAttributesReturnsNone ()
10569                 {
10570                         TypeBuilder tb = module.DefineType (genTypeName ());
10571                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#1");
10572
10573                         tb.DefineGenericParameters ("T");
10574                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#2");
10575
10576                         tb.CreateType ();
10577                         Assert.AreEqual (GenericParameterAttributes.None, tb.GenericParameterAttributes, "#3");
10578                 }
10579
10580                 [Test]
10581                 public void GetGenericArgumentsReturnsNullForNonGenericTypeBuilder ()
10582                 {
10583                         TypeBuilder tb = module.DefineType (genTypeName ());
10584                         Assert.IsNull (tb.GetGenericArguments (), "#1");
10585                 }
10586
10587                 public interface IFaceA {}
10588                 public interface IFaceB : IFaceA {}
10589                 [Test]
10590                 public void GetInterfacesAfterCreate ()
10591                 {
10592                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type[] { typeof (IFaceB) });
10593
10594                         Type[] ifaces = tb.GetInterfaces ();
10595                         Assert.AreEqual (1, ifaces.Length, "#1");
10596                         Assert.AreEqual (typeof (IFaceB), ifaces [0], "#2");
10597
10598                         tb.CreateType ();
10599                         ifaces = tb.GetInterfaces ();
10600                         Assert.AreEqual (2, ifaces.Length, "#3");
10601                         //Interfaces can come in any particular order
10602                         if (ifaces [0] == typeof (IFaceB)) {
10603                                 Assert.AreEqual (typeof (IFaceB), ifaces [0], "#4");
10604                                 Assert.AreEqual (typeof (IFaceA), ifaces [1], "#5");
10605                         } else {
10606                                 Assert.AreEqual (typeof (IFaceB), ifaces [1], "#4");
10607                                 Assert.AreEqual (typeof (IFaceA), ifaces [0], "#5");
10608                         }
10609                 }
10610
10611                 public interface MB_Iface
10612                 {
10613                     int Test ();
10614                 }
10615
10616                 public class MB_Impl : MB_Iface
10617                 {
10618                     public virtual int Test () { return 1; }
10619                 }
10620                 [Test]
10621                 public void MethodOverrideBodyMustBelongToTypeBuilder ()
10622                 {
10623                         TypeBuilder tb = module.DefineType (genTypeName ());
10624                         MethodInfo md = typeof (MB_Iface).GetMethod("Test");
10625             MethodInfo md2 = typeof (MB_Impl).GetMethod("Test");
10626                         try {
10627                 tb.DefineMethodOverride (md, md2);
10628                 Assert.Fail ("#1");
10629                         } catch (ArgumentException) {}
10630                 }
10631
10632                 [Test]
10633                 public void GetConstructorsThrowWhenIncomplete ()
10634                 {
10635                         TypeBuilder tb = module.DefineType (genTypeName ());
10636                         try {
10637                                 tb.GetConstructors (BindingFlags.Instance);
10638                                 Assert.Fail ("#1");
10639                         } catch (NotSupportedException) { }
10640
10641                         tb.CreateType ();
10642                         Assert.IsNotNull (tb.GetConstructors (BindingFlags.Instance), "#2");
10643                 }
10644
10645                 [Test]
10646                 public void GetEventsThrowWhenIncomplete ()
10647                 {
10648                         TypeBuilder tb = module.DefineType (genTypeName ());
10649                         try {
10650                                 tb.GetEvents (BindingFlags.Instance);
10651                                 Assert.Fail ("#1");
10652                         } catch (NotSupportedException) { }
10653
10654                         tb.CreateType ();
10655                         Assert.IsNotNull (tb.GetEvents (BindingFlags.Instance), "#2");
10656                 }
10657
10658                 [Test]
10659                 public void GetNestedTypeCreatedAfterTypeIsCreated ()
10660                 {
10661                         TypeBuilder tb = module.DefineType (genTypeName ());
10662                         TypeBuilder nested = tb.DefineNestedType ("Bar", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10663                         tb.CreateType ();
10664                         Assert.IsNull (tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#1");
10665                         Type res = nested.CreateType ();
10666                         Assert.AreEqual (res, tb.GetNestedType ("Bar", BindingFlags.NonPublic), "#2");
10667
10668                         TypeBuilder nested2 = tb.DefineNestedType ("Bar2", TypeAttributes.Class | TypeAttributes.NestedPrivate);
10669                         Assert.IsNull (tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#3");
10670                         res = nested2.CreateType ();
10671                         Assert.AreEqual (res, tb.GetNestedType ("Bar2", BindingFlags.NonPublic), "#4");
10672                 }
10673
10674
10675                 [Test]
10676                 public void IsDefinedThrowWhenIncomplete ()
10677                 {
10678                         TypeBuilder tb = module.DefineType (genTypeName ());
10679                         try {
10680                                 tb.IsDefined (typeof (string), true);
10681                                 Assert.Fail ("#1");
10682                         } catch (NotSupportedException) { }
10683
10684                         tb.CreateType ();
10685                         Assert.IsNotNull (tb.IsDefined (typeof (string), true), "#2");
10686                 }
10687
10688                 [Test] //Bug #594728
10689                 public void IsSubclassOfWorksIfSetParentIsCalledOnParent ()
10690                 {
10691                         var tb_a = module.DefineType ("A", TypeAttributes.Public);
10692                         var tb_b = module.DefineType ("B", TypeAttributes.Public);
10693         
10694                         tb_b.SetParent (tb_a);
10695                         tb_a.SetParent (typeof (Attribute));
10696         
10697                         Assert.IsTrue (tb_b.IsSubclassOf (tb_a), "#1");
10698                         Assert.IsTrue (tb_b.IsSubclassOf (typeof (Attribute)), "#2");
10699                         Assert.IsFalse (tb_a.IsSubclassOf (tb_b), "#3");
10700         
10701         
10702                         var a = tb_a.CreateType ();
10703                         var b = tb_b.CreateType ();
10704         
10705                         Assert.IsTrue (b.IsSubclassOf (a), "#4");
10706                         Assert.IsTrue (b.IsSubclassOf (typeof (Attribute)), "#5");
10707                         Assert.IsFalse (a.IsSubclassOf (b), "#6");
10708                 }
10709
10710                 [Test]
10711                 public void DefinedDefaultConstructorWorksWithGenericBaseType ()
10712                 {
10713                         AssemblyName assemblyName = new AssemblyName ("a");
10714                         AssemblyBuilder ass = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.RunAndSave);
10715                         var mb = ass.DefineDynamicModule ("a.dll");
10716
10717                         var tb = mb.DefineType ("Base");
10718                         tb.DefineGenericParameters ("F");
10719
10720                         var inst = tb.MakeGenericType (typeof (int));
10721                         var tb2 = mb.DefineType ("Child", TypeAttributes.Public, inst);
10722
10723                         tb.CreateType ();
10724                         var res = tb2.CreateType ();
10725
10726                         Assert.IsNotNull (res, "#1");
10727                         Assert.AreEqual (1, res.GetConstructors ().Length, "#2");
10728                 }
10729
10730                 /* 
10731                  * Tests for passing user types to Ref.Emit. Currently these only test
10732                  * whenever the runtime code can handle them without crashing, since we
10733                  * don't support user types yet.
10734                  * These tests are disabled for windows since the MS runtime trips on them.
10735                  */
10736                 [Test]
10737                 [Category ("NotDotNet")] //Proper UT handling is a mono extension to SRE bugginess
10738                 public void UserTypes () {
10739                         TypeDelegator t = new TypeDelegator (typeof (int));
10740
10741                         try {
10742                                 /* Parent */
10743                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10744                         } catch {
10745                         }
10746
10747                         try {
10748                                 /* Interfaces */
10749                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10750                                 tb.CreateType ();
10751                         } catch {
10752                         }
10753
10754                         try {
10755                                 /* Fields */
10756                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10757                                 tb.DefineField ("Foo", t, FieldAttributes.Public);
10758                                 tb.CreateType ();
10759                         } catch {
10760                         }
10761
10762                         try {
10763                                 /* Custom modifiers on fields */
10764                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10765                                 tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10766                                 tb.CreateType ();
10767                         } catch {
10768                         }
10769 /* this is mono only
10770                         try {
10771                                 UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10772                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10773                                 FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10774                                 fb.SetMarshal (m);
10775                                 tb.CreateType ();
10776                         } catch {
10777                         }
10778 */
10779                         try {
10780                                 /* Properties */
10781                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10782                                 tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10783                                 tb.CreateType ();
10784                         } catch {
10785                         }
10786
10787                         try {
10788                                 /* Custom modifiers on properties */
10789                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10790                                 // FIXME: These seems to be ignored
10791                                 tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10792                                 tb.CreateType ();
10793                         } catch {
10794                         }
10795
10796                         try {
10797                                 /* Method return types */
10798                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10799                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10800                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10801                                 tb.CreateType ();
10802                         } catch {
10803                         }
10804
10805                         try {
10806                                 /* Custom modifiers on method return types */
10807                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10808                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10809                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10810                                 tb.CreateType ();
10811                         } catch {
10812                         }
10813
10814                         try {
10815                                 /* Method parameters */
10816                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10817                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10818                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10819                                 tb.CreateType ();
10820                         } catch {
10821                         }
10822
10823                         try {
10824                                 /* Custom modifiers on method parameters */
10825                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10826                                 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 }});
10827                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10828                                 tb.CreateType ();
10829                         } catch {
10830                         }
10831
10832                         try {
10833                                 /* Ctor parameters */
10834                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10835                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10836                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10837                                 tb.CreateType ();
10838                         } catch {
10839                         }
10840                         
10841                         try {
10842                                 /* Custom modifiers on ctor parameters */
10843                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10844                                 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10845                                 mb.GetILGenerator ().Emit (OpCodes.Ret);
10846                                 tb.CreateType ();
10847                         } catch {
10848                         }
10849
10850                         try {
10851                                 /* SignatureHelper arguments */
10852                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10853                                 sighelper.AddArgument (t, false);
10854                                 byte[] arr = sighelper.GetSignature ();
10855                         } catch {
10856                         }
10857
10858                         try {
10859                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10860                                 sighelper.AddArgument (t, false);
10861                                 byte[] arr = sighelper.GetSignature ();
10862                         } catch {
10863                         }
10864
10865                         try {
10866                                 /* Custom modifiers on SignatureHelper arguments */
10867                                 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10868                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10869                                 byte[] arr = sighelper.GetSignature ();
10870                         } catch {
10871                         }
10872
10873                         try {
10874                                 /* Custom modifiers on SignatureHelper arguments */
10875                                 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10876                                 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10877                                 byte[] arr = sighelper.GetSignature ();
10878                         } catch {
10879                         }
10880
10881                         /* Arguments to ILGenerator methods */
10882                         try {
10883                                 /* Emit () */
10884                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10885                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10886                                 ILGenerator ig = mb.GetILGenerator ();
10887                                 ig.Emit (OpCodes.Ldnull);
10888                                 ig.Emit (OpCodes.Castclass, t);
10889                                 ig.Emit (OpCodes.Pop);
10890                                 ig.Emit (OpCodes.Ret);
10891                                 tb.CreateType ();
10892                         } catch {
10893                         }
10894
10895                         try {
10896                                 /* DeclareLocal () */
10897                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10898                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10899                                 ILGenerator ig = mb.GetILGenerator ();
10900                                 ig.DeclareLocal (t);
10901                                 ig.Emit (OpCodes.Ret);
10902                                 tb.CreateType ();
10903                         } catch {
10904                         }
10905
10906                         try {
10907                                 /* BeginExceptionCatchBlock () */
10908                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10909                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10910                                 ILGenerator ig = mb.GetILGenerator ();
10911                                 ig.BeginExceptionBlock ();
10912                                 ig.BeginCatchBlock (t);
10913                                 ig.Emit (OpCodes.Ret);
10914                                 tb.CreateType ();
10915                         } catch {
10916                         }
10917
10918                         try {
10919                                 /* EmitCalli () */
10920                                 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10921                                 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10922                                 ILGenerator ig = mb.GetILGenerator ();
10923                                 ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
10924                                 ig.Emit (OpCodes.Ret);
10925                                 tb.CreateType ();
10926                         } catch {
10927                         }
10928                 }
10929
10930                 //Test for #572660
10931         [Test]
10932         [Category ("MobileNotWorking")] // Mono.CompilerServices.SymbolWriter not available in XA
10933         public void CircularArrayType()
10934         {
10935                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndSave);
10936                         var moduleBuilder = assemblyBuilder.DefineDynamicModule("Test", "Test.dll", true);
10937                         var typeBuilder = moduleBuilder.DefineType("Foo", TypeAttributes.Public);
10938                         var fieldBuilder = typeBuilder.DefineField("Foos", typeBuilder.MakeArrayType(), FieldAttributes.Public);
10939
10940                         var fooType = typeBuilder.CreateType();
10941                         Assert.AreSame(fooType.MakeArrayType(), fooType.GetField("Foos").FieldType);
10942         }
10943
10944
10945                 [Test] //Test for #422113
10946                 [ExpectedException (typeof (TypeLoadException))]
10947                 public void CreateInstanceOfIncompleteType ()
10948                 {
10949                         TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class, null, new Type[] { typeof (IComparable) });
10950                         Type proxyType = tb.CreateType();
10951                         Activator.CreateInstance(proxyType);
10952                 }
10953
10954                 [Test] //Test for #640780
10955                 public void StaticMethodNotUsedInIfaceVtable ()
10956                 {
10957                         TypeBuilder tb1 = module.DefineType("Interface", TypeAttributes.Interface | TypeAttributes.Abstract);
10958                         tb1.DefineTypeInitializer().GetILGenerator().Emit(OpCodes.Ret);
10959                         tb1.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract);
10960                         tb1.CreateType();
10961                         
10962                         TypeBuilder tb2 = module.DefineType("Class", TypeAttributes.Sealed);
10963                         tb2.AddInterfaceImplementation(tb1);
10964                         tb2.DefineMethod("m", MethodAttributes.Public | MethodAttributes.Virtual)
10965                             .GetILGenerator().Emit(OpCodes.Ret);
10966                         tb2.DefineDefaultConstructor(MethodAttributes.Public);
10967                         
10968                         Activator.CreateInstance(tb2.CreateType());
10969                 }
10970
10971                 [Test] //Test for #648391
10972                 public void GetConstructorCheckCtorDeclaringType ()
10973                 {
10974                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10975                         string[] typeParamNames = { "TFirst" };
10976                         GenericTypeParameterBuilder[] typeParams = myType.DefineGenericParameters (typeParamNames);
10977                         var ctor = myType.DefineDefaultConstructor (MethodAttributes.Public);
10978                         var ctori = TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (int)), ctor);
10979                         try {
10980                                 TypeBuilder.GetConstructor (myType.MakeGenericType (typeof (bool)), ctori);
10981                                 Assert.Fail ("#1");
10982                         } catch (ArgumentException) {
10983                                 //OK
10984                         }
10985                 }
10986
10987                 [Test] //Test for #649237
10988                 public void GetFieldCheckFieldDeclaringType () {
10989                         TypeBuilder myType = module.DefineType ("Sample", TypeAttributes.Public);
10990                         myType.DefineGenericParameters ( "TFirst");
10991                         TypeBuilder otherType = module.DefineType ("Sample2", TypeAttributes.Public);
10992                         otherType.DefineGenericParameters ( "TFirst");
10993
10994                         var field = myType.DefineField ("field", typeof (object), FieldAttributes.Public);
10995
10996                         try {
10997                                 TypeBuilder.GetField (otherType.MakeGenericType (typeof (int)), field);
10998                                 Assert.Fail ("#1");
10999                         } catch (ArgumentException) {
11000                                 //OK
11001                         }
11002                 }
11003
11004                 [Test]
11005                 public void TypeWithFieldRVAWorksUnderSgen () {
11006                 AssemblyName an = new AssemblyName("MAIN");
11007                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an,
11008                     AssemblyBuilderAccess.Run, ".");
11009                 ModuleBuilder mob = ab.DefineDynamicModule("MAIN");
11010                 TypeBuilder tb = mob.DefineType("MAIN", TypeAttributes.Public |
11011                     TypeAttributes.Sealed | TypeAttributes.Abstract |
11012                     TypeAttributes.Class | TypeAttributes.BeforeFieldInit);
11013
11014                 byte[] source = new byte[] { 42 };
11015                 FieldBuilder fb = tb.DefineInitializedData("A0", source, 0);
11016
11017                 MethodBuilder mb = tb.DefineMethod("EVAL", MethodAttributes.Static |
11018                     MethodAttributes.Public, typeof(byte[]), new Type[] { });
11019                 ILGenerator il = mb.GetILGenerator();
11020
11021                 il.Emit(OpCodes.Ldc_I4_1);
11022                 il.Emit(OpCodes.Newarr, typeof(byte));
11023                 il.Emit(OpCodes.Dup);
11024                 il.Emit(OpCodes.Ldtoken, fb);
11025                 il.Emit(OpCodes.Call, typeof(RuntimeHelpers).GetMethod("InitializeArray"));
11026                 il.Emit(OpCodes.Ret);
11027
11028                 Type t = tb.CreateType();
11029
11030                 GC.Collect();
11031
11032                 byte[] res = (byte[]) t.InvokeMember("EVAL", BindingFlags.Public |
11033                     BindingFlags.Static | BindingFlags.InvokeMethod, null, null,
11034                     new object[] { });
11035
11036                 Assert.AreEqual (42, res[0]);
11037             }
11038
11039
11040                 [Test]
11041                 public void Ldfld_Regress_9531 () {
11042                         Build<Example<int>> ();
11043                 }
11044
11045                 void Build<T> () {
11046             var base_class = typeof(T);
11047
11048             var builder = module.DefineType(genTypeName (),
11049                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11050                 base_class);
11051
11052             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11053             
11054             var cb = builder.DefineConstructor(
11055                 MethodAttributes.Public | MethodAttributes.SpecialName,
11056                 CallingConventions.HasThis,
11057                 new[] { typeof(string) });
11058             
11059             var il = cb.GetILGenerator();
11060             
11061             if (field == null)
11062             {
11063                 throw new InvalidOperationException("wtf");
11064             }
11065             
11066             il.Emit(OpCodes.Ldarg_0);
11067             il.Emit(OpCodes.Ldarg_1);
11068             il.Emit(OpCodes.Stfld, field);
11069             il.Emit(OpCodes.Ret);
11070             
11071             builder.CreateType();
11072                 }
11073
11074                 public class Example<T> {
11075                         public string Field;
11076                         public T Field2;
11077                 }
11078
11079                 [Test]
11080                 [Category ("AndroidNotWorking")]
11081                 // It's not possible to save the assembly in the current directory on Android and AssemblyBuilder.DefineDynamicModule will not
11082                 // allow a full path to the assembly to be passed to it. Trying to change the current directory before saving will not work either as
11083                 // FileStream will then prepend / to the file name (perhaps it's another bug) and write access to the filesystem root is, obviously, denied
11084                 public void Ldfld_Encoding_10122 () {
11085                         Build2<Example<int>> ();
11086                 }
11087
11088                 void Build2<T> () {
11089                         var base_class = typeof(T);
11090
11091                 string AssemblyName = genTypeName ();
11092                 string AssemblyFileName = AssemblyName + ".dll";
11093
11094                         var assemblyBuilderAccess = AssemblyBuilderAccess.Save;
11095                         var assemblyName = new AssemblyName(AssemblyName);
11096                         var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
11097                         var moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName, AssemblyFileName);
11098
11099
11100                         var builder = moduleBuilder.DefineType("Wrapped",
11101                 TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
11102                 base_class);
11103
11104             var field = builder.BaseType.GetField("Field", BindingFlags.Instance | BindingFlags.Public);
11105             
11106             var cb = builder.DefineConstructor(
11107                 MethodAttributes.Public | MethodAttributes.SpecialName,
11108                 CallingConventions.HasThis,
11109                 new[] { typeof(string) });
11110             
11111             var il = cb.GetILGenerator();
11112             
11113             if (field == null)
11114             {
11115                 throw new InvalidOperationException("wtf");
11116             }
11117             
11118             il.Emit(OpCodes.Ldarg_0);
11119             il.Emit(OpCodes.Ldarg_1);
11120             il.Emit(OpCodes.Stfld, field);
11121             il.Emit(OpCodes.Ret);
11122             
11123             builder.CreateType();
11124
11125                         assemblyBuilder.Save (AssemblyFileName);
11126
11127                         var fromDisk = Assembly.Load (AssemblyName);
11128                         Console.WriteLine (fromDisk);
11129                         var t = fromDisk.GetType ("Wrapped");
11130                         Activator.CreateInstance (t, new object[] { "string"});
11131                 }
11132
11133                 public interface IFace16096 {
11134                         object Bar ();
11135                 }
11136
11137                 [Test]
11138                 public void MemberRef_Caching_16096 () {
11139                         var outer_class = module.DefineType(
11140                                 "container",
11141                                 TypeAttributes.Class | TypeAttributes.Public,
11142                                 typeof(object));
11143
11144                         var builder = outer_class.DefineNestedType(
11145                                 "bind@32-1",
11146                                 TypeAttributes.Class | TypeAttributes.Public,
11147                                 typeof(object));
11148
11149                         builder.AddInterfaceImplementation (typeof (IFace16096));
11150
11151                         var ctor = builder.DefineDefaultConstructor (MethodAttributes.Public);
11152                         var field = builder.DefineField ("Field", typeof (object), FieldAttributes.Public);
11153                         var g_args = builder.DefineGenericParameters("b","a");
11154                         var method = builder.DefineMethod ("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof (object), new Type [0]);
11155
11156                         var il = method.GetILGenerator();
11157                         il.Emit (OpCodes.Ldarg_0);
11158                         il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (builder.MakeGenericType (g_args), field));
11159                         il.Emit (OpCodes.Pop);
11160                         il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (builder.MakeGenericType (g_args), ctor));
11161                         il.Emit (OpCodes.Ret);
11162
11163                         var type = builder.CreateType ();
11164
11165                         /*Build a gshared instance. */
11166                         var ginst = type.MakeGenericType (typeof (List<char>), typeof (object));
11167                         var ins = (IFace16096)Activator.CreateInstance (ginst);
11168
11169                         /* This will trigger the runtime to cache the MEMBER_REF to the .ctor as it won't have a context. */
11170                         var ins2 = ins.Bar ();
11171                         Assert.IsNotNull (ins2);
11172
11173                         /* Build an unsharable version. */
11174                         var ginst2 = type.MakeGenericType (typeof (List<char>), typeof (char));
11175                         var ins3 = (IFace16096)Activator.CreateInstance (ginst2);
11176
11177                         /* This will trigger the runtime to use the cached version, which is wrong as it's an open type. */
11178                         var ins4 = ins3.Bar ();
11179                         Assert.IsNotNull (ins4);
11180                 }
11181
11182                 // #22059
11183                 [Test]
11184                 [ExpectedException (typeof (TypeLoadException))]
11185                 public void PrivateIface ()
11186                 {
11187                         TypeBuilder tb = module.DefineType ("Sample", TypeAttributes.Public, typeof (object), new[] { typeof (IFoo) });
11188             tb.CreateType();
11189                 }
11190
11191                 interface IFoo {
11192                 }
11193         }
11194 }