2009-02-23 Zoltan Varga <vargaz@gmail.com>
[mcs.git] / class / corlib / Test / System.Reflection.Emit / TypeBuilderTest.cs
blobc336f6b95251d948af37d19bbdab6e05ada56667
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
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;
28 #if NET_2_0
29 using System.Collections.Generic;
30 #endif
32 namespace MonoTests.System.Reflection.Emit
34 public interface EmptyInterface
38 public interface OneMethodInterface
40 void foo ();
43 public class SimpleTestAttribute : Attribute
46 public class EmptyIfaceImpl : EmptyInterface
50 #if NET_2_0
51 public class Gen<T> {
52 public static T field = default(T);
54 #endif
56 [TestFixture]
57 public class TypeBuilderTest
59 private interface AnInterface
63 public interface Foo
67 public interface Bar : Foo
71 public interface Baz : Bar
75 public interface IMoveable
79 public interface IThrowable : IMoveable
83 public interface ILiquid
87 public interface IWater : ILiquid
91 public interface IAir
95 public interface IDestroyable
98 #if NET_2_0
100 public class Tuple <A,B> {
101 A a;
102 B b;
104 #endif
106 private AssemblyBuilder assembly;
108 private ModuleBuilder module;
110 static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
112 [SetUp]
113 protected void SetUp ()
115 AssemblyName assemblyName = new AssemblyName ();
116 assemblyName.Name = ASSEMBLY_NAME;
118 assembly =
119 Thread.GetDomain ().DefineDynamicAssembly (
120 assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
122 module = assembly.DefineDynamicModule ("module1");
125 static int typeIndexer = 0;
127 // Return a unique type name
128 private string genTypeName ()
130 return "t" + (typeIndexer++);
133 private string nullName ()
135 return String.Format ("{0}", (char) 0);
138 [Test]
139 public void TestAssembly ()
141 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
142 Assert.AreEqual (assembly, tb.Assembly);
145 [Test]
146 public void TestAssemblyQualifiedName ()
148 TypeBuilder tb = module.DefineType ("A.B.C.D", TypeAttributes.Public);
149 Assert.AreEqual ("A.B.C.D, " + assembly.GetName ().FullName,
150 tb.AssemblyQualifiedName);
153 [Test]
154 public void TestAttributes ()
156 TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
157 TypeBuilder tb = module.DefineType (genTypeName (), attrs);
158 Assert.AreEqual (attrs, tb.Attributes);
161 [Test]
162 public void TestBaseTypeClass ()
164 TypeAttributes attrs = TypeAttributes.Public;
165 TypeBuilder tb = module.DefineType (genTypeName (), attrs);
166 Assert.AreEqual (typeof (object), tb.BaseType, "#1");
168 TypeBuilder tb2 = module.DefineType (genTypeName (), attrs, tb);
169 Assert.AreEqual (tb, tb2.BaseType, "#2");
172 [Test] // bug #71301
173 public void TestBaseTypeInterface ()
175 TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
176 Assert.IsNull (tb3.BaseType);
179 [Test]
180 public void TestDeclaringType ()
182 TypeAttributes attrs = 0;
183 TypeBuilder tb = module.DefineType (genTypeName (), attrs);
184 Assert.IsNull (tb.DeclaringType, "#1");
186 attrs = TypeAttributes.NestedPublic;
187 TypeBuilder tb2 = tb.DefineNestedType (genTypeName (), attrs);
188 TypeBuilder tb3 = tb2.DefineNestedType (genTypeName (), attrs);
189 Assert.AreEqual (tb3.DeclaringType.DeclaringType, tb, "#2");
192 [Test]
193 public void TestFullName ()
195 string name = genTypeName ();
196 TypeAttributes attrs = 0;
197 TypeBuilder tb = module.DefineType (name, attrs);
198 Assert.AreEqual (name, tb.FullName, "#1");
200 string name2 = genTypeName ();
201 attrs = TypeAttributes.NestedPublic;
202 TypeBuilder tb2 = tb.DefineNestedType (name2, attrs);
204 string name3 = genTypeName ();
205 attrs = TypeAttributes.NestedPublic;
206 TypeBuilder tb3 = tb2.DefineNestedType (name3, attrs);
208 Assert.AreEqual (name + "+" + name2 + "+" + name3, tb3.FullName, "#2");
211 [Test]
212 public void DefineCtorUsingDefineMethod ()
214 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Class);
215 MethodBuilder mb = tb.DefineMethod(
216 ".ctor", MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
217 null, null);
218 ILGenerator ilgen = mb.GetILGenerator();
219 ilgen.Emit(OpCodes.Ldarg_0);
220 ilgen.Emit(OpCodes.Call,
221 typeof(object).GetConstructor(Type.EmptyTypes));
222 ilgen.Emit(OpCodes.Ret);
223 Type t = tb.CreateType();
225 Assert.AreEqual (1, t.GetConstructors ().Length);
228 [Test]
229 public void TestGUIDIncomplete ()
231 TypeBuilder tb = module.DefineType (genTypeName ());
232 try {
233 Guid g = tb.GUID;
234 Assert.Fail ("#1");
235 } catch (NotSupportedException ex) {
236 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
237 Assert.IsNull (ex.InnerException, "#3");
238 Assert.IsNotNull (ex.Message, "#4");
242 [Test] // bug #71302
243 [Category ("NotWorking")]
244 public void TestGUIDComplete ()
246 TypeBuilder tb = module.DefineType (genTypeName ());
247 tb.CreateType ();
248 Assert.IsTrue (tb.GUID != Guid.Empty);
251 [Test]
252 [Category ("NotWorking")]
253 public void TestFixedGUIDComplete ()
255 TypeBuilder tb = module.DefineType (genTypeName ());
257 Guid guid = Guid.NewGuid ();
259 ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
260 new Type [] { typeof (string) });
262 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
263 new object [] { guid.ToString ("D") }, new FieldInfo [0], new object [0]);
265 tb.SetCustomAttribute (caBuilder);
266 tb.CreateType ();
267 Assert.AreEqual (guid, tb.GUID);
270 [Test]
271 public void TestHasElementType_Incomplete ()
273 // According to the MSDN docs, this member works, but in reality, it
274 // returns a NotSupportedException
275 TypeBuilder tb = module.DefineType (genTypeName ());
276 #if NET_2_0
277 Assert.IsFalse (tb.HasElementType);
278 #else
279 try {
280 bool b = tb.HasElementType;
281 Assert.Fail ("#1: " + b);
282 } catch (NotSupportedException ex) {
283 // The invoked member is not supported in a
284 // dynamic module
285 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
286 Assert.IsNull (ex.InnerException, "#3");
287 Assert.IsNotNull (ex.Message, "#4");
289 #endif
292 [Test]
293 #if ONLY_1_1
294 [Category ("NotWorking")]
295 #endif
296 public void TestHasElementType_Complete ()
298 // According to the MSDN docs, this member works, but in reality, it
299 // returns a NotSupportedException
300 TypeBuilder tb = module.DefineType (genTypeName ());
301 tb.CreateType ();
302 #if NET_2_0
303 Assert.IsFalse (tb.HasElementType);
304 #else
305 try {
306 bool b = tb.HasElementType;
307 Assert.Fail ("#1: " + b);
308 } catch (NotSupportedException ex) {
309 // The invoked member is not supported in a
310 // dynamic module
311 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
312 Assert.IsNull (ex.InnerException, "#3");
313 Assert.IsNotNull (ex.Message, "#4");
315 #endif
318 [Test] // bug #324692
319 public void CreateType_Enum_NoInstanceField ()
321 TypeBuilder tb = module.DefineType (genTypeName (),
322 TypeAttributes.Sealed | TypeAttributes.Serializable,
323 typeof (Enum));
325 try {
326 tb.CreateType ();
327 Assert.Fail ("#1: must throw TypeLoadException");
328 } catch (TypeLoadException) {
331 #if NET_2_0
332 //Assert.IsTrue (tb.IsCreated (), "#2");
333 #endif
336 [Test] // bug #324692
337 #if ONLY_1_1
338 [Category ("NotWorking")] // we do not throw IOE when repeatedly invoking CreateType
339 #endif
340 public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
342 TypeBuilder tb = module.DefineType (genTypeName (),
343 TypeAttributes.Sealed | TypeAttributes.Serializable,
344 typeof (Enum));
346 try {
347 tb.CreateType ();
348 Assert.Fail ("#A1");
349 } catch (TypeLoadException ex) {
350 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
351 Assert.IsNull (ex.InnerException, "#A3");
352 Assert.IsNotNull (ex.Message, "#A4");
355 #if NET_2_0
356 //Assert.IsTrue (tb.IsCreated (), "#B1");
357 Assert.IsNull (tb.CreateType (), "#B2");
358 //Assert.IsTrue (tb.IsCreated (), "#B3");
359 #else
360 try {
361 tb.CreateType ();
362 Assert.Fail ("#B1");
363 } catch (InvalidOperationException ex) {
364 // Unable to change after type has been created
365 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
366 Assert.IsNull (ex.InnerException, "#B3");
367 Assert.IsNotNull (ex.Message, "#B4");
369 #endif
372 [Test]
373 public void TestEnumWithEmptyInterfaceBuildsOk ()
375 TypeBuilder tb = module.DefineType (genTypeName (),
376 TypeAttributes.Sealed | TypeAttributes.Serializable,
377 typeof (Enum));
378 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
379 FieldAttributes.Private | FieldAttributes.RTSpecialName);
381 tb.AddInterfaceImplementation (typeof (EmptyInterface));
383 try {
384 tb.CreateType ();
385 } catch (TypeLoadException) {
386 Assert.Fail ("#1: must build enum type ok");
389 #if NET_2_0
390 Assert.IsTrue (tb.IsCreated (), "#2");
391 #endif
394 [Test]
395 [Category ("NotWorking")]
396 public void TestEnumWithNonEmptyInterfaceBuildsFails ()
398 TypeBuilder tb = module.DefineType (genTypeName (),
399 TypeAttributes.Sealed | TypeAttributes.Serializable,
400 typeof (Enum));
401 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
402 FieldAttributes.Private | FieldAttributes.RTSpecialName);
404 tb.AddInterfaceImplementation (typeof (OneMethodInterface));
406 try {
407 tb.CreateType ();
408 Assert.Fail ("#1: type doesn't have all interface methods");
409 } catch (TypeLoadException) {
412 #if NET_2_0
413 Assert.IsTrue (tb.IsCreated (), "#2");
414 #endif
417 [Test]
418 [Category ("NotWorking")]
419 public void TestTypeDontImplementInterfaceMethodBuildsFails ()
421 TypeBuilder tb = module.DefineType (genTypeName (),
422 TypeAttributes.Sealed | TypeAttributes.Serializable,
423 typeof (object));
425 tb.AddInterfaceImplementation (typeof (OneMethodInterface));
427 try {
428 tb.CreateType ();
429 Assert.Fail ("#1: type doesn't have all interface methods");
430 } catch (TypeLoadException) {
433 #if NET_2_0
434 Assert.IsTrue (tb.IsCreated (), "#2");
435 #endif
438 [Test]
439 public void TestEnumWithSequentialLayoutBuildsFails ()
441 TypeBuilder tb = module.DefineType (genTypeName (),
442 TypeAttributes.Sealed | TypeAttributes.Serializable |
443 TypeAttributes.SequentialLayout, typeof (Enum));
444 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
445 FieldAttributes.Private | FieldAttributes.RTSpecialName);
447 try {
448 tb.CreateType ();
449 Assert.Fail ("#1: type doesn't have all interface methods");
450 } catch (TypeLoadException) {
453 #if NET_2_0
454 //Assert.IsTrue (tb.IsCreated (), "#2");
455 #endif
458 [Test]
459 public void TestEnumWithExplicitLayoutBuildsFails ()
461 TypeBuilder tb = module.DefineType (genTypeName (),
462 TypeAttributes.Sealed | TypeAttributes.Serializable |
463 TypeAttributes.ExplicitLayout, typeof (Enum));
464 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
465 FieldAttributes.Private | FieldAttributes.RTSpecialName);
467 try {
468 tb.CreateType ();
469 Assert.Fail ("#1: type doesn't have all interface methods");
470 } catch (TypeLoadException) {
473 #if NET_2_0
474 //Assert.IsTrue (tb.IsCreated (), "#2");
475 #endif
478 [Test]
479 public void TestEnumWithMethodsBuildFails ()
481 TypeBuilder tb = module.DefineType ("FooEnum7",
482 TypeAttributes.Sealed | TypeAttributes.Serializable,
483 typeof (Enum));
484 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
485 FieldAttributes.Private | FieldAttributes.RTSpecialName);
487 MethodBuilder methodBuilder = tb.DefineMethod("mmm",
488 MethodAttributes.Public | MethodAttributes.Virtual,
489 null,
490 new Type[] { });
492 methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
493 try {
494 tb.CreateType ();
495 Assert.Fail ("#1: enum has method");
496 } catch (TypeLoadException) {
499 #if NET_2_0
500 //Assert.IsTrue (tb.IsCreated (), "#2");
501 #endif
504 [Test]
505 public void TestEnumWithBadTypeValueFieldBuildFails ()
507 Type[] badTypes = {
508 typeof (object),
509 typeof (string),
510 typeof (DateTime)
513 foreach (Type type in badTypes) {
514 TypeBuilder tb = module.DefineType (genTypeName (),
515 TypeAttributes.Sealed | TypeAttributes.Serializable,
516 typeof (Enum));
517 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
518 FieldAttributes.Private | FieldAttributes.RTSpecialName);
520 try {
521 tb.CreateType ();
522 Assert.Fail ("#1: enum using bad type: " + type);
523 } catch (TypeLoadException) {
526 #if NET_2_0
527 //Assert.IsTrue (tb.IsCreated (), "#2");
528 #endif
532 [Test]
533 public void TestEnumWithGoodTypeValueFieldBuildOk ()
535 Type[] goodTypes = {
536 typeof (byte),typeof (sbyte),typeof (bool),
537 typeof (ushort),typeof (short),typeof (char),
538 typeof (uint),typeof (int),
539 typeof (ulong),typeof (long),
540 typeof (UIntPtr),typeof (IntPtr),
543 foreach (Type type in goodTypes) {
544 TypeBuilder tb = module.DefineType (genTypeName (),
545 TypeAttributes.Sealed | TypeAttributes.Serializable,
546 typeof (Enum));
547 tb.DefineField ("value__", type, FieldAttributes.SpecialName |
548 FieldAttributes.Private | FieldAttributes.RTSpecialName);
550 try {
551 tb.CreateType ();
552 } catch (TypeLoadException) {
553 Assert.Fail ("#1: enum using good type: " + type);
558 [Test]
559 public void TestEnumWithMultipleValueFieldsBuildFals ()
561 TypeBuilder tb = module.DefineType (genTypeName (),
562 TypeAttributes.Sealed | TypeAttributes.Serializable,
563 typeof (Enum));
564 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
565 FieldAttributes.Private | FieldAttributes.RTSpecialName);
566 tb.DefineField ("value2__", typeof (int), FieldAttributes.SpecialName |
567 FieldAttributes.Private | FieldAttributes.RTSpecialName);
569 try {
570 tb.CreateType ();
571 Assert.Fail ("#1: invalid enum type");
572 } catch (TypeLoadException) {
575 #if NET_2_0
576 //Assert.IsTrue (tb.IsCreated (), "#2");
577 #endif
580 [Test]
581 [Category ("NotWorking")]
582 public void TestEnumWithEmptyInterfaceCanBeCasted ()
584 TypeBuilder tb = module.DefineType (genTypeName (),
585 TypeAttributes.Sealed | TypeAttributes.Serializable,
586 typeof (Enum));
587 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
588 FieldAttributes.Private | FieldAttributes.RTSpecialName);
589 tb.AddInterfaceImplementation (typeof (EmptyInterface));
591 try {
592 tb.CreateType ();
593 } catch (TypeLoadException) {
594 Assert.Fail ("#1: must build enum type ok");
597 try {
598 EmptyInterface obj = (EmptyInterface) Activator.CreateInstance (tb);
599 Assert.IsNotNull (obj, "#2");
600 } catch (TypeLoadException) {
601 Assert.Fail ("#3: must cast enum to interface");
605 [Test]
606 public void TestEnumWithValueFieldBuildOk ()
608 TypeBuilder tb = module.DefineType (genTypeName (),
609 TypeAttributes.Sealed | TypeAttributes.Serializable,
610 typeof (Enum));
611 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
612 FieldAttributes.Private | FieldAttributes.RTSpecialName);
614 try {
615 tb.CreateType ();
616 } catch (TypeLoadException) {
617 Assert.Fail ("#1: must build enum type ok");
621 [Test]
622 public void TestIsAbstract ()
624 TypeBuilder tb = module.DefineType (genTypeName ());
625 Assert.IsFalse (tb.IsAbstract, "#1");
627 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Abstract);
628 Assert.IsTrue (tb2.IsAbstract, "#2");
631 [Test]
632 public void TestIsAnsiClass ()
634 TypeBuilder tb = module.DefineType (genTypeName ());
635 Assert.IsTrue (tb.IsAnsiClass, "#1");
637 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
638 Assert.IsFalse (tb2.IsAnsiClass, "#2");
641 [Test]
642 public void TestIsArray ()
644 // How can a TypeBuilder be an array ?
645 string name = genTypeName ();
646 TypeBuilder tb = module.DefineType (name);
647 Assert.IsFalse (tb.IsArray);
650 [Test]
651 public void TestIsAutoClass ()
653 TypeBuilder tb = module.DefineType (genTypeName ());
654 Assert.IsFalse (tb.IsAutoClass, "#1");
656 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.AutoClass);
657 Assert.IsTrue (tb2.IsAutoClass, "#2");
660 [Test]
661 public void TestIsAutoLayout ()
663 TypeBuilder tb = module.DefineType (genTypeName ());
664 Assert.IsTrue (tb.IsAutoLayout, "#1");
666 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
667 Assert.IsFalse (tb2.IsAutoLayout, "#2");
670 [Test]
671 public void TestIsByRef ()
673 // How can a TypeBuilder be ByRef ?
674 TypeBuilder tb = module.DefineType (genTypeName ());
675 Assert.IsFalse (tb.IsByRef);
678 [Test]
679 public void TestIsClass ()
681 TypeBuilder tb = module.DefineType (genTypeName ());
682 Assert.IsTrue (tb.IsClass, "#1");
684 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
685 Assert.IsFalse (tb2.IsClass, "#2");
687 TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
688 Assert.IsFalse (tb3.IsClass, "#3");
690 TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
691 Assert.IsFalse (tb4.IsClass, "#4");
694 [Test] // bug #71304
695 public void TestIsCOMObject ()
697 TypeBuilder tb = module.DefineType (genTypeName ());
698 Assert.IsFalse (tb.IsCOMObject, "#1");
700 tb = module.DefineType (genTypeName (), TypeAttributes.Import);
701 Assert.IsTrue (tb.IsCOMObject, "#2");
704 [Test]
705 public void TestIsContextful ()
707 TypeBuilder tb = module.DefineType (genTypeName ());
708 Assert.IsFalse (tb.IsContextful, "#1");
710 TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
711 Assert.IsTrue (tb2.IsContextful, "#2");
714 [Test]
715 public void TestIsEnum ()
717 TypeBuilder tb = module.DefineType (genTypeName ());
718 Assert.IsFalse (tb.IsEnum, "#1");
720 TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (ValueType));
721 Assert.IsFalse (tb2.IsEnum, "#2");
723 TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (Enum));
724 Assert.IsTrue (tb3.IsEnum, "#3");
727 [Test]
728 public void TestIsExplicitLayout ()
730 TypeBuilder tb = module.DefineType (genTypeName ());
731 Assert.IsFalse (tb.IsExplicitLayout, "#1");
733 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.ExplicitLayout);
734 Assert.IsTrue (tb2.IsExplicitLayout, "#2");
737 [Test]
738 public void TestIsImport ()
740 TypeBuilder tb = module.DefineType (genTypeName ());
741 Assert.IsFalse (tb.IsImport, "#1");
743 tb = module.DefineType (genTypeName (), TypeAttributes.Import);
744 Assert.IsTrue (tb.IsImport, "#2");
747 [Test]
748 public void TestIsInterface ()
750 TypeBuilder tb = module.DefineType (genTypeName ());
751 Assert.IsFalse (tb.IsInterface, "#1");
753 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
754 Assert.IsTrue (tb2.IsInterface, "#2");
756 TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
757 Assert.IsFalse (tb3.IsInterface, "#3");
760 [Test]
761 public void TestIsLayoutSequential ()
763 TypeBuilder tb = module.DefineType (genTypeName ());
764 Assert.IsFalse (tb.IsLayoutSequential, "#1");
766 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SequentialLayout);
767 Assert.IsTrue (tb2.IsLayoutSequential, "#2");
770 [Test]
771 public void TestIsMarshalByRef ()
773 TypeBuilder tb = module.DefineType (genTypeName ());
774 Assert.IsFalse (tb.IsMarshalByRef, "#1");
776 TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (MarshalByRefObject));
777 Assert.IsTrue (tb2.IsMarshalByRef, "#2");
779 TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ContextBoundObject));
780 Assert.IsTrue (tb3.IsMarshalByRef, "#3");
783 // TODO: Visibility properties
785 [Test]
786 public void TestIsPointer ()
788 // How can this be true?
789 TypeBuilder tb = module.DefineType (genTypeName ());
790 Assert.IsFalse (tb.IsPointer);
793 [Test]
794 public void TestIsPrimitive ()
796 TypeBuilder tb = module.DefineType ("int");
797 Assert.IsFalse (tb.IsPrimitive);
800 [Test]
801 public void IsSealed ()
803 TypeBuilder tb = module.DefineType (genTypeName ());
804 Assert.IsFalse (tb.IsSealed, "#1");
806 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
807 Assert.IsTrue (tb2.IsSealed, "#2");
810 static string CreateTempAssembly ()
812 FileStream f = null;
813 string path;
814 Random rnd;
815 int num = 0;
817 rnd = new Random ();
818 do {
819 num = rnd.Next ();
820 num++;
821 path = Path.Combine (Path.GetTempPath (), "tmp" + num.ToString ("x") + ".dll");
823 try {
824 f = new FileStream (path, FileMode.CreateNew);
825 } catch { }
826 } while (f == null);
828 f.Close ();
831 return "tmp" + num.ToString ("x") + ".dll";
834 [Test]
835 public void IsSerializable ()
837 TypeBuilder tb = module.DefineType (genTypeName ());
838 Assert.IsFalse (tb.IsSerializable, "#1");
840 ConstructorInfo [] ctors = typeof (SerializableAttribute).GetConstructors (BindingFlags.Instance | BindingFlags.Public);
841 Assert.IsTrue (ctors.Length > 0, "#2");
843 tb.SetCustomAttribute (new CustomAttributeBuilder (ctors [0], new object [0]));
844 Type createdType = tb.CreateType ();
846 string an = CreateTempAssembly ();
847 assembly.Save (an);
848 Assert.IsTrue (createdType.IsSerializable, "#3");
849 File.Delete (Path.Combine (Path.GetTempPath (), an));
852 [Test]
853 public void TestIsSpecialName ()
855 TypeBuilder tb = module.DefineType (genTypeName ());
856 Assert.IsFalse (tb.IsSpecialName, "#1");
858 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.SpecialName);
859 Assert.IsTrue (tb2.IsSpecialName, "#2");
862 [Test]
863 public void TestIsUnicodeClass ()
865 TypeBuilder tb = module.DefineType (genTypeName ());
866 Assert.IsFalse (tb.IsUnicodeClass, "#1");
868 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.UnicodeClass);
869 Assert.IsTrue (tb2.IsUnicodeClass, "#2");
872 [Test]
873 public void TestIsValueType ()
875 TypeBuilder tb = module.DefineType (genTypeName ());
876 Assert.IsFalse (tb.IsValueType, "#1");
878 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
879 Assert.IsFalse (tb2.IsValueType, "#2");
881 TypeBuilder tb3 = module.DefineType (genTypeName (), 0, typeof (ValueType));
882 Assert.IsTrue (tb3.IsValueType, "#3");
884 TypeBuilder tb4 = module.DefineType (genTypeName (), 0, typeof (Enum));
885 Assert.IsTrue (tb4.IsValueType, "#4");
888 [Test]
889 public void TestMemberType ()
891 TypeBuilder tb = module.DefineType (genTypeName ());
892 Assert.AreEqual (MemberTypes.TypeInfo, tb.MemberType);
895 [Test]
896 public void TestModule ()
898 TypeBuilder tb = module.DefineType (genTypeName ());
899 Assert.AreEqual (module, tb.Module);
902 [Test]
903 public void TestName ()
905 TypeBuilder tb = module.DefineType ("A");
906 Assert.AreEqual ("A", tb.Name, "#1");
908 TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
909 Assert.AreEqual ("E", tb2.Name, "#2");
911 TypeBuilder tb3 = tb2.DefineNestedType ("A");
912 Assert.AreEqual ("A", tb3.Name, "#3");
914 /* Is .E a valid name ?
915 TypeBuilder tb4 = module.DefineType (".E");
916 AssertEquals ("",
917 "E", tb4.Name);
921 [Test]
922 public void TestNamespace ()
924 TypeBuilder tb = module.DefineType ("A");
925 Assert.AreEqual (string.Empty, tb.Namespace, "#1");
927 TypeBuilder tb2 = module.DefineType ("A.B.C.D.E");
928 Assert.AreEqual ("A.B.C.D", tb2.Namespace, "#2");
930 TypeBuilder tb3 = tb2.DefineNestedType ("A");
931 Assert.AreEqual (string.Empty, tb3.Namespace, "#3");
933 /* Is .E a valid name ?
934 TypeBuilder tb4 = module.DefineType (".E");
935 AssertEquals ("",
936 "E", tb4.Name);
940 [Test]
941 public void TestPackingSize ()
943 TypeBuilder tb = module.DefineType (genTypeName ());
944 Assert.AreEqual (PackingSize.Unspecified, tb.PackingSize, "#1");
946 TypeBuilder tb2 = module.DefineType (genTypeName (), 0, typeof (object),
947 PackingSize.Size16, 16);
948 Assert.AreEqual (PackingSize.Size16, tb2.PackingSize, "#2");
951 [Test]
952 public void TestReflectedType ()
954 // It is the same as DeclaringType, but why?
955 TypeBuilder tb = module.DefineType (genTypeName ());
956 Assert.IsNull (tb.ReflectedType, "#1");
958 TypeBuilder tb2 = tb.DefineNestedType (genTypeName ());
959 Assert.AreEqual (tb, tb2.ReflectedType, "#2");
962 [Test]
963 public void SetParent_Parent_Null ()
965 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class,
966 typeof (Attribute));
967 #if NET_2_0
968 tb.SetParent (null);
969 Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
970 #else
971 try {
972 tb.SetParent (null);
973 Assert.Fail ("#A1");
974 } catch (ArgumentNullException ex) {
975 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
976 Assert.IsNull (ex.InnerException, "#A3");
977 Assert.IsNotNull (ex.Message, "#A4");
978 Assert.AreEqual ("parent", ex.ParamName, "#A5");
980 #endif
982 tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
983 TypeAttributes.Abstract);
984 #if NET_2_0
985 tb.SetParent (null);
986 Assert.IsNull (tb.BaseType, "#B1");
987 #else
988 try {
989 tb.SetParent (null);
990 Assert.Fail ("#B1");
991 } catch (ArgumentNullException ex) {
992 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
993 Assert.IsNull (ex.InnerException, "#B3");
994 Assert.IsNotNull (ex.Message, "#B4");
995 Assert.AreEqual ("parent", ex.ParamName, "#B5");
997 #endif
999 #if NET_2_0
1000 tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1001 TypeAttributes.Abstract, typeof (ICloneable));
1002 Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#C1");
1003 tb.SetParent (null);
1004 Assert.IsNull (tb.BaseType, "#C2");
1006 tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
1007 typeof (IDisposable));
1008 try {
1009 tb.SetParent (null);
1010 Assert.Fail ("#D1");
1011 } catch (InvalidOperationException ex) {
1012 // Interface must be declared abstract
1013 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1014 Assert.IsNull (ex.InnerException, "#D3");
1015 Assert.IsNotNull (ex.Message, "#D4");
1017 #endif
1020 [Test]
1021 public void SetParent_Parent_Interface ()
1023 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Class);
1024 tb.SetParent (typeof (ICloneable));
1025 Assert.AreEqual (typeof (ICloneable), tb.BaseType);
1028 [Test]
1029 public void TestSetParentIncomplete ()
1031 TypeBuilder tb = module.DefineType (genTypeName ());
1032 tb.SetParent (typeof (Attribute));
1033 Assert.AreEqual (typeof (Attribute), tb.BaseType, "#1");
1035 tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1036 TypeAttributes.Abstract);
1037 tb.SetParent (typeof (IDisposable));
1038 Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#2");
1040 tb = module.DefineType (genTypeName ());
1041 tb.SetParent (typeof (IDisposable));
1042 Assert.AreEqual (typeof (IDisposable), tb.BaseType, "#3");
1044 #if NET_2_0
1045 tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1046 TypeAttributes.Abstract, typeof (IDisposable));
1047 tb.SetParent (typeof (ICloneable));
1048 Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#4");
1050 tb = module.DefineType (genTypeName (), TypeAttributes.Interface |
1051 TypeAttributes.Abstract, typeof (IDisposable));
1052 tb.SetParent (typeof (ICloneable));
1053 Assert.AreEqual (typeof (ICloneable), tb.BaseType, "#5");
1054 #endif
1057 [Test]
1058 public void TestSetParentComplete ()
1060 TypeBuilder tb = module.DefineType (genTypeName ());
1061 tb.CreateType ();
1062 try {
1063 tb.SetParent (typeof (Attribute));
1064 Assert.Fail ("#1");
1065 } catch (InvalidOperationException ex) {
1066 // Unable to change after type has been created
1067 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1068 Assert.IsNull (ex.InnerException, "#3");
1069 Assert.IsNotNull (ex.Message, "#4");
1073 [Test]
1074 public void TestSize ()
1077 TypeBuilder tb = module.DefineType (genTypeName ());
1078 Assert.AreEqual (0, tb.Size, "#1");
1079 tb.CreateType ();
1080 Assert.AreEqual (0, tb.Size, "#2");
1084 TypeBuilder tb = module.DefineType (genTypeName (), 0, typeof (object),
1085 PackingSize.Size16, 32);
1086 Assert.AreEqual (32, tb.Size, "#3");
1090 [Test]
1091 public void TestTypeHandle ()
1093 TypeBuilder tb = module.DefineType (genTypeName ());
1094 try {
1095 RuntimeTypeHandle handle = tb.TypeHandle;
1096 Assert.Fail ("#1:" + handle);
1097 } catch (NotSupportedException ex) {
1098 // The invoked member is not supported in a
1099 // dynamic module
1100 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1101 Assert.IsNull (ex.InnerException, "#3");
1102 Assert.IsNotNull (ex.Message, "#4");
1106 [Test]
1107 public void TestTypeInitializerIncomplete ()
1109 TypeBuilder tb = module.DefineType (genTypeName ());
1110 try {
1111 ConstructorInfo cb = tb.TypeInitializer;
1112 Assert.Fail ("#1:" + (cb != null));
1113 } catch (NotSupportedException ex) {
1114 // The invoked member is not supported in a
1115 // dynamic module
1116 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1117 Assert.IsNull (ex.InnerException, "#3");
1118 Assert.IsNotNull (ex.Message, "#4");
1122 [Test]
1123 public void TestTypeInitializerComplete ()
1125 TypeBuilder tb = module.DefineType (genTypeName ());
1126 tb.CreateType ();
1127 ConstructorInfo cb = tb.TypeInitializer;
1130 [Test]
1131 public void TestTypeToken ()
1133 TypeBuilder tb = module.DefineType (genTypeName ());
1134 TypeToken token = tb.TypeToken;
1137 [Test]
1138 public void UnderlyingSystemType ()
1140 TypeBuilder tb;
1141 Type emitted_type;
1143 tb = module.DefineType (genTypeName ());
1144 Assert.AreSame (tb, tb.UnderlyingSystemType, "#A1");
1145 emitted_type = tb.CreateType ();
1146 Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#A2");
1148 tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1149 Assert.AreSame (tb, tb.UnderlyingSystemType, "#B1");
1150 emitted_type = tb.CreateType ();
1151 Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#B2");
1153 tb = module.DefineType (genTypeName (), 0, typeof (ValueType));
1154 Assert.AreSame (tb, tb.UnderlyingSystemType, "#C1");
1155 emitted_type = tb.CreateType ();
1156 Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#C2");
1158 tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1159 try {
1160 Type t = tb.UnderlyingSystemType;
1161 Assert.Fail ("#D1:" + t);
1162 } catch (InvalidOperationException ex) {
1163 // Underlying type information on enumeration
1164 // is not specified
1165 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1166 Assert.IsNull (ex.InnerException, "#D3");
1167 Assert.IsNotNull (ex.Message, "#D4");
1169 tb.DefineField ("val", typeof (int), FieldAttributes.Private);
1170 Assert.AreEqual (typeof (int), tb.UnderlyingSystemType, "#D5");
1171 emitted_type = tb.CreateType ();
1172 Assert.AreSame (emitted_type, tb.UnderlyingSystemType, "#D6");
1174 tb = module.DefineType (genTypeName (), 0, typeof (Enum));
1175 tb.DefineField ("val", typeof (int), FieldAttributes.Static);
1176 try {
1177 Type t = tb.UnderlyingSystemType;
1178 Assert.Fail ("#E1:" + t);
1179 } catch (InvalidOperationException ex) {
1180 // Underlying type information on enumeration
1181 // is not specified
1182 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1183 Assert.IsNull (ex.InnerException, "#E3");
1184 Assert.IsNotNull (ex.Message, "#E4");
1186 tb.DefineField ("foo", typeof (long), FieldAttributes.Private);
1187 Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E5");
1188 tb.DefineField ("bar", typeof (short), FieldAttributes.Private);
1189 Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E6");
1190 tb.DefineField ("boo", typeof (int), FieldAttributes.Static);
1191 Assert.AreEqual (typeof (long), tb.UnderlyingSystemType, "#E7");
1194 [Test]
1195 public void AddInterfaceImplementation_InterfaceType_Null ()
1197 TypeBuilder tb = module.DefineType (genTypeName ());
1198 try {
1199 tb.AddInterfaceImplementation (null);
1200 Assert.Fail ("#1");
1201 } catch (ArgumentNullException ex) {
1202 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1203 Assert.IsNull (ex.InnerException, "#3");
1204 Assert.IsNotNull (ex.Message, "#4");
1205 Assert.AreEqual ("interfaceType", ex.ParamName, "#5");
1209 [Test]
1210 public void TestAddInterfaceImplementation ()
1212 TypeBuilder tb = module.DefineType (genTypeName ());
1213 tb.AddInterfaceImplementation (typeof (AnInterface));
1214 tb.AddInterfaceImplementation (typeof (AnInterface));
1216 Type t = tb.CreateType ();
1217 Assert.AreEqual (1, tb.GetInterfaces ().Length, "#2");
1219 // Can not be called on a created type
1220 try {
1221 tb.AddInterfaceImplementation (typeof (AnInterface));
1222 Assert.Fail ("#3");
1223 } catch (InvalidOperationException) {
1227 [Test]
1228 #if ONLY_1_1
1229 [Category ("NotWorking")] // we allow CreateType to be invoked multiple times
1230 #endif
1231 public void TestCreateType_Created ()
1233 TypeBuilder tb = module.DefineType (genTypeName ());
1234 #if NET_2_0
1235 Assert.IsFalse (tb.IsCreated (), "#A1");
1236 #endif
1237 Type emittedType1 = tb.CreateType ();
1238 #if NET_2_0
1239 Assert.IsTrue (tb.IsCreated (), "#A2");
1240 #endif
1241 Assert.IsNotNull (emittedType1, "#A3");
1243 #if NET_2_0
1244 Type emittedType2 = tb.CreateType ();
1245 Assert.IsNotNull (emittedType2, "#B1");
1246 Assert.IsTrue (tb.IsCreated (), "#B2");
1247 Assert.AreSame (emittedType1, emittedType2, "#B3");
1248 #else
1249 try {
1250 tb.CreateType ();
1251 Assert.Fail ("#B1");
1252 } catch (InvalidOperationException ex) {
1253 // Unable to change after type has been created
1254 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1255 Assert.IsNull (ex.InnerException, "#B3");
1256 Assert.IsNotNull (ex.Message, "#B4");
1258 #endif
1261 [Test]
1262 public void TestDefineConstructor ()
1264 TypeBuilder tb = module.DefineType (genTypeName ());
1266 ConstructorBuilder cb = tb.DefineConstructor (0, 0, null);
1267 cb.GetILGenerator ().Emit (OpCodes.Ret);
1268 tb.CreateType ();
1270 // Can not be called on a created type
1271 try {
1272 tb.DefineConstructor (0, 0, null);
1273 Assert.Fail ("#1");
1274 } catch (InvalidOperationException ex) {
1275 // Unable to change after type has been created
1276 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1277 Assert.IsNull (ex.InnerException, "#3");
1278 Assert.IsNotNull (ex.Message, "#4");
1282 [Test]
1283 public void DefineDefaultConstructor ()
1285 TypeBuilder tb = module.DefineType (genTypeName ());
1286 tb.DefineDefaultConstructor (0);
1287 tb.CreateType ();
1289 // Can not be called on a created type, altough the MSDN docs does not mention this
1290 try {
1291 tb.DefineDefaultConstructor (0);
1292 Assert.Fail ("#1");
1293 } catch (InvalidOperationException ex) {
1294 // Unable to change after type has been created
1295 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1296 Assert.IsNull (ex.InnerException, "#3");
1297 Assert.IsNotNull (ex.Message, "#4");
1301 [Test]
1302 public void DefineDefaultConstructor_Parent_DefaultCtorInaccessible ()
1304 TypeBuilder tb;
1306 tb = module.DefineType (genTypeName ());
1307 tb.DefineDefaultConstructor (MethodAttributes.Private);
1308 Type parent_type = tb.CreateType ();
1310 tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1311 parent_type);
1312 tb.DefineDefaultConstructor (MethodAttributes.Public);
1313 Type emitted_type = tb.CreateType ();
1314 try {
1315 Activator.CreateInstance (emitted_type);
1316 Assert.Fail ("#1");
1317 } catch (TargetInvocationException ex) {
1318 Assert.AreEqual (typeof (TargetInvocationException), ex.GetType (), "#2");
1319 Assert.IsNotNull (ex.InnerException, "#3");
1320 Assert.IsNotNull (ex.Message, "#4");
1322 MethodAccessException mae = ex.InnerException as MethodAccessException;
1323 Assert.IsNotNull (mae, "#5");
1324 Assert.AreEqual (typeof (MethodAccessException), mae.GetType (), "#6");
1325 Assert.IsNull (mae.InnerException, "#7");
1326 Assert.IsNotNull (mae.Message, "#8");
1327 Assert.IsTrue (mae.Message.IndexOf (parent_type.FullName) != -1, "#9:" + mae.Message);
1328 Assert.IsTrue (mae.Message.IndexOf (".ctor") != -1, "#10:" + mae.Message);
1332 [Test]
1333 public void DefineDefaultConstructor_Parent_DefaultCtorMissing ()
1335 TypeBuilder tb;
1337 tb = module.DefineType (genTypeName ());
1338 ConstructorBuilder cb = tb.DefineConstructor (
1339 MethodAttributes.Public,
1340 CallingConventions.Standard,
1341 new Type [] { typeof (string) });
1342 cb.GetILGenerator ().Emit (OpCodes.Ret);
1343 Type parent_type = tb.CreateType ();
1345 tb = module.DefineType (genTypeName (), TypeAttributes.Class,
1346 parent_type);
1347 try {
1348 tb.DefineDefaultConstructor (MethodAttributes.Public);
1349 Assert.Fail ("#1");
1350 } catch (NotSupportedException ex) {
1351 // Parent does not have a default constructor.
1352 // The default constructor must be explicitly defined
1353 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
1354 Assert.IsNull (ex.InnerException, "#3");
1355 Assert.IsNotNull (ex.Message, "#4");
1359 [Test]
1360 public void DefineEvent_Name_NullChar ()
1362 TypeBuilder tb = module.DefineType (genTypeName ());
1364 try {
1365 tb.DefineEvent ("\0test", EventAttributes.None,
1366 typeof (int));
1367 Assert.Fail ("#A1");
1368 } catch (ArgumentException ex) {
1369 // Illegal name
1370 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1371 Assert.IsNull (ex.InnerException, "#A3");
1372 Assert.IsNotNull (ex.Message, "#A4");
1373 Assert.AreEqual ("name", ex.ParamName, "#A5");
1376 EventBuilder eb = tb.DefineEvent ("te\0st", EventAttributes.None,
1377 typeof (int));
1378 Assert.IsNotNull (eb, "#B1");
1381 [Test]
1382 public void TestDefineEvent ()
1384 TypeBuilder tb = module.DefineType (genTypeName ());
1386 // Test invalid arguments
1387 try {
1388 tb.DefineEvent (null, 0, typeof (int));
1389 Assert.Fail ("#A1");
1390 } catch (ArgumentNullException ex) {
1391 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1392 Assert.IsNull (ex.InnerException, "#A3");
1393 Assert.IsNotNull (ex.Message, "#A4");
1394 Assert.AreEqual ("name", ex.ParamName, "#A5");
1397 try {
1398 tb.DefineEvent ("FOO", 0, null);
1399 Assert.Fail ("#B1");
1400 } catch (ArgumentNullException ex) {
1401 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1402 Assert.IsNull (ex.InnerException, "#B3");
1403 Assert.IsNotNull (ex.Message, "#B4");
1404 Assert.AreEqual ("type", ex.ParamName, "#B5");
1407 try {
1408 tb.DefineEvent (string.Empty, 0, typeof (int));
1409 Assert.Fail ("#C1");
1410 } catch (ArgumentException ex) {
1411 // Empty name is not legal
1412 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1413 Assert.IsNull (ex.InnerException, "#C3");
1414 Assert.IsNotNull (ex.Message, "#C4");
1415 Assert.AreEqual ("name", ex.ParamName, "#C5");
1418 tb.CreateType ();
1420 // Can not be called on a created type
1421 try {
1422 tb.DefineEvent ("BAR", 0, typeof (int));
1423 Assert.Fail ("#D1");
1424 } catch (InvalidOperationException ex) {
1425 // Unable to change after type has been created
1426 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1427 Assert.IsNull (ex.InnerException, "#D3");
1428 Assert.IsNotNull (ex.Message, "#D4");
1432 [Test] // DefineField (String, Type, FieldAttributes)
1433 public void DefineField1 ()
1435 TypeBuilder tb = module.DefineType (genTypeName ());
1437 // Check invalid arguments
1438 try {
1439 tb.DefineField (null, typeof (int), 0);
1440 Assert.Fail ("#A1");
1441 } catch (ArgumentNullException ex) {
1442 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1443 Assert.IsNull (ex.InnerException, "#A3");
1444 Assert.IsNotNull (ex.Message, "#A4");
1445 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1448 try {
1449 tb.DefineField (string.Empty, typeof (int), 0);
1450 Assert.Fail ("#B1");
1451 } catch (ArgumentException ex) {
1452 // Empty name is not legal
1453 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1454 Assert.IsNull (ex.InnerException, "#B3");
1455 Assert.IsNotNull (ex.Message, "#B4");
1456 Assert.AreEqual ("fieldName", ex.ParamName, "#B5");
1459 try {
1460 // Strangely, 'A<NULL>' is accepted...
1461 string name = String.Format ("{0}", (char) 0);
1462 tb.DefineField (name, typeof (int), 0);
1463 Assert.Fail ("#C1");
1464 } catch (ArgumentException ex) {
1465 // Illegal name
1466 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1467 Assert.IsNull (ex.InnerException, "#C3");
1468 Assert.IsNotNull (ex.Message, "#C4");
1469 Assert.AreEqual ("fieldName", ex.ParamName, "#C5");
1472 try {
1473 tb.DefineField ("A", typeof (void), 0);
1474 Assert.Fail ("#D1");
1475 } catch (ArgumentException ex) {
1476 // Bad field type in defining field
1477 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1478 Assert.IsNull (ex.InnerException, "#D3");
1479 Assert.IsNotNull (ex.Message, "#D4");
1480 Assert.IsNull (ex.ParamName, "#D5");
1483 tb.CreateType ();
1485 // Can not be called on a created type
1486 try {
1487 tb.DefineField ("B", typeof (int), 0);
1488 Assert.Fail ("#E1");
1489 } catch (InvalidOperationException ex) {
1490 // Unable to change after type has been created
1491 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
1492 Assert.IsNull (ex.InnerException, "#E3");
1493 Assert.IsNotNull (ex.Message, "#E4");
1497 [Test] // DefineField (String, Type, FieldAttributes)
1498 public void DefineField1_Name_NullChar ()
1500 TypeBuilder tb = module.DefineType (genTypeName ());
1502 try {
1503 tb.DefineField ("\0test", typeof (int),
1504 FieldAttributes.Private);
1505 Assert.Fail ("#A1");
1506 } catch (ArgumentException ex) {
1507 // Illegal name
1508 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1509 Assert.IsNull (ex.InnerException, "#A3");
1510 Assert.IsNotNull (ex.Message, "#A4");
1511 Assert.AreEqual ("fieldName", ex.ParamName, "#A5");
1514 FieldBuilder fb = tb.DefineField ("te\0st", typeof (int),
1515 FieldAttributes.Private);
1516 Assert.IsNotNull (fb, "#B1");
1517 Assert.AreEqual ("te\0st", fb.Name, "#B2");
1520 [Test] // DefineField (String, Type, FieldAttributes)
1521 public void DefineField1_Type_Null ()
1523 TypeBuilder tb = module.DefineType (genTypeName ());
1525 try {
1526 tb.DefineField ("test", (Type) null,
1527 FieldAttributes.Private);
1528 Assert.Fail ("#1");
1529 } catch (ArgumentNullException ex) {
1530 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1531 Assert.IsNull (ex.InnerException, "#3");
1532 Assert.IsNotNull (ex.Message, "#4");
1533 Assert.AreEqual ("type", ex.ParamName, "#5");
1537 #if NET_2_0
1538 [Test] // DefineField (String, Type, Type [], Type [], FieldAttributes)
1539 public void DefineField2_Type_Null ()
1541 TypeBuilder tb = module.DefineType (genTypeName ());
1543 try {
1544 tb.DefineField ("test", (Type) null, Type.EmptyTypes,
1545 Type.EmptyTypes, FieldAttributes.Private);
1546 Assert.Fail ("#1");
1547 } catch (ArgumentNullException ex) {
1548 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1549 Assert.IsNull (ex.InnerException, "#3");
1550 Assert.IsNotNull (ex.Message, "#4");
1551 Assert.AreEqual ("type", ex.ParamName, "#5");
1554 #endif
1556 [Test]
1557 public void TestDefineInitializedData ()
1559 TypeBuilder tb = module.DefineType (genTypeName ());
1561 // Check invalid arguments
1562 try {
1563 tb.DefineInitializedData (null, new byte [1], 0);
1564 Assert.Fail ("#A1");
1565 } catch (ArgumentNullException ex) {
1566 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1567 Assert.IsNull (ex.InnerException, "#A3");
1568 Assert.IsNotNull (ex.Message, "#A4");
1569 Assert.AreEqual ("name", ex.ParamName, "#A5");
1572 try {
1573 tb.DefineInitializedData ("FOO", null, 0);
1574 Assert.Fail ("#B1");
1575 } catch (ArgumentNullException ex) {
1576 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
1577 Assert.IsNull (ex.InnerException, "#B3");
1578 Assert.IsNotNull (ex.Message, "#B4");
1579 Assert.AreEqual ("data", ex.ParamName, "#B5");
1582 try {
1583 tb.DefineInitializedData (string.Empty, new byte [1], 0);
1584 Assert.Fail ("#C1");
1585 } catch (ArgumentException ex) {
1586 // Empty name is not legal
1587 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1588 Assert.IsNull (ex.InnerException, "#C3");
1589 Assert.IsNotNull (ex.Message, "#C4");
1590 Assert.AreEqual ("name", ex.ParamName, "#C5");
1593 // The size of the data is less than or equal to zero ???
1594 try {
1595 tb.DefineInitializedData ("BAR", new byte [0], 0);
1596 Assert.Fail ("#D1");
1597 } catch (ArgumentException ex) {
1598 // Data size must be > 0 and < 0x3f0000
1599 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1600 Assert.IsNull (ex.InnerException, "#D3");
1601 Assert.IsNotNull (ex.Message, "#D4");
1602 Assert.IsNull (ex.ParamName, "#D5");
1605 try {
1606 string name = String.Format ("{0}", (char) 0);
1607 tb.DefineInitializedData (name, new byte [1], 0);
1608 Assert.Fail ("#E1");
1609 } catch (ArgumentException ex) {
1610 // Illegal name
1611 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
1612 Assert.IsNull (ex.InnerException, "#E3");
1613 Assert.IsNotNull (ex.Message, "#E4");
1614 Assert.AreEqual ("fieldName", ex.ParamName, "#E5");
1617 tb.CreateType ();
1619 // Can not be called on a created type, altough the MSDN docs does not mention this
1620 try {
1621 tb.DefineInitializedData ("BAR2", new byte [1], 0);
1622 Assert.Fail ("#F1");
1623 } catch (InvalidOperationException ex) {
1624 // Unable to change after type has been created
1625 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
1626 Assert.IsNull (ex.InnerException, "#F3");
1627 Assert.IsNotNull (ex.Message, "#F4");
1631 [Test]
1632 public void DefineUninitializedDataInvalidArgs ()
1634 TypeBuilder tb = module.DefineType (genTypeName ());
1636 try {
1637 tb.DefineUninitializedData (null, 1, 0);
1638 Assert.Fail ("#A1");
1639 } catch (ArgumentNullException ex) {
1640 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1641 Assert.IsNull (ex.InnerException, "#A3");
1642 Assert.IsNotNull (ex.Message, "#A4");
1643 Assert.AreEqual ("name", ex.ParamName, "#A5");
1646 try {
1647 tb.DefineUninitializedData (string.Empty, 1, 0);
1648 Assert.Fail ("#B1");
1649 } catch (ArgumentException ex) {
1650 // Empty name is not legal
1651 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1652 Assert.IsNull (ex.InnerException, "#B3");
1653 Assert.IsNotNull (ex.Message, "#B4");
1654 Assert.AreEqual ("name", ex.ParamName, "#B5");
1657 // The size of the data is less than or equal to zero ???
1658 try {
1659 tb.DefineUninitializedData ("BAR", 0, 0);
1660 Assert.Fail ("#C1");
1661 } catch (ArgumentException ex) {
1662 // Data size must be > 0 and < 0x3f0000
1663 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1664 Assert.IsNull (ex.InnerException, "#C3");
1665 Assert.IsNotNull (ex.Message, "#C4");
1666 Assert.IsNull (ex.ParamName, "#C5");
1669 try {
1670 string name = String.Format ("{0}", (char) 0);
1671 tb.DefineUninitializedData (name, 1, 0);
1672 Assert.Fail ("#D1");
1673 } catch (ArgumentException ex) {
1674 // Illegal name
1675 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
1676 Assert.IsNull (ex.InnerException, "#D3");
1677 Assert.IsNotNull (ex.Message, "#D4");
1678 Assert.AreEqual ("fieldName", ex.ParamName, "#D5");
1682 [Test]
1683 public void DefineUninitializedDataAlreadyCreated ()
1685 TypeBuilder tb = module.DefineType (genTypeName ());
1686 tb.CreateType ();
1687 try {
1688 tb.DefineUninitializedData ("BAR2", 1, 0);
1689 Assert.Fail ("#1");
1690 } catch (InvalidOperationException ex) {
1691 // Unable to change after type has been created
1692 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1693 Assert.IsNull (ex.InnerException, "#3");
1694 Assert.IsNotNull (ex.Message, "#4");
1698 [Test]
1699 public void DefineUninitializedData ()
1701 TypeBuilder tb = module.DefineType (genTypeName ());
1703 tb.DefineUninitializedData ("foo", 4, FieldAttributes.Public);
1705 Type t = tb.CreateType ();
1707 object o = Activator.CreateInstance (t);
1709 FieldInfo fi = t.GetField ("foo");
1711 object fieldVal = fi.GetValue (o);
1713 IntPtr ptr = Marshal.AllocHGlobal (4);
1714 Marshal.StructureToPtr (fieldVal, ptr, true);
1715 Marshal.FreeHGlobal (ptr);
1718 [Test]
1719 public void DefineMethod_Name_NullChar ()
1721 TypeBuilder tb = module.DefineType (genTypeName ());
1722 try {
1723 tb.DefineMethod ("\0test", MethodAttributes.Private,
1724 typeof (string), Type.EmptyTypes);
1725 Assert.Fail ("#A1");
1726 } catch (ArgumentException ex) {
1727 // Illegal name
1728 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1729 Assert.IsNull (ex.InnerException, "#A3");
1730 Assert.IsNotNull (ex.Message, "#A4");
1731 Assert.AreEqual ("name", ex.ParamName, "#A5");
1734 MethodBuilder mb = tb.DefineMethod ("te\0st", MethodAttributes.Private,
1735 typeof (string), Type.EmptyTypes);
1736 Assert.IsNotNull (mb, "#B1");
1737 Assert.AreEqual ("te\0st", mb.Name, "#B2");
1740 [Test]
1741 public void TestDefineMethod ()
1743 TypeBuilder tb = module.DefineType (genTypeName ());
1745 // Check invalid arguments
1746 try {
1747 tb.DefineMethod (null, 0, null, null);
1748 Assert.Fail ("#A1");
1749 } catch (ArgumentNullException ex) {
1750 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1751 Assert.IsNull (ex.InnerException, "#A3");
1752 Assert.IsNotNull (ex.Message, "#A4");
1753 Assert.AreEqual ("name", ex.ParamName, "#A5");
1756 try {
1757 tb.DefineMethod (string.Empty, 0, null, null);
1758 Assert.Fail ("#B1");
1759 } catch (ArgumentException ex) {
1760 // Empty name is not legal
1761 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1762 Assert.IsNull (ex.InnerException, "#B3");
1763 Assert.IsNotNull (ex.Message, "#B4");
1764 Assert.AreEqual ("name", ex.ParamName, "#B5");
1767 // Check non-virtual methods on an interface
1768 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1769 try {
1770 tb2.DefineMethod ("FOO", MethodAttributes.Abstract, null, null);
1771 Assert.Fail ("#C1");
1772 } catch (ArgumentException ex) {
1773 // Interface method must be abstract and virtual
1774 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1775 Assert.IsNull (ex.InnerException, "#C3");
1776 Assert.IsNotNull (ex.Message, "#C4");
1777 Assert.IsNull (ex.ParamName, "#C5");
1780 // Check static methods on an interface
1781 tb2.DefineMethod ("BAR", MethodAttributes.Public | MethodAttributes.Static,
1782 typeof (void),
1783 Type.EmptyTypes);
1785 tb.CreateType ();
1786 // Can not be called on a created type
1787 try {
1788 tb.DefineMethod ("bar", 0, null, null);
1789 Assert.Fail ("#D1");
1790 } catch (InvalidOperationException ex) {
1791 // Unable to change after type has been created
1792 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1793 Assert.IsNull (ex.InnerException, "#D3");
1794 Assert.IsNotNull (ex.Message, "#D4");
1798 [Test] // bug #327484
1799 [Category ("NotWorking")]
1800 public void TestDefineMethod_Abstract ()
1802 TypeBuilder tb = module.DefineType (genTypeName ());
1803 tb.DefineMethod ("Run", MethodAttributes.Public |
1804 MethodAttributes.Abstract | MethodAttributes.Virtual,
1805 typeof (void), Type.EmptyTypes);
1807 try {
1808 tb.CreateType ();
1809 Assert.Fail ("#A1");
1810 } catch (InvalidOperationException ex) {
1811 // Type must be declared abstract if any of its
1812 // methods are abstract
1813 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1814 Assert.IsNull (ex.InnerException, "#A3");
1815 Assert.IsNotNull (ex.Message, "#A4");
1818 tb = module.DefineType (genTypeName (), TypeAttributes.Abstract);
1819 tb.DefineMethod ("Run", MethodAttributes.Public |
1820 MethodAttributes.Abstract, typeof (void),
1821 Type.EmptyTypes);
1823 try {
1824 tb.CreateType ();
1825 Assert.Fail ("#B1");
1826 } catch (TypeLoadException ex) {
1827 // Non-virtual abstract method
1828 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B2");
1829 Assert.IsNull (ex.InnerException, "#B3");
1830 Assert.IsNotNull (ex.Message, "#B4");
1833 tb = module.DefineType (genTypeName (), TypeAttributes.Abstract |
1834 TypeAttributes.Public);
1835 tb.DefineMethod ("Run", MethodAttributes.Public |
1836 MethodAttributes.Abstract | MethodAttributes.Virtual,
1837 typeof (void), Type.EmptyTypes);
1838 Type emittedType = tb.CreateType ();
1840 MethodInfo mi1 = emittedType.GetMethod ("Run");
1841 Assert.IsNotNull (mi1, "#C1");
1842 Assert.IsTrue (mi1.IsAbstract, "#C2");
1844 MethodInfo mi2 = tb.GetMethod ("Run");
1845 Assert.IsNotNull (mi2, "#D1");
1846 Assert.IsTrue (mi2.IsAbstract, "#D2");
1849 // TODO: DefineMethodOverride
1851 [Test]
1852 public void TestDefineNestedType ()
1854 TypeBuilder tb = module.DefineType (genTypeName ());
1856 // Check invalid arguments
1857 try {
1858 tb.DefineNestedType (null);
1859 Assert.Fail ("#A1");
1860 } catch (ArgumentNullException ex) {
1861 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1862 Assert.IsNull (ex.InnerException, "#A3");
1863 Assert.IsNotNull (ex.Message, "#A4");
1864 Assert.AreEqual ("fullname", ex.ParamName, "#A5");
1867 try {
1868 tb.DefineNestedType (string.Empty);
1869 Assert.Fail ("#B1");
1870 } catch (ArgumentException ex) {
1871 // Empty name is not legal
1872 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1873 Assert.IsNull (ex.InnerException, "#B3");
1874 Assert.IsNotNull (ex.Message, "#B4");
1875 Assert.AreEqual ("fullname", ex.ParamName, "#B5");
1878 try {
1879 tb.DefineNestedType (nullName ());
1880 Assert.Fail ("#C1");
1881 } catch (ArgumentException ex) {
1882 // Illegal name
1883 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1884 Assert.IsNull (ex.InnerException, "#C3");
1885 Assert.IsNotNull (ex.Message, "#C4");
1886 Assert.AreEqual ("fullname", ex.ParamName, "#C5");
1889 // If I fix the code so this works then mcs breaks -> how can mcs
1890 // works under MS .NET in the first place ???
1892 try {
1893 tb.DefineNestedType ("AA", TypeAttributes.Public, null, null);
1894 Fail ("Nested visibility must be specified.");
1896 catch (ArgumentException) {
1900 try {
1901 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1902 new Type [1]);
1903 Assert.Fail ("#D1");
1904 } catch (ArgumentNullException ex) {
1905 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2");
1906 Assert.IsNull (ex.InnerException, "#D3");
1907 Assert.IsNotNull (ex.Message, "#D4");
1908 Assert.AreEqual ("interfaces", ex.ParamName, "#D5");
1911 // I think this should reject non-interfaces, but it does not
1912 tb.DefineNestedType ("BB", TypeAttributes.NestedPublic, null,
1913 new Type [1] { typeof (object) });
1915 // Normal invocation
1916 tb.DefineNestedType ("Nest");
1918 tb.CreateType ();
1920 // According to the MSDN docs, this cannnot be called after the type
1921 // is created, but it works.
1922 tb.DefineNestedType ("Nest2");
1924 // According to the MSDN docs, a Sealed class can't contain nested
1925 // types, but this is not true
1926 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Sealed);
1927 tb2.DefineNestedType ("AA");
1929 // According to the MSDN docs, interfaces can only contain interfaces,
1930 // but this is not true
1931 TypeBuilder tb3 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
1933 tb3.DefineNestedType ("AA");
1935 // Check shorter versions
1937 TypeBuilder nested = tb.DefineNestedType ("N1");
1939 Assert.AreEqual ("N1", nested.Name, "#E1");
1940 Assert.AreEqual (typeof (object), nested.BaseType, "#E2");
1941 Assert.AreEqual (TypeAttributes.NestedPrivate, nested.Attributes, "#E3");
1942 Assert.AreEqual (0, nested.GetInterfaces ().Length, "#E4");
1945 // TODO:
1948 [Test]
1949 public void DefinePInvokeMethod_Name_NullChar ()
1951 TypeBuilder tb = module.DefineType (genTypeName ());
1952 try {
1953 tb.DefinePInvokeMethod ("\0test", "B", "C",
1954 MethodAttributes.Private, CallingConventions.Standard,
1955 typeof (string),Type.EmptyTypes, CallingConvention.Cdecl,
1956 CharSet.Unicode);
1957 Assert.Fail ("#A1");
1958 } catch (ArgumentException ex) {
1959 // Illegal name
1960 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1961 Assert.IsNull (ex.InnerException, "#A3");
1962 Assert.IsNotNull (ex.Message, "#A4");
1963 Assert.AreEqual ("name", ex.ParamName, "#A5");
1966 MethodBuilder mb = tb.DefinePInvokeMethod ("te\0st", "B", "C",
1967 MethodAttributes.Private, CallingConventions.Standard,
1968 typeof (string), Type.EmptyTypes, CallingConvention.Cdecl,
1969 CharSet.Unicode);
1970 Assert.IsNotNull (mb, "#B1");
1971 Assert.AreEqual ("te\0st", mb.Name, "#B2");
1974 [Test]
1975 public void TestDefinePInvokeMethod ()
1977 TypeBuilder tb = module.DefineType (genTypeName ());
1979 tb.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
1981 // Try invalid parameters
1982 try {
1983 tb.DefinePInvokeMethod (null, "B", "C", 0, 0, null, null, 0, 0);
1984 Assert.Fail ("#A1");
1985 } catch (ArgumentNullException ex) {
1986 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1987 Assert.IsNull (ex.InnerException, "#A3");
1988 Assert.IsNotNull (ex.Message, "#A4");
1989 Assert.AreEqual ("name", ex.ParamName, "#A5");
1991 // etc...
1993 // Try invalid attributes
1994 try {
1995 tb.DefinePInvokeMethod ("A2", "B", "C", MethodAttributes.Abstract, 0, null, null, 0, 0);
1996 Assert.Fail ("#B1");
1997 } catch (ArgumentException ex) {
1998 // PInvoke methods must be static and native and
1999 // cannot be abstract
2000 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
2001 Assert.IsNull (ex.InnerException, "#B3");
2002 Assert.IsNotNull (ex.Message, "#B4");
2003 Assert.IsNull (ex.ParamName, "#B5");
2006 // Try an interface parent
2007 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract);
2009 try {
2010 tb2.DefinePInvokeMethod ("A", "B", "C", 0, 0, null, null, 0, 0);
2011 Assert.Fail ("#C1");
2012 } catch (ArgumentException ex) {
2013 // PInvoke methods cannot exist on interfaces
2014 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
2015 Assert.IsNull (ex.InnerException, "#B3");
2016 Assert.IsNotNull (ex.Message, "#B4");
2017 Assert.IsNull (ex.ParamName, "#B5");
2021 [Test]
2022 public void DefineProperty_Name_NullChar ()
2024 TypeBuilder tb = module.DefineType (genTypeName ());
2026 try {
2027 tb.DefineProperty ("\0test", 0, typeof (string), Type.EmptyTypes);
2028 Assert.Fail ("#A1");
2029 } catch (ArgumentException ex) {
2030 // Illegal name
2031 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
2032 Assert.IsNull (ex.InnerException, "#A3");
2033 Assert.IsNotNull (ex.Message, "#A4");
2034 Assert.AreEqual ("name", ex.ParamName, "#A5");
2037 PropertyBuilder pb = tb.DefineProperty ("te\0st", 0,
2038 typeof (string), Type.EmptyTypes);
2039 Assert.IsNotNull (pb, "#B1");
2040 Assert.AreEqual ("te\0st", pb.Name, "#B2");
2043 [Test]
2044 public void DefineProperty_ParameterTypes_ItemNull ()
2046 TypeBuilder tb = module.DefineType (genTypeName ());
2048 try {
2049 tb.DefineProperty ("A", 0, typeof (string), new Type [1]);
2050 Assert.Fail ("#1");
2051 } catch (ArgumentNullException ex) {
2052 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2053 Assert.IsNull (ex.InnerException, "#3");
2054 Assert.IsNotNull (ex.Message, "#4");
2058 [Test]
2059 public void DefineProperty_ReturnType_Null ()
2061 TypeBuilder tb = module.DefineType (genTypeName ());
2062 tb.DefineProperty ("A", 0, null, Type.EmptyTypes);
2065 #if NET_2_0
2066 [Test]
2067 public void GetMethod_RejectMethodFromInflatedTypeBuilder () {
2068 TypeBuilder tb = module.DefineType (genTypeName ());
2069 tb.DefineGenericParameters ("T");
2070 MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2072 Type ginst = tb.MakeGenericType (typeof (int));
2074 MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2075 try {
2076 TypeBuilder.GetMethod (ginst, mi);
2077 Assert.Fail ("#1");
2078 } catch (ArgumentException ex) {
2079 Assert.AreEqual ("method", ex.ParamName, "#5");
2083 [Test]
2084 public void GetMethod_WorkWithInstancesOfCreatedTypeBuilder () {
2085 TypeBuilder tb = module.DefineType (genTypeName ());
2086 tb.DefineGenericParameters ("T");
2087 MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2088 ILGenerator ig = mb.GetILGenerator ();
2089 ig.Emit (OpCodes.Ret);
2091 tb.CreateType ();
2093 MethodInfo mi = TypeBuilder.GetMethod (tb.MakeGenericType (typeof (int)), mb);
2094 Assert.IsNotNull (mi);
2097 [Test]
2098 [Category ("NotDotNet")]
2099 [Category ("NotWorking")]
2100 public void GetMethod_AcceptMethodFromInflatedTypeBuilder_UnderCompilerContext () {
2101 AssemblyName assemblyName = new AssemblyName ();
2102 assemblyName.Name = ASSEMBLY_NAME;
2104 assembly =
2105 Thread.GetDomain ().DefineDynamicAssembly (
2106 assemblyName, AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800, Path.GetTempPath ());
2108 module = assembly.DefineDynamicModule ("module1");
2110 TypeBuilder tb = module.DefineType (genTypeName ());
2111 tb.DefineGenericParameters ("T");
2112 MethodBuilder mb = tb.DefineMethod ("create", MethodAttributes.Public, typeof (void), Type.EmptyTypes);
2114 Type ginst = tb.MakeGenericType (typeof (int));
2116 MethodInfo mi = TypeBuilder.GetMethod (ginst, mb);
2118 try {
2119 TypeBuilder.GetMethod (ginst, mi);
2120 } catch (ArgumentException ex) {
2121 Assert.Fail ("#1");
2126 [Test]
2127 // Test that changes made to the method builder after a call to GetMethod ()
2128 // are visible
2129 public void TestGetMethod ()
2131 TypeBuilder tb = module.DefineType (genTypeName ());
2132 GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2134 ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2135 ILGenerator ig;
2136 ig = cb.GetILGenerator ();
2137 ig.Emit (OpCodes.Ret);
2139 Type fooOfT = tb.MakeGenericType (typeParams [0]);
2141 // Create a method builder but do not emit IL yet
2142 MethodBuilder mb1 = tb.DefineMethod ("create", MethodAttributes.Public|MethodAttributes.Static, fooOfT, Type.EmptyTypes);
2144 Type t = tb.MakeGenericType (typeof (int));
2146 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2148 ig = mb.GetILGenerator ();
2149 ig.Emit (OpCodes.Call, TypeBuilder.GetMethod (t, mb1));
2150 ig.Emit (OpCodes.Ret);
2152 // Finish the method
2153 ig = mb1.GetILGenerator ();
2154 ig.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (fooOfT, cb));
2155 ig.Emit (OpCodes.Ret);
2157 Type t2 = tb.CreateType ();
2159 Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2162 [Test]
2163 public void TestGetConstructor ()
2165 TypeBuilder tb = module.DefineType (genTypeName ());
2166 GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
2168 ConstructorBuilder cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
2169 ILGenerator ig;
2171 Type t = tb.MakeGenericType (typeof (int));
2173 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public|MethodAttributes.Static, t, Type.EmptyTypes);
2175 ig = mb.GetILGenerator ();
2177 ConstructorInfo ci = TypeBuilder.GetConstructor (t, cb);
2179 ig.Emit (OpCodes.Newobj, ci);
2180 ig.Emit (OpCodes.Ret);
2182 // Finish the ctorbuilder
2183 ig = cb.GetILGenerator ();
2184 ig.Emit (OpCodes.Ret);
2186 Type t2 = tb.CreateType ();
2188 Assert.AreEqual (tb.Name + "[System.Int32]", t2.MakeGenericType (typeof (int)).GetMethod ("foo").Invoke (null, null).GetType ().ToString ());
2190 #endif
2192 [Test]
2193 [Category ("NotWorking")]
2194 public void TestIsDefinedIncomplete ()
2196 TypeBuilder tb = module.DefineType (genTypeName ());
2197 try {
2198 tb.IsDefined (typeof (int), true);
2199 Assert.Fail ("#1");
2200 } catch (NotSupportedException ex) {
2201 // The invoked member is not supported in a
2202 // dynamic module
2203 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2204 Assert.IsNull (ex.InnerException, "#3");
2205 Assert.IsNotNull (ex.Message, "#4");
2209 [Test]
2210 public void TestIsDefinedComplete ()
2212 TypeBuilder tb = module.DefineType (genTypeName ());
2214 ConstructorInfo obsoleteCtor = typeof (ObsoleteAttribute).GetConstructor (
2215 new Type [] { typeof (string) });
2217 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (obsoleteCtor,
2218 new object [] { "obsolete message" }, new FieldInfo [0], new object [0]);
2220 tb.SetCustomAttribute (caBuilder);
2221 tb.CreateType ();
2222 Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
2225 [Test]
2226 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
2227 public void IsDefined_AttributeType_Null ()
2229 TypeBuilder tb = module.DefineType (genTypeName ());
2230 tb.CreateType ();
2232 try {
2233 tb.IsDefined ((Type) null, false);
2234 Assert.Fail ("#1");
2235 } catch (ArgumentNullException ex) {
2236 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2237 Assert.IsNull (ex.InnerException, "#3");
2238 Assert.IsNotNull (ex.Message, "#4");
2239 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
2243 [Test] // GetConstructor (Type [])
2244 public void GetConstructor1_Incomplete ()
2246 TypeBuilder tb = module.DefineType (genTypeName ());
2247 ConstructorBuilder cb = tb.DefineConstructor (
2248 MethodAttributes.Public,
2249 CallingConventions.Standard,
2250 Type.EmptyTypes);
2251 cb.GetILGenerator ().Emit (OpCodes.Ret);
2253 try {
2254 tb.GetConstructor (Type.EmptyTypes);
2255 Assert.Fail ("#1");
2256 } catch (NotSupportedException ex) {
2257 // The invoked member is not supported in a
2258 // dynamic module
2259 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
2260 Assert.IsNull (ex.InnerException, "#3");
2261 Assert.IsNotNull (ex.Message, "#4");
2265 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2266 public void GetConstructor2_Complete ()
2268 BindingFlags flags;
2269 ConstructorInfo ctor;
2271 TypeBuilder redType = module.DefineType (genTypeName (),
2272 TypeAttributes.Public);
2273 CreateMembers (redType, "Red", true);
2275 TypeBuilder greenType = module.DefineType (genTypeName (),
2276 TypeAttributes.Public, redType);
2277 CreateMembers (greenType, "Green", false);
2278 ConstructorBuilder cb = greenType.DefineConstructor (
2279 MethodAttributes.Public,
2280 CallingConventions.Standard,
2281 Type.EmptyTypes);
2282 cb.GetILGenerator ().Emit (OpCodes.Ret);
2284 redType.CreateType ();
2285 greenType.CreateType ();
2287 flags = BindingFlags.Instance | BindingFlags.NonPublic;
2289 ctor = greenType.GetConstructor (flags, null,
2290 new Type [] { typeof (int), typeof (int) },
2291 new ParameterModifier [0]);
2292 Assert.IsNull (ctor, "#A1");
2294 ctor = greenType.GetConstructor (flags, null,
2295 new Type [] { typeof (string) },
2296 new ParameterModifier [0]);
2297 Assert.IsNull (ctor, "#A2");
2299 ctor = greenType.GetConstructor (flags, null,
2300 new Type [] { typeof (string), typeof (string) },
2301 new ParameterModifier [0]);
2302 Assert.IsNull (ctor, "#A3");
2304 ctor = greenType.GetConstructor (flags, null,
2305 new Type [] { typeof (int) },
2306 new ParameterModifier [0]);
2307 Assert.IsNull (ctor, "#A4");
2309 ctor = greenType.GetConstructor (flags, null,
2310 new Type [] { typeof (int), typeof (bool) },
2311 new ParameterModifier [0]);
2312 Assert.IsNull (ctor, "#A5");
2314 ctor = greenType.GetConstructor (flags, null,
2315 new Type [] { typeof (string), typeof (int) },
2316 new ParameterModifier [0]);
2317 Assert.IsNull (ctor, "#A6");
2319 ctor = greenType.GetConstructor (flags, null,
2320 Type.EmptyTypes,
2321 new ParameterModifier [0]);
2322 Assert.IsNull (ctor, "#A7");
2324 ctor = redType.GetConstructor (flags, null,
2325 new Type [] { typeof (int), typeof (int) },
2326 new ParameterModifier [0]);
2327 Assert.IsNotNull (ctor, "#A8a");
2328 Assert.IsTrue (ctor.IsPrivate, "#A8b");
2329 Assert.IsFalse (ctor.IsStatic, "#A8c");
2330 Assert.AreEqual (2, ctor.GetParameters ().Length, "#A8d");
2331 Assert.IsFalse (ctor is ConstructorBuilder, "#A8e");
2333 ctor = redType.GetConstructor (flags, null,
2334 new Type [] { typeof (string) },
2335 new ParameterModifier [0]);
2336 Assert.IsNotNull (ctor, "#A9a");
2337 Assert.IsTrue (ctor.IsFamily, "#A9b");
2338 Assert.IsFalse (ctor.IsStatic, "#A9c");
2339 Assert.AreEqual (1, ctor.GetParameters ().Length, "#A9d");
2340 Assert.IsFalse (ctor is ConstructorBuilder, "#A9e");
2342 ctor = redType.GetConstructor (flags, null,
2343 new Type [] { typeof (string), typeof (string) },
2344 new ParameterModifier [0]);
2345 Assert.IsNotNull (ctor, "#A10a");
2346 Assert.IsTrue (ctor.IsFamilyAndAssembly, "#A10b");
2347 Assert.IsFalse (ctor.IsStatic, "#A10c");
2348 Assert.AreEqual (2, ctor.GetParameters ().Length, "#A10d");
2349 Assert.IsFalse (ctor is ConstructorBuilder, "#A10e");
2351 ctor = redType.GetConstructor (flags, null,
2352 new Type [] { typeof (int) },
2353 new ParameterModifier [0]);
2354 Assert.IsNotNull (ctor, "#A11a");
2355 Assert.IsTrue (ctor.IsFamilyOrAssembly, "#A11b");
2356 Assert.IsFalse (ctor.IsStatic, "#A11c");
2357 Assert.AreEqual (1, ctor.GetParameters ().Length, "#A11d");
2358 Assert.IsFalse (ctor is ConstructorBuilder, "#A11e");
2360 ctor = redType.GetConstructor (flags, null,
2361 new Type [] { typeof (int), typeof (bool) },
2362 new ParameterModifier [0]);
2363 Assert.IsNull (ctor, "#A12");
2365 ctor = redType.GetConstructor (flags, null,
2366 new Type [] { typeof (string), typeof (int) },
2367 new ParameterModifier [0]);
2368 Assert.IsNotNull (ctor, "#A13a");
2369 Assert.IsTrue (ctor.IsAssembly, "#A13b");
2370 Assert.IsFalse (ctor.IsStatic, "#A13c");
2371 Assert.AreEqual (2, ctor.GetParameters ().Length, "#A13d");
2372 Assert.IsFalse (ctor is ConstructorBuilder, "#A13e");
2374 ctor = redType.GetConstructor (flags, null,
2375 Type.EmptyTypes,
2376 new ParameterModifier [0]);
2377 Assert.IsNull (ctor, "#A14");
2379 flags = BindingFlags.Instance | BindingFlags.Public;
2381 ctor = greenType.GetConstructor (flags, null,
2382 new Type [] { typeof (int), typeof (int) },
2383 new ParameterModifier [0]);
2384 Assert.IsNull (ctor, "#B1");
2386 ctor = greenType.GetConstructor (flags, null,
2387 new Type [] { typeof (string) },
2388 new ParameterModifier [0]);
2389 Assert.IsNull (ctor, "#B2");
2391 ctor = greenType.GetConstructor (flags, null,
2392 new Type [] { typeof (string), typeof (string) },
2393 new ParameterModifier [0]);
2394 Assert.IsNull (ctor, "#B3");
2396 ctor = greenType.GetConstructor (flags, null,
2397 new Type [] { typeof (int) },
2398 new ParameterModifier [0]);
2399 Assert.IsNull (ctor, "#B4");
2401 ctor = greenType.GetConstructor (flags, null,
2402 new Type [] { typeof (int), typeof (bool) },
2403 new ParameterModifier [0]);
2404 Assert.IsNull (ctor, "#B5");
2406 ctor = greenType.GetConstructor (flags, null,
2407 new Type [] { typeof (string), typeof (int) },
2408 new ParameterModifier [0]);
2409 Assert.IsNull (ctor, "#B6");
2411 ctor = greenType.GetConstructor (flags, null,
2412 Type.EmptyTypes,
2413 new ParameterModifier [0]);
2414 Assert.IsNotNull (ctor, "#B7a");
2415 Assert.IsTrue (ctor.IsPublic, "#B7b");
2416 Assert.IsFalse (ctor.IsStatic, "#B7c");
2417 Assert.AreEqual (0, ctor.GetParameters ().Length, "#B7d");
2418 Assert.IsFalse (ctor is ConstructorBuilder, "#B7e");
2420 ctor = redType.GetConstructor (flags, null,
2421 new Type [] { typeof (int), typeof (int) },
2422 new ParameterModifier [0]);
2423 Assert.IsNull (ctor, "#B8");
2425 ctor = redType.GetConstructor (flags, null,
2426 new Type [] { typeof (string) },
2427 new ParameterModifier [0]);
2428 Assert.IsNull (ctor, "#B9");
2430 ctor = redType.GetConstructor (flags, null,
2431 new Type [] { typeof (string), typeof (string) },
2432 new ParameterModifier [0]);
2433 Assert.IsNull (ctor, "#B10");
2435 ctor = redType.GetConstructor (flags, null,
2436 new Type [] { typeof (int) },
2437 new ParameterModifier [0]);
2438 Assert.IsNull (ctor, "#B11");
2440 ctor = redType.GetConstructor (flags, null,
2441 new Type [] { typeof (int), typeof (bool) },
2442 new ParameterModifier [0]);
2443 Assert.IsNotNull (ctor, "#B12a");
2444 Assert.IsTrue (ctor.IsPublic, "#B12b");
2445 Assert.IsFalse (ctor.IsStatic, "#B12c");
2446 Assert.AreEqual (2, ctor.GetParameters ().Length, "#B12d");
2447 Assert.IsFalse (ctor is ConstructorBuilder, "#B12e");
2449 ctor = redType.GetConstructor (flags, null,
2450 new Type [] { typeof (string), typeof (int) },
2451 new ParameterModifier [0]);
2452 Assert.IsNull (ctor, "#B13");
2454 ctor = redType.GetConstructor (flags, null,
2455 Type.EmptyTypes,
2456 new ParameterModifier [0]);
2457 Assert.IsNull (ctor, "#B14");
2459 flags = BindingFlags.Static | BindingFlags.Public;
2461 ctor = greenType.GetConstructor (flags, null,
2462 new Type [] { typeof (int), typeof (int) },
2463 new ParameterModifier [0]);
2464 Assert.IsNull (ctor, "#C1");
2466 ctor = greenType.GetConstructor (flags, null,
2467 new Type [] { typeof (string) },
2468 new ParameterModifier [0]);
2469 Assert.IsNull (ctor, "#C2");
2471 ctor = greenType.GetConstructor (flags, null,
2472 new Type [] { typeof (string), typeof (string) },
2473 new ParameterModifier [0]);
2474 Assert.IsNull (ctor, "#C3");
2476 ctor = greenType.GetConstructor (flags, null,
2477 new Type [] { typeof (int) },
2478 new ParameterModifier [0]);
2479 Assert.IsNull (ctor, "#C4");
2481 ctor = greenType.GetConstructor (flags, null,
2482 new Type [] { typeof (int), typeof (bool) },
2483 new ParameterModifier [0]);
2484 Assert.IsNull (ctor, "#C5");
2486 ctor = greenType.GetConstructor (flags, null,
2487 new Type [] { typeof (string), typeof (int) },
2488 new ParameterModifier [0]);
2489 Assert.IsNull (ctor, "#C6");
2491 ctor = greenType.GetConstructor (flags, null,
2492 Type.EmptyTypes,
2493 new ParameterModifier [0]);
2494 Assert.IsNull (ctor, "#C7");
2496 ctor = redType.GetConstructor (flags, null,
2497 new Type [] { typeof (int), typeof (int) },
2498 new ParameterModifier [0]);
2499 Assert.IsNull (ctor, "#C8");
2501 ctor = redType.GetConstructor (flags, null,
2502 new Type [] { typeof (string) },
2503 new ParameterModifier [0]);
2504 Assert.IsNull (ctor, "#C9");
2506 ctor = redType.GetConstructor (flags, null,
2507 new Type [] { typeof (string), typeof (string) },
2508 new ParameterModifier [0]);
2509 Assert.IsNull (ctor, "#C10");
2511 ctor = redType.GetConstructor (flags, null,
2512 new Type [] { typeof (int) },
2513 new ParameterModifier [0]);
2514 Assert.IsNull (ctor, "#C11a");
2516 ctor = redType.GetConstructor (flags, null,
2517 new Type [] { typeof (int), typeof (bool) },
2518 new ParameterModifier [0]);
2519 Assert.IsNull (ctor, "#C12");
2521 ctor = redType.GetConstructor (flags, null,
2522 new Type [] { typeof (string), typeof (int) },
2523 new ParameterModifier [0]);
2524 Assert.IsNull (ctor, "#C13");
2526 ctor = redType.GetConstructor (flags, null,
2527 Type.EmptyTypes,
2528 new ParameterModifier [0]);
2529 Assert.IsNull (ctor, "#C14");
2531 flags = BindingFlags.Static | BindingFlags.NonPublic;
2533 ctor = greenType.GetConstructor (flags, null,
2534 new Type [] { typeof (int), typeof (int) },
2535 new ParameterModifier [0]);
2536 Assert.IsNull (ctor, "#D1");
2538 ctor = greenType.GetConstructor (flags, null,
2539 new Type [] { typeof (string) },
2540 new ParameterModifier [0]);
2541 Assert.IsNull (ctor, "#D2");
2543 ctor = greenType.GetConstructor (flags, null,
2544 new Type [] { typeof (string), typeof (string) },
2545 new ParameterModifier [0]);
2546 Assert.IsNull (ctor, "#D3");
2548 ctor = greenType.GetConstructor (flags, null,
2549 new Type [] { typeof (int) },
2550 new ParameterModifier [0]);
2551 Assert.IsNull (ctor, "#D4");
2553 ctor = greenType.GetConstructor (flags, null,
2554 new Type [] { typeof (int), typeof (bool) },
2555 new ParameterModifier [0]);
2556 Assert.IsNull (ctor, "#D5");
2558 ctor = greenType.GetConstructor (flags, null,
2559 new Type [] { typeof (string), typeof (int) },
2560 new ParameterModifier [0]);
2561 Assert.IsNull (ctor, "#D6");
2563 ctor = greenType.GetConstructor (flags, null,
2564 Type.EmptyTypes,
2565 new ParameterModifier [0]);
2566 Assert.IsNull (ctor, "#D7");
2568 ctor = redType.GetConstructor (flags, null,
2569 new Type [] { typeof (int), typeof (int) },
2570 new ParameterModifier [0]);
2571 Assert.IsNull (ctor, "#D8");
2573 ctor = redType.GetConstructor (flags, null,
2574 new Type [] { typeof (string) },
2575 new ParameterModifier [0]);
2576 Assert.IsNull (ctor, "#D9");
2578 ctor = redType.GetConstructor (flags, null,
2579 new Type [] { typeof (string), typeof (string) },
2580 new ParameterModifier [0]);
2581 Assert.IsNull (ctor, "#D10");
2583 ctor = redType.GetConstructor (flags, null,
2584 new Type [] { typeof (int) },
2585 new ParameterModifier [0]);
2586 Assert.IsNull (ctor, "#D11");
2588 ctor = redType.GetConstructor (flags, null,
2589 new Type [] { typeof (int), typeof (bool) },
2590 new ParameterModifier [0]);
2591 Assert.IsNull (ctor, "#D12");
2593 ctor = redType.GetConstructor (flags, null,
2594 new Type [] { typeof (string), typeof (int) },
2595 new ParameterModifier [0]);
2596 Assert.IsNull (ctor, "#D13");
2598 ctor = redType.GetConstructor (flags, null,
2599 Type.EmptyTypes,
2600 new ParameterModifier [0]);
2601 Assert.IsNotNull (ctor, "#D14a");
2602 Assert.IsTrue (ctor.IsPrivate, "#D14b");
2603 Assert.IsTrue (ctor.IsStatic, "#B14c");
2604 Assert.AreEqual (0, ctor.GetParameters ().Length, "#B14d");
2605 Assert.IsFalse (ctor is ConstructorBuilder, "#B14e");
2607 flags = BindingFlags.Instance | BindingFlags.NonPublic |
2608 BindingFlags.FlattenHierarchy;
2610 ctor = greenType.GetConstructor (flags, null,
2611 new Type [] { typeof (int), typeof (int) },
2612 new ParameterModifier [0]);
2613 Assert.IsNull (ctor, "#E1");
2615 ctor = greenType.GetConstructor (flags, null,
2616 new Type [] { typeof (string) },
2617 new ParameterModifier [0]);
2618 Assert.IsNull (ctor, "#E2");
2620 ctor = greenType.GetConstructor (flags, null,
2621 new Type [] { typeof (string), typeof (string) },
2622 new ParameterModifier [0]);
2623 Assert.IsNull (ctor, "#E3");
2625 ctor = greenType.GetConstructor (flags, null,
2626 new Type [] { typeof (int) },
2627 new ParameterModifier [0]);
2628 Assert.IsNull (ctor, "#E4");
2630 ctor = greenType.GetConstructor (flags, null,
2631 new Type [] { typeof (int), typeof (bool) },
2632 new ParameterModifier [0]);
2633 Assert.IsNull (ctor, "#E5");
2635 ctor = greenType.GetConstructor (flags, null,
2636 new Type [] { typeof (string), typeof (int) },
2637 new ParameterModifier [0]);
2638 Assert.IsNull (ctor, "#E6");
2640 ctor = greenType.GetConstructor (flags, null,
2641 Type.EmptyTypes,
2642 new ParameterModifier [0]);
2643 Assert.IsNull (ctor, "#E7");
2645 ctor = redType.GetConstructor (flags, null,
2646 new Type [] { typeof (int), typeof (int) },
2647 new ParameterModifier [0]);
2648 Assert.IsNotNull (ctor, "#E8a");
2649 Assert.IsTrue (ctor.IsPrivate, "#E8b");
2650 Assert.IsFalse (ctor.IsStatic, "#E8c");
2651 Assert.AreEqual (2, ctor.GetParameters ().Length, "#E8d");
2652 Assert.IsFalse (ctor is ConstructorBuilder, "#E8e");
2654 ctor = redType.GetConstructor (flags, null,
2655 new Type [] { typeof (string) },
2656 new ParameterModifier [0]);
2657 Assert.IsNotNull (ctor, "#E9a");
2658 Assert.IsTrue (ctor.IsFamily, "#E9b");
2659 Assert.IsFalse (ctor.IsStatic, "#E9c");
2660 Assert.AreEqual (1, ctor.GetParameters ().Length, "#E9d");
2661 Assert.IsFalse (ctor is ConstructorBuilder, "#E9e");
2663 ctor = redType.GetConstructor (flags, null,
2664 new Type [] { typeof (string), typeof (string) },
2665 new ParameterModifier [0]);
2666 Assert.IsNotNull (ctor, "#E10a");
2667 Assert.IsTrue (ctor.IsFamilyAndAssembly, "#E10b");
2668 Assert.IsFalse (ctor.IsStatic, "#E10c");
2669 Assert.AreEqual (2, ctor.GetParameters ().Length, "#E10d");
2670 Assert.IsFalse (ctor is ConstructorBuilder, "#E10e");
2672 ctor = redType.GetConstructor (flags, null,
2673 new Type [] { typeof (int) },
2674 new ParameterModifier [0]);
2675 Assert.IsNotNull (ctor, "#E11a");
2676 Assert.IsTrue (ctor.IsFamilyOrAssembly, "#E11b");
2677 Assert.IsFalse (ctor.IsStatic, "#E11c");
2678 Assert.AreEqual (1, ctor.GetParameters ().Length, "#E11d");
2679 Assert.IsFalse (ctor is ConstructorBuilder, "#E11e");
2681 ctor = redType.GetConstructor (flags, null,
2682 new Type [] { typeof (int), typeof (bool) },
2683 new ParameterModifier [0]);
2684 Assert.IsNull (ctor, "#E12");
2686 ctor = redType.GetConstructor (flags, null,
2687 new Type [] { typeof (string), typeof (int) },
2688 new ParameterModifier [0]);
2689 Assert.IsNotNull (ctor, "#E13a");
2690 Assert.IsTrue (ctor.IsAssembly, "#E13b");
2691 Assert.IsFalse (ctor.IsStatic, "#E13c");
2692 Assert.AreEqual (2, ctor.GetParameters ().Length, "#E13d");
2693 Assert.IsFalse (ctor is ConstructorBuilder, "#E13e");
2695 ctor = redType.GetConstructor (flags, null,
2696 Type.EmptyTypes,
2697 new ParameterModifier [0]);
2698 Assert.IsNull (ctor, "#E14");
2700 flags = BindingFlags.Instance | BindingFlags.Public |
2701 BindingFlags.FlattenHierarchy;
2703 ctor = greenType.GetConstructor (flags, null,
2704 new Type [] { typeof (int), typeof (int) },
2705 new ParameterModifier [0]);
2706 Assert.IsNull (ctor, "#F1");
2708 ctor = greenType.GetConstructor (flags, null,
2709 new Type [] { typeof (string) },
2710 new ParameterModifier [0]);
2711 Assert.IsNull (ctor, "#F2");
2713 ctor = greenType.GetConstructor (flags, null,
2714 new Type [] { typeof (string), typeof (string) },
2715 new ParameterModifier [0]);
2716 Assert.IsNull (ctor, "#F3");
2718 ctor = greenType.GetConstructor (flags, null,
2719 new Type [] { typeof (int) },
2720 new ParameterModifier [0]);
2721 Assert.IsNull (ctor, "#F4");
2723 ctor = greenType.GetConstructor (flags, null,
2724 new Type [] { typeof (int), typeof (bool) },
2725 new ParameterModifier [0]);
2726 Assert.IsNull (ctor, "#F5");
2728 ctor = greenType.GetConstructor (flags, null,
2729 new Type [] { typeof (string), typeof (int) },
2730 new ParameterModifier [0]);
2731 Assert.IsNull (ctor, "#F6");
2733 ctor = greenType.GetConstructor (flags, null,
2734 Type.EmptyTypes,
2735 new ParameterModifier [0]);
2736 Assert.IsNotNull (ctor, "#F7a");
2737 Assert.IsTrue (ctor.IsPublic, "#F7b");
2738 Assert.IsFalse (ctor.IsStatic, "#F7c");
2739 Assert.AreEqual (0, ctor.GetParameters ().Length, "#F7d");
2740 Assert.IsFalse (ctor is ConstructorBuilder, "#F7e");
2742 ctor = redType.GetConstructor (flags, null,
2743 new Type [] { typeof (int), typeof (int) },
2744 new ParameterModifier [0]);
2745 Assert.IsNull (ctor, "#F8");
2747 ctor = redType.GetConstructor (flags, null,
2748 new Type [] { typeof (string) },
2749 new ParameterModifier [0]);
2750 Assert.IsNull (ctor, "#F9");
2752 ctor = redType.GetConstructor (flags, null,
2753 new Type [] { typeof (string), typeof (string) },
2754 new ParameterModifier [0]);
2755 Assert.IsNull (ctor, "#F10");
2757 ctor = redType.GetConstructor (flags, null,
2758 new Type [] { typeof (int) },
2759 new ParameterModifier [0]);
2760 Assert.IsNull (ctor, "#F11");
2762 ctor = redType.GetConstructor (flags, null,
2763 new Type [] { typeof (int), typeof (bool) },
2764 new ParameterModifier [0]);
2765 Assert.IsNotNull (ctor, "#F12a");
2766 Assert.IsTrue (ctor.IsPublic, "#F12b");
2767 Assert.IsFalse (ctor.IsStatic, "#F12c");
2768 Assert.AreEqual (2, ctor.GetParameters ().Length, "#F12d");
2769 Assert.IsFalse (ctor is ConstructorBuilder, "#F12e");
2771 ctor = redType.GetConstructor (flags, null,
2772 new Type [] { typeof (string), typeof (int) },
2773 new ParameterModifier [0]);
2774 Assert.IsNull (ctor, "#F13");
2776 ctor = redType.GetConstructor (flags, null,
2777 Type.EmptyTypes,
2778 new ParameterModifier [0]);
2779 Assert.IsNull (ctor, "#F14");
2781 flags = BindingFlags.Static | BindingFlags.Public |
2782 BindingFlags.FlattenHierarchy;
2784 ctor = greenType.GetConstructor (flags, null,
2785 new Type [] { typeof (int), typeof (int) },
2786 new ParameterModifier [0]);
2787 Assert.IsNull (ctor, "#G1");
2789 ctor = greenType.GetConstructor (flags, null,
2790 new Type [] { typeof (string) },
2791 new ParameterModifier [0]);
2792 Assert.IsNull (ctor, "#G2");
2794 ctor = greenType.GetConstructor (flags, null,
2795 new Type [] { typeof (string), typeof (string) },
2796 new ParameterModifier [0]);
2797 Assert.IsNull (ctor, "#G3");
2799 ctor = greenType.GetConstructor (flags, null,
2800 new Type [] { typeof (int) },
2801 new ParameterModifier [0]);
2802 Assert.IsNull (ctor, "#G4");
2804 ctor = greenType.GetConstructor (flags, null,
2805 new Type [] { typeof (int), typeof (bool) },
2806 new ParameterModifier [0]);
2807 Assert.IsNull (ctor, "#G5");
2809 ctor = greenType.GetConstructor (flags, null,
2810 new Type [] { typeof (string), typeof (int) },
2811 new ParameterModifier [0]);
2812 Assert.IsNull (ctor, "#G6");
2814 ctor = greenType.GetConstructor (flags, null,
2815 Type.EmptyTypes,
2816 new ParameterModifier [0]);
2817 Assert.IsNull (ctor, "#G7");
2819 ctor = redType.GetConstructor (flags, null,
2820 new Type [] { typeof (int), typeof (int) },
2821 new ParameterModifier [0]);
2822 Assert.IsNull (ctor, "#G8");
2824 ctor = redType.GetConstructor (flags, null,
2825 new Type [] { typeof (string) },
2826 new ParameterModifier [0]);
2827 Assert.IsNull (ctor, "#G9");
2829 ctor = redType.GetConstructor (flags, null,
2830 new Type [] { typeof (string), typeof (string) },
2831 new ParameterModifier [0]);
2832 Assert.IsNull (ctor, "#G10");
2834 ctor = redType.GetConstructor (flags, null,
2835 new Type [] { typeof (int) },
2836 new ParameterModifier [0]);
2837 Assert.IsNull (ctor, "#G11");
2839 ctor = redType.GetConstructor (flags, null,
2840 new Type [] { typeof (int), typeof (bool) },
2841 new ParameterModifier [0]);
2842 Assert.IsNull (ctor, "#G12");
2844 ctor = redType.GetConstructor (flags, null,
2845 new Type [] { typeof (string), typeof (int) },
2846 new ParameterModifier [0]);
2847 Assert.IsNull (ctor, "#G13");
2849 ctor = redType.GetConstructor (flags, null,
2850 Type.EmptyTypes,
2851 new ParameterModifier [0]);
2852 Assert.IsNull (ctor, "#G14");
2854 flags = BindingFlags.Static | BindingFlags.NonPublic |
2855 BindingFlags.FlattenHierarchy;
2857 ctor = greenType.GetConstructor (flags, null,
2858 new Type [] { typeof (int), typeof (int) },
2859 new ParameterModifier [0]);
2860 Assert.IsNull (ctor, "#H1");
2862 ctor = greenType.GetConstructor (flags, null,
2863 new Type [] { typeof (string) },
2864 new ParameterModifier [0]);
2865 Assert.IsNull (ctor, "#H2");
2867 ctor = greenType.GetConstructor (flags, null,
2868 new Type [] { typeof (string), typeof (string) },
2869 new ParameterModifier [0]);
2870 Assert.IsNull (ctor, "#H3");
2872 ctor = greenType.GetConstructor (flags, null,
2873 new Type [] { typeof (int) },
2874 new ParameterModifier [0]);
2875 Assert.IsNull (ctor, "#H4");
2877 ctor = greenType.GetConstructor (flags, null,
2878 new Type [] { typeof (int), typeof (bool) },
2879 new ParameterModifier [0]);
2880 Assert.IsNull (ctor, "#H5");
2882 ctor = greenType.GetConstructor (flags, null,
2883 new Type [] { typeof (string), typeof (int) },
2884 new ParameterModifier [0]);
2885 Assert.IsNull (ctor, "#H6");
2887 ctor = greenType.GetConstructor (flags, null,
2888 Type.EmptyTypes,
2889 new ParameterModifier [0]);
2890 Assert.IsNull (ctor, "#H7");
2892 ctor = redType.GetConstructor (flags, null,
2893 new Type [] { typeof (int), typeof (int) },
2894 new ParameterModifier [0]);
2895 Assert.IsNull (ctor, "#H8");
2897 ctor = redType.GetConstructor (flags, null,
2898 new Type [] { typeof (string) },
2899 new ParameterModifier [0]);
2900 Assert.IsNull (ctor, "#H9");
2902 ctor = redType.GetConstructor (flags, null,
2903 new Type [] { typeof (string), typeof (string) },
2904 new ParameterModifier [0]);
2905 Assert.IsNull (ctor, "#H10");
2907 ctor = redType.GetConstructor (flags, null,
2908 new Type [] { typeof (int) },
2909 new ParameterModifier [0]);
2910 Assert.IsNull (ctor, "#H11");
2912 ctor = redType.GetConstructor (flags, null,
2913 new Type [] { typeof (int), typeof (bool) },
2914 new ParameterModifier [0]);
2915 Assert.IsNull (ctor, "#H12");
2917 ctor = redType.GetConstructor (flags, null,
2918 new Type [] { typeof (string), typeof (int) },
2919 new ParameterModifier [0]);
2920 Assert.IsNull (ctor, "#H13");
2922 ctor = redType.GetConstructor (flags, null,
2923 Type.EmptyTypes,
2924 new ParameterModifier [0]);
2925 Assert.IsNotNull (ctor, "#H14");
2926 Assert.IsTrue (ctor.IsPrivate, "#H14b");
2927 Assert.IsTrue (ctor.IsStatic, "#H14c");
2928 Assert.AreEqual (0, ctor.GetParameters ().Length, "#H14d");
2929 Assert.IsFalse (ctor is ConstructorBuilder, "#H14e");
2931 flags = BindingFlags.Instance | BindingFlags.NonPublic |
2932 BindingFlags.DeclaredOnly;
2934 ctor = greenType.GetConstructor (flags, null,
2935 new Type [] { typeof (int), typeof (int) },
2936 new ParameterModifier [0]);
2937 Assert.IsNull (ctor, "#I1");
2939 ctor = greenType.GetConstructor (flags, null,
2940 new Type [] { typeof (string) },
2941 new ParameterModifier [0]);
2942 Assert.IsNull (ctor, "#I2");
2944 ctor = greenType.GetConstructor (flags, null,
2945 new Type [] { typeof (string), typeof (string) },
2946 new ParameterModifier [0]);
2947 Assert.IsNull (ctor, "#I3");
2949 ctor = greenType.GetConstructor (flags, null,
2950 new Type [] { typeof (int) },
2951 new ParameterModifier [0]);
2952 Assert.IsNull (ctor, "#I4");
2954 ctor = greenType.GetConstructor (flags, null,
2955 new Type [] { typeof (int), typeof (bool) },
2956 new ParameterModifier [0]);
2957 Assert.IsNull (ctor, "#I5");
2959 ctor = greenType.GetConstructor (flags, null,
2960 new Type [] { typeof (string), typeof (int) },
2961 new ParameterModifier [0]);
2962 Assert.IsNull (ctor, "#I6");
2964 ctor = greenType.GetConstructor (flags, null,
2965 Type.EmptyTypes,
2966 new ParameterModifier [0]);
2967 Assert.IsNull (ctor, "#I7");
2969 ctor = redType.GetConstructor (flags, null,
2970 new Type [] { typeof (int), typeof (int) },
2971 new ParameterModifier [0]);
2972 Assert.IsNotNull (ctor, "#I8a");
2973 Assert.IsTrue (ctor.IsPrivate, "#I8b");
2974 Assert.IsFalse (ctor.IsStatic, "#I8c");
2975 Assert.AreEqual (2, ctor.GetParameters ().Length, "#I8d");
2976 Assert.IsFalse (ctor is ConstructorBuilder, "#I8e");
2978 ctor = redType.GetConstructor (flags, null,
2979 new Type [] { typeof (string) },
2980 new ParameterModifier [0]);
2981 Assert.IsNotNull (ctor, "#I9a");
2982 Assert.IsTrue (ctor.IsFamily, "#I9b");
2983 Assert.IsFalse (ctor.IsStatic, "#I9c");
2984 Assert.AreEqual (1, ctor.GetParameters ().Length, "#I9d");
2985 Assert.IsFalse (ctor is ConstructorBuilder, "#I9e");
2987 ctor = redType.GetConstructor (flags, null,
2988 new Type [] { typeof (string), typeof (string) },
2989 new ParameterModifier [0]);
2990 Assert.IsNotNull (ctor, "#I10a");
2991 Assert.IsTrue (ctor.IsFamilyAndAssembly, "#I10b");
2992 Assert.IsFalse (ctor.IsStatic, "#I10c");
2993 Assert.AreEqual (2, ctor.GetParameters ().Length, "#I10d");
2994 Assert.IsFalse (ctor is ConstructorBuilder, "#I10e");
2996 ctor = redType.GetConstructor (flags, null,
2997 new Type [] { typeof (int) },
2998 new ParameterModifier [0]);
2999 Assert.IsNotNull (ctor, "#I11a");
3000 Assert.IsTrue (ctor.IsFamilyOrAssembly, "#I11b");
3001 Assert.IsFalse (ctor.IsStatic, "#I11c");
3002 Assert.AreEqual (1, ctor.GetParameters ().Length, "#I11d");
3003 Assert.IsFalse (ctor is ConstructorBuilder, "#I11e");
3005 ctor = redType.GetConstructor (flags, null,
3006 new Type [] { typeof (int), typeof (bool) },
3007 new ParameterModifier [0]);
3008 Assert.IsNull (ctor, "#I12");
3010 ctor = redType.GetConstructor (flags, null,
3011 new Type [] { typeof (string), typeof (int) },
3012 new ParameterModifier [0]);
3013 Assert.IsNotNull (ctor, "#I13a");
3014 Assert.IsTrue (ctor.IsAssembly, "#I13b");
3015 Assert.IsFalse (ctor.IsStatic, "#I13c");
3016 Assert.AreEqual (2, ctor.GetParameters ().Length, "#I13d");
3017 Assert.IsFalse (ctor is ConstructorBuilder, "#I13e");
3019 ctor = redType.GetConstructor (flags, null,
3020 Type.EmptyTypes,
3021 new ParameterModifier [0]);
3022 Assert.IsNull (ctor, "#I14");
3024 flags = BindingFlags.Instance | BindingFlags.Public |
3025 BindingFlags.DeclaredOnly;
3027 ctor = greenType.GetConstructor (flags, null,
3028 new Type [] { typeof (int), typeof (int) },
3029 new ParameterModifier [0]);
3030 Assert.IsNull (ctor, "#J1");
3032 ctor = greenType.GetConstructor (flags, null,
3033 new Type [] { typeof (string) },
3034 new ParameterModifier [0]);
3035 Assert.IsNull (ctor, "#J2");
3037 ctor = greenType.GetConstructor (flags, null,
3038 new Type [] { typeof (string), typeof (string) },
3039 new ParameterModifier [0]);
3040 Assert.IsNull (ctor, "#J3");
3042 ctor = greenType.GetConstructor (flags, null,
3043 new Type [] { typeof (int) },
3044 new ParameterModifier [0]);
3045 Assert.IsNull (ctor, "#J4");
3047 ctor = greenType.GetConstructor (flags, null,
3048 new Type [] { typeof (int), typeof (bool) },
3049 new ParameterModifier [0]);
3050 Assert.IsNull (ctor, "#J5");
3052 ctor = greenType.GetConstructor (flags, null,
3053 new Type [] { typeof (string), typeof (int) },
3054 new ParameterModifier [0]);
3055 Assert.IsNull (ctor, "#J6");
3057 ctor = greenType.GetConstructor (flags, null,
3058 Type.EmptyTypes,
3059 new ParameterModifier [0]);
3060 Assert.IsNotNull (ctor, "#J7a");
3061 Assert.IsTrue (ctor.IsPublic, "#J7b");
3062 Assert.IsFalse (ctor.IsStatic, "#J7c");
3063 Assert.AreEqual (0, ctor.GetParameters ().Length, "#J7d");
3064 Assert.IsFalse (ctor is ConstructorBuilder, "#J7e");
3066 ctor = redType.GetConstructor (flags, null,
3067 new Type [] { typeof (int), typeof (int) },
3068 new ParameterModifier [0]);
3069 Assert.IsNull (ctor, "#J8");
3071 ctor = redType.GetConstructor (flags, null,
3072 new Type [] { typeof (string) },
3073 new ParameterModifier [0]);
3074 Assert.IsNull (ctor, "#J9");
3076 ctor = redType.GetConstructor (flags, null,
3077 new Type [] { typeof (string), typeof (string) },
3078 new ParameterModifier [0]);
3079 Assert.IsNull (ctor, "#J10");
3081 ctor = redType.GetConstructor (flags, null,
3082 new Type [] { typeof (int) },
3083 new ParameterModifier [0]);
3084 Assert.IsNull (ctor, "#J11");
3086 ctor = redType.GetConstructor (flags, null,
3087 new Type [] { typeof (int), typeof (bool) },
3088 new ParameterModifier [0]);
3089 Assert.IsNotNull (ctor, "#J12a");
3090 Assert.IsTrue (ctor.IsPublic, "#J12b");
3091 Assert.IsFalse (ctor.IsStatic, "#J12c");
3092 Assert.AreEqual (2, ctor.GetParameters ().Length, "#J12d");
3093 Assert.IsFalse (ctor is ConstructorBuilder, "#J12e");
3095 ctor = redType.GetConstructor (flags, null,
3096 new Type [] { typeof (string), typeof (int) },
3097 new ParameterModifier [0]);
3098 Assert.IsNull (ctor, "#J13");
3100 ctor = redType.GetConstructor (flags, null,
3101 Type.EmptyTypes,
3102 new ParameterModifier [0]);
3103 Assert.IsNull (ctor, "#J14");
3105 flags = BindingFlags.Static | BindingFlags.Public |
3106 BindingFlags.DeclaredOnly;
3108 ctor = greenType.GetConstructor (flags, null,
3109 new Type [] { typeof (int), typeof (int) },
3110 new ParameterModifier [0]);
3111 Assert.IsNull (ctor, "#K1");
3113 ctor = greenType.GetConstructor (flags, null,
3114 new Type [] { typeof (string) },
3115 new ParameterModifier [0]);
3116 Assert.IsNull (ctor, "#K2");
3118 ctor = greenType.GetConstructor (flags, null,
3119 new Type [] { typeof (string), typeof (string) },
3120 new ParameterModifier [0]);
3121 Assert.IsNull (ctor, "#K3");
3123 ctor = greenType.GetConstructor (flags, null,
3124 new Type [] { typeof (int) },
3125 new ParameterModifier [0]);
3126 Assert.IsNull (ctor, "#K4");
3128 ctor = greenType.GetConstructor (flags, null,
3129 new Type [] { typeof (int), typeof (bool) },
3130 new ParameterModifier [0]);
3131 Assert.IsNull (ctor, "#K5");
3133 ctor = greenType.GetConstructor (flags, null,
3134 new Type [] { typeof (string), typeof (int) },
3135 new ParameterModifier [0]);
3136 Assert.IsNull (ctor, "#K6");
3138 ctor = greenType.GetConstructor (flags, null,
3139 Type.EmptyTypes,
3140 new ParameterModifier [0]);
3141 Assert.IsNull (ctor, "#K7");
3143 ctor = redType.GetConstructor (flags, null,
3144 new Type [] { typeof (int), typeof (int) },
3145 new ParameterModifier [0]);
3146 Assert.IsNull (ctor, "#K8");
3148 ctor = redType.GetConstructor (flags, null,
3149 new Type [] { typeof (string) },
3150 new ParameterModifier [0]);
3151 Assert.IsNull (ctor, "#K9");
3153 ctor = redType.GetConstructor (flags, null,
3154 new Type [] { typeof (string), typeof (string) },
3155 new ParameterModifier [0]);
3156 Assert.IsNull (ctor, "#K10");
3158 ctor = redType.GetConstructor (flags, null,
3159 new Type [] { typeof (int) },
3160 new ParameterModifier [0]);
3161 Assert.IsNull (ctor, "#K11");
3163 ctor = redType.GetConstructor (flags, null,
3164 new Type [] { typeof (int), typeof (bool) },
3165 new ParameterModifier [0]);
3166 Assert.IsNull (ctor, "#K12");
3168 ctor = redType.GetConstructor (flags, null,
3169 new Type [] { typeof (string), typeof (int) },
3170 new ParameterModifier [0]);
3171 Assert.IsNull (ctor, "#K13");
3173 ctor = redType.GetConstructor (flags, null,
3174 Type.EmptyTypes,
3175 new ParameterModifier [0]);
3176 Assert.IsNull (ctor, "#K14");
3178 flags = BindingFlags.Static | BindingFlags.NonPublic |
3179 BindingFlags.DeclaredOnly;
3181 ctor = greenType.GetConstructor (flags, null,
3182 new Type [] { typeof (int), typeof (int) },
3183 new ParameterModifier [0]);
3184 Assert.IsNull (ctor, "#L1");
3186 ctor = greenType.GetConstructor (flags, null,
3187 new Type [] { typeof (string) },
3188 new ParameterModifier [0]);
3189 Assert.IsNull (ctor, "#L2");
3191 ctor = greenType.GetConstructor (flags, null,
3192 new Type [] { typeof (string), typeof (string) },
3193 new ParameterModifier [0]);
3194 Assert.IsNull (ctor, "#L3");
3196 ctor = greenType.GetConstructor (flags, null,
3197 new Type [] { typeof (int) },
3198 new ParameterModifier [0]);
3199 Assert.IsNull (ctor, "#L4");
3201 ctor = greenType.GetConstructor (flags, null,
3202 new Type [] { typeof (int), typeof (bool) },
3203 new ParameterModifier [0]);
3204 Assert.IsNull (ctor, "#L5");
3206 ctor = greenType.GetConstructor (flags, null,
3207 new Type [] { typeof (string), typeof (int) },
3208 new ParameterModifier [0]);
3209 Assert.IsNull (ctor, "#L6");
3211 ctor = greenType.GetConstructor (flags, null,
3212 Type.EmptyTypes,
3213 new ParameterModifier [0]);
3214 Assert.IsNull (ctor, "#L7");
3216 ctor = redType.GetConstructor (flags, null,
3217 new Type [] { typeof (int), typeof (int) },
3218 new ParameterModifier [0]);
3219 Assert.IsNull (ctor, "#L8");
3221 ctor = redType.GetConstructor (flags, null,
3222 new Type [] { typeof (string) },
3223 new ParameterModifier [0]);
3224 Assert.IsNull (ctor, "#L9");
3226 ctor = redType.GetConstructor (flags, null,
3227 new Type [] { typeof (string), typeof (string) },
3228 new ParameterModifier [0]);
3229 Assert.IsNull (ctor, "#L10");
3231 ctor = redType.GetConstructor (flags, null,
3232 new Type [] { typeof (int) },
3233 new ParameterModifier [0]);
3234 Assert.IsNull (ctor, "#L11");
3236 ctor = redType.GetConstructor (flags, null,
3237 new Type [] { typeof (int), typeof (bool) },
3238 new ParameterModifier [0]);
3239 Assert.IsNull (ctor, "#L12");
3241 ctor = redType.GetConstructor (flags, null,
3242 new Type [] { typeof (string), typeof (int) },
3243 new ParameterModifier [0]);
3244 Assert.IsNull (ctor, "#L13");
3246 ctor = redType.GetConstructor (flags, null,
3247 Type.EmptyTypes,
3248 new ParameterModifier [0]);
3249 Assert.IsNotNull (ctor, "#L14a");
3250 Assert.IsTrue (ctor.IsPrivate, "#L14b");
3251 Assert.IsTrue (ctor.IsStatic, "#L14c");
3252 Assert.AreEqual (0, ctor.GetParameters ().Length, "#L14d");
3253 Assert.IsFalse (ctor is ConstructorBuilder, "#L14e");
3255 flags = BindingFlags.Instance | BindingFlags.NonPublic |
3256 BindingFlags.Public;
3258 ctor = greenType.GetConstructor (flags, null,
3259 new Type [] { typeof (int), typeof (int) },
3260 new ParameterModifier [0]);
3261 Assert.IsNull (ctor, "#M1");
3263 ctor = greenType.GetConstructor (flags, null,
3264 new Type [] { typeof (string) },
3265 new ParameterModifier [0]);
3266 Assert.IsNull (ctor, "#M2");
3268 ctor = greenType.GetConstructor (flags, null,
3269 new Type [] { typeof (string), typeof (string) },
3270 new ParameterModifier [0]);
3271 Assert.IsNull (ctor, "#M3");
3273 ctor = greenType.GetConstructor (flags, null,
3274 new Type [] { typeof (int) },
3275 new ParameterModifier [0]);
3276 Assert.IsNull (ctor, "#M4");
3278 ctor = greenType.GetConstructor (flags, null,
3279 new Type [] { typeof (int), typeof (bool) },
3280 new ParameterModifier [0]);
3281 Assert.IsNull (ctor, "#M5");
3283 ctor = greenType.GetConstructor (flags, null,
3284 new Type [] { typeof (string), typeof (int) },
3285 new ParameterModifier [0]);
3286 Assert.IsNull (ctor, "#M6");
3288 ctor = greenType.GetConstructor (flags, null,
3289 Type.EmptyTypes,
3290 new ParameterModifier [0]);
3291 Assert.IsNotNull (ctor, "#M7a");
3292 Assert.IsTrue (ctor.IsPublic, "#M7b");
3293 Assert.IsFalse (ctor.IsStatic, "#M7c");
3294 Assert.AreEqual (0, ctor.GetParameters ().Length, "#M7d");
3295 Assert.IsFalse (ctor is ConstructorBuilder, "#M7e");
3297 ctor = redType.GetConstructor (flags, null,
3298 new Type [] { typeof (int), typeof (int) },
3299 new ParameterModifier [0]);
3300 Assert.IsNotNull (ctor, "#M8a");
3301 Assert.IsTrue (ctor.IsPrivate, "#M8b");
3302 Assert.IsFalse (ctor.IsStatic, "#M8c");
3303 Assert.AreEqual (2, ctor.GetParameters ().Length, "#M8d");
3304 Assert.IsFalse (ctor is ConstructorBuilder, "#M8e");
3306 ctor = redType.GetConstructor (flags, null,
3307 new Type [] { typeof (string) },
3308 new ParameterModifier [0]);
3309 Assert.IsNotNull (ctor, "#M9a");
3310 Assert.IsTrue (ctor.IsFamily, "#M9b");
3311 Assert.IsFalse (ctor.IsStatic, "#M9c");
3312 Assert.AreEqual (1, ctor.GetParameters ().Length, "#M9d");
3313 Assert.IsFalse (ctor is ConstructorBuilder, "#M9e");
3315 ctor = redType.GetConstructor (flags, null,
3316 new Type [] { typeof (string), typeof (string) },
3317 new ParameterModifier [0]);
3318 Assert.IsNotNull (ctor, "#M10a");
3319 Assert.IsTrue (ctor.IsFamilyAndAssembly, "#M10b");
3320 Assert.IsFalse (ctor.IsStatic, "#M10c");
3321 Assert.AreEqual (2, ctor.GetParameters ().Length, "#M10d");
3322 Assert.IsFalse (ctor is ConstructorBuilder, "#M10e");
3324 ctor = redType.GetConstructor (flags, null,
3325 new Type [] { typeof (int) },
3326 new ParameterModifier [0]);
3327 Assert.IsNotNull (ctor, "#M11a");
3328 Assert.IsTrue (ctor.IsFamilyOrAssembly, "#M11b");
3329 Assert.IsFalse (ctor.IsStatic, "#M11c");
3330 Assert.AreEqual (1, ctor.GetParameters ().Length, "#M11d");
3331 Assert.IsFalse (ctor is ConstructorBuilder, "#M11e");
3333 ctor = redType.GetConstructor (flags, null,
3334 new Type [] { typeof (int), typeof (bool) },
3335 new ParameterModifier [0]);
3336 Assert.IsNotNull (ctor, "#M12a");
3337 Assert.IsTrue (ctor.IsPublic, "#M12b");
3338 Assert.IsFalse (ctor.IsStatic, "#M12c");
3339 Assert.AreEqual (2, ctor.GetParameters ().Length, "#M12d");
3340 Assert.IsFalse (ctor is ConstructorBuilder, "#M12e");
3342 ctor = redType.GetConstructor (flags, null,
3343 new Type [] { typeof (string), typeof (int) },
3344 new ParameterModifier [0]);
3345 Assert.IsNotNull (ctor, "#M13a");
3346 Assert.IsTrue (ctor.IsAssembly, "#M13b");
3347 Assert.IsFalse (ctor.IsStatic, "#M13c");
3348 Assert.AreEqual (2, ctor.GetParameters ().Length, "#M13d");
3349 Assert.IsFalse (ctor is ConstructorBuilder, "#M13e");
3351 ctor = redType.GetConstructor (flags, null,
3352 Type.EmptyTypes,
3353 new ParameterModifier [0]);
3354 Assert.IsNull (ctor, "#M14");
3356 flags = BindingFlags.Static | BindingFlags.NonPublic |
3357 BindingFlags.Public;
3359 ctor = greenType.GetConstructor (flags, null,
3360 new Type [] { typeof (int), typeof (int) },
3361 new ParameterModifier [0]);
3362 Assert.IsNull (ctor, "#N1");
3364 ctor = greenType.GetConstructor (flags, null,
3365 new Type [] { typeof (string) },
3366 new ParameterModifier [0]);
3367 Assert.IsNull (ctor, "#N2");
3369 ctor = greenType.GetConstructor (flags, null,
3370 new Type [] { typeof (string), typeof (string) },
3371 new ParameterModifier [0]);
3372 Assert.IsNull (ctor, "#N3");
3374 ctor = greenType.GetConstructor (flags, null,
3375 new Type [] { typeof (int) },
3376 new ParameterModifier [0]);
3377 Assert.IsNull (ctor, "#N4");
3379 ctor = greenType.GetConstructor (flags, null,
3380 new Type [] { typeof (int), typeof (bool) },
3381 new ParameterModifier [0]);
3382 Assert.IsNull (ctor, "#N5");
3384 ctor = greenType.GetConstructor (flags, null,
3385 new Type [] { typeof (string), typeof (int) },
3386 new ParameterModifier [0]);
3387 Assert.IsNull (ctor, "#N6");
3389 ctor = greenType.GetConstructor (flags, null,
3390 Type.EmptyTypes,
3391 new ParameterModifier [0]);
3392 Assert.IsNull (ctor, "#N7");
3394 ctor = redType.GetConstructor (flags, null,
3395 new Type [] { typeof (int), typeof (int) },
3396 new ParameterModifier [0]);
3397 Assert.IsNull (ctor, "#N8");
3399 ctor = redType.GetConstructor (flags, null,
3400 new Type [] { typeof (string) },
3401 new ParameterModifier [0]);
3402 Assert.IsNull (ctor, "#N9");
3404 ctor = redType.GetConstructor (flags, null,
3405 new Type [] { typeof (string), typeof (string) },
3406 new ParameterModifier [0]);
3407 Assert.IsNull (ctor, "#N10");
3409 ctor = redType.GetConstructor (flags, null,
3410 new Type [] { typeof (int) },
3411 new ParameterModifier [0]);
3412 Assert.IsNull (ctor, "#N11");
3414 ctor = redType.GetConstructor (flags, null,
3415 new Type [] { typeof (int), typeof (bool) },
3416 new ParameterModifier [0]);
3417 Assert.IsNull (ctor, "#N12");
3419 ctor = redType.GetConstructor (flags, null,
3420 new Type [] { typeof (string), typeof (int) },
3421 new ParameterModifier [0]);
3422 Assert.IsNull (ctor, "#N13");
3424 ctor = redType.GetConstructor (flags, null,
3425 Type.EmptyTypes,
3426 new ParameterModifier [0]);
3427 Assert.IsNotNull (ctor, "#N14a");
3428 Assert.IsTrue (ctor.IsPrivate, "#N14b");
3429 Assert.IsTrue (ctor.IsStatic, "#N14c");
3430 Assert.AreEqual (0, ctor.GetParameters ().Length, "#N14d");
3431 Assert.IsFalse (ctor is ConstructorBuilder, "#N14e");
3434 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
3435 public void GetConstructor2_Incomplete ()
3437 TypeBuilder tb = module.DefineType (genTypeName ());
3438 ConstructorBuilder cb = tb.DefineConstructor (
3439 MethodAttributes.Public,
3440 CallingConventions.Standard,
3441 Type.EmptyTypes);
3442 cb.GetILGenerator ().Emit (OpCodes.Ret);
3444 try {
3445 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3446 null, Type.EmptyTypes, new ParameterModifier [0]);
3447 Assert.Fail ("#1");
3448 } catch (NotSupportedException ex) {
3449 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3450 Assert.IsNull (ex.InnerException, "#3");
3451 Assert.IsNotNull (ex.Message, "#4");
3455 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
3456 public void GetConstructor3_Incomplete ()
3458 TypeBuilder tb = module.DefineType (genTypeName ());
3459 ConstructorBuilder cb = tb.DefineConstructor (
3460 MethodAttributes.Public,
3461 CallingConventions.Standard,
3462 Type.EmptyTypes);
3463 cb.GetILGenerator ().Emit (OpCodes.Ret);
3465 try {
3466 tb.GetConstructor (BindingFlags.Public | BindingFlags.Instance,
3467 null, CallingConventions.Standard, Type.EmptyTypes,
3468 new ParameterModifier [0]);
3469 Assert.Fail ("#1");
3470 } catch (NotSupportedException ex) {
3471 // The invoked member is not supported in a
3472 // dynamic module
3473 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3474 Assert.IsNull (ex.InnerException, "#3");
3475 Assert.IsNotNull (ex.Message, "#4");
3479 [Test] // GetConstructors ()
3480 [Category ("NotWorking")] // mcs depends on this
3481 public void GetConstructors1_Incomplete ()
3483 TypeBuilder tb = module.DefineType (genTypeName ());
3484 ConstructorBuilder cb = tb.DefineConstructor (
3485 MethodAttributes.Public,
3486 CallingConventions.Standard,
3487 Type.EmptyTypes);
3488 cb.GetILGenerator ().Emit (OpCodes.Ret);
3490 try {
3491 tb.GetConstructors ();
3492 Assert.Fail ("#1");
3493 } catch (NotSupportedException ex) {
3494 // The invoked member is not supported in a
3495 // dynamic module
3496 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3497 Assert.IsNull (ex.InnerException, "#3");
3498 Assert.IsNotNull (ex.Message, "#4");
3502 [Test] // GetConstructors (BindingFlags)
3503 public void GetConstructors2_Complete ()
3505 BindingFlags flags;
3506 ConstructorInfo [] ctors;
3508 TypeBuilder redType = module.DefineType (genTypeName (),
3509 TypeAttributes.Public);
3510 CreateMembers (redType, "Red", true);
3512 TypeBuilder greenType = module.DefineType (genTypeName (),
3513 TypeAttributes.Public, redType);
3514 CreateMembers (greenType, "Green", false);
3515 ConstructorBuilder cb = greenType.DefineConstructor (
3516 MethodAttributes.Public,
3517 CallingConventions.Standard,
3518 Type.EmptyTypes);
3519 cb.GetILGenerator ().Emit (OpCodes.Ret);
3521 redType.CreateType ();
3522 greenType.CreateType ();
3524 flags = BindingFlags.Instance | BindingFlags.NonPublic;
3526 ctors = greenType.GetConstructors (flags);
3527 Assert.AreEqual (0, ctors.Length, "#A1");
3529 ctors = redType.GetConstructors (flags);
3530 Assert.AreEqual (5, ctors.Length, "#A2");
3531 Assert.IsTrue (ctors [0].IsPrivate, "#A3a");
3532 Assert.IsFalse (ctors [0].IsStatic, "#A3b");
3533 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#A3c");
3534 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#A3d");
3535 Assert.IsTrue (ctors [1].IsFamily, "#A4a");
3536 Assert.IsFalse (ctors [1].IsStatic, "#A4b");
3537 Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#A4c");
3538 Assert.IsFalse (ctors [1] is ConstructorBuilder, "#A4d");
3539 Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#A5a");
3540 Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3541 Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#A5c");
3542 Assert.IsFalse (ctors [2] is ConstructorBuilder, "#A5d");
3543 Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#A6a");
3544 Assert.IsFalse (ctors [3].IsStatic, "#A6b");
3545 Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#A6c");
3546 Assert.IsFalse (ctors [3] is ConstructorBuilder, "#A6d");
3547 Assert.IsTrue (ctors [4].IsAssembly, "#A7a");
3548 Assert.IsFalse (ctors [4].IsStatic, "#A7b");
3549 Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#A7c");
3550 Assert.IsFalse (ctors [4] is ConstructorBuilder, "#A7d");
3552 flags = BindingFlags.Instance | BindingFlags.Public;
3554 ctors = greenType.GetConstructors (flags);
3555 Assert.AreEqual (1, ctors.Length, "#B1");
3556 Assert.IsTrue (ctors [0].IsPublic, "#B2a");
3557 Assert.IsFalse (ctors [0].IsStatic, "#B2b");
3558 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#B2c");
3559 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B2d");
3561 ctors = redType.GetConstructors (flags);
3562 Assert.AreEqual (1, ctors.Length, "#B3");
3563 Assert.IsTrue (ctors [0].IsPublic, "#B4a");
3564 Assert.IsFalse (ctors [0].IsStatic, "#B4b");
3565 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#B4c");
3566 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#B4d");
3568 flags = BindingFlags.Static | BindingFlags.Public;
3570 ctors = greenType.GetConstructors (flags);
3571 Assert.AreEqual (0, ctors.Length, "#C1");
3573 ctors = redType.GetConstructors (flags);
3574 Assert.AreEqual (0, ctors.Length, "#C2");
3576 flags = BindingFlags.Static | BindingFlags.NonPublic;
3578 ctors = greenType.GetConstructors (flags);
3579 Assert.AreEqual (0, ctors.Length, "#D1");
3581 ctors = redType.GetConstructors (flags);
3582 Assert.AreEqual (1, ctors.Length, "#D2");
3583 Assert.IsTrue (ctors [0].IsPrivate, "#D3a");
3584 Assert.IsTrue (ctors [0].IsStatic, "#D3b");
3585 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#D3c");
3586 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#D3d");
3588 flags = BindingFlags.Instance | BindingFlags.NonPublic |
3589 BindingFlags.FlattenHierarchy;
3591 ctors = greenType.GetConstructors (flags);
3592 Assert.AreEqual (0, ctors.Length, "#E1");
3594 ctors = redType.GetConstructors (flags);
3595 Assert.AreEqual (5, ctors.Length, "#E2");
3596 Assert.IsTrue (ctors [0].IsPrivate, "#E3a");
3597 Assert.IsFalse (ctors [0].IsStatic, "#E3b");
3598 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#E3c");
3599 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#E3d");
3600 Assert.IsTrue (ctors [1].IsFamily, "#E4a");
3601 Assert.IsFalse (ctors [1].IsStatic, "#E4b");
3602 Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#E4c");
3603 Assert.IsFalse (ctors [1] is ConstructorBuilder, "#E4d");
3604 Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#E5a");
3605 Assert.IsFalse (ctors [2].IsStatic, "#A5b");
3606 Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#E5c");
3607 Assert.IsFalse (ctors [2] is ConstructorBuilder, "#E5d");
3608 Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#E6a");
3609 Assert.IsFalse (ctors [3].IsStatic, "#E6b");
3610 Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#E6c");
3611 Assert.IsFalse (ctors [3] is ConstructorBuilder, "#E6d");
3612 Assert.IsTrue (ctors [4].IsAssembly, "#E7a");
3613 Assert.IsFalse (ctors [4].IsStatic, "#E7b");
3614 Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#E7c");
3615 Assert.IsFalse (ctors [4] is ConstructorBuilder, "#E7d");
3617 flags = BindingFlags.Instance | BindingFlags.Public |
3618 BindingFlags.FlattenHierarchy;
3620 ctors = greenType.GetConstructors (flags);
3621 Assert.AreEqual (1, ctors.Length, "#F1");
3622 Assert.IsTrue (ctors [0].IsPublic, "#F2a");
3623 Assert.IsFalse (ctors [0].IsStatic, "#F2b");
3624 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#F2c");
3625 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F2d");
3627 ctors = redType.GetConstructors (flags);
3628 Assert.AreEqual (1, ctors.Length, "#F3");
3629 Assert.IsTrue (ctors [0].IsPublic, "#F4a");
3630 Assert.IsFalse (ctors [0].IsStatic, "#F4b");
3631 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#F4c");
3632 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#F4d");
3634 flags = BindingFlags.Static | BindingFlags.Public |
3635 BindingFlags.FlattenHierarchy;
3637 ctors = greenType.GetConstructors (flags);
3638 Assert.AreEqual (0, ctors.Length, "#G1");
3640 ctors = redType.GetConstructors (flags);
3641 Assert.AreEqual (0, ctors.Length, "#G2");
3643 flags = BindingFlags.Static | BindingFlags.NonPublic |
3644 BindingFlags.FlattenHierarchy;
3646 ctors = greenType.GetConstructors (flags);
3647 Assert.AreEqual (0, ctors.Length, "#H1");
3649 ctors = redType.GetConstructors (flags);
3650 Assert.AreEqual (1, ctors.Length, "#H2");
3651 Assert.IsTrue (ctors [0].IsPrivate, "#H3a");
3652 Assert.IsTrue (ctors [0].IsStatic, "#H3b");
3653 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#H3c");
3654 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#H3d");
3656 flags = BindingFlags.Instance | BindingFlags.NonPublic |
3657 BindingFlags.DeclaredOnly;
3659 ctors = greenType.GetConstructors (flags);
3660 Assert.AreEqual (0, ctors.Length, "#I1");
3662 ctors = redType.GetConstructors (flags);
3663 Assert.AreEqual (5, ctors.Length, "#I2");
3664 Assert.IsTrue (ctors [0].IsPrivate, "#I3a");
3665 Assert.IsFalse (ctors [0].IsStatic, "#I3b");
3666 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#I3c");
3667 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#I3d");
3668 Assert.IsTrue (ctors [1].IsFamily, "#I4a");
3669 Assert.IsFalse (ctors [1].IsStatic, "#I4b");
3670 Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#I4c");
3671 Assert.IsFalse (ctors [1] is ConstructorBuilder, "#I4d");
3672 Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#I5a");
3673 Assert.IsFalse (ctors [2].IsStatic, "#I5b");
3674 Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#I5c");
3675 Assert.IsFalse (ctors [2] is ConstructorBuilder, "#I5d");
3676 Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#I6a");
3677 Assert.IsFalse (ctors [3].IsStatic, "#I6b");
3678 Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#I6c");
3679 Assert.IsFalse (ctors [3] is ConstructorBuilder, "#I6d");
3680 Assert.IsTrue (ctors [4].IsAssembly, "#I7a");
3681 Assert.IsFalse (ctors [4].IsStatic, "#I7b");
3682 Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#I7c");
3683 Assert.IsFalse (ctors [4] is ConstructorBuilder, "#I7d");
3685 flags = BindingFlags.Instance | BindingFlags.Public |
3686 BindingFlags.DeclaredOnly;
3688 ctors = greenType.GetConstructors (flags);
3689 Assert.AreEqual (1, ctors.Length, "#J1");
3690 Assert.IsTrue (ctors [0].IsPublic, "#J2a");
3691 Assert.IsFalse (ctors [0].IsStatic, "#J2b");
3692 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#J2c");
3693 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J2d");
3695 ctors = redType.GetConstructors (flags);
3696 Assert.AreEqual (1, ctors.Length, "#J3");
3697 Assert.IsTrue (ctors [0].IsPublic, "#J4a");
3698 Assert.IsFalse (ctors [0].IsStatic, "#J4b");
3699 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#J4c");
3700 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#J4d");
3702 flags = BindingFlags.Static | BindingFlags.Public |
3703 BindingFlags.DeclaredOnly;
3705 ctors = greenType.GetConstructors (flags);
3706 Assert.AreEqual (0, ctors.Length, "#K1");
3708 ctors = redType.GetConstructors (flags);
3709 Assert.AreEqual (0, ctors.Length, "#K2");
3711 flags = BindingFlags.Static | BindingFlags.NonPublic |
3712 BindingFlags.DeclaredOnly;
3714 ctors = greenType.GetConstructors (flags);
3715 Assert.AreEqual (0, ctors.Length, "#L1");
3717 ctors = redType.GetConstructors (flags);
3718 Assert.AreEqual (1, ctors.Length, "#L2");
3719 Assert.IsTrue (ctors [0].IsPrivate, "#L3a");
3720 Assert.IsTrue (ctors [0].IsStatic, "#L3b");
3721 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#L3c");
3722 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#L3d");
3724 flags = BindingFlags.Instance | BindingFlags.NonPublic |
3725 BindingFlags.Public;
3727 ctors = greenType.GetConstructors (flags);
3728 Assert.AreEqual (1, ctors.Length, "#M1");
3729 Assert.IsTrue (ctors [0].IsPublic, "#M2a");
3730 Assert.IsFalse (ctors [0].IsStatic, "#M2b");
3731 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#M2c");
3732 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M2d");
3734 ctors = redType.GetConstructors (flags);
3735 Assert.AreEqual (6, ctors.Length, "#M3");
3736 Assert.IsTrue (ctors [0].IsPrivate, "#M4a");
3737 Assert.IsFalse (ctors [0].IsStatic, "#M4b");
3738 Assert.AreEqual (2, ctors [0].GetParameters ().Length, "#M4c");
3739 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#M4d");
3740 Assert.IsTrue (ctors [1].IsFamily, "#M5a");
3741 Assert.IsFalse (ctors [1].IsStatic, "#M5b");
3742 Assert.AreEqual (1, ctors [1].GetParameters ().Length, "#M5c");
3743 Assert.IsFalse (ctors [1] is ConstructorBuilder, "#M5d");
3744 Assert.IsTrue (ctors [2].IsFamilyAndAssembly, "#M6a");
3745 Assert.IsFalse (ctors [2].IsStatic, "#M6b");
3746 Assert.AreEqual (2, ctors [2].GetParameters ().Length, "#M6c");
3747 Assert.IsFalse (ctors [2] is ConstructorBuilder, "#M6d");
3748 Assert.IsTrue (ctors [3].IsFamilyOrAssembly, "#M7a");
3749 Assert.IsFalse (ctors [3].IsStatic, "#M7b");
3750 Assert.AreEqual (1, ctors [3].GetParameters ().Length, "#M7c");
3751 Assert.IsFalse (ctors [3] is ConstructorBuilder, "#M7d");
3752 Assert.IsTrue (ctors [4].IsPublic, "#M8a");
3753 Assert.IsFalse (ctors [4].IsStatic, "#M8b");
3754 Assert.AreEqual (2, ctors [4].GetParameters ().Length, "#M8c");
3755 Assert.IsFalse (ctors [4] is ConstructorBuilder, "#M8d");
3756 Assert.IsTrue (ctors [5].IsAssembly, "#M9a");
3757 Assert.IsFalse (ctors [5].IsStatic, "#M9b");
3758 Assert.AreEqual (2, ctors [5].GetParameters ().Length, "#M9c");
3759 Assert.IsFalse (ctors [5] is ConstructorBuilder, "#M9d");
3761 flags = BindingFlags.Static | BindingFlags.NonPublic |
3762 BindingFlags.Public;
3764 ctors = greenType.GetConstructors (flags);
3765 Assert.AreEqual (0, ctors.Length, "#N1");
3767 ctors = redType.GetConstructors (flags);
3768 Assert.AreEqual (1, ctors.Length, "#N2");
3769 Assert.IsTrue (ctors [0].IsPrivate, "#N3a");
3770 Assert.IsTrue (ctors [0].IsStatic, "#N3b");
3771 Assert.AreEqual (0, ctors [0].GetParameters ().Length, "#N3c");
3772 Assert.IsFalse (ctors [0] is ConstructorBuilder, "#N3d");
3775 [Test] // GetConstructors (BindingFlags)
3776 [Category ("NotWorking")] // mcs depends on this
3777 public void GetConstructors2_Incomplete ()
3779 TypeBuilder tb = module.DefineType (genTypeName ());
3780 ConstructorBuilder cb = tb.DefineConstructor (
3781 MethodAttributes.Public,
3782 CallingConventions.Standard,
3783 Type.EmptyTypes);
3784 cb.GetILGenerator ().Emit (OpCodes.Ret);
3786 try {
3787 tb.GetConstructors (BindingFlags.Public |
3788 BindingFlags.Instance);
3789 Assert.Fail ("#1");
3790 } catch (NotSupportedException ex) {
3791 // The invoked member is not supported in a
3792 // dynamic module
3793 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3794 Assert.IsNull (ex.InnerException, "#3");
3795 Assert.IsNotNull (ex.Message, "#4");
3799 [Test]
3800 public void TestGetCustomAttributesIncomplete ()
3802 TypeBuilder tb = module.DefineType (genTypeName ());
3803 try {
3804 tb.GetCustomAttributes (false);
3805 Assert.Fail ("#1");
3806 } catch (NotSupportedException ex) {
3807 // The invoked member is not supported in a
3808 // dynamic module
3809 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3810 Assert.IsNull (ex.InnerException, "#3");
3811 Assert.IsNotNull (ex.Message, "#4");
3815 [Test]
3816 public void TestGetCustomAttributesComplete ()
3818 TypeBuilder tb = module.DefineType (genTypeName ());
3820 ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3821 new Type [] { typeof (string) });
3823 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3824 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3826 tb.SetCustomAttribute (caBuilder);
3827 tb.CreateType ();
3829 Assert.AreEqual (1, tb.GetCustomAttributes (false).Length);
3832 [Test]
3833 public void TestGetCustomAttributesOfTypeIncomplete ()
3835 TypeBuilder tb = module.DefineType (genTypeName ());
3836 try {
3837 tb.GetCustomAttributes (typeof (ObsoleteAttribute), false);
3838 Assert.Fail ("#1");
3839 } catch (NotSupportedException ex) {
3840 // The invoked member is not supported in a
3841 // dynamic module
3842 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3843 Assert.IsNull (ex.InnerException, "#3");
3844 Assert.IsNotNull (ex.Message, "#4");
3848 [Test]
3849 public void TestGetCustomAttributesOfTypeComplete ()
3851 TypeBuilder tb = module.DefineType (genTypeName ());
3853 ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
3854 new Type [] { typeof (string) });
3856 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
3857 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
3859 tb.SetCustomAttribute (caBuilder);
3860 tb.CreateType ();
3862 Assert.AreEqual (1, tb.GetCustomAttributes (typeof (GuidAttribute), false).Length, "#1");
3863 Assert.AreEqual (0, tb.GetCustomAttributes (typeof (ObsoleteAttribute), false).Length, "#2");
3866 [Test]
3867 public void TestGetCustomAttributesOfNullTypeComplete ()
3869 TypeBuilder tb = module.DefineType (genTypeName ());
3870 tb.CreateType ();
3871 try {
3872 tb.GetCustomAttributes (null, false);
3873 Assert.Fail ("#1");
3874 } catch (ArgumentNullException ex) {
3875 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3876 Assert.IsNull (ex.InnerException, "#3");
3877 Assert.IsNotNull (ex.Message, "#4");
3878 Assert.AreEqual ("attributeType", ex.ParamName, "#5");
3882 [Test]
3883 [Ignore ("mcs depends on this")]
3884 public void TestGetEventsIncomplete ()
3886 TypeBuilder tb = module.DefineType (genTypeName ());
3887 try {
3888 tb.GetEvents ();
3889 Assert.Fail ("#1");
3890 } catch (NotSupportedException ex) {
3891 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3892 Assert.IsNull (ex.InnerException, "#3");
3893 Assert.IsNotNull (ex.Message, "#4");
3894 throw;
3898 [Test]
3899 public void TestGetEventsComplete ()
3901 TypeBuilder tb = module.DefineType (genTypeName ());
3903 MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3904 typeof (void), new Type [] { typeof (Object) });
3905 onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
3907 // create public event
3908 EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
3909 typeof (ResolveEventHandler));
3910 eventbuilder.SetRaiseMethod (onclickMethod);
3912 Type emittedType = tb.CreateType ();
3914 Assert.AreEqual (1, tb.GetEvents ().Length, "#1");
3915 Assert.AreEqual (tb.GetEvents ().Length, emittedType.GetEvents ().Length, "#2");
3919 [Test]
3920 [Ignore ("mcs depends on this")]
3921 public void TestGetEventsFlagsIncomplete ()
3923 TypeBuilder tb = module.DefineType (genTypeName ());
3924 try {
3925 tb.GetEvents (BindingFlags.Public);
3926 Assert.Fail ("#1");
3927 } catch (NotSupportedException ex) {
3928 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
3929 Assert.IsNull (ex.InnerException, "#3");
3930 Assert.IsNotNull (ex.Message, "#4");
3931 throw;
3935 [Test]
3936 public void TestGetEventsFlagsComplete ()
3938 TypeBuilder tb = module.DefineType (genTypeName ());
3940 MethodBuilder onchangeMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
3941 typeof (void), new Type [] { typeof (Object) });
3942 onchangeMethod.GetILGenerator ().Emit (OpCodes.Ret);
3944 // create public event
3945 EventBuilder changeEvent = tb.DefineEvent ("Change", EventAttributes.None,
3946 typeof (ResolveEventHandler));
3947 changeEvent.SetRaiseMethod (onchangeMethod);
3949 // create non-public event
3950 EventBuilder redoChangeEvent = tb.DefineEvent ("RedoChange", EventAttributes.None,
3951 typeof (ResolveEventHandler));
3953 Type emittedType = tb.CreateType ();
3955 Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3956 Assert.AreEqual (1, tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3957 Assert.AreEqual (2, tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3958 Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length,
3959 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public).Length);
3960 Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length,
3961 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.NonPublic).Length);
3962 Assert.AreEqual (tb.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length,
3963 emittedType.GetEvents (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length);
3966 [Test]
3967 public void TestGetEventsFlagsComplete_Inheritance ()
3969 EventInfo [] events;
3970 BindingFlags flags;
3972 TypeBuilder blueType = module.DefineType (genTypeName (),
3973 TypeAttributes.Public);
3974 CreateMembers (blueType, "Blue", false);
3976 TypeBuilder redType = module.DefineType (genTypeName (),
3977 TypeAttributes.Public, blueType);
3978 CreateMembers (redType, "Red", false);
3980 TypeBuilder greenType = module.DefineType (genTypeName (),
3981 TypeAttributes.Public, redType);
3982 CreateMembers (greenType, "Green", false);
3984 blueType.CreateType ();
3985 redType.CreateType ();
3986 greenType.CreateType ();
3988 flags = BindingFlags.Instance | BindingFlags.NonPublic;
3989 events = greenType.GetEvents (flags);
3991 Assert.AreEqual (13, events.Length, "#A1");
3992 Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#A2");
3993 Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#A3");
3994 Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#A4");
3995 Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#A5");
3996 Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#A6");
3997 Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#A7");
3998 Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#A8");
3999 Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#A9");
4000 Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#A10");
4001 Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#A11");
4002 Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#A12");
4003 Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#A13");
4004 Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#A14");
4006 flags = BindingFlags.Instance | BindingFlags.Public;
4007 events = greenType.GetEvents (flags);
4009 Assert.AreEqual (3, events.Length, "#B1");
4010 Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#B2");
4011 Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#B3");
4012 Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#B4");
4014 flags = BindingFlags.Static | BindingFlags.Public;
4015 events = greenType.GetEvents (flags);
4017 Assert.AreEqual (1, events.Length, "#C1");
4018 Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#C2");
4020 flags = BindingFlags.Static | BindingFlags.NonPublic;
4021 events = greenType.GetEvents (flags);
4023 Assert.AreEqual (5, events.Length, "#D1");
4024 Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#D2");
4025 Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#D3");
4026 Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#D4");
4027 Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#D5");
4028 Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#D6");
4030 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4031 BindingFlags.FlattenHierarchy;
4032 events = greenType.GetEvents (flags);
4034 Assert.AreEqual (13, events.Length, "#E1");
4035 Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#E2");
4036 Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#E3");
4037 Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#E4");
4038 Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#E5");
4039 Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#E6");
4040 Assert.AreEqual ("OnFamilyInstanceRed", events [5].Name, "#E7");
4041 Assert.AreEqual ("OnFamANDAssemInstanceRed", events [6].Name, "#E8");
4042 Assert.AreEqual ("OnFamORAssemInstanceRed", events [7].Name, "#E9");
4043 Assert.AreEqual ("OnAssemblyInstanceRed", events [8].Name, "#E10");
4044 Assert.AreEqual ("OnFamilyInstanceBlue", events [9].Name, "#E11");
4045 Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [10].Name, "#E12");
4046 Assert.AreEqual ("OnFamORAssemInstanceBlue", events [11].Name, "#E13");
4047 Assert.AreEqual ("OnAssemblyInstanceBlue", events [12].Name, "#E14");
4049 flags = BindingFlags.Instance | BindingFlags.Public |
4050 BindingFlags.FlattenHierarchy;
4051 events = greenType.GetEvents (flags);
4053 Assert.AreEqual (3, events.Length, "#F1");
4054 Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#F2");
4055 Assert.AreEqual ("OnPublicInstanceRed", events [1].Name, "#F3");
4056 Assert.AreEqual ("OnPublicInstanceBlue", events [2].Name, "#F4");
4058 flags = BindingFlags.Static | BindingFlags.Public |
4059 BindingFlags.FlattenHierarchy;
4060 events = greenType.GetEvents (flags);
4062 Assert.AreEqual (3, events.Length, "#G1");
4063 Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#G2");
4064 Assert.AreEqual ("OnPublicStaticRed", events [1].Name, "#G3");
4065 Assert.AreEqual ("OnPublicStaticBlue", events [2].Name, "#G4");
4067 flags = BindingFlags.Static | BindingFlags.NonPublic |
4068 BindingFlags.FlattenHierarchy;
4069 events = greenType.GetEvents (flags);
4071 Assert.AreEqual (13, events.Length, "#H1");
4072 Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#H2");
4073 Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#H3");
4074 Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#H4");
4075 Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#H5");
4076 Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#H6");
4077 Assert.AreEqual ("OnFamilyStaticRed", events [5].Name, "#H7");
4078 Assert.AreEqual ("OnFamANDAssemStaticRed", events [6].Name, "#H8");
4079 Assert.AreEqual ("OnFamORAssemStaticRed", events [7].Name, "#H9");
4080 Assert.AreEqual ("OnAssemblyStaticRed", events [8].Name, "#H10");
4081 Assert.AreEqual ("OnFamilyStaticBlue", events [9].Name, "#H11");
4082 Assert.AreEqual ("OnFamANDAssemStaticBlue", events [10].Name, "#H12");
4083 Assert.AreEqual ("OnFamORAssemStaticBlue", events [11].Name, "#H13");
4084 Assert.AreEqual ("OnAssemblyStaticBlue", events [12].Name, "#H14");
4086 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4087 BindingFlags.DeclaredOnly;
4088 events = greenType.GetEvents (flags);
4090 Assert.AreEqual (5, events.Length, "#I1");
4091 Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#I2");
4092 Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#I3");
4093 Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#I4");
4094 Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#I5");
4095 Assert.AreEqual ("OnAssemblyInstanceGreen", events [4].Name, "#I6");
4097 flags = BindingFlags.Instance | BindingFlags.Public |
4098 BindingFlags.DeclaredOnly;
4099 events = greenType.GetEvents (flags);
4101 Assert.AreEqual (1, events.Length, "#J1");
4102 Assert.AreEqual ("OnPublicInstanceGreen", events [0].Name, "#J2");
4104 flags = BindingFlags.Static | BindingFlags.Public |
4105 BindingFlags.DeclaredOnly;
4106 events = greenType.GetEvents (flags);
4108 Assert.AreEqual (1, events.Length, "#K1");
4109 Assert.AreEqual ("OnPublicStaticGreen", events [0].Name, "#K2");
4111 flags = BindingFlags.Static | BindingFlags.NonPublic |
4112 BindingFlags.DeclaredOnly;
4113 events = greenType.GetEvents (flags);
4115 Assert.AreEqual (5, events.Length, "#L1");
4116 Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#L2");
4117 Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#L3");
4118 Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#L4");
4119 Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#L5");
4120 Assert.AreEqual ("OnAssemblyStaticGreen", events [4].Name, "#L6");
4122 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4123 BindingFlags.Public;
4124 events = greenType.GetEvents (flags);
4126 Assert.AreEqual (16, events.Length, "#M1");
4127 Assert.AreEqual ("OnPrivateInstanceGreen", events [0].Name, "#M2");
4128 Assert.AreEqual ("OnFamilyInstanceGreen", events [1].Name, "#M3");
4129 Assert.AreEqual ("OnFamANDAssemInstanceGreen", events [2].Name, "#M4");
4130 Assert.AreEqual ("OnFamORAssemInstanceGreen", events [3].Name, "#M5");
4131 Assert.AreEqual ("OnPublicInstanceGreen", events [4].Name, "#M6");
4132 Assert.AreEqual ("OnAssemblyInstanceGreen", events [5].Name, "#M7");
4133 Assert.AreEqual ("OnFamilyInstanceRed", events [6].Name, "#M8");
4134 Assert.AreEqual ("OnFamANDAssemInstanceRed", events [7].Name, "#M9");
4135 Assert.AreEqual ("OnFamORAssemInstanceRed", events [8].Name, "#M10");
4136 Assert.AreEqual ("OnPublicInstanceRed", events [9].Name, "#M11");
4137 Assert.AreEqual ("OnAssemblyInstanceRed", events [10].Name, "#M12");
4138 Assert.AreEqual ("OnFamilyInstanceBlue", events [11].Name, "#M13");
4139 Assert.AreEqual ("OnFamANDAssemInstanceBlue", events [12].Name, "#M14");
4140 Assert.AreEqual ("OnFamORAssemInstanceBlue", events [13].Name, "#M15");
4141 Assert.AreEqual ("OnPublicInstanceBlue", events [14].Name, "#M16");
4142 Assert.AreEqual ("OnAssemblyInstanceBlue", events [15].Name, "#M17");
4144 flags = BindingFlags.Static | BindingFlags.NonPublic |
4145 BindingFlags.Public;
4146 events = greenType.GetEvents (flags);
4148 Assert.AreEqual (6, events.Length, "#N1");
4149 Assert.AreEqual ("OnPrivateStaticGreen", events [0].Name, "#N2");
4150 Assert.AreEqual ("OnFamilyStaticGreen", events [1].Name, "#N3");
4151 Assert.AreEqual ("OnFamANDAssemStaticGreen", events [2].Name, "#N4");
4152 Assert.AreEqual ("OnFamORAssemStaticGreen", events [3].Name, "#N5");
4153 Assert.AreEqual ("OnPublicStaticGreen", events [4].Name, "#N6");
4154 Assert.AreEqual ("OnAssemblyStaticGreen", events [5].Name, "#N7");
4157 [Test]
4158 [Ignore ("mcs depends on this")]
4159 public void TestGetEventIncomplete ()
4161 TypeBuilder tb = module.DefineType (genTypeName ());
4162 try {
4163 tb.GetEvent ("FOO");
4164 Assert.Fail ("#1");
4165 } catch (NotSupportedException ex) {
4166 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4167 Assert.IsNull (ex.InnerException, "#3");
4168 Assert.IsNotNull (ex.Message, "#4");
4169 throw;
4173 [Test]
4174 public void TestGetEventComplete ()
4176 TypeBuilder tb = module.DefineType (genTypeName ());
4178 MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4179 typeof (void), new Type [] { typeof (Object) });
4180 onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4182 EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4183 typeof (ResolveEventHandler));
4184 eventbuilder.SetRaiseMethod (onclickMethod);
4186 Type emittedType = tb.CreateType ();
4188 Assert.IsNotNull (tb.GetEvent ("Change"));
4189 Assert.AreEqual (tb.GetEvent ("Change"), emittedType.GetEvent ("Change"));
4190 Assert.IsNull (tb.GetEvent ("NotChange"));
4191 Assert.AreEqual (tb.GetEvent ("NotChange"), emittedType.GetEvent ("NotChange"));
4194 [Test]
4195 [Ignore ("mcs depends on this")]
4196 public void TestGetEventFlagsIncomplete ()
4198 TypeBuilder tb = module.DefineType (genTypeName ());
4199 try {
4200 tb.GetEvent ("FOO", BindingFlags.Public);
4201 Assert.Fail ("#1");
4202 } catch (NotSupportedException ex) {
4203 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4204 Assert.IsNull (ex.InnerException, "#3");
4205 Assert.IsNotNull (ex.Message, "#4");
4206 throw;
4210 [Test]
4211 public void TestGetEventFlagsComplete ()
4213 TypeBuilder tb = module.DefineType (genTypeName ());
4215 MethodBuilder onclickMethod = tb.DefineMethod ("OnChange", MethodAttributes.Public,
4216 typeof (void), new Type [] { typeof (Object) });
4217 onclickMethod.GetILGenerator ().Emit (OpCodes.Ret);
4219 EventBuilder eventbuilder = tb.DefineEvent ("Change", EventAttributes.None,
4220 typeof (ResolveEventHandler));
4221 eventbuilder.SetRaiseMethod (onclickMethod);
4223 Type emittedType = tb.CreateType ();
4225 Assert.IsNotNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4226 Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public),
4227 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.Public));
4228 Assert.IsNull (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4229 Assert.AreEqual (tb.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic),
4230 emittedType.GetEvent ("Change", BindingFlags.Instance | BindingFlags.NonPublic));
4233 [Test]
4234 public void TestGetEventFlagsComplete_Inheritance ()
4236 BindingFlags flags;
4238 TypeBuilder blueType = module.DefineType (genTypeName (),
4239 TypeAttributes.Public);
4240 CreateMembers (blueType, "Blue", false);
4242 TypeBuilder redType = module.DefineType (genTypeName (),
4243 TypeAttributes.Public, blueType);
4244 CreateMembers (redType, "Red", false);
4246 TypeBuilder greenType = module.DefineType (genTypeName (),
4247 TypeAttributes.Public, redType);
4248 CreateMembers (greenType, "Green", false);
4250 blueType.CreateType ();
4251 redType.CreateType ();
4252 greenType.CreateType ();
4254 flags = BindingFlags.Instance | BindingFlags.NonPublic;
4256 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#A1");
4257 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#A2");
4258 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#A3");
4259 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#A4");
4260 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#A5");
4261 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#A6");
4262 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#A7");
4263 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#A8");
4264 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#A9");
4265 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#A10");
4266 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#A11");
4267 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#A12");
4268 Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#A13");
4269 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#A14");
4270 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#A15");
4271 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#A16");
4272 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#A17");
4273 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#A18");
4274 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#A19");
4275 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#A20");
4276 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#A21");
4277 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#A22");
4278 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#A23");
4279 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#A24");
4280 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#A25");
4281 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#A26");
4282 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#A27");
4283 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#A28");
4284 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#A29");
4285 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#A30");
4286 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#A31");
4287 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#A32");
4288 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#A33");
4289 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#A34");
4290 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#A35");
4291 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#A36");
4293 flags = BindingFlags.Instance | BindingFlags.Public;
4295 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#B1");
4296 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#B2");
4297 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#B3");
4298 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#B4");
4299 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#B5");
4300 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#B6");
4301 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#B7");
4302 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#B8");
4303 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#B9");
4304 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#B10");
4305 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#B11");
4306 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#B12");
4307 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#B13");
4308 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#B14");
4309 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#B15");
4310 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#B16");
4311 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#B17");
4312 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#B18");
4313 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#B19");
4314 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#B20");
4315 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#B21");
4316 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#B22");
4317 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#B23");
4318 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#B24");
4319 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#B25");
4320 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#B26");
4321 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#B27");
4322 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#B28");
4323 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#B29");
4324 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#B30");
4325 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#B31");
4326 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#B32");
4327 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#B33");
4328 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#B34");
4329 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#B35");
4330 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#B36");
4332 flags = BindingFlags.Static | BindingFlags.Public;
4334 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#C1");
4335 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#C2");
4336 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#C3");
4337 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#C4");
4338 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#C5");
4339 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#C6");
4340 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#C7");
4341 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#C8");
4342 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#C9");
4343 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#C10");
4344 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#C11");
4345 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#C12");
4346 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#C13");
4347 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#C14");
4348 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#C15");
4349 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#C16");
4350 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#C17");
4351 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#C18");
4352 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#C19");
4353 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#C20");
4354 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#C21");
4355 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#C22");
4356 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#C23");
4357 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#C24");
4358 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#C25");
4359 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#C26");
4360 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#C27");
4361 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#C28");
4362 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#C29");
4363 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#C30");
4364 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#C31");
4365 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#C32");
4366 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#C33");
4367 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#C34");
4368 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#C35");
4369 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#C36");
4371 flags = BindingFlags.Static | BindingFlags.NonPublic;
4373 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#D1");
4374 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#D2");
4375 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#D3");
4376 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#D4");
4377 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#D5");
4378 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#D6");
4379 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#D7");
4380 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#D8");
4381 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#D9");
4382 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#D10");
4383 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#D11");
4384 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#D12");
4385 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#D13");
4386 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#D14");
4387 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#D15");
4388 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#D16");
4389 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#D17");
4390 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#D18");
4391 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#D19");
4392 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#D20");
4393 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#D21");
4394 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#D22");
4395 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#D23");
4396 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#D24");
4397 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#D25");
4398 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#D26");
4399 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#D27");
4400 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#D28");
4401 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#D29");
4402 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#D30");
4403 Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#D31");
4404 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#D32");
4405 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#D33");
4406 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#D34");
4407 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#D35");
4408 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#D36");
4410 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4411 BindingFlags.FlattenHierarchy;
4413 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#E1");
4414 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#E2");
4415 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#E3");
4416 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#E4");
4417 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#E5");
4418 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#E6");
4419 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#E7");
4420 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#E8");
4421 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#E9");
4422 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#E10");
4423 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#E11");
4424 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#E12");
4425 Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#E13");
4426 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#E14");
4427 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#E15");
4428 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#E16");
4429 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#E17");
4430 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#E18");
4431 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#E19");
4432 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#E20");
4433 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#E21");
4434 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#E22");
4435 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#E23");
4436 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#E24");
4437 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#E25");
4438 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#E26");
4439 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#E27");
4440 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#E28");
4441 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#E29");
4442 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#E30");
4443 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#E31");
4444 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#E32");
4445 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#E33");
4446 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#E34");
4447 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#E35");
4448 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#E36");
4450 flags = BindingFlags.Instance | BindingFlags.Public |
4451 BindingFlags.FlattenHierarchy;
4453 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#F1");
4454 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#F2");
4455 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#F3");
4456 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#F4");
4457 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#F5");
4458 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#F6");
4459 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#F7");
4460 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#F8");
4461 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#F9");
4462 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#F10");
4463 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#F11");
4464 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#F12");
4465 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#F13");
4466 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#F14");
4467 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#F15");
4468 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#F16");
4469 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#F17");
4470 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#F18");
4471 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#F19");
4472 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#F20");
4473 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#F21");
4474 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#F22");
4475 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#F23");
4476 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#F24");
4477 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#F25");
4478 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#F26");
4479 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#F27");
4480 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#F28");
4481 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#F29");
4482 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#F30");
4483 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#F31");
4484 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#F32");
4485 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#F33");
4486 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#F34");
4487 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#F35");
4488 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#F36");
4490 flags = BindingFlags.Static | BindingFlags.Public |
4491 BindingFlags.FlattenHierarchy;
4493 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#G1");
4494 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#G2");
4495 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#G3");
4496 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#G4");
4497 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#G5");
4498 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#G6");
4499 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#G7");
4500 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#G8");
4501 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#G9");
4502 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#G10");
4503 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#G11");
4504 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#G12");
4505 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#G13");
4506 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#G14");
4507 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#G15");
4508 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#G16");
4509 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#G17");
4510 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#G18");
4511 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#G19");
4512 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#G20");
4513 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#G21");
4514 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#G22");
4515 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#G23");
4516 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#G24");
4517 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#G25");
4518 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#G26");
4519 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#G27");
4520 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#G28");
4521 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#G29");
4522 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#G30");
4523 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#G31");
4524 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#G32");
4525 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#G33");
4526 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#G34");
4527 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#G35");
4528 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#G36");
4530 flags = BindingFlags.Static | BindingFlags.NonPublic |
4531 BindingFlags.FlattenHierarchy;
4533 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#H1");
4534 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#H2");
4535 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#H3");
4536 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#H4");
4537 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#H5");
4538 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#H6");
4539 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#H7");
4540 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#H8");
4541 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#H9");
4542 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#H10");
4543 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#H11");
4544 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#H12");
4545 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#H13");
4546 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#H14");
4547 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#H15");
4548 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#H16");
4549 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#H17");
4550 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#H18");
4551 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#H19");
4552 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#H20");
4553 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#H21");
4554 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#H22");
4555 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#H23");
4556 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#H24");
4557 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#H25");
4558 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#H26");
4559 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#H27");
4560 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#H28");
4561 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#H29");
4562 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#H30");
4563 Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#H31");
4564 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#H32");
4565 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#H33");
4566 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#H34");
4567 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#H35");
4568 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#H36");
4570 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4571 BindingFlags.DeclaredOnly;
4573 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#I1");
4574 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#I2");
4575 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#I3");
4576 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#I4");
4577 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#I5");
4578 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#I6");
4579 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#I7");
4580 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#I8");
4581 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#I9");
4582 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#I10");
4583 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#I11");
4584 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#I12");
4585 Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#I13");
4586 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#I14");
4587 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#I15");
4588 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#I16");
4589 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#I17");
4590 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#I18");
4591 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#I19");
4592 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#I20");
4593 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#I21");
4594 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#I22");
4595 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#I23");
4596 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#I24");
4597 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#I25");
4598 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#I26");
4599 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#I27");
4600 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#I28");
4601 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#I29");
4602 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#I30");
4603 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#I31");
4604 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#I32");
4605 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#I33");
4606 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#I34");
4607 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#I35");
4608 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#I36");
4610 flags = BindingFlags.Instance | BindingFlags.Public |
4611 BindingFlags.DeclaredOnly;
4613 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#J1");
4614 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#J2");
4615 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#J3");
4616 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#J4");
4617 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#J5");
4618 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#J6");
4619 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#J7");
4620 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#J8");
4621 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#J9");
4622 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#J10");
4623 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#J11");
4624 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#J12");
4625 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#J13");
4626 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#J14");
4627 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#J15");
4628 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#J16");
4629 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#J17");
4630 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#J18");
4631 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#J19");
4632 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#J20");
4633 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#J21");
4634 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#J22");
4635 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#J23");
4636 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#J24");
4637 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#J25");
4638 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#J26");
4639 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#J27");
4640 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#J28");
4641 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#J29");
4642 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#J30");
4643 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#J31");
4644 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#J32");
4645 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#J33");
4646 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#J34");
4647 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#J35");
4648 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#J36");
4650 flags = BindingFlags.Static | BindingFlags.Public |
4651 BindingFlags.DeclaredOnly;
4653 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#K1");
4654 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#K2");
4655 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#K3");
4656 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#K4");
4657 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#K5");
4658 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#K6");
4659 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#K7");
4660 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#K8");
4661 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#K9");
4662 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#K10");
4663 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#K11");
4664 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#K12");
4665 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#K13");
4666 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#K14");
4667 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#K15");
4668 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#K16");
4669 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#K17");
4670 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#K18");
4671 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#K19");
4672 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#K20");
4673 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#K21");
4674 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#K22");
4675 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#K23");
4676 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#K24");
4677 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#K25");
4678 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#K26");
4679 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#K27");
4680 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#K28");
4681 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#K29");
4682 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#K30");
4683 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#K31");
4684 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#K32");
4685 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#K33");
4686 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#K34");
4687 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#K35");
4688 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#K36");
4690 flags = BindingFlags.Static | BindingFlags.NonPublic |
4691 BindingFlags.DeclaredOnly;
4693 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#L1");
4694 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#L2");
4695 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#L3");
4696 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#L4");
4697 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#L5");
4698 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#L6");
4699 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#L7");
4700 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#L8");
4701 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#L9");
4702 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#L10");
4703 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#L11");
4704 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#L12");
4705 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#L13");
4706 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#L14");
4707 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#L15");
4708 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#L16");
4709 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#L17");
4710 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#L18");
4711 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#L19");
4712 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#L20");
4713 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#L21");
4714 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#L22");
4715 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#L23");
4716 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#L24");
4717 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#L25");
4718 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#L26");
4719 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#L27");
4720 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#L28");
4721 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#L29");
4722 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#L30");
4723 Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#L31");
4724 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#L32");
4725 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#L33");
4726 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#L34");
4727 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#L35");
4728 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#L36");
4730 flags = BindingFlags.Instance | BindingFlags.NonPublic |
4731 BindingFlags.Public;
4733 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#M1");
4734 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#M2");
4735 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#M3");
4736 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#M4");
4737 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#M5");
4738 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#M6");
4739 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#M7");
4740 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#M8");
4741 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#M9");
4742 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#M10");
4743 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#M11");
4744 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#M12");
4745 Assert.IsNotNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#M13");
4746 Assert.IsNotNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#M14");
4747 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#M15");
4748 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#M16");
4749 Assert.IsNotNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#M17");
4750 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#M18");
4751 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#M19");
4752 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#M20");
4753 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#M21");
4754 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#M22");
4755 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#M23");
4756 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#M24");
4757 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#M25");
4758 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#M26");
4759 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#M27");
4760 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#M28");
4761 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#M29");
4762 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#M30");
4763 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#M31");
4764 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#M32");
4765 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#M33");
4766 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#M34");
4767 Assert.IsNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#M35");
4768 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#M36");
4770 flags = BindingFlags.Static | BindingFlags.NonPublic |
4771 BindingFlags.Public;
4773 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceBlue", flags), "#N1");
4774 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceBlue", flags), "#N2");
4775 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceBlue", flags), "#N3");
4776 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceBlue", flags), "#N4");
4777 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceBlue", flags), "#N5");
4778 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceBlue", flags), "#N6");
4779 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceRed", flags), "#N7");
4780 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceRed", flags), "#N8");
4781 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceRed", flags), "#N9");
4782 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceRed", flags), "#N10");
4783 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceRed", flags), "#N11");
4784 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceRed", flags), "#N12");
4785 Assert.IsNull (greenType.GetEvent ("OnPrivateInstanceGreen", flags), "#N13");
4786 Assert.IsNull (greenType.GetEvent ("OnFamilyInstanceGreen", flags), "#N14");
4787 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemInstanceGreen", flags), "#N15");
4788 Assert.IsNull (greenType.GetEvent ("OnFamORAssemInstanceGreen", flags), "#N16");
4789 Assert.IsNull (greenType.GetEvent ("OnPublicInstanceGreen", flags), "#N17");
4790 Assert.IsNull (greenType.GetEvent ("OnAssemblyInstanceGreen", flags), "#N18");
4791 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticBlue", flags), "#N19");
4792 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticBlue", flags), "#N20");
4793 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticBlue", flags), "#N21");
4794 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticBlue", flags), "#N22");
4795 Assert.IsNull (greenType.GetEvent ("OnPublicStaticBlue", flags), "#N23");
4796 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticBlue", flags), "#N24");
4797 Assert.IsNull (greenType.GetEvent ("OnPrivateStaticRed", flags), "#N25");
4798 Assert.IsNull (greenType.GetEvent ("OnFamilyStaticRed", flags), "#N26");
4799 Assert.IsNull (greenType.GetEvent ("OnFamANDAssemStaticRed", flags), "#N27");
4800 Assert.IsNull (greenType.GetEvent ("OnFamORAssemStaticRed", flags), "#N28");
4801 Assert.IsNull (greenType.GetEvent ("OnPublicStaticRed", flags), "#N29");
4802 Assert.IsNull (greenType.GetEvent ("OnAssemblyStaticRed", flags), "#N30");
4803 Assert.IsNotNull (greenType.GetEvent ("OnPrivateStaticGreen", flags), "#N31");
4804 Assert.IsNotNull (greenType.GetEvent ("OnFamilyStaticGreen", flags), "#N32");
4805 Assert.IsNotNull (greenType.GetEvent ("OnFamANDAssemStaticGreen", flags), "#N33");
4806 Assert.IsNotNull (greenType.GetEvent ("OnFamORAssemStaticGreen", flags), "#N34");
4807 Assert.IsNotNull (greenType.GetEvent ("OnPublicStaticGreen", flags), "#N35");
4808 Assert.IsNotNull (greenType.GetEvent ("OnAssemblyStaticGreen", flags), "#N36");
4811 [Test]
4812 [Category ("NotWorking")] // mcs depends on this
4813 public void TestGetFieldsIncomplete_MS ()
4815 TypeBuilder tb = module.DefineType (genTypeName ());
4816 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4817 try {
4818 tb.GetFields ();
4819 Assert.Fail ("#1");
4820 } catch (NotSupportedException ex) {
4821 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4822 Assert.IsNull (ex.InnerException, "#3");
4823 Assert.IsNotNull (ex.Message, "#4");
4827 [Test]
4828 [Category ("NotDotNet")] // mcs depends on this
4829 public void TestGetFieldsIncomplete_Mono ()
4831 TypeBuilder tb = module.DefineType (genTypeName ());
4832 tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4833 tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4834 tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4835 tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4837 FieldInfo [] fields = tb.GetFields ();
4838 Assert.AreEqual (2, fields.Length, "#A1");
4839 Assert.AreEqual ("Sex", fields [0].Name, "#A2");
4840 Assert.AreEqual ("MALE", fields [1].Name, "#A3");
4842 #if NET_2_0
4843 tb = module.DefineType (genTypeName ());
4844 GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4845 tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4846 tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4847 tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4848 tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4849 tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4851 fields = tb.GetFields ();
4852 Assert.AreEqual (4, fields.Length, "#B1");
4853 Assert.AreEqual ("First", fields [0].Name, "#B2");
4854 Assert.AreEqual ("Second", fields [1].Name, "#B3");
4855 Assert.AreEqual ("Sex", fields [2].Name, "#B4");
4856 Assert.AreEqual ("MALE", fields [3].Name, "#B5");
4857 #endif
4860 [Test]
4861 public void TestGetFieldsComplete ()
4863 TypeBuilder tb = module.DefineType (genTypeName ());
4864 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4866 Type emittedType = tb.CreateType ();
4867 FieldInfo [] dynamicFields = tb.GetFields ();
4868 FieldInfo [] emittedFields = emittedType.GetFields ();
4870 Assert.AreEqual (1, dynamicFields.Length, "#A1");
4871 Assert.AreEqual (dynamicFields.Length, emittedFields.Length, "#A2");
4872 Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#A3");
4873 Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#A4");
4875 // bug #81638
4876 object value = Activator.CreateInstance (emittedType);
4877 emittedFields [0].SetValue (value, 5);
4878 Assert.AreEqual (5, emittedFields [0].GetValue (value), "#B1");
4879 Assert.AreEqual (5, dynamicFields [0].GetValue (value), "#B2");
4880 dynamicFields [0].SetValue (value, 4);
4881 Assert.AreEqual (4, emittedFields [0].GetValue (value), "#B3");
4882 Assert.AreEqual (4, dynamicFields [0].GetValue (value), "#B4");
4885 #if NET_2_0
4886 [Test] // bug #82625 / 325292
4887 public void TestGetFieldsComplete_Generic ()
4889 // FIXME: merge this with TestGetFieldsComplete when
4890 // bug #82625 is fixed
4892 TypeBuilder tb;
4893 Type emittedType;
4894 FieldInfo [] dynamicFields;
4895 FieldInfo [] emittedFields;
4897 tb = module.DefineType (genTypeName ());
4898 GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("K", "V");
4899 tb.DefineField ("First", typeParams [0], FieldAttributes.Public);
4900 tb.DefineField ("Second", typeParams [1], FieldAttributes.Public);
4901 tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4902 tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4903 tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4905 emittedType = tb.CreateType ();
4906 dynamicFields = tb.GetFields ();
4907 emittedFields = emittedType.GetFields ();
4909 Assert.AreEqual (4, dynamicFields.Length, "#C1");
4910 Assert.IsFalse ((dynamicFields [0]) is FieldBuilder, "#C2");
4911 Assert.IsFalse ((dynamicFields [1]) is FieldBuilder, "#C3");
4912 Assert.IsFalse ((dynamicFields [2]) is FieldBuilder, "#C4");
4913 Assert.IsFalse ((dynamicFields [3]) is FieldBuilder, "#C5");
4914 Assert.AreEqual ("First", dynamicFields [0].Name, "#C6");
4915 Assert.AreEqual ("Second", dynamicFields [1].Name, "#C7");
4916 Assert.AreEqual ("Sex", dynamicFields [2].Name, "#C8");
4917 Assert.AreEqual ("MALE", dynamicFields [3].Name, "#C9");
4919 Assert.AreEqual (4, emittedFields.Length, "#D1");
4920 Assert.IsFalse ((emittedFields [0]) is FieldBuilder, "#D2");
4921 Assert.IsFalse ((emittedFields [1]) is FieldBuilder, "#D3");
4922 Assert.IsFalse ((emittedFields [2]) is FieldBuilder, "#D4");
4923 Assert.IsFalse ((emittedFields [3]) is FieldBuilder, "#D5");
4924 Assert.AreEqual ("First", emittedFields [0].Name, "#D6");
4925 Assert.AreEqual ("Second", emittedFields [1].Name, "#D7");
4926 Assert.AreEqual ("Sex", emittedFields [2].Name, "#D8");
4927 Assert.AreEqual ("MALE", emittedFields [3].Name, "#D9");
4929 #endif
4931 [Test]
4932 [Category ("NotWorking")] // mcs depends on this
4933 public void TestGetFieldsFlagsIncomplete_MS ()
4935 TypeBuilder tb = module.DefineType (genTypeName ());
4936 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4937 try {
4938 tb.GetFields (BindingFlags.Instance | BindingFlags.Public);
4939 Assert.Fail ("#1");
4940 } catch (NotSupportedException ex) {
4941 // The invoked member is not supported in a
4942 // dynamic module
4943 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
4944 Assert.IsNull (ex.InnerException, "#3");
4945 Assert.IsNotNull (ex.Message, "#4");
4949 [Test]
4950 [Category ("NotDotNet")] // mcs depends on this
4951 public void TestGetFieldsFlagsIncomplete_Mono ()
4953 FieldInfo [] fields;
4955 TypeBuilder tb = module.DefineType (genTypeName ());
4956 tb.DefineField ("name", typeof (string), FieldAttributes.Private);
4957 tb.DefineField ("Sex", typeof (int), FieldAttributes.Public);
4958 tb.DefineField ("MALE", typeof (int), FieldAttributes.Public | FieldAttributes.Static);
4959 tb.DefineField ("FEMALE", typeof (int), FieldAttributes.Private | FieldAttributes.Static);
4961 fields = tb.GetFields (BindingFlags.Public |
4962 BindingFlags.NonPublic | BindingFlags.Instance);
4963 Assert.AreEqual (2, fields.Length, "#A1");
4964 Assert.AreEqual ("name", fields [0].Name, "#A2");
4965 Assert.AreEqual ("Sex", fields [1].Name, "#A3");
4967 fields = tb.GetFields (BindingFlags.Public |
4968 BindingFlags.Instance | BindingFlags.Static);
4969 Assert.AreEqual (2, fields.Length, "#B1");
4970 Assert.AreEqual ("Sex", fields [0].Name, "#B2");
4971 Assert.AreEqual ("MALE", fields [1].Name, "#B3");
4973 fields = tb.GetFields (BindingFlags.Public |
4974 BindingFlags.NonPublic | BindingFlags.Instance |
4975 BindingFlags.Static);
4976 Assert.AreEqual (4, fields.Length, "#C1");
4977 Assert.AreEqual ("name", fields [0].Name, "#C2");
4978 Assert.AreEqual ("Sex", fields [1].Name, "#C3");
4979 Assert.AreEqual ("MALE", fields [2].Name, "#C4");
4980 Assert.AreEqual ("FEMALE", fields [3].Name, "#C5");
4983 [Test]
4984 public void TestGetFieldsFlagsComplete ()
4986 TypeBuilder tb = module.DefineType (genTypeName ());
4987 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
4989 Type emittedType = tb.CreateType ();
4991 Assert.AreEqual (1, tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4992 Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.Public).Length,
4993 emittedType.GetFields (BindingFlags.Instance | BindingFlags.Public).Length);
4994 Assert.AreEqual (0, tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4995 Assert.AreEqual (tb.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length,
4996 emittedType.GetFields (BindingFlags.Instance | BindingFlags.NonPublic).Length);
4999 [Test]
5000 public void TestGetFieldsFlagsComplete_Inheritance ()
5002 FieldInfo [] fields;
5003 BindingFlags flags;
5005 TypeBuilder blueType = module.DefineType (genTypeName (),
5006 TypeAttributes.Public);
5007 CreateMembers (blueType, "Blue", false);
5009 TypeBuilder redType = module.DefineType (genTypeName (),
5010 TypeAttributes.Public, blueType);
5011 CreateMembers (redType, "Red", false);
5013 TypeBuilder greenType = module.DefineType (genTypeName (),
5014 TypeAttributes.Public, redType);
5015 CreateMembers (greenType, "Green", false);
5017 blueType.CreateType ();
5018 redType.CreateType ();
5019 greenType.CreateType ();
5021 flags = BindingFlags.Instance | BindingFlags.NonPublic;
5022 fields = greenType.GetFields (flags);
5024 Assert.AreEqual (13, fields.Length, "#A1");
5025 Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#A2");
5026 Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#A3");
5027 Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#A4");
5028 Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#A5");
5029 Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#A6");
5030 Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#A7");
5031 Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#A8");
5032 Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#A9");
5033 Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#A10");
5034 Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#A11");
5035 Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#A12");
5036 Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#A13");
5037 Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#A14");
5039 flags = BindingFlags.Instance | BindingFlags.Public;
5040 fields = greenType.GetFields (flags);
5042 Assert.AreEqual (3, fields.Length, "#B1");
5043 Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#B2");
5044 Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#B3");
5045 Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#B4");
5047 flags = BindingFlags.Static | BindingFlags.Public;
5048 fields = greenType.GetFields (flags);
5050 Assert.AreEqual (1, fields.Length, "#C1");
5051 Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#C2");
5053 flags = BindingFlags.Static | BindingFlags.NonPublic;
5054 fields = greenType.GetFields (flags);
5056 Assert.AreEqual (5, fields.Length, "#D1");
5057 Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#D2");
5058 Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#D3");
5059 Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#D4");
5060 Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#D5");
5061 Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#D6");
5063 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5064 BindingFlags.FlattenHierarchy;
5065 fields = greenType.GetFields (flags);
5067 Assert.AreEqual (13, fields.Length, "#E1");
5068 Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#E2");
5069 Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#E3");
5070 Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#E4");
5071 Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#E5");
5072 Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#E6");
5073 Assert.AreEqual ("familyInstanceRed", fields [5].Name, "#E7");
5074 Assert.AreEqual ("famANDAssemInstanceRed", fields [6].Name, "#E8");
5075 Assert.AreEqual ("famORAssemInstanceRed", fields [7].Name, "#E9");
5076 Assert.AreEqual ("assemblyInstanceRed", fields [8].Name, "#E10");
5077 Assert.AreEqual ("familyInstanceBlue", fields [9].Name, "#E11");
5078 Assert.AreEqual ("famANDAssemInstanceBlue", fields [10].Name, "#E12");
5079 Assert.AreEqual ("famORAssemInstanceBlue", fields [11].Name, "#E13");
5080 Assert.AreEqual ("assemblyInstanceBlue", fields [12].Name, "#E14");
5082 flags = BindingFlags.Instance | BindingFlags.Public |
5083 BindingFlags.FlattenHierarchy;
5084 fields = greenType.GetFields (flags);
5086 Assert.AreEqual (3, fields.Length, "#F1");
5087 Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#F2");
5088 Assert.AreEqual ("publicInstanceRed", fields [1].Name, "#F3");
5089 Assert.AreEqual ("publicInstanceBlue", fields [2].Name, "#F4");
5091 flags = BindingFlags.Static | BindingFlags.Public |
5092 BindingFlags.FlattenHierarchy;
5093 fields = greenType.GetFields (flags);
5095 Assert.AreEqual (3, fields.Length, "#G1");
5096 Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#G2");
5097 Assert.AreEqual ("publicStaticRed", fields [1].Name, "#G3");
5098 Assert.AreEqual ("publicStaticBlue", fields [2].Name, "#G4");
5100 flags = BindingFlags.Static | BindingFlags.NonPublic |
5101 BindingFlags.FlattenHierarchy;
5102 fields = greenType.GetFields (flags);
5104 Assert.AreEqual (13, fields.Length, "#H1");
5105 Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#H2");
5106 Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#H3");
5107 Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#H4");
5108 Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#H5");
5109 Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#H6");
5110 Assert.AreEqual ("familyStaticRed", fields [5].Name, "#H7");
5111 Assert.AreEqual ("famANDAssemStaticRed", fields [6].Name, "#H8");
5112 Assert.AreEqual ("famORAssemStaticRed", fields [7].Name, "#H9");
5113 Assert.AreEqual ("assemblyStaticRed", fields [8].Name, "#H10");
5114 Assert.AreEqual ("familyStaticBlue", fields [9].Name, "#H11");
5115 Assert.AreEqual ("famANDAssemStaticBlue", fields [10].Name, "#H12");
5116 Assert.AreEqual ("famORAssemStaticBlue", fields [11].Name, "#H13");
5117 Assert.AreEqual ("assemblyStaticBlue", fields [12].Name, "#H14");
5119 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5120 BindingFlags.DeclaredOnly;
5121 fields = greenType.GetFields (flags);
5123 Assert.AreEqual (5, fields.Length, "#I1");
5124 Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#I2");
5125 Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#I3");
5126 Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#I4");
5127 Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#I5");
5128 Assert.AreEqual ("assemblyInstanceGreen", fields [4].Name, "#I6");
5130 flags = BindingFlags.Instance | BindingFlags.Public |
5131 BindingFlags.DeclaredOnly;
5132 fields = greenType.GetFields (flags);
5134 Assert.AreEqual (1, fields.Length, "#J1");
5135 Assert.AreEqual ("publicInstanceGreen", fields [0].Name, "#J2");
5137 flags = BindingFlags.Static | BindingFlags.Public |
5138 BindingFlags.DeclaredOnly;
5139 fields = greenType.GetFields (flags);
5141 Assert.AreEqual (1, fields.Length, "#K1");
5142 Assert.AreEqual ("publicStaticGreen", fields [0].Name, "#K2");
5144 flags = BindingFlags.Static | BindingFlags.NonPublic |
5145 BindingFlags.DeclaredOnly;
5146 fields = greenType.GetFields (flags);
5148 Assert.AreEqual (5, fields.Length, "#L1");
5149 Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#L2");
5150 Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#L3");
5151 Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#L4");
5152 Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#L5");
5153 Assert.AreEqual ("assemblyStaticGreen", fields [4].Name, "#L6");
5155 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5156 BindingFlags.Public;
5157 fields = greenType.GetFields (flags);
5159 Assert.AreEqual (16, fields.Length, "#M1");
5160 Assert.AreEqual ("privateInstanceGreen", fields [0].Name, "#M2");
5161 Assert.AreEqual ("familyInstanceGreen", fields [1].Name, "#M3");
5162 Assert.AreEqual ("famANDAssemInstanceGreen", fields [2].Name, "#M4");
5163 Assert.AreEqual ("famORAssemInstanceGreen", fields [3].Name, "#M5");
5164 Assert.AreEqual ("publicInstanceGreen", fields [4].Name, "#M6");
5165 Assert.AreEqual ("assemblyInstanceGreen", fields [5].Name, "#M7");
5166 Assert.AreEqual ("familyInstanceRed", fields [6].Name, "#M8");
5167 Assert.AreEqual ("famANDAssemInstanceRed", fields [7].Name, "#M9");
5168 Assert.AreEqual ("famORAssemInstanceRed", fields [8].Name, "#M10");
5169 Assert.AreEqual ("publicInstanceRed", fields [9].Name, "#M11");
5170 Assert.AreEqual ("assemblyInstanceRed", fields [10].Name, "#M12");
5171 Assert.AreEqual ("familyInstanceBlue", fields [11].Name, "#M13");
5172 Assert.AreEqual ("famANDAssemInstanceBlue", fields [12].Name, "#M14");
5173 Assert.AreEqual ("famORAssemInstanceBlue", fields [13].Name, "#M15");
5174 Assert.AreEqual ("publicInstanceBlue", fields [14].Name, "#M16");
5175 Assert.AreEqual ("assemblyInstanceBlue", fields [15].Name, "#M17");
5177 flags = BindingFlags.Static | BindingFlags.NonPublic |
5178 BindingFlags.Public;
5179 fields = greenType.GetFields (flags);
5181 Assert.AreEqual (6, fields.Length, "#N1");
5182 Assert.AreEqual ("privateStaticGreen", fields [0].Name, "#N2");
5183 Assert.AreEqual ("familyStaticGreen", fields [1].Name, "#N3");
5184 Assert.AreEqual ("famANDAssemStaticGreen", fields [2].Name, "#N4");
5185 Assert.AreEqual ("famORAssemStaticGreen", fields [3].Name, "#N5");
5186 Assert.AreEqual ("publicStaticGreen", fields [4].Name, "#N6");
5187 Assert.AreEqual ("assemblyStaticGreen", fields [5].Name, "#N7");
5190 [Test]
5191 [Category ("NotWorking")] // mcs depends on this
5192 public void TestGetFieldIncomplete_MS ()
5194 TypeBuilder tb = module.DefineType (genTypeName ());
5195 tb.DefineField ("test", typeof (int), FieldAttributes.Public);
5196 try {
5197 tb.GetField ("test");
5198 Assert.Fail ("#1");
5199 } catch (NotSupportedException ex) {
5200 // The invoked member is not supported in a
5201 // dynamic module
5202 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5203 Assert.IsNull (ex.InnerException, "#3");
5204 Assert.IsNotNull (ex.Message, "#4");
5208 [Test]
5209 [Category ("NotDotNet")] // mcs depends on this
5210 public void TestGetFieldIncomplete_Mono ()
5212 TypeBuilder tb = module.DefineType (genTypeName ());
5213 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5214 tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5216 FieldInfo field = tb.GetField ("TestField");
5217 Assert.IsNotNull (field, "#A1");
5218 Assert.AreEqual ("TestField", field.Name, "#A2");
5219 Assert.IsTrue (field is FieldBuilder, "#A3");
5221 Assert.IsNull (tb.GetField ("OtherField"), "#B1");
5222 Assert.IsNull (tb.GetField ("TestOtherField"), "#B2");
5225 [Test]
5226 public void TestGetFieldComplete ()
5228 TypeBuilder tb = module.DefineType (genTypeName ());
5229 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5231 Type emittedType = tb.CreateType ();
5233 FieldInfo dynamicField = tb.GetField ("TestField");
5234 FieldInfo emittedField = emittedType.GetField ("TestField");
5235 Assert.IsNotNull (dynamicField, "#A1");
5236 Assert.AreEqual (dynamicField.Name, emittedField.Name, "#A2");
5237 Assert.IsNull (tb.GetField ("TestOtherField"), "#A3");
5238 Assert.IsFalse (emittedField is FieldBuilder, "#A4");
5239 Assert.IsFalse (dynamicField is FieldBuilder, "#A5");
5241 // bug #81638
5242 object value = Activator.CreateInstance (emittedType);
5243 emittedField.SetValue (value, 5);
5244 Assert.AreEqual (5, emittedField.GetValue (value), "#B1");
5245 Assert.AreEqual (5, dynamicField.GetValue (value), "#B2");
5246 dynamicField.SetValue (value, 4);
5247 Assert.AreEqual (4, emittedField.GetValue (value), "#B3");
5248 Assert.AreEqual (4, dynamicField.GetValue (value), "#B4");
5251 [Test] // bug #81640
5252 public void TestGetFieldComplete_Type ()
5254 TypeBuilder tb = module.DefineType (genTypeName ());
5255 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5256 Type emittedType = tb.CreateType ();
5257 FieldInfo dynamicField = tb.GetField ("TestField");
5258 Assert.IsFalse (dynamicField is FieldBuilder, "#1");
5260 object value = Activator.CreateInstance (emittedType);
5261 Assert.AreEqual (0, dynamicField.GetValue (value), "#2");
5264 [Test]
5265 [Category ("NotWorking")] // mcs depends on this
5266 public void TestGetFieldFlagsIncomplete_MS ()
5268 TypeBuilder tb = module.DefineType (genTypeName ());
5269 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5270 tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5271 try {
5272 tb.GetField ("test", BindingFlags.Public);
5273 Assert.Fail ("#1");
5274 } catch (NotSupportedException ex) {
5275 // The invoked member is not supported in a
5276 // dynamic module
5277 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5278 Assert.IsNull (ex.InnerException, "#3");
5279 Assert.IsNotNull (ex.Message, "#4");
5283 [Test]
5284 [Category ("NotDotNet")] // mcs depends on this
5285 public void TestGetFieldFlagsIncomplete_Mono ()
5287 TypeBuilder tb = module.DefineType (genTypeName ());
5288 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5289 tb.DefineField ("OtherField", typeof (int), FieldAttributes.Private);
5291 FieldInfo field = tb.GetField ("TestField", BindingFlags.Public
5292 | BindingFlags.Instance);
5293 Assert.IsNotNull (field, "#A1");
5294 Assert.AreEqual ("TestField", field.Name, "#A2");
5295 Assert.IsTrue (field is FieldBuilder, "#A3");
5297 field = tb.GetField ("OtherField", BindingFlags.NonPublic |
5298 BindingFlags.Instance);
5299 Assert.IsNotNull (field, "#B1");
5300 Assert.AreEqual ("OtherField", field.Name, "#B2");
5301 Assert.IsTrue (field is FieldBuilder, "#B3");
5303 Assert.IsNull (tb.GetField ("TestField", BindingFlags.NonPublic |
5304 BindingFlags.Instance), "#C1");
5305 Assert.IsNull (tb.GetField ("TestField", BindingFlags.Public |
5306 BindingFlags.Static), "#C2");
5307 Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5308 BindingFlags.Instance), "#C3");
5309 Assert.IsNull (tb.GetField ("OtherField", BindingFlags.Public |
5310 BindingFlags.Static), "#C4");
5311 Assert.IsNull (tb.GetField ("NotExist", BindingFlags.NonPublic |
5312 BindingFlags.Instance), "#C5");
5313 Assert.IsNull (tb.GetField ("NotExist", BindingFlags.Public |
5314 BindingFlags.Instance), "#C6");
5317 [Test]
5318 public void TestGetFieldFlagsComplete ()
5320 TypeBuilder tb = module.DefineType (genTypeName ());
5321 tb.DefineField ("TestField", typeof (int), FieldAttributes.Public);
5323 Type emittedType = tb.CreateType ();
5325 Assert.IsNotNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public));
5326 Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name,
5327 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.Public).Name);
5328 Assert.IsNull (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5329 Assert.AreEqual (tb.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic),
5330 emittedType.GetField ("TestField", BindingFlags.Instance | BindingFlags.NonPublic));
5333 [Test]
5334 public void TestGetFieldFlagsComplete_Inheritance ()
5336 BindingFlags flags;
5338 TypeBuilder blueType = module.DefineType (genTypeName (),
5339 TypeAttributes.Public);
5340 CreateMembers (blueType, "Blue", false);
5342 TypeBuilder redType = module.DefineType (genTypeName (),
5343 TypeAttributes.Public, blueType);
5344 CreateMembers (redType, "Red", false);
5346 TypeBuilder greenType = module.DefineType (genTypeName (),
5347 TypeAttributes.Public, redType);
5348 CreateMembers (greenType, "Green", false);
5350 blueType.CreateType ();
5351 redType.CreateType ();
5352 greenType.CreateType ();
5354 flags = BindingFlags.Instance | BindingFlags.NonPublic;
5356 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#A1");
5357 Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#A2");
5358 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#A3");
5359 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#A4");
5360 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#A5");
5361 Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#A6");
5362 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#A7");
5363 Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#A8");
5364 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#A9");
5365 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#A10");
5366 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#A11");
5367 Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#A12");
5368 Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#A13");
5369 Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#A14");
5370 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#A15");
5371 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#A16");
5372 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#A17");
5373 Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#A18");
5374 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#A19");
5375 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#A20");
5376 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#A21");
5377 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#A22");
5378 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#A23");
5379 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#A24");
5380 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#A25");
5381 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#A26");
5382 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#A27");
5383 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#A28");
5384 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#A29");
5385 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#A30");
5386 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#A31");
5387 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#A32");
5388 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#A33");
5389 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#A34");
5390 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#A35");
5391 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#A36");
5393 flags = BindingFlags.Instance | BindingFlags.Public;
5395 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#B1");
5396 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#B2");
5397 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#B3");
5398 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#B4");
5399 Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#B5");
5400 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#B6");
5401 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#B7");
5402 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#B8");
5403 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#B9");
5404 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#B10");
5405 Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#B11");
5406 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#B12");
5407 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#B13");
5408 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#B14");
5409 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#B15");
5410 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#B16");
5411 Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#B17");
5412 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#B18");
5413 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#B19");
5414 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#B20");
5415 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#B21");
5416 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#B22");
5417 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#B23");
5418 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#B24");
5419 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#B25");
5420 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#B26");
5421 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#B27");
5422 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#B28");
5423 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#B29");
5424 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#B30");
5425 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#B31");
5426 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#B32");
5427 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#B33");
5428 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#B34");
5429 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#B35");
5430 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#B36");
5432 flags = BindingFlags.Static | BindingFlags.Public;
5434 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#C1");
5435 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#C2");
5436 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#C3");
5437 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#C4");
5438 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#C5");
5439 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#C6");
5440 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#C7");
5441 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#C8");
5442 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#C9");
5443 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#C10");
5444 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#C11");
5445 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#C12");
5446 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#C13");
5447 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#C14");
5448 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#C15");
5449 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#C16");
5450 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#C17");
5451 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#C18");
5452 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#C19");
5453 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#C20");
5454 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#C21");
5455 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#C22");
5456 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#C23");
5457 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#C24");
5458 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#C25");
5459 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#C26");
5460 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#C27");
5461 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#C28");
5462 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#C29");
5463 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#C30");
5464 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#C31");
5465 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#C32");
5466 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#C33");
5467 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#C34");
5468 Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#C35");
5469 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#C36");
5471 flags = BindingFlags.Static | BindingFlags.NonPublic;
5473 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#D1");
5474 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#D2");
5475 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#D3");
5476 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#D4");
5477 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#D5");
5478 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#D6");
5479 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#D7");
5480 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#D8");
5481 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#D9");
5482 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#D10");
5483 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#D11");
5484 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#D12");
5485 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#D13");
5486 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#D14");
5487 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#D15");
5488 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#D16");
5489 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#D17");
5490 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#D18");
5491 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#D19");
5492 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#D20");
5493 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#D21");
5494 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#D22");
5495 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#D23");
5496 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#D24");
5497 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#D25");
5498 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#D26");
5499 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#D27");
5500 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#D28");
5501 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#D29");
5502 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#D30");
5503 Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#D31");
5504 Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#D32");
5505 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#D33");
5506 Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#D34");
5507 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#D35");
5508 Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#D36");
5510 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5511 BindingFlags.FlattenHierarchy;
5513 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#E1");
5514 Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#E2");
5515 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#E3");
5516 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#E4");
5517 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#E5");
5518 Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#E6");
5519 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#E7");
5520 Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#E8");
5521 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#E9");
5522 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#E10");
5523 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#E11");
5524 Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#E12");
5525 Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#E13");
5526 Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#E14");
5527 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#E15");
5528 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#E16");
5529 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#E17");
5530 Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#E18");
5531 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#E19");
5532 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#E20");
5533 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#E21");
5534 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#E22");
5535 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#E23");
5536 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#E24");
5537 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#E25");
5538 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#E26");
5539 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#E27");
5540 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#E28");
5541 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#E29");
5542 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#E30");
5543 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#E31");
5544 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#E32");
5545 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#E33");
5546 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#E34");
5547 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#E35");
5548 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#E36");
5550 flags = BindingFlags.Instance | BindingFlags.Public |
5551 BindingFlags.FlattenHierarchy;
5553 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#F1");
5554 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#F2");
5555 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#F3");
5556 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#F4");
5557 Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#F5");
5558 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#F6");
5559 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#F7");
5560 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#F8");
5561 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#F9");
5562 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#F10");
5563 Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#F11");
5564 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#F12");
5565 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#F13");
5566 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#F14");
5567 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#F15");
5568 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#F16");
5569 Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#F17");
5570 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#F18");
5571 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#F19");
5572 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#F20");
5573 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#F21");
5574 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#F22");
5575 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#F23");
5576 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#F24");
5577 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#F25");
5578 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#F26");
5579 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#F27");
5580 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#F28");
5581 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#F29");
5582 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#F30");
5583 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#F31");
5584 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#F32");
5585 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#F33");
5586 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#F34");
5587 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#F35");
5588 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#F36");
5590 flags = BindingFlags.Static | BindingFlags.Public |
5591 BindingFlags.FlattenHierarchy;
5593 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#G1");
5594 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#G2");
5595 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#G3");
5596 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#G4");
5597 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#G5");
5598 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#G6");
5599 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#G7");
5600 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#G8");
5601 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#G9");
5602 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#G10");
5603 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#G11");
5604 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#G12");
5605 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#G13");
5606 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#G14");
5607 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#G15");
5608 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#G16");
5609 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#G17");
5610 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#G18");
5611 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#G19");
5612 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#G20");
5613 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#G21");
5614 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#G22");
5615 Assert.IsNotNull (greenType.GetField ("publicStaticBlue", flags), "#G23");
5616 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#G24");
5617 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#G25");
5618 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#G26");
5619 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#G27");
5620 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#G28");
5621 Assert.IsNotNull (greenType.GetField ("publicStaticRed", flags), "#G29");
5622 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#G30");
5623 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#G31");
5624 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#G32");
5625 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#G33");
5626 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#G34");
5627 Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#G35");
5628 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#G36");
5630 flags = BindingFlags.Static | BindingFlags.NonPublic |
5631 BindingFlags.FlattenHierarchy;
5633 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#H1");
5634 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#H2");
5635 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#H3");
5636 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#H4");
5637 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#H5");
5638 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#H6");
5639 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#H7");
5640 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#H8");
5641 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#H9");
5642 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#H10");
5643 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#H11");
5644 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#H12");
5645 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#H13");
5646 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#H14");
5647 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#H15");
5648 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#H16");
5649 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#H17");
5650 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#H18");
5651 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#H19");
5652 Assert.IsNotNull (greenType.GetField ("familyStaticBlue", flags), "#H20");
5653 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#H21");
5654 Assert.IsNotNull (greenType.GetField ("famORAssemStaticBlue", flags), "#H22");
5655 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#H23");
5656 Assert.IsNotNull (greenType.GetField ("assemblyStaticBlue", flags), "#H24");
5657 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#H25");
5658 Assert.IsNotNull (greenType.GetField ("familyStaticRed", flags), "#H26");
5659 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticRed", flags), "#H27");
5660 Assert.IsNotNull (greenType.GetField ("famORAssemStaticRed", flags), "#H28");
5661 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#H29");
5662 Assert.IsNotNull (greenType.GetField ("assemblyStaticRed", flags), "#H30");
5663 Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#H31");
5664 Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#H32");
5665 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#H33");
5666 Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#H34");
5667 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#H35");
5668 Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#H36");
5670 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5671 BindingFlags.DeclaredOnly;
5673 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#I1");
5674 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#I2");
5675 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#I3");
5676 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#I4");
5677 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#I5");
5678 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#I6");
5679 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#I7");
5680 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#I8");
5681 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#I9");
5682 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#I10");
5683 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#I11");
5684 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#I12");
5685 Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#I13");
5686 Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#I14");
5687 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#I15");
5688 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#I16");
5689 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#I17");
5690 Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#I18");
5691 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#I19");
5692 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#I20");
5693 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#I21");
5694 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#I22");
5695 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#I23");
5696 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#I24");
5697 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#I25");
5698 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#I26");
5699 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#I27");
5700 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#I28");
5701 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#I29");
5702 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#I30");
5703 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#I31");
5704 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#I32");
5705 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#I33");
5706 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#I34");
5707 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#I35");
5708 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#I36");
5710 flags = BindingFlags.Instance | BindingFlags.Public |
5711 BindingFlags.DeclaredOnly;
5713 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#J1");
5714 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#J2");
5715 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#J3");
5716 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#J4");
5717 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#J5");
5718 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#J6");
5719 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#J7");
5720 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#J8");
5721 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#J9");
5722 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#J10");
5723 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#J11");
5724 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#J12");
5725 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#J13");
5726 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#J14");
5727 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#J15");
5728 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#J16");
5729 Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#J17");
5730 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#J18");
5731 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#J19");
5732 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#J20");
5733 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#J21");
5734 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#J22");
5735 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#J23");
5736 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#J24");
5737 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#J25");
5738 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#J26");
5739 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#J27");
5740 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#J28");
5741 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#J29");
5742 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#J30");
5743 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#J31");
5744 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#J32");
5745 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#J33");
5746 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#J34");
5747 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#J35");
5748 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#J36");
5750 flags = BindingFlags.Static | BindingFlags.Public |
5751 BindingFlags.DeclaredOnly;
5753 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#K1");
5754 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#K2");
5755 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#K3");
5756 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#K4");
5757 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#K5");
5758 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#K6");
5759 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#K7");
5760 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#K8");
5761 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#K9");
5762 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#K10");
5763 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#K11");
5764 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#K12");
5765 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#K13");
5766 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#K14");
5767 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#K15");
5768 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#K16");
5769 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#K17");
5770 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#K18");
5771 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#K19");
5772 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#K20");
5773 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#K21");
5774 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#K22");
5775 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#K23");
5776 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#K24");
5777 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#K25");
5778 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#K26");
5779 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#K27");
5780 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#K28");
5781 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#K29");
5782 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#K30");
5783 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#K31");
5784 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#K32");
5785 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#K33");
5786 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#K34");
5787 Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#K35");
5788 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#K36");
5790 flags = BindingFlags.Static | BindingFlags.NonPublic |
5791 BindingFlags.DeclaredOnly;
5793 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#L1");
5794 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#L2");
5795 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#L3");
5796 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#L4");
5797 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#L5");
5798 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#L6");
5799 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#L7");
5800 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#L8");
5801 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#L9");
5802 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#L10");
5803 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#L11");
5804 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#L12");
5805 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#L13");
5806 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#L14");
5807 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#L15");
5808 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#L16");
5809 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#L17");
5810 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#L18");
5811 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#L19");
5812 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#L20");
5813 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#L21");
5814 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#L22");
5815 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#L23");
5816 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#L24");
5817 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#L25");
5818 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#L26");
5819 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#L27");
5820 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#L28");
5821 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#L29");
5822 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#L30");
5823 Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#L31");
5824 Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#L32");
5825 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#L33");
5826 Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#L34");
5827 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#L35");
5828 Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#L36");
5830 flags = BindingFlags.Instance | BindingFlags.NonPublic |
5831 BindingFlags.Public;
5833 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#M1");
5834 Assert.IsNotNull (greenType.GetField ("familyInstanceBlue", flags), "#M2");
5835 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#M3");
5836 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#M4");
5837 Assert.IsNotNull (greenType.GetField ("publicInstanceBlue", flags), "#M5");
5838 Assert.IsNotNull (greenType.GetField ("assemblyInstanceBlue", flags), "#M6");
5839 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#M7");
5840 Assert.IsNotNull (greenType.GetField ("familyInstanceRed", flags), "#M8");
5841 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#M9");
5842 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceRed", flags), "#M10");
5843 Assert.IsNotNull (greenType.GetField ("publicInstanceRed", flags), "#M11");
5844 Assert.IsNotNull (greenType.GetField ("assemblyInstanceRed", flags), "#M12");
5845 Assert.IsNotNull (greenType.GetField ("privateInstanceGreen", flags), "#M13");
5846 Assert.IsNotNull (greenType.GetField ("familyInstanceGreen", flags), "#M14");
5847 Assert.IsNotNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#M15");
5848 Assert.IsNotNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#M16");
5849 Assert.IsNotNull (greenType.GetField ("publicInstanceGreen", flags), "#M17");
5850 Assert.IsNotNull (greenType.GetField ("assemblyInstanceGreen", flags), "#M18");
5851 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#M19");
5852 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#M20");
5853 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#M21");
5854 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#M22");
5855 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#M23");
5856 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#M24");
5857 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#M25");
5858 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#M26");
5859 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#M27");
5860 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#M28");
5861 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#M29");
5862 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#M30");
5863 Assert.IsNull (greenType.GetField ("privateStaticGreen", flags), "#M31");
5864 Assert.IsNull (greenType.GetField ("familyStaticGreen", flags), "#M32");
5865 Assert.IsNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#M33");
5866 Assert.IsNull (greenType.GetField ("famORAssemStaticGreen", flags), "#M34");
5867 Assert.IsNull (greenType.GetField ("publicStaticGreen", flags), "#M35");
5868 Assert.IsNull (greenType.GetField ("assemblyStaticGreen", flags), "#M36");
5870 flags = BindingFlags.Static | BindingFlags.NonPublic |
5871 BindingFlags.Public;
5873 Assert.IsNull (greenType.GetField ("privateInstanceBlue", flags), "#N1");
5874 Assert.IsNull (greenType.GetField ("familyInstanceBlue", flags), "#N2");
5875 Assert.IsNull (greenType.GetField ("famANDAssemInstanceBlue", flags), "#N3");
5876 Assert.IsNull (greenType.GetField ("famORAssemInstanceBlue", flags), "#N4");
5877 Assert.IsNull (greenType.GetField ("publicInstanceBlue", flags), "#N5");
5878 Assert.IsNull (greenType.GetField ("assemblyInstanceBlue", flags), "#N6");
5879 Assert.IsNull (greenType.GetField ("privateInstanceRed", flags), "#N7");
5880 Assert.IsNull (greenType.GetField ("familyInstanceRed", flags), "#N8");
5881 Assert.IsNull (greenType.GetField ("famANDAssemInstanceRed", flags), "#N9");
5882 Assert.IsNull (greenType.GetField ("famORAssemInstanceRed", flags), "#N10");
5883 Assert.IsNull (greenType.GetField ("publicInstanceRed", flags), "#N11");
5884 Assert.IsNull (greenType.GetField ("assemblyInstanceRed", flags), "#N12");
5885 Assert.IsNull (greenType.GetField ("privateInstanceGreen", flags), "#N13");
5886 Assert.IsNull (greenType.GetField ("familyInstanceGreen", flags), "#N14");
5887 Assert.IsNull (greenType.GetField ("famANDAssemInstanceGreen", flags), "#N15");
5888 Assert.IsNull (greenType.GetField ("famORAssemInstanceGreen", flags), "#N16");
5889 Assert.IsNull (greenType.GetField ("publicInstanceGreen", flags), "#N17");
5890 Assert.IsNull (greenType.GetField ("assemblyInstanceGreen", flags), "#N18");
5891 Assert.IsNull (greenType.GetField ("privateStaticBlue", flags), "#N19");
5892 Assert.IsNull (greenType.GetField ("familyStaticBlue", flags), "#N20");
5893 Assert.IsNull (greenType.GetField ("famANDAssemStaticBlue", flags), "#N21");
5894 Assert.IsNull (greenType.GetField ("famORAssemStaticBlue", flags), "#N22");
5895 Assert.IsNull (greenType.GetField ("publicStaticBlue", flags), "#N23");
5896 Assert.IsNull (greenType.GetField ("assemblyStaticBlue", flags), "#N24");
5897 Assert.IsNull (greenType.GetField ("privateStaticRed", flags), "#N25");
5898 Assert.IsNull (greenType.GetField ("familyStaticRed", flags), "#N26");
5899 Assert.IsNull (greenType.GetField ("famANDAssemStaticRed", flags), "#N27");
5900 Assert.IsNull (greenType.GetField ("famORAssemStaticRed", flags), "#N28");
5901 Assert.IsNull (greenType.GetField ("publicStaticRed", flags), "#N29");
5902 Assert.IsNull (greenType.GetField ("assemblyStaticRed", flags), "#N30");
5903 Assert.IsNotNull (greenType.GetField ("privateStaticGreen", flags), "#N31");
5904 Assert.IsNotNull (greenType.GetField ("familyStaticGreen", flags), "#N32");
5905 Assert.IsNotNull (greenType.GetField ("famANDAssemStaticGreen", flags), "#N33");
5906 Assert.IsNotNull (greenType.GetField ("famORAssemStaticGreen", flags), "#N34");
5907 Assert.IsNotNull (greenType.GetField ("publicStaticGreen", flags), "#N35");
5908 Assert.IsNotNull (greenType.GetField ("assemblyStaticGreen", flags), "#N36");
5911 [Test]
5912 [Category ("NotDotNet")] // mcs depends on this
5913 public void TestGetPropertiesIncomplete_Mono ()
5915 TypeBuilder tb = module.DefineType (genTypeName ());
5916 DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5917 DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5918 DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5920 PropertyInfo [] properties = tb.GetProperties ();
5921 Assert.AreEqual (2, properties.Length, "#1");
5922 Assert.AreEqual ("Name", properties [0].Name, "#2");
5923 Assert.AreEqual ("FirstName", properties [1].Name, "#3");
5926 [Test]
5927 [Category ("NotWorking")] // mcs depends on this
5928 public void TestGetPropertiesIncomplete_MS ()
5930 TypeBuilder tb = module.DefineType (genTypeName ());
5931 DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5932 DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5933 DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5935 try {
5936 tb.GetProperties ();
5937 Assert.Fail ("#1");
5938 } catch (NotSupportedException ex) {
5939 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
5940 Assert.IsNull (ex.InnerException, "#3");
5941 Assert.IsNotNull (ex.Message, "#4");
5945 [Test]
5946 public void TestGetPropertiesComplete ()
5948 TypeBuilder tb = module.DefineType (genTypeName ());
5949 DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
5951 Type emittedType = tb.CreateType ();
5953 Assert.AreEqual (1, tb.GetProperties ().Length);
5954 Assert.AreEqual (tb.GetProperties ().Length, emittedType.GetProperties ().Length);
5957 [Test]
5958 [Category ("NotDotNet")] // mcs depends on this
5959 public void TestGetPropertiesFlagsIncomplete_Mono ()
5961 PropertyInfo [] properties;
5963 TypeBuilder tb = module.DefineType (genTypeName ());
5964 DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5965 DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5966 DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5968 properties = tb.GetProperties (BindingFlags.Public |
5969 BindingFlags.NonPublic | BindingFlags.Instance);
5970 Assert.AreEqual (3, properties.Length, "#A1");
5971 Assert.AreEqual ("Name", properties [0].Name, "#A2");
5972 Assert.AreEqual ("Income", properties [1].Name, "#A3");
5973 Assert.AreEqual ("FirstName", properties [2].Name, "#A4");
5975 properties = tb.GetProperties (BindingFlags.Public |
5976 BindingFlags.Instance);
5977 Assert.AreEqual (2, properties.Length, "#B1");
5978 Assert.AreEqual ("Name", properties [0].Name, "#B2");
5979 Assert.AreEqual ("FirstName", properties [1].Name, "#B3");
5981 properties = tb.GetProperties (BindingFlags.NonPublic |
5982 BindingFlags.Instance);
5983 Assert.AreEqual (1, properties.Length, "#C1");
5984 Assert.AreEqual ("Income", properties [0].Name, "#C2");
5987 [Test]
5988 [Category ("NotWorking")] // mcs depends on this
5989 public void TestGetPropertiesFlagsIncomplete_MS ()
5991 TypeBuilder tb = module.DefineType (genTypeName ());
5992 DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
5993 DefineStringProperty (tb, "Income", "income", MethodAttributes.Private);
5994 DefineStringProperty (tb, "FirstName", "firstName", MethodAttributes.Public);
5996 try {
5997 tb.GetProperties (BindingFlags.Public);
5998 Assert.Fail ("#1");
5999 } catch (NotSupportedException ex) {
6000 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6001 Assert.IsNull (ex.InnerException, "#3");
6002 Assert.IsNotNull (ex.Message, "#4");
6006 [Test]
6007 public void TestGetPropertiesFlagsComplete ()
6009 TypeBuilder tb = module.DefineType (genTypeName ());
6010 DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6012 Type emittedType = tb.CreateType ();
6014 Assert.AreEqual (1, tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6015 Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length,
6016 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.Public).Length);
6017 Assert.AreEqual (0, tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6018 Assert.AreEqual (tb.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length,
6019 emittedType.GetProperties (BindingFlags.Instance | BindingFlags.NonPublic).Length);
6022 [Test]
6023 public void TestGetPropertiesFlagsComplete_Inheritance ()
6025 PropertyInfo [] props;
6026 BindingFlags flags;
6028 TypeBuilder blueType = module.DefineType (genTypeName (),
6029 TypeAttributes.Public);
6030 CreateMembers (blueType, "Blue", false);
6032 TypeBuilder redType = module.DefineType (genTypeName (),
6033 TypeAttributes.Public, blueType);
6034 CreateMembers (redType, "Red", false);
6036 TypeBuilder greenType = module.DefineType (genTypeName (),
6037 TypeAttributes.Public, redType);
6038 CreateMembers (greenType, "Green", false);
6040 blueType.CreateType ();
6041 redType.CreateType ();
6042 greenType.CreateType ();
6044 flags = BindingFlags.Instance | BindingFlags.NonPublic;
6045 props = greenType.GetProperties (flags);
6047 #if NET_2_0
6048 Assert.AreEqual (13, props.Length, "#A1");
6049 #else
6050 Assert.AreEqual (11, props.Length, "#A1");
6051 #endif
6052 Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#A2");
6053 Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#A3");
6054 Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#A4");
6055 Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#A5");
6056 Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#A6");
6057 Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#A7");
6058 Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#A8");
6059 Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#A9");
6060 #if NET_2_0
6061 Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#A10");
6062 Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#A11");
6063 Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#A12");
6064 Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#A13");
6065 Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#A15");
6066 #else
6067 Assert.AreEqual ("FamilyInstanceBlue", props [8].Name, "#A10");
6068 Assert.AreEqual ("FamANDAssemInstanceBlue", props [9].Name, "#A11");
6069 Assert.AreEqual ("FamORAssemInstanceBlue", props [10].Name, "#A12");
6070 #endif
6072 flags = BindingFlags.Instance | BindingFlags.Public;
6073 props = greenType.GetProperties (flags);
6075 Assert.AreEqual (3, props.Length, "#B1");
6076 Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#B2");
6077 Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#B3");
6078 Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#B4");
6080 flags = BindingFlags.Static | BindingFlags.Public;
6081 props = greenType.GetProperties (flags);
6083 Assert.AreEqual (1, props.Length, "#C1");
6084 Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#C2");
6086 flags = BindingFlags.Static | BindingFlags.NonPublic;
6087 props = greenType.GetProperties (flags);
6089 Assert.AreEqual (5, props.Length, "#D1");
6090 Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#D2");
6091 Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#D3");
6092 Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#D4");
6093 Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#D5");
6094 Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#D6");
6096 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6097 BindingFlags.FlattenHierarchy;
6098 props = greenType.GetProperties (flags);
6100 #if NET_2_0
6101 Assert.AreEqual (13, props.Length, "#E1");
6102 #else
6103 Assert.AreEqual (11, props.Length, "#E1");
6104 #endif
6105 Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#E2");
6106 Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#E3");
6107 Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#E4");
6108 Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#E5");
6109 Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#E6");
6110 Assert.AreEqual ("FamilyInstanceRed", props [5].Name, "#E7");
6111 Assert.AreEqual ("FamANDAssemInstanceRed", props [6].Name, "#E8");
6112 Assert.AreEqual ("FamORAssemInstanceRed", props [7].Name, "#E9");
6113 #if NET_2_0
6114 Assert.AreEqual ("AssemblyInstanceRed", props [8].Name, "#E10");
6115 Assert.AreEqual ("FamilyInstanceBlue", props [9].Name, "#E11");
6116 Assert.AreEqual ("FamANDAssemInstanceBlue", props [10].Name, "#E12");
6117 Assert.AreEqual ("FamORAssemInstanceBlue", props [11].Name, "#E13");
6118 Assert.AreEqual ("AssemblyInstanceBlue", props [12].Name, "#E14");
6119 #else
6120 Assert.AreEqual ("FamilyInstanceBlue", props [8].Name, "#E10");
6121 Assert.AreEqual ("FamANDAssemInstanceBlue", props [9].Name, "#E11");
6122 Assert.AreEqual ("FamORAssemInstanceBlue", props [10].Name, "#E12");
6123 #endif
6125 flags = BindingFlags.Instance | BindingFlags.Public |
6126 BindingFlags.FlattenHierarchy;
6127 props = greenType.GetProperties (flags);
6129 Assert.AreEqual (3, props.Length, "#F1");
6130 Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#F2");
6131 Assert.AreEqual ("PublicInstanceRed", props [1].Name, "#F3");
6132 Assert.AreEqual ("PublicInstanceBlue", props [2].Name, "#F4");
6134 flags = BindingFlags.Static | BindingFlags.Public |
6135 BindingFlags.FlattenHierarchy;
6136 props = greenType.GetProperties (flags);
6138 Assert.AreEqual (3, props.Length, "#G1");
6139 Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#G2");
6140 Assert.AreEqual ("PublicStaticRed", props [1].Name, "#G3");
6141 Assert.AreEqual ("PublicStaticBlue", props [2].Name, "#G4");
6143 flags = BindingFlags.Static | BindingFlags.NonPublic |
6144 BindingFlags.FlattenHierarchy;
6145 props = greenType.GetProperties (flags);
6147 #if NET_2_0
6148 Assert.AreEqual (13, props.Length, "#H1");
6149 #else
6150 Assert.AreEqual (11, props.Length, "#H1");
6151 #endif
6152 Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#H2");
6153 Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#H3");
6154 Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#H4");
6155 Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#H5");
6156 Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#H6");
6157 Assert.AreEqual ("FamilyStaticRed", props [5].Name, "#H7");
6158 Assert.AreEqual ("FamANDAssemStaticRed", props [6].Name, "#H8");
6159 Assert.AreEqual ("FamORAssemStaticRed", props [7].Name, "#H9");
6160 #if NET_2_0
6161 Assert.AreEqual ("AssemblyStaticRed", props [8].Name, "#H10");
6162 Assert.AreEqual ("FamilyStaticBlue", props [9].Name, "#H11");
6163 Assert.AreEqual ("FamANDAssemStaticBlue", props [10].Name, "#H12");
6164 Assert.AreEqual ("FamORAssemStaticBlue", props [11].Name, "#H13");
6165 Assert.AreEqual ("AssemblyStaticBlue", props [12].Name, "#H14");
6166 #else
6167 Assert.AreEqual ("FamilyStaticBlue", props [8].Name, "#H10");
6168 Assert.AreEqual ("FamANDAssemStaticBlue", props [9].Name, "#H11");
6169 Assert.AreEqual ("FamORAssemStaticBlue", props [10].Name, "#H12");
6170 #endif
6172 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6173 BindingFlags.DeclaredOnly;
6174 props = greenType.GetProperties (flags);
6176 Assert.AreEqual (5, props.Length, "#I1");
6177 Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#I2");
6178 Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#I3");
6179 Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#I4");
6180 Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#I5");
6181 Assert.AreEqual ("AssemblyInstanceGreen", props [4].Name, "#I6");
6183 flags = BindingFlags.Instance | BindingFlags.Public |
6184 BindingFlags.DeclaredOnly;
6185 props = greenType.GetProperties (flags);
6187 Assert.AreEqual (1, props.Length, "#J1");
6188 Assert.AreEqual ("PublicInstanceGreen", props [0].Name, "#J2");
6190 flags = BindingFlags.Static | BindingFlags.Public |
6191 BindingFlags.DeclaredOnly;
6192 props = greenType.GetProperties (flags);
6194 Assert.AreEqual (1, props.Length, "#K1");
6195 Assert.AreEqual ("PublicStaticGreen", props [0].Name, "#K2");
6197 flags = BindingFlags.Static | BindingFlags.NonPublic |
6198 BindingFlags.DeclaredOnly;
6199 props = greenType.GetProperties (flags);
6201 Assert.AreEqual (5, props.Length, "#L1");
6202 Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#L2");
6203 Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#L3");
6204 Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#L4");
6205 Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#L5");
6206 Assert.AreEqual ("AssemblyStaticGreen", props [4].Name, "#L6");
6208 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6209 BindingFlags.Public;
6210 props = greenType.GetProperties (flags);
6212 #if NET_2_0
6213 Assert.AreEqual (16, props.Length, "#M1");
6214 #else
6215 Assert.AreEqual (14, props.Length, "#M1");
6216 #endif
6217 Assert.AreEqual ("PrivateInstanceGreen", props [0].Name, "#M2");
6218 Assert.AreEqual ("FamilyInstanceGreen", props [1].Name, "#M3");
6219 Assert.AreEqual ("FamANDAssemInstanceGreen", props [2].Name, "#M4");
6220 Assert.AreEqual ("FamORAssemInstanceGreen", props [3].Name, "#M5");
6221 Assert.AreEqual ("PublicInstanceGreen", props [4].Name, "#M6");
6222 Assert.AreEqual ("AssemblyInstanceGreen", props [5].Name, "#M7");
6223 Assert.AreEqual ("FamilyInstanceRed", props [6].Name, "#M8");
6224 Assert.AreEqual ("FamANDAssemInstanceRed", props [7].Name, "#M9");
6225 Assert.AreEqual ("FamORAssemInstanceRed", props [8].Name, "#M10");
6226 Assert.AreEqual ("PublicInstanceRed", props [9].Name, "#M11");
6227 #if NET_2_0
6228 Assert.AreEqual ("AssemblyInstanceRed", props [10].Name, "#M12");
6229 Assert.AreEqual ("FamilyInstanceBlue", props [11].Name, "#M13");
6230 Assert.AreEqual ("FamANDAssemInstanceBlue", props [12].Name, "#M14");
6231 Assert.AreEqual ("FamORAssemInstanceBlue", props [13].Name, "#M15");
6232 Assert.AreEqual ("PublicInstanceBlue", props [14].Name, "#M16");
6233 Assert.AreEqual ("AssemblyInstanceBlue", props [15].Name, "#M17");
6234 #else
6235 Assert.AreEqual ("FamilyInstanceBlue", props [10].Name, "#M12");
6236 Assert.AreEqual ("FamANDAssemInstanceBlue", props [11].Name, "#M13");
6237 Assert.AreEqual ("FamORAssemInstanceBlue", props [12].Name, "#M14");
6238 Assert.AreEqual ("PublicInstanceBlue", props [13].Name, "#M15");
6239 #endif
6241 flags = BindingFlags.Static | BindingFlags.NonPublic |
6242 BindingFlags.Public;
6243 props = greenType.GetProperties (flags);
6245 Assert.AreEqual (6, props.Length, "#N1");
6246 Assert.AreEqual ("PrivateStaticGreen", props [0].Name, "#N2");
6247 Assert.AreEqual ("FamilyStaticGreen", props [1].Name, "#N3");
6248 Assert.AreEqual ("FamANDAssemStaticGreen", props [2].Name, "#N4");
6249 Assert.AreEqual ("FamORAssemStaticGreen", props [3].Name, "#N5");
6250 Assert.AreEqual ("PublicStaticGreen", props [4].Name, "#N6");
6251 Assert.AreEqual ("AssemblyStaticGreen", props [5].Name, "#N7");
6254 [Test]
6255 public void TestGetPropertyIncomplete ()
6257 TypeBuilder tb = module.DefineType (genTypeName ());
6258 try {
6259 tb.GetProperty ("test");
6260 Assert.Fail ("#1");
6261 } catch (NotSupportedException ex) {
6262 // The invoked member is not supported in a
6263 // dynamic module
6264 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6265 Assert.IsNull (ex.InnerException, "#3");
6266 Assert.IsNotNull (ex.Message, "#4");
6270 [Test]
6271 public void TestGetPropertyComplete ()
6273 TypeBuilder tb = module.DefineType (genTypeName ());
6274 DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6276 Type emittedType = tb.CreateType ();
6278 Assert.IsNotNull (emittedType.GetProperty ("CustomerName"));
6279 Assert.IsNull (emittedType.GetProperty ("OtherCustomerName"));
6281 try {
6282 tb.GetProperty ("CustomerName");
6283 Assert.Fail ("#1");
6284 } catch (NotSupportedException ex) {
6285 // The invoked member is not supported in a
6286 // dynamic module
6287 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6288 Assert.IsNull (ex.InnerException, "#3");
6289 Assert.IsNotNull (ex.Message, "#4");
6293 [Test]
6294 public void TestGetPropertyFlagsIncomplete ()
6296 TypeBuilder tb = module.DefineType (genTypeName ());
6297 try {
6298 tb.GetProperty ("test", BindingFlags.Public);
6299 Assert.Fail ("#1");
6300 } catch (NotSupportedException ex) {
6301 // The invoked member is not supported in a
6302 // dynamic module
6303 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6304 Assert.IsNull (ex.InnerException, "#3");
6305 Assert.IsNotNull (ex.Message, "#4");
6309 [Test]
6310 public void TestGetPropertyFlagsComplete ()
6312 TypeBuilder tb = module.DefineType (genTypeName ());
6313 DefineStringProperty (tb, "CustomerName", "customerName", MethodAttributes.Public);
6315 Type emittedType = tb.CreateType ();
6317 Assert.IsNotNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6318 BindingFlags.Public));
6319 Assert.IsNull (emittedType.GetProperty ("CustomerName", BindingFlags.Instance |
6320 BindingFlags.NonPublic));
6322 try {
6323 tb.GetProperty ("CustomerName", BindingFlags.Instance | BindingFlags.Public);
6324 Assert.Fail ("#1");
6325 } catch (NotSupportedException ex) {
6326 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
6327 Assert.IsNull (ex.InnerException, "#3");
6328 Assert.IsNotNull (ex.Message, "#4");
6332 [Test]
6333 public void TestGetMethodFlagsComplete ()
6335 BindingFlags flags;
6337 TypeBuilder blueType = module.DefineType (genTypeName (),
6338 TypeAttributes.Public);
6339 CreateMembers (blueType, "Blue", false);
6341 TypeBuilder redType = module.DefineType (genTypeName (),
6342 TypeAttributes.Public, blueType);
6343 CreateMembers (redType, "Red", false);
6345 TypeBuilder greenType = module.DefineType (genTypeName (),
6346 TypeAttributes.Public, redType);
6347 CreateMembers (greenType, "Green", false);
6349 blueType.CreateType ();
6350 redType.CreateType ();
6351 greenType.CreateType ();
6353 flags = BindingFlags.Instance | BindingFlags.NonPublic;
6355 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#A1");
6356 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#A2");
6357 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#A3");
6358 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#A4");
6359 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#A5");
6360 #if NET_2_0
6361 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6362 #else
6363 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#A6");
6364 #endif
6365 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#A7");
6366 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#A8");
6367 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#A9");
6368 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#A10");
6369 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#A11");
6370 #if NET_2_0
6371 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6372 #else
6373 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#A12");
6374 #endif
6375 Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#A13");
6376 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#A14");
6377 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#A15");
6378 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#A16");
6379 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#A17");
6380 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#A18");
6381 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#A19");
6382 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#A20");
6383 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#A21");
6384 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#A22");
6385 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#A23");
6386 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#A24");
6387 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#A25");
6388 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#A26");
6389 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#A27");
6390 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#A28");
6391 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#A29");
6392 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#A30");
6393 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#A31");
6394 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#A32");
6395 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#A33");
6396 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#A34");
6397 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#A35");
6398 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#A36");
6400 flags = BindingFlags.Instance | BindingFlags.Public;
6402 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#B1");
6403 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#B2");
6404 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#B3");
6405 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#B4");
6406 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#B5");
6407 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#B6");
6408 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#B7");
6409 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#B8");
6410 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#B9");
6411 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#B10");
6412 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#B11");
6413 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#B12");
6414 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#B13");
6415 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#B14");
6416 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#B15");
6417 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#B16");
6418 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#B17");
6419 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#B18");
6420 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#B19");
6421 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#B20");
6422 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#B21");
6423 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#B22");
6424 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#B23");
6425 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#B24");
6426 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#B25");
6427 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#B26");
6428 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#B27");
6429 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#B28");
6430 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#B29");
6431 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#B30");
6432 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#B31");
6433 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#B32");
6434 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#B33");
6435 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#B34");
6436 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#B35");
6437 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#B36");
6439 flags = BindingFlags.Static | BindingFlags.Public;
6441 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#C1");
6442 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#C2");
6443 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#C3");
6444 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#C4");
6445 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#C5");
6446 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#C6");
6447 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#C7");
6448 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#C8");
6449 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#C9");
6450 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#C10");
6451 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#C11");
6452 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#C12");
6453 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#C13");
6454 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#C14");
6455 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#C15");
6456 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#C16");
6457 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#C17");
6458 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#C18");
6459 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#C19");
6460 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#C20");
6461 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#C21");
6462 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#C22");
6463 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#C23");
6464 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#C24");
6465 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#C25");
6466 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#C26");
6467 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#C27");
6468 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#C28");
6469 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#C29");
6470 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#C30");
6471 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#C31");
6472 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#C32");
6473 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#C33");
6474 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#C34");
6475 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#C35");
6476 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#C36");
6478 flags = BindingFlags.Static | BindingFlags.NonPublic;
6480 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#D1");
6481 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#D2");
6482 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#D3");
6483 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#D4");
6484 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#D5");
6485 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#D6");
6486 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#D7");
6487 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#D8");
6488 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#D9");
6489 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#D10");
6490 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#D11");
6491 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#D12");
6492 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#D13");
6493 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#D14");
6494 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#D15");
6495 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#D16");
6496 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#D17");
6497 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#D18");
6498 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#D19");
6499 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#D20");
6500 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#D21");
6501 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#D22");
6502 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#D23");
6503 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#D24");
6504 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#D25");
6505 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#D26");
6506 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#D27");
6507 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#D28");
6508 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#D29");
6509 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#D30");
6510 Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#D31");
6511 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#D32");
6512 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#D33");
6513 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#D34");
6514 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#D35");
6515 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#D36");
6517 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6518 BindingFlags.FlattenHierarchy;
6520 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#E1");
6521 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#E2");
6522 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#E3");
6523 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#E4");
6524 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#E5");
6525 #if NET_2_0
6526 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6527 #else
6528 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#E6");
6529 #endif
6530 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#E7");
6531 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#E8");
6532 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#E9");
6533 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#E10");
6534 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#E11");
6535 #if NET_2_0
6536 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6537 #else
6538 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#E12");
6539 #endif
6540 Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#E13");
6541 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#E14");
6542 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#E15");
6543 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#E16");
6544 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#E17");
6545 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#E18");
6546 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#E19");
6547 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#E20");
6548 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#E21");
6549 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#E22");
6550 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#E23");
6551 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#E24");
6552 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#E25");
6553 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#E26");
6554 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#E27");
6555 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#E28");
6556 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#E29");
6557 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#E30");
6558 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#E31");
6559 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#E32");
6560 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#E33");
6561 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#E34");
6562 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#E35");
6563 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#E36");
6565 flags = BindingFlags.Instance | BindingFlags.Public |
6566 BindingFlags.FlattenHierarchy;
6568 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#F1");
6569 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#F2");
6570 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#F3");
6571 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#F4");
6572 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#F5");
6573 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#F6");
6574 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#F7");
6575 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#F8");
6576 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#F9");
6577 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#F10");
6578 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#F11");
6579 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#F12");
6580 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#F13");
6581 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#F14");
6582 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#F15");
6583 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#F16");
6584 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#F17");
6585 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#F18");
6586 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#F19");
6587 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#F20");
6588 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#F21");
6589 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#F22");
6590 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#F23");
6591 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#F24");
6592 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#F25");
6593 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#F26");
6594 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#F27");
6595 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#F28");
6596 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#F29");
6597 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#F30");
6598 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#F31");
6599 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#F32");
6600 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#F33");
6601 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#F34");
6602 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#F35");
6603 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#F36");
6605 flags = BindingFlags.Static | BindingFlags.Public |
6606 BindingFlags.FlattenHierarchy;
6608 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#G1");
6609 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#G2");
6610 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#G3");
6611 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#G4");
6612 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#G5");
6613 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#G6");
6614 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#G7");
6615 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#G8");
6616 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#G9");
6617 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#G10");
6618 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#G11");
6619 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#G12");
6620 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#G13");
6621 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#G14");
6622 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#G15");
6623 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#G16");
6624 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#G17");
6625 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#G18");
6626 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#G19");
6627 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#G20");
6628 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#G21");
6629 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#G22");
6630 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#G23");
6631 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#G24");
6632 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#G25");
6633 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#G26");
6634 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#G27");
6635 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#G28");
6636 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#G29");
6637 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#G30");
6638 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#G31");
6639 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#G32");
6640 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#G33");
6641 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#G34");
6642 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#G35");
6643 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#G36");
6645 flags = BindingFlags.Static | BindingFlags.NonPublic |
6646 BindingFlags.FlattenHierarchy;
6648 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#H1");
6649 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#H2");
6650 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#H3");
6651 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#H4");
6652 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#H5");
6653 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#H6");
6654 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#H7");
6655 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#H8");
6656 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#H9");
6657 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#H10");
6658 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#H11");
6659 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#H12");
6660 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#H13");
6661 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#H14");
6662 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#H15");
6663 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#H16");
6664 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#H17");
6665 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#H18");
6666 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#H19");
6667 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#H20");
6668 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#H21");
6669 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#H22");
6670 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#H23");
6671 #if NET_2_0
6672 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6673 #else
6674 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#H24");
6675 #endif
6676 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#H25");
6677 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#H26");
6678 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#H27");
6679 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#H28");
6680 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#H29");
6681 #if NET_2_0
6682 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6683 #else
6684 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#H30");
6685 #endif
6686 Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#H31");
6687 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#H32");
6688 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#H33");
6689 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#H34");
6690 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#H35");
6691 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#H36");
6693 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6694 BindingFlags.DeclaredOnly;
6696 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#I1");
6697 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#I2");
6698 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#I3");
6699 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#I4");
6700 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#I5");
6701 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#I6");
6702 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#I7");
6703 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#I8");
6704 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#I9");
6705 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#I10");
6706 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#I11");
6707 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#I12");
6708 Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#I13");
6709 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#I14");
6710 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#I15");
6711 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#I16");
6712 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#I17");
6713 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#I18");
6714 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#I19");
6715 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#I20");
6716 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#I21");
6717 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#I22");
6718 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#I23");
6719 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#I24");
6720 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#I25");
6721 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#I26");
6722 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#I27");
6723 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#I28");
6724 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#I29");
6725 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#I30");
6726 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#I31");
6727 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#I32");
6728 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#I33");
6729 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#I34");
6730 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#I35");
6731 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#I36");
6733 flags = BindingFlags.Instance | BindingFlags.Public |
6734 BindingFlags.DeclaredOnly;
6736 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#J1");
6737 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#J2");
6738 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#J3");
6739 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#J4");
6740 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#J5");
6741 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#J6");
6742 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#J7");
6743 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#J8");
6744 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#J9");
6745 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#J10");
6746 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#J11");
6747 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#J12");
6748 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#J13");
6749 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#J14");
6750 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#J15");
6751 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#J16");
6752 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#J17");
6753 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#J18");
6754 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#J19");
6755 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#J20");
6756 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#J21");
6757 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#J22");
6758 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#J23");
6759 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#J24");
6760 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#J25");
6761 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#J26");
6762 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#J27");
6763 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#J28");
6764 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#J29");
6765 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#J30");
6766 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#J31");
6767 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#J32");
6768 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#J33");
6769 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#J34");
6770 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#J35");
6771 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#J36");
6773 flags = BindingFlags.Static | BindingFlags.Public |
6774 BindingFlags.DeclaredOnly;
6776 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#K1");
6777 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#K2");
6778 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#K3");
6779 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#K4");
6780 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#K5");
6781 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#K6");
6782 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#K7");
6783 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#K8");
6784 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#K9");
6785 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#K10");
6786 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#K11");
6787 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#K12");
6788 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#K13");
6789 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#K14");
6790 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#K15");
6791 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#K16");
6792 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#K17");
6793 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#K18");
6794 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#K19");
6795 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#K20");
6796 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#K21");
6797 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#K22");
6798 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#K23");
6799 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#K24");
6800 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#K25");
6801 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#K26");
6802 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#K27");
6803 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#K28");
6804 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#K29");
6805 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#K30");
6806 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#K31");
6807 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#K32");
6808 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#K33");
6809 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#K34");
6810 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#K35");
6811 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#K36");
6813 flags = BindingFlags.Static | BindingFlags.NonPublic |
6814 BindingFlags.DeclaredOnly;
6816 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#L1");
6817 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#L2");
6818 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#L3");
6819 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#L4");
6820 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#L5");
6821 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#L6");
6822 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#L7");
6823 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#L8");
6824 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#L9");
6825 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#L10");
6826 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#L11");
6827 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#L12");
6828 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#L13");
6829 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#L14");
6830 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#L15");
6831 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#L16");
6832 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#L17");
6833 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#L18");
6834 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#L19");
6835 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#L20");
6836 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#L21");
6837 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#L22");
6838 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#L23");
6839 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#L24");
6840 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#L25");
6841 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#L26");
6842 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#L27");
6843 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#L28");
6844 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#L29");
6845 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#L30");
6846 Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#L31");
6847 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#L32");
6848 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#L33");
6849 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#L34");
6850 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#L35");
6851 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#L36");
6853 flags = BindingFlags.Instance | BindingFlags.NonPublic |
6854 BindingFlags.Public;
6856 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#M1");
6857 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#M2");
6858 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#M3");
6859 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#M4");
6860 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#M5");
6861 #if NET_2_0
6862 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6863 #else
6864 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#M6");
6865 #endif
6866 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#M7");
6867 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#M8");
6868 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#M9");
6869 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#M10");
6870 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#M11");
6871 #if NET_2_0
6872 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6873 #else
6874 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#M12");
6875 #endif
6876 Assert.IsNotNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#M13");
6877 Assert.IsNotNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#M14");
6878 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#M15");
6879 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#M16");
6880 Assert.IsNotNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#M17");
6881 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#M18");
6882 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#M19");
6883 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#M20");
6884 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#M21");
6885 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#M22");
6886 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#M23");
6887 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#M24");
6888 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#M25");
6889 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#M26");
6890 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#M27");
6891 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#M28");
6892 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#M29");
6893 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#M30");
6894 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#M31");
6895 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#M32");
6896 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#M33");
6897 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#M34");
6898 Assert.IsNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#M35");
6899 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#M36");
6901 flags = BindingFlags.Static | BindingFlags.NonPublic |
6902 BindingFlags.Public;
6904 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceBlue", flags), "#N1");
6905 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceBlue", flags), "#N2");
6906 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceBlue", flags), "#N3");
6907 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceBlue", flags), "#N4");
6908 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceBlue", flags), "#N5");
6909 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceBlue", flags), "#N6");
6910 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceRed", flags), "#N7");
6911 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceRed", flags), "#N8");
6912 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceRed", flags), "#N9");
6913 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceRed", flags), "#N10");
6914 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceRed", flags), "#N11");
6915 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceRed", flags), "#N12");
6916 Assert.IsNull (greenType.GetMethod ("GetPrivateInstanceGreen", flags), "#N13");
6917 Assert.IsNull (greenType.GetMethod ("GetFamilyInstanceGreen", flags), "#N14");
6918 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemInstanceGreen", flags), "#N15");
6919 Assert.IsNull (greenType.GetMethod ("GetFamORAssemInstanceGreen", flags), "#N16");
6920 Assert.IsNull (greenType.GetMethod ("GetPublicInstanceGreen", flags), "#N17");
6921 Assert.IsNull (greenType.GetMethod ("GetAssemblyInstanceGreen", flags), "#N18");
6922 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticBlue", flags), "#N19");
6923 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticBlue", flags), "#N20");
6924 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticBlue", flags), "#N21");
6925 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticBlue", flags), "#N22");
6926 Assert.IsNull (greenType.GetMethod ("GetPublicStaticBlue", flags), "#N23");
6927 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticBlue", flags), "#N24");
6928 Assert.IsNull (greenType.GetMethod ("GetPrivateStaticRed", flags), "#N25");
6929 Assert.IsNull (greenType.GetMethod ("GetFamilyStaticRed", flags), "#N26");
6930 Assert.IsNull (greenType.GetMethod ("GetFamANDAssemStaticRed", flags), "#N27");
6931 Assert.IsNull (greenType.GetMethod ("GetFamORAssemStaticRed", flags), "#N28");
6932 Assert.IsNull (greenType.GetMethod ("GetPublicStaticRed", flags), "#N29");
6933 Assert.IsNull (greenType.GetMethod ("GetAssemblyStaticRed", flags), "#N30");
6934 Assert.IsNotNull (greenType.GetMethod ("GetPrivateStaticGreen", flags), "#N31");
6935 Assert.IsNotNull (greenType.GetMethod ("GetFamilyStaticGreen", flags), "#N32");
6936 Assert.IsNotNull (greenType.GetMethod ("GetFamANDAssemStaticGreen", flags), "#N33");
6937 Assert.IsNotNull (greenType.GetMethod ("GetFamORAssemStaticGreen", flags), "#N34");
6938 Assert.IsNotNull (greenType.GetMethod ("GetPublicStaticGreen", flags), "#N35");
6939 Assert.IsNotNull (greenType.GetMethod ("GetAssemblyStaticGreen", flags), "#N36");
6942 [Test]
6943 [Category ("NotDotNet")] // mcs depends on this
6944 public void TestGetMethodsIncomplete_Mono ()
6946 MethodBuilder mb;
6947 ILGenerator ilgen;
6949 TypeBuilder tb = module.DefineType (genTypeName (),
6950 TypeAttributes.Abstract);
6951 mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
6952 typeof (void), Type.EmptyTypes);
6953 ilgen = mb.GetILGenerator ();
6954 ilgen.Emit (OpCodes.Ret);
6956 mb = tb.DefineMethod ("Run", MethodAttributes.Private,
6957 typeof (void), Type.EmptyTypes);
6958 ilgen = mb.GetILGenerator ();
6959 ilgen.Emit (OpCodes.Ret);
6961 mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
6962 MethodAttributes.Static,
6963 typeof (void), Type.EmptyTypes);
6964 ilgen = mb.GetILGenerator ();
6965 ilgen.Emit (OpCodes.Ret);
6967 mb = tb.DefineMethod ("Init", MethodAttributes.Public |
6968 MethodAttributes.Abstract | MethodAttributes.Virtual,
6969 typeof (void), Type.EmptyTypes);
6971 MethodInfo [] methods = tb.GetMethods ();
6972 Assert.AreEqual (7, methods.Length, "#A");
6974 Assert.AreEqual ("Equals", methods [0].Name, "#B1");
6975 Assert.IsFalse (methods [0].IsStatic, "#B2");
6976 Assert.IsFalse (methods [0].IsAbstract, "#B3");
6978 Assert.AreEqual ("GetHashCode", methods [1].Name, "#C1");
6979 Assert.IsFalse (methods [1].IsStatic, "#C2");
6980 Assert.IsFalse (methods [1].IsAbstract, "#C3");
6982 Assert.AreEqual ("GetType", methods [2].Name, "#D1");
6983 Assert.IsFalse (methods [2].IsStatic, "#D2");
6984 Assert.IsFalse (methods [2].IsAbstract, "#D3");
6986 Assert.AreEqual ("ToString", methods [3].Name, "#E1");
6987 Assert.IsFalse (methods [3].IsStatic, "#E2");
6988 Assert.IsFalse (methods [3].IsAbstract, "#E3");
6990 Assert.AreEqual ("Hello", methods [4].Name, "#F1");
6991 Assert.IsFalse (methods [4].IsStatic, "#F2");
6992 Assert.IsFalse (methods [4].IsAbstract, "#F3");
6994 Assert.AreEqual ("Execute", methods [5].Name, "#G1");
6995 Assert.IsTrue (methods [5].IsStatic, "#G2");
6996 Assert.IsFalse (methods [5].IsAbstract, "#G3");
6998 Assert.AreEqual ("Init", methods [6].Name, "#H1");
6999 Assert.IsFalse (methods [6].IsStatic, "#H2");
7000 Assert.IsTrue (methods [6].IsAbstract, "#H3");
7003 [Test]
7004 [Category ("NotWorking")] // mcs depends on this
7005 public void TestGetMethodsIncomplete_MS ()
7007 MethodBuilder mb;
7008 ILGenerator ilgen;
7010 TypeBuilder tb = module.DefineType (genTypeName (),
7011 TypeAttributes.Abstract);
7012 mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7013 typeof (void), Type.EmptyTypes);
7014 ilgen = mb.GetILGenerator ();
7015 ilgen.Emit (OpCodes.Ret);
7017 mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7018 typeof (void), Type.EmptyTypes);
7019 ilgen = mb.GetILGenerator ();
7020 ilgen.Emit (OpCodes.Ret);
7022 mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7023 MethodAttributes.Static,
7024 typeof (void), Type.EmptyTypes);
7025 ilgen = mb.GetILGenerator ();
7026 ilgen.Emit (OpCodes.Ret);
7028 mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7029 MethodAttributes.Abstract | MethodAttributes.Virtual,
7030 typeof (void), Type.EmptyTypes);
7032 try {
7033 tb.GetMethods ();
7034 Assert.Fail ("#1");
7035 } catch (NotSupportedException ex) {
7036 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7037 Assert.IsNull (ex.InnerException, "#3");
7038 Assert.IsNotNull (ex.Message, "#4");
7042 [Test]
7043 public void TestGetMethodsComplete ()
7045 MethodBuilder mb;
7046 ILGenerator ilgen;
7047 MethodInfo mi;
7049 TypeBuilder tb = module.DefineType (genTypeName (),
7050 TypeAttributes.Abstract);
7051 mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7052 typeof (string), Type.EmptyTypes);
7053 ilgen = mb.GetILGenerator ();
7054 ilgen.Emit (OpCodes.Ldstr, "Hi! ");
7055 ilgen.Emit (OpCodes.Ldarg_1);
7056 MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7057 new Type [] { typeof (string), typeof (string) });
7058 ilgen.Emit (OpCodes.Call, infoMethod);
7059 ilgen.Emit (OpCodes.Ret);
7061 mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7062 typeof (void), Type.EmptyTypes);
7063 ilgen = mb.GetILGenerator ();
7064 ilgen.Emit (OpCodes.Ret);
7066 mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7067 MethodAttributes.Static,
7068 typeof (void), Type.EmptyTypes);
7069 ilgen = mb.GetILGenerator ();
7070 ilgen.Emit (OpCodes.Ret);
7072 mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7073 MethodAttributes.Abstract | MethodAttributes.Virtual,
7074 typeof (void), Type.EmptyTypes);
7076 Type emittedType = tb.CreateType ();
7078 MethodInfo [] methods = emittedType.GetMethods ();
7079 Assert.AreEqual (7, methods.Length, "#A1");
7080 Assert.AreEqual (7, tb.GetMethods ().Length, "#A2");
7082 mi = GetMethodByName (methods, "Hello");
7083 Assert.IsNotNull (mi, "#B1");
7084 Assert.IsFalse (mi.IsStatic, "#B2");
7085 Assert.IsFalse (mi.IsAbstract, "#B3");
7087 mi = GetMethodByName (methods, "Execute");
7088 Assert.IsNotNull (mi, "#C1");
7089 Assert.IsTrue (mi.IsStatic, "#C2");
7090 Assert.IsFalse (mi.IsAbstract, "#C3");
7092 mi = GetMethodByName (methods, "Init");
7093 Assert.IsNotNull (mi, "#D1");
7094 Assert.IsFalse (mi.IsStatic, "#D2");
7095 Assert.IsTrue (mi.IsAbstract, "#D3");
7097 mi = GetMethodByName (methods, "GetType");
7098 Assert.IsNotNull (mi, "#E1");
7099 Assert.IsFalse (methods [3].IsStatic, "#E2");
7100 Assert.IsFalse (methods [3].IsAbstract, "#E3");
7102 mi = GetMethodByName (methods, "ToString");
7103 Assert.IsNotNull (mi, "#F1");
7104 Assert.IsFalse (mi.IsStatic, "#F2");
7105 Assert.IsFalse (mi.IsAbstract, "#F3");
7107 mi = GetMethodByName (methods, "Equals");
7108 Assert.IsNotNull (mi, "#G1");
7109 Assert.IsFalse (mi.IsStatic, "#G2");
7110 Assert.IsFalse (mi.IsAbstract, "#G3");
7112 mi = GetMethodByName (methods, "GetHashCode");
7113 Assert.IsNotNull (mi, "#H1");
7114 Assert.IsFalse (mi.IsStatic, "#H2");
7115 Assert.IsFalse (mi.IsAbstract, "#H3");
7118 [Test]
7119 [Category ("NotDotNet")] // mcs depends on this
7120 public void TestGetMethodsFlagsIncomplete_Inheritance ()
7122 MethodInfo [] methods;
7123 BindingFlags flags;
7125 TypeBuilder blueType = module.DefineType (genTypeName (),
7126 TypeAttributes.Public);
7127 CreateMembers (blueType, "Blue", false);
7129 TypeBuilder redType = module.DefineType (genTypeName (),
7130 TypeAttributes.Public, blueType);
7131 CreateMembers (redType, "Red", false);
7133 TypeBuilder greenType = module.DefineType (genTypeName (),
7134 TypeAttributes.Public, redType);
7135 CreateMembers (greenType, "Green", false);
7137 flags = BindingFlags.Instance | BindingFlags.NonPublic;
7138 methods = greenType.GetMethods (flags);
7140 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7141 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7142 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7143 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7144 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7145 #if NET_2_0
7146 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7147 #else
7148 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7149 #endif
7150 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7151 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7152 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7153 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7154 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7155 #if NET_2_0
7156 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7157 #else
7158 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7159 #endif
7160 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7161 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7162 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7163 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7164 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7165 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7166 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7167 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7168 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7169 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7170 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7171 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7172 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7173 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7174 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7175 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7176 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7177 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7178 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7179 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7180 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7181 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7182 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7183 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7185 flags = BindingFlags.Instance | BindingFlags.Public;
7186 methods = greenType.GetMethods (flags);
7188 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7189 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7190 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7191 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7192 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7193 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7194 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7195 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7196 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7197 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7198 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7199 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7200 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7201 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7202 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7203 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7204 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7205 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7206 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7207 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7208 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7209 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7210 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7211 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7212 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7213 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7214 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7215 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7216 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7217 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7218 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7219 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7220 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7221 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7222 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7223 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7225 flags = BindingFlags.Static | BindingFlags.Public;
7226 methods = greenType.GetMethods (flags);
7228 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7229 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7230 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7231 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7232 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7233 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7234 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7235 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7236 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7237 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7238 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7239 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7240 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7241 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7242 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7243 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7244 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7245 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7246 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7247 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7248 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7249 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
7250 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
7251 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
7252 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
7253 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
7254 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
7255 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
7256 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
7257 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
7258 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
7259 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
7260 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
7261 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
7262 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
7263 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
7265 flags = BindingFlags.Static | BindingFlags.NonPublic;
7266 methods = greenType.GetMethods (flags);
7268 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
7269 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
7270 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
7271 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
7272 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
7273 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
7274 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
7275 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
7276 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
7277 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
7278 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
7279 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
7280 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
7281 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
7282 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
7283 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
7284 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
7285 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
7286 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
7287 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
7288 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
7289 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
7290 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
7291 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
7292 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
7293 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
7294 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
7295 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
7296 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
7297 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
7298 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
7299 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
7300 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
7301 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
7302 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
7303 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
7305 flags = BindingFlags.Instance | BindingFlags.NonPublic |
7306 BindingFlags.FlattenHierarchy;
7307 methods = greenType.GetMethods (flags);
7309 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
7310 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
7311 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
7312 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
7313 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
7314 #if NET_2_0
7315 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7316 #else
7317 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
7318 #endif
7319 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
7320 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
7321 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
7322 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
7323 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
7324 #if NET_2_0
7325 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7326 #else
7327 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
7328 #endif
7329 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
7330 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
7331 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
7332 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
7333 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
7334 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
7335 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
7336 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
7337 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
7338 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
7339 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
7340 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
7341 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
7342 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
7343 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
7344 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
7345 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
7346 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
7347 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
7348 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
7349 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
7350 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
7351 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
7352 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
7354 flags = BindingFlags.Instance | BindingFlags.Public |
7355 BindingFlags.FlattenHierarchy;
7356 methods = greenType.GetMethods (flags);
7358 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
7359 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
7360 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
7361 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
7362 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
7363 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
7364 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
7365 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
7366 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
7367 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
7368 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
7369 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
7370 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
7371 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
7372 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
7373 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
7374 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
7375 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
7376 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
7377 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
7378 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
7379 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
7380 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
7381 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
7382 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
7383 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
7384 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
7385 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
7386 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
7387 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
7388 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
7389 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
7390 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
7391 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
7392 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
7393 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
7395 flags = BindingFlags.Static | BindingFlags.Public |
7396 BindingFlags.FlattenHierarchy;
7397 methods = greenType.GetMethods (flags);
7399 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
7400 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
7401 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
7402 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
7403 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
7404 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
7405 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
7406 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
7407 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
7408 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
7409 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
7410 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
7411 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
7412 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
7413 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
7414 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
7415 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
7416 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
7417 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
7418 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
7419 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
7420 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
7421 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
7422 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
7423 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
7424 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
7425 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
7426 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
7427 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
7428 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
7429 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
7430 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
7431 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
7432 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
7433 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
7434 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
7436 flags = BindingFlags.Static | BindingFlags.NonPublic |
7437 BindingFlags.FlattenHierarchy;
7438 methods = greenType.GetMethods (flags);
7440 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
7441 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
7442 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
7443 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
7444 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
7445 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
7446 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
7447 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
7448 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
7449 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
7450 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
7451 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
7452 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
7453 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
7454 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
7455 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
7456 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
7457 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
7458 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
7459 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
7460 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
7461 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
7462 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
7463 #if NET_2_0
7464 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7465 #else
7466 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
7467 #endif
7468 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
7469 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
7470 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
7471 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
7472 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
7473 #if NET_2_0
7474 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7475 #else
7476 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
7477 #endif
7478 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
7479 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
7480 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
7481 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
7482 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
7483 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
7485 flags = BindingFlags.Instance | BindingFlags.NonPublic |
7486 BindingFlags.DeclaredOnly;
7487 methods = greenType.GetMethods (flags);
7489 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
7490 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
7491 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
7492 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
7493 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
7494 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
7495 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
7496 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
7497 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
7498 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
7499 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
7500 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
7501 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
7502 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
7503 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
7504 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
7505 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
7506 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
7507 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
7508 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
7509 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
7510 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
7511 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
7512 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
7513 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
7514 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
7515 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
7516 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
7517 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
7518 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
7519 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
7520 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
7521 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
7522 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
7523 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
7524 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
7526 flags = BindingFlags.Instance | BindingFlags.Public |
7527 BindingFlags.DeclaredOnly;
7528 methods = greenType.GetMethods (flags);
7530 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
7531 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
7532 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
7533 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
7534 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
7535 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
7536 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
7537 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
7538 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
7539 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
7540 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
7541 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
7542 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
7543 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
7544 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
7545 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
7546 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
7547 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
7548 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
7549 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
7550 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
7551 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
7552 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
7553 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
7554 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
7555 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
7556 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
7557 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
7558 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
7559 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
7560 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
7561 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
7562 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
7563 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
7564 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
7565 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
7567 flags = BindingFlags.Static | BindingFlags.Public |
7568 BindingFlags.DeclaredOnly;
7569 methods = greenType.GetMethods (flags);
7571 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
7572 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
7573 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
7574 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
7575 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
7576 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
7577 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
7578 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
7579 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
7580 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
7581 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
7582 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
7583 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
7584 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
7585 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
7586 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
7587 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
7588 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
7589 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
7590 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
7591 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
7592 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
7593 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
7594 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
7595 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
7596 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
7597 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
7598 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
7599 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
7600 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
7601 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
7602 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
7603 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
7604 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
7605 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
7606 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
7608 flags = BindingFlags.Static | BindingFlags.NonPublic |
7609 BindingFlags.DeclaredOnly;
7610 methods = greenType.GetMethods (flags);
7612 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
7613 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
7614 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
7615 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
7616 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
7617 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
7618 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
7619 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
7620 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
7621 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
7622 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
7623 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
7624 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
7625 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
7626 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
7627 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
7628 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
7629 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
7630 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
7631 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
7632 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
7633 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
7634 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
7635 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
7636 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
7637 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
7638 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
7639 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
7640 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
7641 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
7642 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
7643 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
7644 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
7645 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
7646 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
7647 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
7649 flags = BindingFlags.Instance | BindingFlags.NonPublic |
7650 BindingFlags.Public;
7651 methods = greenType.GetMethods (flags);
7653 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
7654 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
7655 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
7656 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
7657 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
7658 #if NET_2_0
7659 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7660 #else
7661 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
7662 #endif
7663 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
7664 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
7665 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
7666 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
7667 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
7668 #if NET_2_0
7669 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7670 #else
7671 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
7672 #endif
7673 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
7674 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
7675 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
7676 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
7677 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
7678 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
7679 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
7680 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
7681 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
7682 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
7683 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
7684 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
7685 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
7686 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
7687 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
7688 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
7689 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
7690 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
7691 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
7692 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
7693 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
7694 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
7695 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
7696 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
7698 flags = BindingFlags.Static | BindingFlags.NonPublic |
7699 BindingFlags.Public;
7700 methods = greenType.GetMethods (flags);
7702 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
7703 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
7704 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
7705 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
7706 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
7707 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
7708 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
7709 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
7710 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
7711 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
7712 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
7713 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
7714 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
7715 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
7716 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
7717 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
7718 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
7719 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
7720 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
7721 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
7722 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
7723 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
7724 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
7725 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
7726 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
7727 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
7728 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
7729 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
7730 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
7731 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
7732 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
7733 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
7734 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
7735 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
7736 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
7737 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
7740 [Test]
7741 [Category ("NotDotNet")] // mcs depends on this
7742 public void TestGetMethodsFlagsIncomplete_Mono ()
7744 MethodBuilder mb;
7745 ILGenerator ilgen;
7746 MethodInfo [] methods;
7748 TypeBuilder tb = module.DefineType (genTypeName (),
7749 TypeAttributes.Abstract);
7750 mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7751 typeof (void), Type.EmptyTypes);
7752 ilgen = mb.GetILGenerator ();
7753 ilgen.Emit (OpCodes.Ret);
7755 mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7756 typeof (void), Type.EmptyTypes);
7757 ilgen = mb.GetILGenerator ();
7758 ilgen.Emit (OpCodes.Ret);
7760 mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7761 MethodAttributes.Static,
7762 typeof (void), Type.EmptyTypes);
7763 ilgen = mb.GetILGenerator ();
7764 ilgen.Emit (OpCodes.Ret);
7766 mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7767 MethodAttributes.Abstract | MethodAttributes.Virtual,
7768 typeof (void), Type.EmptyTypes);
7770 methods = tb.GetMethods (BindingFlags.Public |
7771 BindingFlags.Instance);
7772 Assert.AreEqual (6, methods.Length, "#A1");
7773 Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#A2");
7774 Assert.IsNotNull (GetMethodByName (methods, "Init"), "#A3");
7775 Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#A4");
7776 Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#A5");
7777 Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#A6");
7779 methods = tb.GetMethods (BindingFlags.Public |
7780 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7781 Assert.AreEqual (2, methods.Length, "#B1");
7782 Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#B2");
7783 Assert.IsNotNull (GetMethodByName (methods, "Init"), "#B3");
7785 methods = tb.GetMethods (BindingFlags.Public |
7786 BindingFlags.Instance | BindingFlags.Static);
7787 Assert.AreEqual (7, methods.Length, "#C1");
7788 Assert.IsNotNull (GetMethodByName (methods, "Hello"), "#C2");
7789 Assert.IsNotNull (GetMethodByName (methods, "Init"), "#C3");
7790 Assert.IsNotNull (GetMethodByName (methods, "Execute"), "#C4");
7791 Assert.IsNotNull (GetMethodByName (methods, "ToString"), "#C5");
7792 Assert.IsNotNull (GetMethodByName (methods, "Equals"), "#C6");
7793 Assert.IsNotNull (GetMethodByName (methods, "GetHashCode"), "#C7");
7795 methods = tb.GetMethods (BindingFlags.NonPublic |
7796 BindingFlags.Instance | BindingFlags.DeclaredOnly);
7797 Assert.AreEqual (1, methods.Length, "#D1");
7798 Assert.IsNotNull (GetMethodByName (methods, "Run"), "#D2");
7802 [Test]
7803 [Category ("NotWorking")] // mcs depends on this
7804 public void TestGetMethodsFlagsIncomplete_MS ()
7806 MethodBuilder mb;
7807 ILGenerator ilgen;
7809 TypeBuilder tb = module.DefineType (genTypeName (),
7810 TypeAttributes.Abstract);
7811 mb = tb.DefineMethod ("Hello", MethodAttributes.Public,
7812 typeof (void), Type.EmptyTypes);
7813 ilgen = mb.GetILGenerator ();
7814 ilgen.Emit (OpCodes.Ret);
7816 mb = tb.DefineMethod ("Run", MethodAttributes.Private,
7817 typeof (void), Type.EmptyTypes);
7818 ilgen = mb.GetILGenerator ();
7819 ilgen.Emit (OpCodes.Ret);
7821 mb = tb.DefineMethod ("Execute", MethodAttributes.Public |
7822 MethodAttributes.Static,
7823 typeof (void), Type.EmptyTypes);
7824 ilgen = mb.GetILGenerator ();
7825 ilgen.Emit (OpCodes.Ret);
7827 mb = tb.DefineMethod ("Init", MethodAttributes.Public |
7828 MethodAttributes.Abstract | MethodAttributes.Virtual,
7829 typeof (void), Type.EmptyTypes);
7831 try {
7832 tb.GetMethods (BindingFlags.Public | BindingFlags.Instance);
7833 Assert.Fail ("#1");
7834 } catch (NotSupportedException ex) {
7835 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
7836 Assert.IsNull (ex.InnerException, "#3");
7837 Assert.IsNotNull (ex.Message, "#4");
7841 [Test]
7842 public void TestGetMethodsFlagsComplete ()
7844 TypeBuilder tb = module.DefineType (genTypeName ());
7845 MethodBuilder helloMethod = tb.DefineMethod ("HelloMethod",
7846 MethodAttributes.Public, typeof (string), Type.EmptyTypes);
7847 ILGenerator helloMethodIL = helloMethod.GetILGenerator ();
7848 helloMethodIL.Emit (OpCodes.Ldstr, "Hi! ");
7849 helloMethodIL.Emit (OpCodes.Ldarg_1);
7850 MethodInfo infoMethod = typeof (string).GetMethod ("Concat",
7851 new Type [] { typeof (string), typeof (string) });
7852 helloMethodIL.Emit (OpCodes.Call, infoMethod);
7853 helloMethodIL.Emit (OpCodes.Ret);
7855 Type emittedType = tb.CreateType ();
7857 Assert.AreEqual (1, tb.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Length, "#1");
7858 Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length,
7859 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.Public).Length, "#2");
7860 Assert.AreEqual (0, tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Length, "#3");
7861 Assert.AreEqual (tb.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length,
7862 emittedType.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic).Length, "#4");
7865 [Test]
7866 public void TestGetMethodsFlagsComplete_Inheritance ()
7868 MethodInfo [] methods;
7869 BindingFlags flags;
7871 TypeBuilder blueType = module.DefineType (genTypeName (),
7872 TypeAttributes.Public);
7873 CreateMembers (blueType, "Blue", false);
7875 TypeBuilder redType = module.DefineType (genTypeName (),
7876 TypeAttributes.Public, blueType);
7877 CreateMembers (redType, "Red", false);
7879 TypeBuilder greenType = module.DefineType (genTypeName (),
7880 TypeAttributes.Public, redType);
7881 CreateMembers (greenType, "Green", false);
7883 blueType.CreateType ();
7884 redType.CreateType ();
7885 greenType.CreateType ();
7887 flags = BindingFlags.Instance | BindingFlags.NonPublic;
7888 methods = greenType.GetMethods (flags);
7890 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#A1");
7891 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#A2");
7892 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#A3");
7893 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#A4");
7894 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#A5");
7895 #if NET_2_0
7896 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7897 #else
7898 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#A6");
7899 #endif
7900 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#A7");
7901 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#A8");
7902 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#A9");
7903 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#A10");
7904 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#A11");
7905 #if NET_2_0
7906 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7907 #else
7908 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#A12");
7909 #endif
7910 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#A13");
7911 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#A14");
7912 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#A15");
7913 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#A16");
7914 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#A17");
7915 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#A18");
7916 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#A19");
7917 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#A20");
7918 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#A21");
7919 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#A22");
7920 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#A23");
7921 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#A24");
7922 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#A25");
7923 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#A26");
7924 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#A27");
7925 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#A28");
7926 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#A29");
7927 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#A30");
7928 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#A31");
7929 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#A32");
7930 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#A33");
7931 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#A34");
7932 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#A35");
7933 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#A36");
7935 flags = BindingFlags.Instance | BindingFlags.Public;
7936 methods = greenType.GetMethods (flags);
7938 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#B1");
7939 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#B2");
7940 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#B3");
7941 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#B4");
7942 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#B5");
7943 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#B6");
7944 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#B7");
7945 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#B8");
7946 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#B9");
7947 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#B10");
7948 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#B11");
7949 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#B12");
7950 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#B13");
7951 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#B14");
7952 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#B15");
7953 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#B16");
7954 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#B17");
7955 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#B18");
7956 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#B19");
7957 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#B20");
7958 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#B21");
7959 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#B22");
7960 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#B23");
7961 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#B24");
7962 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#B25");
7963 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#B26");
7964 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#B27");
7965 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#B28");
7966 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#B29");
7967 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#B30");
7968 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#B31");
7969 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#B32");
7970 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#B33");
7971 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#B34");
7972 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#B35");
7973 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#B36");
7975 flags = BindingFlags.Static | BindingFlags.Public;
7976 methods = greenType.GetMethods (flags);
7978 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#C1");
7979 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#C2");
7980 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#C3");
7981 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#C4");
7982 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#C5");
7983 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#C6");
7984 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#C7");
7985 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#C8");
7986 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#C9");
7987 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#C10");
7988 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#C11");
7989 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#C12");
7990 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#C13");
7991 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#C14");
7992 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#C15");
7993 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#C16");
7994 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#C17");
7995 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#C18");
7996 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#C19");
7997 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#C20");
7998 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#C21");
7999 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#C22");
8000 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#C23");
8001 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#C24");
8002 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#C25");
8003 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#C26");
8004 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#C27");
8005 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#C28");
8006 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#C29");
8007 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#C30");
8008 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#C31");
8009 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#C32");
8010 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#C33");
8011 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#C34");
8012 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#C35");
8013 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#C36");
8015 flags = BindingFlags.Static | BindingFlags.NonPublic;
8016 methods = greenType.GetMethods (flags);
8018 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#D1");
8019 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#D2");
8020 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#D3");
8021 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#D4");
8022 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#D5");
8023 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#D6");
8024 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#D7");
8025 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#D8");
8026 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#D9");
8027 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#D10");
8028 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#D11");
8029 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#D12");
8030 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#D13");
8031 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#D14");
8032 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#D15");
8033 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#D16");
8034 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#D17");
8035 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#D18");
8036 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#D19");
8037 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#D20");
8038 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#D21");
8039 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#D22");
8040 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#D23");
8041 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#D24");
8042 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#D25");
8043 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#D26");
8044 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#D27");
8045 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#D28");
8046 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#D29");
8047 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#D30");
8048 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#D31");
8049 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#D32");
8050 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#D33");
8051 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#D34");
8052 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#D35");
8053 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#D36");
8055 flags = BindingFlags.Instance | BindingFlags.NonPublic |
8056 BindingFlags.FlattenHierarchy;
8057 methods = greenType.GetMethods (flags);
8059 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#E1");
8060 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#E2");
8061 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#E3");
8062 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#E4");
8063 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#E5");
8064 #if NET_2_0
8065 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
8066 #else
8067 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#E6");
8068 #endif
8069 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#E7");
8070 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#E8");
8071 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#E9");
8072 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#E10");
8073 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#E11");
8074 #if NET_2_0
8075 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
8076 #else
8077 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#E12");
8078 #endif
8079 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#E13");
8080 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#E14");
8081 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#E15");
8082 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#E16");
8083 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#E17");
8084 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#E18");
8085 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#E19");
8086 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#E20");
8087 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#E21");
8088 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#E22");
8089 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#E23");
8090 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#E24");
8091 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#E25");
8092 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#E26");
8093 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#E27");
8094 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#E28");
8095 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#E29");
8096 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#E30");
8097 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#E31");
8098 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#E32");
8099 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#E33");
8100 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#E34");
8101 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#E35");
8102 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#E36");
8104 flags = BindingFlags.Instance | BindingFlags.Public |
8105 BindingFlags.FlattenHierarchy;
8106 methods = greenType.GetMethods (flags);
8108 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#F1");
8109 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#F2");
8110 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#F3");
8111 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#F4");
8112 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#F5");
8113 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#F6");
8114 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#F7");
8115 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#F8");
8116 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#F9");
8117 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#F10");
8118 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#F11");
8119 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#F12");
8120 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#F13");
8121 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#F14");
8122 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#F15");
8123 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#F16");
8124 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#F17");
8125 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#F18");
8126 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#F19");
8127 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#F20");
8128 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#F21");
8129 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#F22");
8130 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#F23");
8131 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#F24");
8132 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#F25");
8133 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#F26");
8134 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#F27");
8135 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#F28");
8136 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#F29");
8137 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#F30");
8138 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#F31");
8139 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#F32");
8140 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#F33");
8141 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#F34");
8142 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#F35");
8143 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#F36");
8145 flags = BindingFlags.Static | BindingFlags.Public |
8146 BindingFlags.FlattenHierarchy;
8147 methods = greenType.GetMethods (flags);
8149 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#G1");
8150 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#G2");
8151 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#G3");
8152 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#G4");
8153 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#G5");
8154 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#G6");
8155 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#G7");
8156 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#G8");
8157 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#G9");
8158 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#G10");
8159 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#G11");
8160 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#G12");
8161 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#G13");
8162 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#G14");
8163 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#G15");
8164 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#G16");
8165 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#G17");
8166 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#G18");
8167 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#G19");
8168 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#G20");
8169 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#G21");
8170 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#G22");
8171 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#G23");
8172 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#G24");
8173 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#G25");
8174 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#G26");
8175 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#G27");
8176 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#G28");
8177 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticRed"), "#G29");
8178 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#G30");
8179 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#G31");
8180 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#G32");
8181 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#G33");
8182 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#G34");
8183 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#G35");
8184 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#G36");
8186 flags = BindingFlags.Static | BindingFlags.NonPublic |
8187 BindingFlags.FlattenHierarchy;
8188 methods = greenType.GetMethods (flags);
8190 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#H1");
8191 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#H2");
8192 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#H3");
8193 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#H4");
8194 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#H5");
8195 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#H6");
8196 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#H7");
8197 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#H8");
8198 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#H9");
8199 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#H10");
8200 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#H11");
8201 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#H12");
8202 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#H13");
8203 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#H14");
8204 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#H15");
8205 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#H16");
8206 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#H17");
8207 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#H18");
8208 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#H19");
8209 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#H20");
8210 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#H21");
8211 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#H22");
8212 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#H23");
8213 #if NET_2_0
8214 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8215 #else
8216 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#H24");
8217 #endif
8218 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#H25");
8219 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#H26");
8220 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#H27");
8221 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#H28");
8222 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#H29");
8223 #if NET_2_0
8224 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8225 #else
8226 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#H30");
8227 #endif
8228 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#H31");
8229 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#H32");
8230 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#H33");
8231 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#H34");
8232 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#H35");
8233 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#H36");
8235 flags = BindingFlags.Instance | BindingFlags.NonPublic |
8236 BindingFlags.DeclaredOnly;
8237 methods = greenType.GetMethods (flags);
8239 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#I1");
8240 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#I2");
8241 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#I3");
8242 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#I4");
8243 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#I5");
8244 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#I6");
8245 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#I7");
8246 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#I8");
8247 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#I9");
8248 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#I10");
8249 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#I11");
8250 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#I12");
8251 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#I13");
8252 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#I14");
8253 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#I15");
8254 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#I16");
8255 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#I17");
8256 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#I18");
8257 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#I19");
8258 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#I20");
8259 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#I21");
8260 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#I22");
8261 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#I23");
8262 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#I24");
8263 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#I25");
8264 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#I26");
8265 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#I27");
8266 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#I28");
8267 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#I29");
8268 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#I30");
8269 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#I31");
8270 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#I32");
8271 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#I33");
8272 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#I34");
8273 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#I35");
8274 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#I36");
8276 flags = BindingFlags.Instance | BindingFlags.Public |
8277 BindingFlags.DeclaredOnly;
8278 methods = greenType.GetMethods (flags);
8280 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#J1");
8281 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#J2");
8282 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#J3");
8283 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#J4");
8284 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#J5");
8285 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#J6");
8286 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#J7");
8287 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#J8");
8288 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#J9");
8289 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#J10");
8290 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#J11");
8291 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#J12");
8292 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#J13");
8293 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#J14");
8294 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#J15");
8295 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#J16");
8296 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#J17");
8297 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#J18");
8298 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#J19");
8299 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#J20");
8300 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#J21");
8301 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#J22");
8302 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#J23");
8303 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#J24");
8304 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#J25");
8305 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#J26");
8306 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#J27");
8307 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#J28");
8308 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#J29");
8309 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#J30");
8310 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#J31");
8311 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#J32");
8312 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#J33");
8313 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#J34");
8314 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#J35");
8315 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#J36");
8317 flags = BindingFlags.Static | BindingFlags.Public |
8318 BindingFlags.DeclaredOnly;
8319 methods = greenType.GetMethods (flags);
8321 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#K1");
8322 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#K2");
8323 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#K3");
8324 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#K4");
8325 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#K5");
8326 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#K6");
8327 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#K7");
8328 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#K8");
8329 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#K9");
8330 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#K10");
8331 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#K11");
8332 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#K12");
8333 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#K13");
8334 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#K14");
8335 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#K15");
8336 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#K16");
8337 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#K17");
8338 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#K18");
8339 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#K19");
8340 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#K20");
8341 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#K21");
8342 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#K22");
8343 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#K23");
8344 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#K24");
8345 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#K25");
8346 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#K26");
8347 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#K27");
8348 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#K28");
8349 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#K29");
8350 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#K30");
8351 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#K31");
8352 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#K32");
8353 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#K33");
8354 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#K34");
8355 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#K35");
8356 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#K36");
8358 flags = BindingFlags.Static | BindingFlags.NonPublic |
8359 BindingFlags.DeclaredOnly;
8360 methods = greenType.GetMethods (flags);
8362 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#L1");
8363 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#L2");
8364 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#L3");
8365 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#L4");
8366 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#L5");
8367 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#L6");
8368 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#L7");
8369 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#L8");
8370 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#L9");
8371 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#L10");
8372 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#L11");
8373 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#L12");
8374 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#L13");
8375 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#L14");
8376 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#L15");
8377 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#L16");
8378 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#L17");
8379 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#L18");
8380 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#L19");
8381 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#L20");
8382 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#L21");
8383 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#L22");
8384 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#L23");
8385 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#L24");
8386 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#L25");
8387 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#L26");
8388 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#L27");
8389 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#L28");
8390 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#L29");
8391 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#L30");
8392 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#L31");
8393 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#L32");
8394 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#L33");
8395 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#L34");
8396 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#L35");
8397 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#L36");
8399 flags = BindingFlags.Instance | BindingFlags.NonPublic |
8400 BindingFlags.Public;
8401 methods = greenType.GetMethods (flags);
8403 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#M1");
8404 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#M2");
8405 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#M3");
8406 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#M4");
8407 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#M5");
8408 #if NET_2_0
8409 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8410 #else
8411 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#M6");
8412 #endif
8413 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#M7");
8414 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#M8");
8415 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#M9");
8416 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#M10");
8417 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#M11");
8418 #if NET_2_0
8419 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8420 #else
8421 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#M12");
8422 #endif
8423 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#M13");
8424 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#M14");
8425 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#M15");
8426 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#M16");
8427 Assert.IsNotNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#M17");
8428 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#M18");
8429 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#M19");
8430 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#M20");
8431 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#M21");
8432 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#M22");
8433 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#M23");
8434 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#M24");
8435 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#M25");
8436 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#M26");
8437 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#M27");
8438 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#M28");
8439 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#M29");
8440 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#M30");
8441 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#M31");
8442 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#M32");
8443 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#M33");
8444 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#M34");
8445 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#M35");
8446 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#M36");
8448 flags = BindingFlags.Static | BindingFlags.NonPublic |
8449 BindingFlags.Public;
8450 methods = greenType.GetMethods (flags);
8452 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceBlue"), "#N1");
8453 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceBlue"), "#N2");
8454 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceBlue"), "#N3");
8455 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceBlue"), "#N4");
8456 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceBlue"), "#N5");
8457 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceBlue"), "#N6");
8458 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceRed"), "#N7");
8459 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceRed"), "#N8");
8460 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceRed"), "#N9");
8461 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceRed"), "#N10");
8462 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceRed"), "#N11");
8463 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceRed"), "#N12");
8464 Assert.IsNull (GetMethodByName (methods, "GetPrivateInstanceGreen"), "#N13");
8465 Assert.IsNull (GetMethodByName (methods, "GetFamilyInstanceGreen"), "#N14");
8466 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemInstanceGreen"), "#N15");
8467 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemInstanceGreen"), "#N16");
8468 Assert.IsNull (GetMethodByName (methods, "GetPublicInstanceGreen"), "#N17");
8469 Assert.IsNull (GetMethodByName (methods, "GetAssemblyInstanceGreen"), "#N18");
8470 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticBlue"), "#N19");
8471 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticBlue"), "#N20");
8472 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticBlue"), "#N21");
8473 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticBlue"), "#N22");
8474 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticBlue"), "#N23");
8475 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticBlue"), "#N24");
8476 Assert.IsNull (GetMethodByName (methods, "GetPrivateStaticRed"), "#N25");
8477 Assert.IsNull (GetMethodByName (methods, "GetFamilyStaticRed"), "#N26");
8478 Assert.IsNull (GetMethodByName (methods, "GetFamANDAssemStaticRed"), "#N27");
8479 Assert.IsNull (GetMethodByName (methods, "GetFamORAssemStaticRed"), "#N28");
8480 Assert.IsNull (GetMethodByName (methods, "GetPublicStaticRed"), "#N29");
8481 Assert.IsNull (GetMethodByName (methods, "GetAssemblyStaticRed"), "#N30");
8482 Assert.IsNotNull (GetMethodByName (methods, "GetPrivateStaticGreen"), "#N31");
8483 Assert.IsNotNull (GetMethodByName (methods, "GetFamilyStaticGreen"), "#N32");
8484 Assert.IsNotNull (GetMethodByName (methods, "GetFamANDAssemStaticGreen"), "#N33");
8485 Assert.IsNotNull (GetMethodByName (methods, "GetFamORAssemStaticGreen"), "#N34");
8486 Assert.IsNotNull (GetMethodByName (methods, "GetPublicStaticGreen"), "#N35");
8487 Assert.IsNotNull (GetMethodByName (methods, "GetAssemblyStaticGreen"), "#N36");
8490 [Test]
8491 public void TestGetMemberIncomplete ()
8493 TypeBuilder tb = module.DefineType (genTypeName ());
8494 try {
8495 tb.GetMember ("FOO", MemberTypes.All, BindingFlags.Public);
8496 Assert.Fail ("#1");
8497 } catch (NotSupportedException ex) {
8498 // The invoked member is not supported in a
8499 // dynamic module
8500 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8501 Assert.IsNull (ex.InnerException, "#3");
8502 Assert.IsNotNull (ex.Message, "#4");
8506 [Test]
8507 public void TestGetMemberComplete ()
8509 TypeBuilder tb = module.DefineType (genTypeName ());
8510 tb.DefineField ("FOO", typeof (int), FieldAttributes.Private);
8512 Type emittedType = tb.CreateType ();
8514 Assert.AreEqual (1, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.NonPublic).Length);
8515 Assert.AreEqual (0, tb.GetMember ("FOO", MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public).Length);
8518 [Test]
8519 public void TestGetMembersIncomplete ()
8521 TypeBuilder tb = module.DefineType (genTypeName ());
8522 try {
8523 tb.GetMembers ();
8524 Assert.Fail ("#1");
8525 } catch (NotSupportedException ex) {
8526 // The invoked member is not supported in a
8527 // dynamic module
8528 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8529 Assert.IsNull (ex.InnerException, "#3");
8530 Assert.IsNotNull (ex.Message, "#4");
8534 [Test]
8535 public void TestGetMembersComplete ()
8537 TypeBuilder tb = module.DefineType (genTypeName ());
8538 Type emittedType = tb.CreateType ();
8540 Assert.AreEqual (tb.GetMembers ().Length, emittedType.GetMembers ().Length);
8543 [Test]
8544 public void TestGetMembersFlagsIncomplete ()
8546 TypeBuilder tb = module.DefineType (genTypeName ());
8547 try {
8548 tb.GetMembers (BindingFlags.Public);
8549 Assert.Fail ("#1");
8550 } catch (NotSupportedException ex) {
8551 // The invoked member is not supported in a
8552 // dynamic module
8553 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8554 Assert.IsNull (ex.InnerException, "#3");
8555 Assert.IsNotNull (ex.Message, "#4");
8559 [Test]
8560 public void TestGetMembersFlagsComplete ()
8562 TypeBuilder tb = module.DefineType (genTypeName ());
8563 tb.DefineField ("FOO", typeof (int), FieldAttributes.Public);
8565 Type emittedType = tb.CreateType ();
8567 Assert.IsTrue (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length != 0);
8568 Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length,
8569 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.Public).Length);
8570 Assert.AreEqual (tb.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length,
8571 emittedType.GetMembers (BindingFlags.Instance | BindingFlags.NonPublic).Length);
8574 [Test]
8575 public void TestGetInterfaceIncomplete ()
8577 TypeBuilder tb = module.DefineType (genTypeName ());
8578 try {
8579 tb.GetInterface ("FOO", true);
8580 Assert.Fail ("#1");
8581 } catch (NotSupportedException ex) {
8582 // The invoked member is not supported in a
8583 // dynamic module
8584 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
8585 Assert.IsNull (ex.InnerException, "#3");
8586 Assert.IsNotNull (ex.Message, "#4");
8590 [Test]
8591 public void TestGetInterfaces ()
8593 TypeBuilder tb = module.DefineType (genTypeName ());
8594 Type [] interfaces = tb.GetInterfaces ();
8595 Assert.AreEqual (0, interfaces.Length);
8597 TypeBuilder tbInterface = module.DefineType (genTypeName (), TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
8598 Type emittedInterface = tbInterface.CreateType ();
8600 tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { emittedInterface });
8601 interfaces = tb.GetInterfaces ();
8602 Assert.AreEqual (1, interfaces.Length);
8605 [Test]
8606 public void TestAddDeclarativeSecurityAlreadyCreated ()
8608 TypeBuilder tb = module.DefineType (genTypeName ());
8609 tb.CreateType ();
8611 PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8612 try {
8613 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8614 Assert.Fail ("#1");
8615 } catch (InvalidOperationException ex) {
8616 // Unable to change after type has been created
8617 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8618 Assert.IsNull (ex.InnerException, "#3");
8619 Assert.IsNotNull (ex.Message, "#4");
8623 [Test]
8624 public void TestAddDeclarativeSecurityNullPermissionSet ()
8626 TypeBuilder tb = module.DefineType (genTypeName ());
8627 try {
8628 tb.AddDeclarativeSecurity (SecurityAction.Demand, null);
8629 Assert.Fail ("#1");
8630 } catch (ArgumentNullException ex) {
8631 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
8632 Assert.IsNull (ex.InnerException, "#3");
8633 Assert.IsNotNull (ex.Message, "#4");
8634 Assert.AreEqual ("pset", ex.ParamName, "#5");
8639 [Test]
8640 public void TestAddDeclarativeSecurityInvalidAction ()
8642 TypeBuilder tb = module.DefineType (genTypeName ());
8644 SecurityAction [] actions = new SecurityAction [] {
8645 SecurityAction.RequestMinimum,
8646 SecurityAction.RequestOptional,
8647 SecurityAction.RequestRefuse };
8648 PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8650 foreach (SecurityAction action in actions) {
8651 try {
8652 tb.AddDeclarativeSecurity (action, set);
8653 Assert.Fail ();
8654 } catch (ArgumentOutOfRangeException) {
8659 [Test]
8660 public void TestAddDeclarativeSecurityDuplicateAction ()
8662 TypeBuilder tb = module.DefineType (genTypeName ());
8664 PermissionSet set = new PermissionSet (PermissionState.Unrestricted);
8665 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8666 try {
8667 tb.AddDeclarativeSecurity (SecurityAction.Demand, set);
8668 Assert.Fail ("#1");
8669 } catch (InvalidOperationException ex) {
8670 // Multiple permission sets specified with the
8671 // same SecurityAction
8672 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
8673 Assert.IsNull (ex.InnerException, "#3");
8674 Assert.IsNotNull (ex.Message, "#4");
8678 [Test]
8679 public void TestEnums ()
8681 TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
8682 TypeBuilder enumToCreate = module.DefineType (genTypeName (), typeAttrs,
8683 typeof (Enum));
8684 enumToCreate.SetCustomAttribute (new CustomAttributeBuilder (typeof (FlagsAttribute).GetConstructors () [0], Type.EmptyTypes));
8685 // add value__ field, see DefineEnum method of ModuleBuilder
8686 enumToCreate.DefineField ("value__", typeof (Int32),
8687 FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
8689 // add enum entries
8690 FieldBuilder fb = enumToCreate.DefineField ("A", enumToCreate,
8691 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8692 fb.SetConstant ((Int32) 0);
8694 fb = enumToCreate.DefineField ("B", enumToCreate,
8695 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8696 fb.SetConstant ((Int32) 1);
8698 fb = enumToCreate.DefineField ("C", enumToCreate,
8699 FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
8700 fb.SetConstant ((Int32) 2);
8702 Type enumType = enumToCreate.CreateType ();
8704 object enumVal = Enum.ToObject (enumType, (Int32) 3);
8706 Assert.AreEqual ("B, C", enumVal.ToString ());
8707 Assert.AreEqual (3, (Int32) enumVal);
8710 [Test]
8711 public void DefineEnum ()
8713 TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8714 TypeAttributes.Public);
8715 EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8716 TypeAttributes.Public, typeof (int));
8717 typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8718 enumBuilder.CreateType ();
8719 typeBuilder.CreateType ();
8722 [Test]
8723 [Category ("NotWorking")]
8724 public void DefineEnumThrowIfTypeBuilderCalledBeforeEnumBuilder ()
8726 TypeBuilder typeBuilder = module.DefineType (genTypeName (),
8727 TypeAttributes.Public);
8728 EnumBuilder enumBuilder = module.DefineEnum (genTypeName (),
8729 TypeAttributes.Public, typeof (int));
8730 typeBuilder.DefineField ("myField", enumBuilder, FieldAttributes.Private);
8731 try {
8732 typeBuilder.CreateType ();
8733 Assert.Fail ("#1");
8734 } catch (TypeLoadException) {
8735 // Could not load type '...' from assembly
8736 // 'MonoTests.System.Reflection.Emit.TypeBuilderTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
8738 #if NET_2_0
8739 Assert.IsTrue (typeBuilder.IsCreated (), "#2");
8740 Assert.IsNull (typeBuilder.CreateType (), "#3");
8741 #else
8742 try {
8743 typeBuilder.CreateType ();
8744 } catch (InvalidOperationException ex) {
8745 // Unable to change after type has been created
8746 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
8747 Assert.IsNull (ex.InnerException, "#B3");
8748 Assert.IsNotNull (ex.Message, "#B4");
8750 #endif
8753 [Test]
8754 public void SetCustomAttribute_SuppressUnmanagedCodeSecurity ()
8756 TypeBuilder tb = module.DefineType (genTypeName ());
8757 ConstructorInfo attrCtor = typeof (SuppressUnmanagedCodeSecurityAttribute).
8758 GetConstructor (Type.EmptyTypes);
8759 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
8760 attrCtor, new object [0]);
8761 Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#1");
8762 tb.SetCustomAttribute (caBuilder);
8763 //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#2");
8764 Type emittedType = tb.CreateType ();
8765 Assert.AreEqual (TypeAttributes.HasSecurity, emittedType.Attributes & TypeAttributes.HasSecurity, "#3");
8766 //Assert.IsTrue ((tb.Attributes & TypeAttributes.HasSecurity) == 0, "#4");
8767 object [] emittedAttrs = emittedType.GetCustomAttributes (typeof (SuppressUnmanagedCodeSecurityAttribute), true);
8768 Assert.AreEqual (1, emittedAttrs.Length, "#5");
8771 private PropertyBuilder DefineStringProperty (TypeBuilder tb, string propertyName, string fieldName, MethodAttributes methodAttribs)
8773 // define the field holding the property value
8774 FieldBuilder fieldBuilder = tb.DefineField (fieldName,
8775 typeof (string), FieldAttributes.Private);
8777 PropertyBuilder propertyBuilder = tb.DefineProperty (
8778 propertyName, PropertyAttributes.HasDefault, typeof (string),
8779 new Type [] { typeof (string) });
8781 // First, we'll define the behavior of the "get" property for CustomerName as a method.
8782 MethodBuilder getMethodBuilder = tb.DefineMethod ("Get" + propertyName,
8783 methodAttribs,
8784 typeof (string),
8785 new Type [] { });
8787 ILGenerator getIL = getMethodBuilder.GetILGenerator ();
8789 getIL.Emit (OpCodes.Ldarg_0);
8790 getIL.Emit (OpCodes.Ldfld, fieldBuilder);
8791 getIL.Emit (OpCodes.Ret);
8793 // Now, we'll define the behavior of the "set" property for CustomerName.
8794 MethodBuilder setMethodBuilder = tb.DefineMethod ("Set" + propertyName,
8795 methodAttribs,
8796 null,
8797 new Type [] { typeof (string) });
8799 ILGenerator setIL = setMethodBuilder.GetILGenerator ();
8801 setIL.Emit (OpCodes.Ldarg_0);
8802 setIL.Emit (OpCodes.Ldarg_1);
8803 setIL.Emit (OpCodes.Stfld, fieldBuilder);
8804 setIL.Emit (OpCodes.Ret);
8806 // Last, we must map the two methods created above to our PropertyBuilder to
8807 // their corresponding behaviors, "get" and "set" respectively.
8808 propertyBuilder.SetGetMethod (getMethodBuilder);
8809 propertyBuilder.SetSetMethod (setMethodBuilder);
8810 return propertyBuilder;
8813 static int handler_called = 0;
8815 [Test]
8816 public void TestTypeResolve ()
8818 string typeName = genTypeName ();
8820 ResolveEventHandler handler = new ResolveEventHandler (TypeResolve);
8821 AppDomain.CurrentDomain.TypeResolve += handler;
8822 handler_called = 0;
8823 Type t = Type.GetType (typeName);
8824 Assert.AreEqual (typeName, t.Name);
8825 Assert.AreEqual (1, handler_called);
8826 AppDomain.CurrentDomain.TypeResolve -= handler;
8829 Assembly TypeResolve (object sender, ResolveEventArgs args)
8831 TypeBuilder tb = module.DefineType (args.Name, TypeAttributes.Public);
8832 tb.CreateType ();
8833 handler_called++;
8834 return tb.Assembly;
8837 [Test]
8838 public void IsAssignableFrom_Created ()
8840 TypeBuilder tb = module.DefineType (genTypeName (),
8841 TypeAttributes.Public, typeof (MemoryStream),
8842 new Type [] { typeof (IThrowable), typeof (Bar) });
8843 tb.AddInterfaceImplementation (typeof (IDestroyable));
8844 Type emitted_type = tb.CreateType ();
8846 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
8847 Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
8848 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
8849 Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
8850 Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb), "#A5");
8851 Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#A6");
8852 Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#A7");
8853 Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#A8");
8854 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#A9");
8855 Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#A10");
8856 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#A11");
8857 Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#A12");
8858 Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A13");
8859 Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A14");
8860 Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A15");
8861 Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A16");
8862 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A17");
8863 Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A18");
8865 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#B1");
8866 Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#B2");
8867 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#B3");
8868 Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#B4");
8869 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#B5");
8870 Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#B6");
8871 Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#B7");
8872 Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#B8");
8873 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb), "#B9");
8874 Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#B10");
8876 Assert.IsTrue (tb.IsAssignableFrom (tb), "#C1");
8877 Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#C2");
8878 Assert.IsTrue (tb.IsAssignableFrom (emitted_type), "#C3");
8879 Assert.IsTrue (emitted_type.IsAssignableFrom (tb), "#C4");
8880 Assert.IsFalse (emitted_type.IsAssignableFrom ((Type) null), "#C5");
8882 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type), "#D1");
8883 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IThrowable)), "#D2");
8884 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type), "#D3");
8885 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IMoveable)), "#D4");
8886 Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type), "#D5");
8887 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Foo)), "#D6");
8888 Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type), "#D7");
8889 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Bar)), "#D8");
8890 Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type), "#D9");
8891 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Baz)), "#D10");
8892 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type), "#D11");
8893 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDestroyable)), "#D12");
8894 Assert.IsFalse (typeof (IAir).IsAssignableFrom (emitted_type), "#D13");
8895 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IAir)), "#D14");
8896 Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type), "#D15");
8897 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IWater)), "#D16");
8898 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type), "#D17");
8899 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (ILiquid)), "#D18");
8901 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type), "#E1");
8902 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (MemoryStream)), "#E2");
8903 Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type), "#E3");
8904 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (Stream)), "#E4");
8905 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type), "#E5");
8906 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (FileStream)), "#E6");
8907 Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type), "#E7");
8908 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (object)), "#E8");
8909 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type), "#E9");
8910 Assert.IsFalse (emitted_type.IsAssignableFrom (typeof (IDisposable)), "#E10");
8912 Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
8913 tb.FullName + "[]")), "#F1");
8914 Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
8915 tb.FullName + "[]")), "#F2");
8916 Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
8917 tb.FullName + "[]")), "#F3");
8919 TypeBuilder tb2 = module.DefineType (genTypeName (),
8920 TypeAttributes.Public, tb,
8921 new Type [] { typeof (IAir) });
8922 Type emitted_type2 = tb2.CreateType ();
8924 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb2), "#G1");
8925 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#G2");
8926 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb2), "#G3");
8927 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#G4");
8928 Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb2), "#G5");
8929 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#G6");
8930 Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb2), "#G7");
8931 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#G8");
8932 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#G9");
8933 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#G10");
8934 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#G11");
8935 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDestroyable)), "#G12");
8936 Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#G13");
8937 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#G14");
8938 Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#G15");
8939 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#G16");
8940 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#G17");
8941 Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#G18");
8943 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#H1");
8944 Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#H2");
8945 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#H3");
8946 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#H4");
8947 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#H5");
8948 Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#H6");
8949 Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#H7");
8950 Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#H8");
8951 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb2), "#H9");
8952 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#H10");
8954 Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#I1");
8955 Assert.IsFalse (tb2.IsAssignableFrom (tb), "#I2");
8956 Assert.IsTrue (tb2.IsAssignableFrom (emitted_type2), "#I3");
8957 Assert.IsFalse (tb2.IsAssignableFrom (emitted_type), "#I4");
8958 Assert.IsFalse (tb2.IsAssignableFrom ((Type) null), "#I5");
8959 Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type2), "#I6");
8960 Assert.IsFalse (emitted_type2.IsAssignableFrom (emitted_type), "#I7");
8961 Assert.IsTrue (emitted_type2.IsAssignableFrom (tb2), "#I8");
8962 Assert.IsFalse (emitted_type2.IsAssignableFrom (tb), "#I9");
8963 Assert.IsFalse (emitted_type2.IsAssignableFrom ((Type) null), "#I10");
8964 Assert.IsTrue (tb.IsAssignableFrom (tb2), "#I11");
8965 Assert.IsTrue (tb.IsAssignableFrom (emitted_type2), "#I12");
8966 Assert.IsTrue (emitted_type.IsAssignableFrom (tb2), "#I13");
8967 Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type2), "#I14");
8969 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type2), "#J1");
8970 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IThrowable)), "#J2");
8971 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type2), "#J3");
8972 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IMoveable)), "#J4");
8973 Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type2), "#J5");
8974 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Foo)), "#J6");
8975 Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type2), "#J7");
8976 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Bar)), "#J8");
8977 Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type2), "#J9");
8978 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Baz)), "#J10");
8979 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb2), "#J11");
8980 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDestroyable)), "#J12");
8981 Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type2), "#J13");
8982 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IAir)), "#J14");
8983 Assert.IsFalse (typeof (IWater).IsAssignableFrom (emitted_type2), "#J15");
8984 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IWater)), "#J16");
8985 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (emitted_type2), "#J17");
8986 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (ILiquid)), "#J18");
8988 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type2), "#K1");
8989 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (MemoryStream)), "#K2");
8990 Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type2), "#K3");
8991 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (Stream)), "#K4");
8992 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type2), "#K5");
8993 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (FileStream)), "#K6");
8994 Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type2), "#K7");
8995 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (object)), "#K8");
8996 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type2), "#K9");
8997 Assert.IsFalse (emitted_type2.IsAssignableFrom (typeof (IDisposable)), "#K10");
8999 Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9000 tb2.FullName + "[]")), "#L1");
9001 Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9002 tb2.FullName + "[]")), "#L2");
9003 Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9004 tb2.FullName + "[]")), "#L3");
9006 TypeBuilder tb3 = module.DefineType (genTypeName (),
9007 TypeAttributes.Public, tb2,
9008 new Type [] { typeof (IWater) });
9009 Type emitted_type3 = tb3.CreateType ();
9011 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb3), "#M1");
9012 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#M2");
9013 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb3), "#M3");
9014 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#M4");
9015 Assert.IsTrue (typeof (Foo).IsAssignableFrom (tb3), "#M5");
9016 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#M6");
9017 Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb3), "#M7");
9018 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#M8");
9019 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#M9");
9020 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#M10");
9021 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb3), "#M11");
9022 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDestroyable)), "#M12");
9023 Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb3), "#M13");
9024 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#M14");
9025 Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#M15");
9026 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#M16");
9027 Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (tb3), "#M17");
9028 Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#M18");
9030 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#N1");
9031 Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#N2");
9032 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#N3");
9033 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#N4");
9034 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#N5");
9035 Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#N6");
9036 Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#N7");
9037 Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#N8");
9038 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (tb3), "#N9");
9039 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#N10");
9041 Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#O1");
9042 Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#O2");
9043 Assert.IsFalse (tb3.IsAssignableFrom (tb), "#O3");
9044 Assert.IsTrue (tb3.IsAssignableFrom (emitted_type3), "#O4");
9045 Assert.IsFalse (tb3.IsAssignableFrom (emitted_type2), "#O5");
9046 Assert.IsFalse (tb3.IsAssignableFrom (emitted_type), "#O6");
9047 Assert.IsFalse (tb3.IsAssignableFrom ((Type) null), "#O7");
9048 Assert.IsTrue (emitted_type3.IsAssignableFrom (emitted_type3), "#O8");
9049 Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type2), "#O9");
9050 Assert.IsFalse (emitted_type3.IsAssignableFrom (emitted_type), "#O10");
9051 Assert.IsTrue (emitted_type3.IsAssignableFrom (tb3), "#O11");
9052 Assert.IsFalse (emitted_type3.IsAssignableFrom (tb2), "#O12");
9053 Assert.IsFalse (emitted_type3.IsAssignableFrom (tb), "#O13");
9054 Assert.IsFalse (emitted_type3.IsAssignableFrom ((Type) null), "#O14");
9055 Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#O15");
9056 Assert.IsTrue (tb2.IsAssignableFrom (emitted_type3), "#O16");
9057 Assert.IsTrue (emitted_type2.IsAssignableFrom (emitted_type3), "#O17");
9058 Assert.IsTrue (emitted_type2.IsAssignableFrom (tb3), "#O18");
9059 Assert.IsTrue (tb.IsAssignableFrom (tb3), "#O19");
9060 Assert.IsTrue (tb.IsAssignableFrom (emitted_type3), "#O20");
9061 Assert.IsTrue (emitted_type.IsAssignableFrom (tb3), "#021");
9062 Assert.IsTrue (emitted_type.IsAssignableFrom (emitted_type3), "#O22");
9064 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (emitted_type3), "#P1");
9065 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IThrowable)), "#P2");
9066 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (emitted_type3), "#P3");
9067 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IMoveable)), "#P4");
9068 Assert.IsTrue (typeof (Foo).IsAssignableFrom (emitted_type3), "#P5");
9069 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Foo)), "#P6");
9070 Assert.IsTrue (typeof (Bar).IsAssignableFrom (emitted_type3), "#P7");
9071 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Bar)), "#P8");
9072 Assert.IsFalse (typeof (Baz).IsAssignableFrom (emitted_type3), "#P9");
9073 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Baz)), "#P10");
9074 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (emitted_type3), "#P11");
9075 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDestroyable)), "#P12");
9076 Assert.IsTrue (typeof (IAir).IsAssignableFrom (emitted_type3), "#P13");
9077 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IAir)), "#P14");
9078 Assert.IsTrue (typeof (IWater).IsAssignableFrom (emitted_type3), "#P15");
9079 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IWater)), "#P16");
9080 Assert.IsTrue (typeof (ILiquid).IsAssignableFrom (emitted_type3), "#P17");
9081 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (ILiquid)), "#P18");
9083 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (emitted_type3), "#Q1");
9084 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (MemoryStream)), "#Q2");
9085 Assert.IsTrue (typeof (Stream).IsAssignableFrom (emitted_type3), "#Q3");
9086 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (Stream)), "#Q4");
9087 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (emitted_type3), "#Q5");
9088 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (FileStream)), "#Q6");
9089 Assert.IsTrue (typeof (object).IsAssignableFrom (emitted_type3), "#Q7");
9090 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (object)), "#Q8");
9091 Assert.IsTrue (typeof (IDisposable).IsAssignableFrom (emitted_type3), "#Q9");
9092 Assert.IsFalse (emitted_type3.IsAssignableFrom (typeof (IDisposable)), "#Q10");
9094 Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9095 tb3.FullName + "[]")), "#R1");
9096 Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9097 tb3.FullName + "[]")), "#R2");
9098 Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9099 tb3.FullName + "[]")), "#R3");
9101 #if NET_2_0
9102 TypeBuilder tb4 = module.DefineType (genTypeName (),
9103 TypeAttributes.Public, null,
9104 new Type [] { typeof (IWater) });
9105 tb4.DefineGenericParameters ("T");
9107 Type inst = tb4.MakeGenericType (typeof (int));
9108 Type emitted_type4 = tb4.CreateType ();
9109 Assert.IsFalse (typeof (IComparable).IsAssignableFrom (inst));
9110 // This returns True if CreateType () is called _before_ MakeGenericType...
9111 //Assert.IsFalse (typeof (IWater).IsAssignableFrom (inst));
9112 #endif
9115 [Test]
9116 public void IsAssignableFrom_NotCreated ()
9118 TypeBuilder tb = module.DefineType (genTypeName (),
9119 TypeAttributes.Public, typeof (MemoryStream),
9120 new Type [] {
9121 typeof (IThrowable), typeof (Bar),
9122 typeof (IComparable)
9125 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9126 Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9127 //Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#A3");
9128 Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#A4");
9129 Assert.IsTrue (typeof (IComparable).IsAssignableFrom (tb), "#A5");
9130 Assert.IsFalse (tb.IsAssignableFrom (typeof (IComparable)), "#A6");
9131 Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb), "#A7");
9132 Assert.IsFalse (tb.IsAssignableFrom (typeof (IAir)), "#A8");
9133 Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb), "#A9");
9134 Assert.IsFalse (tb.IsAssignableFrom (typeof (IWater)), "#A10");
9135 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb), "#A11");
9136 Assert.IsFalse (tb.IsAssignableFrom (typeof (ILiquid)), "#A12");
9138 //Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb), "#B1");
9139 Assert.IsFalse (tb.IsAssignableFrom (typeof (Foo)), "#B2");
9140 Assert.IsTrue (typeof (Bar).IsAssignableFrom (tb), "#B3");
9141 Assert.IsFalse (tb.IsAssignableFrom (typeof (Bar)), "#B4");
9142 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb), "#B5");
9143 Assert.IsFalse (tb.IsAssignableFrom (typeof (Baz)), "#B6");
9145 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb), "#C1");
9146 Assert.IsFalse (tb.IsAssignableFrom (typeof (MemoryStream)), "#C2");
9147 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb), "#C3");
9148 Assert.IsFalse (tb.IsAssignableFrom (typeof (Stream)), "#C4");
9149 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb), "#C5");
9150 Assert.IsFalse (tb.IsAssignableFrom (typeof (FileStream)), "#C6");
9151 Assert.IsTrue (typeof (object).IsAssignableFrom (tb), "#C7");
9152 Assert.IsFalse (tb.IsAssignableFrom (typeof (object)), "#C8");
9153 Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb), "#C9");
9154 Assert.IsFalse (tb.IsAssignableFrom (typeof (IDisposable)), "#C10");
9156 Assert.IsTrue (tb.IsAssignableFrom (tb), "#D1");
9157 Assert.IsFalse (tb.IsAssignableFrom ((Type) null), "#D2");
9159 TypeBuilder tb2 = module.DefineType (genTypeName (),
9160 TypeAttributes.Public, tb,
9161 new Type [] { typeof (IAir) });
9163 Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb2), "#E1");
9164 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IThrowable)), "#E2");
9165 Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb2), "#E3");
9166 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IMoveable)), "#E4");
9167 Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb2), "#E5");
9168 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IComparable)), "#E6");
9169 Assert.IsTrue (typeof (IAir).IsAssignableFrom (tb2), "#E7");
9170 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IAir)), "#E8");
9171 Assert.IsFalse (typeof (IWater).IsAssignableFrom (tb2), "#E9");
9172 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IWater)), "#E10");
9173 Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb2), "#E11");
9174 Assert.IsFalse (tb2.IsAssignableFrom (typeof (ILiquid)), "#E12");
9176 Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb2), "#F1");
9177 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Foo)), "#F2");
9178 Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb2), "#F3");
9179 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Bar)), "#F4");
9180 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb2), "#F5");
9181 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Baz)), "#F6");
9183 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb2), "#G1");
9184 Assert.IsFalse (tb2.IsAssignableFrom (typeof (MemoryStream)), "#G2");
9185 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb2), "#G3");
9186 Assert.IsFalse (tb2.IsAssignableFrom (typeof (Stream)), "#G4");
9187 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb2), "#G5");
9188 Assert.IsFalse (tb2.IsAssignableFrom (typeof (FileStream)), "#G6");
9189 Assert.IsTrue (typeof (object).IsAssignableFrom (tb2), "#G7");
9190 Assert.IsFalse (tb2.IsAssignableFrom (typeof (object)), "#G8");
9191 Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb2), "#G9");
9192 Assert.IsFalse (tb2.IsAssignableFrom (typeof (IDisposable)), "#G10");
9194 Assert.IsTrue (tb2.IsAssignableFrom (tb2), "#H1");
9195 Assert.IsFalse (tb2.IsAssignableFrom (tb), "#H2");
9196 Assert.IsTrue (tb.IsAssignableFrom (tb2), "#H3");
9198 TypeBuilder tb3 = module.DefineType (genTypeName (),
9199 TypeAttributes.Public, tb2,
9200 new Type [] { typeof (IWater) });
9202 Assert.IsFalse (typeof (IThrowable).IsAssignableFrom (tb3), "#I1");
9203 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IThrowable)), "#I2");
9204 Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb3), "#I3");
9205 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IMoveable)), "#I4");
9206 Assert.IsFalse (typeof (IComparable).IsAssignableFrom (tb3), "#I5");
9207 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IComparable)), "#I6");
9208 Assert.IsFalse (typeof (IAir).IsAssignableFrom (tb3), "#I7");
9209 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IAir)), "#I8");
9210 Assert.IsTrue (typeof (IWater).IsAssignableFrom (tb3), "#I9");
9211 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IWater)), "#I10");
9212 //Assert.IsFalse (typeof (ILiquid).IsAssignableFrom (tb3), "#I11");
9213 Assert.IsFalse (tb3.IsAssignableFrom (typeof (ILiquid)), "#I12");
9215 Assert.IsFalse (typeof (Foo).IsAssignableFrom (tb3), "#J1");
9216 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Foo)), "#J2");
9217 Assert.IsFalse (typeof (Bar).IsAssignableFrom (tb3), "#J3");
9218 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Bar)), "#J4");
9219 Assert.IsFalse (typeof (Baz).IsAssignableFrom (tb3), "#J5");
9220 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Baz)), "#J6");
9222 Assert.IsTrue (typeof (MemoryStream).IsAssignableFrom (tb3), "#K1");
9223 Assert.IsFalse (tb3.IsAssignableFrom (typeof (MemoryStream)), "#K2");
9224 Assert.IsTrue (typeof (Stream).IsAssignableFrom (tb3), "#K3");
9225 Assert.IsFalse (tb3.IsAssignableFrom (typeof (Stream)), "#K4");
9226 Assert.IsFalse (typeof (FileStream).IsAssignableFrom (tb3), "#K5");
9227 Assert.IsFalse (tb3.IsAssignableFrom (typeof (FileStream)), "#K6");
9228 Assert.IsTrue (typeof (object).IsAssignableFrom (tb3), "#K7");
9229 Assert.IsFalse (tb3.IsAssignableFrom (typeof (object)), "#K8");
9230 Assert.IsFalse (typeof (IDisposable).IsAssignableFrom (tb3), "#K9");
9231 Assert.IsFalse (tb3.IsAssignableFrom (typeof (IDisposable)), "#K10");
9233 Assert.IsTrue (tb3.IsAssignableFrom (tb3), "#L1");
9234 Assert.IsFalse (tb3.IsAssignableFrom (tb2), "#L2");
9235 Assert.IsFalse (tb3.IsAssignableFrom (tb), "#L3");
9236 Assert.IsTrue (tb2.IsAssignableFrom (tb3), "#L4");
9237 Assert.IsTrue (tb.IsAssignableFrom (tb3), "#L5");
9240 [Test]
9241 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9242 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_Mono ()
9244 TypeBuilder tb = module.DefineType (genTypeName (),
9245 TypeAttributes.Public, typeof (FormatException),
9246 new Type [] { typeof (IThrowable) });
9247 tb.AddInterfaceImplementation (typeof (IDestroyable));
9249 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9250 Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9252 Assert.IsTrue (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9253 Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9256 [Test]
9257 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344549
9258 public void IsAssignableFrom_NotCreated_AddInterfaceImplementation_MS ()
9260 TypeBuilder tb = module.DefineType (genTypeName (),
9261 TypeAttributes.Public, typeof (FormatException),
9262 new Type [] { typeof (IThrowable) });
9263 tb.AddInterfaceImplementation (typeof (IDestroyable));
9265 Assert.IsTrue (typeof (IThrowable).IsAssignableFrom (tb), "#A1");
9266 Assert.IsFalse (tb.IsAssignableFrom (typeof (IThrowable)), "#A2");
9268 Assert.IsFalse (typeof (IDestroyable).IsAssignableFrom (tb), "#B1");
9269 Assert.IsFalse (tb.IsAssignableFrom (typeof (IDestroyable)), "#B2");
9273 [Test]
9274 [Category ("NotDotNet")]
9275 public void IsAssignableFrom_NotCreated_Array ()
9277 TypeBuilder tb = module.DefineType (genTypeName (),
9278 TypeAttributes.Public, typeof (FormatException),
9279 new Type [] {
9280 typeof (IThrowable), typeof (Bar),
9281 typeof (IComparable)
9284 Assert.IsTrue (typeof (Foo []).IsAssignableFrom (module.GetType (
9285 tb.FullName + "[]")), "#1");
9286 Assert.IsTrue (typeof (Bar []).IsAssignableFrom (module.GetType (
9287 tb.FullName + "[]")), "#2");
9288 Assert.IsFalse (typeof (Baz []).IsAssignableFrom (module.GetType (
9289 tb.FullName + "[]")), "#3");
9292 [Test]
9293 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9294 public void IsAssignableFrom_NotCreated_BaseInterface_Mono ()
9296 TypeBuilder tb = module.DefineType (genTypeName (),
9297 TypeAttributes.Public, typeof (FormatException),
9298 new Type [] {
9299 typeof (IThrowable), typeof (Bar),
9300 typeof (IComparable)
9303 Assert.IsTrue (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9304 Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9307 [Test]
9308 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=344353
9309 public void IsAssignableFrom_NotCreated_BaseInterface_MS ()
9311 TypeBuilder tb = module.DefineType (genTypeName (),
9312 TypeAttributes.Public, typeof (FormatException),
9313 new Type [] {
9314 typeof (IThrowable), typeof (Bar),
9315 typeof (IComparable)
9318 Assert.IsFalse (typeof (IMoveable).IsAssignableFrom (tb), "#1");
9319 Assert.IsFalse (tb.IsAssignableFrom (typeof (IMoveable)), "#2");
9322 [Test]
9323 public void CreateType_EmptyMethodBody ()
9325 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9327 tb.DefineMethod ("foo", MethodAttributes.Public, typeof (void), new Type [] { });
9328 try {
9329 tb.CreateType ();
9330 Assert.Fail ("#1");
9331 } catch (InvalidOperationException ex) {
9332 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9333 Assert.IsNull (ex.InnerException, "#3");
9334 Assert.IsNotNull (ex.Message, "#4");
9338 [Test]
9339 public void CreateType_EmptyCtorBody ()
9341 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9343 tb.DefineConstructor (0, CallingConventions.Standard, null);
9344 try {
9345 tb.CreateType ();
9346 Assert.Fail ("#1");
9347 } catch (InvalidOperationException ex) {
9348 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9349 Assert.IsNull (ex.InnerException, "#3");
9350 Assert.IsNotNull (ex.Message, "#4");
9354 [Test]
9355 #if ONLY_1_1
9356 [Category ("NotDotNet")] // Parent type was not extensible by the given type
9357 #endif
9358 [Category ("NotWorking")]
9359 public void CreateType_Interface_ParentInvalid ()
9361 TypeBuilder tb;
9363 tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9364 typeof (Exception));
9365 Assert.AreEqual (typeof (Exception), tb.BaseType, "#A1");
9366 try {
9367 tb.CreateType ();
9368 Assert.Fail ("#A2");
9369 } catch (TypeLoadException ex) {
9370 // Could not load interface 't5' from assembly '...'
9371 // because it must extend from Object
9372 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A3");
9373 Assert.IsNull (ex.InnerException, "#A4");
9374 Assert.IsNotNull (ex.Message, "#A5");
9375 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#A6");
9376 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#A7");
9379 tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9380 typeof (object));
9381 Assert.AreEqual (typeof (object), tb.BaseType, "#B1");
9382 try {
9383 tb.CreateType ();
9384 Assert.Fail ("#B2");
9385 } catch (TypeLoadException ex) {
9386 // Failure has occurred while loading a type
9387 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#B3");
9388 Assert.IsNull (ex.InnerException, "#B4");
9389 Assert.IsNotNull (ex.Message, "#B5");
9392 tb = module.DefineType (genTypeName (), TypeAttributes.Interface,
9393 typeof (EmptyInterface));
9394 Assert.AreEqual (typeof (EmptyInterface), tb.BaseType, "#C1");
9395 try {
9396 tb.CreateType ();
9397 Assert.Fail ("#C2");
9398 } catch (TypeLoadException ex) {
9399 // Could not load interface 't5' from assembly '...'
9400 // because the parent type is an interface
9401 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#C3");
9402 Assert.IsNull (ex.InnerException, "#C4");
9403 Assert.IsNotNull (ex.Message, "#C5");
9404 Assert.IsTrue (ex.Message.IndexOf (tb.Name) != -1, "#C6");
9405 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#C7");
9409 [Test]
9410 public void CreateType_Parent_DefaultCtorMissing ()
9412 TypeBuilder tb;
9414 tb = module.DefineType (genTypeName ());
9415 ConstructorBuilder cb = tb.DefineConstructor (
9416 MethodAttributes.Public,
9417 CallingConventions.Standard,
9418 new Type [] { typeof (string) });
9419 cb.GetILGenerator ().Emit (OpCodes.Ret);
9420 Type parent_type = tb.CreateType ();
9422 tb = module.DefineType (genTypeName (), TypeAttributes.Class,
9423 parent_type);
9424 try {
9425 tb.CreateType ();
9426 Assert.Fail ("#1");
9427 } catch (NotSupportedException ex) {
9428 // Parent does not have a default constructor.
9429 // The default constructor must be explicitly defined
9430 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
9431 Assert.IsNull (ex.InnerException, "#3");
9432 Assert.IsNotNull (ex.Message, "#4");
9436 [Test]
9437 public void CreateType_Parent_Null ()
9439 TypeBuilder tb;
9440 Type emitted_type;
9442 tb = module.DefineType (genTypeName (), TypeAttributes.Public, null);
9443 Assert.AreEqual (typeof (object), tb.BaseType, "#A1");
9444 emitted_type = tb.CreateType ();
9445 Assert.AreEqual (typeof (object), emitted_type.BaseType, "#A2");
9447 tb = module.DefineType (genTypeName (), TypeAttributes.Interface | TypeAttributes.Abstract, null);
9448 Assert.IsNull (tb.BaseType, "#B1");
9449 emitted_type = tb.CreateType ();
9450 Assert.IsNull (emitted_type.BaseType, "#B2");
9453 #if NET_2_0
9454 [Test]
9455 [Category ("NotWorking")]
9456 public void DefineGenericParameters_AlreadyDefined ()
9458 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9459 tb.DefineGenericParameters ("K");
9460 try {
9461 tb.DefineGenericParameters ("V");
9462 Assert.Fail ("#1");
9463 } catch (InvalidOperationException ex) {
9464 // Operation is not valid due to the current
9465 // state of the object
9466 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9467 Assert.IsNull (ex.InnerException, "#3");
9468 Assert.IsNotNull (ex.Message, "#4");
9472 [Test]
9473 [Category ("NotWorking")]
9474 public void DefineGenericParameters_Names_Empty ()
9476 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9478 try {
9479 tb.DefineGenericParameters (new string [0]);
9480 Assert.Fail ("#1");
9481 } catch (ArgumentException ex) {
9482 // Value does not fall within the expected range
9483 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9484 Assert.IsNull (ex.InnerException, "#3");
9485 Assert.IsNotNull (ex.Message, "#4");
9486 Assert.IsNull (ex.ParamName, "#5");
9490 [Test]
9491 [Category ("NotWorking")]
9492 public void DefineGenericParameters_Names_Null ()
9494 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9496 try {
9497 tb.DefineGenericParameters ((string []) null);
9498 Assert.Fail ("#A1");
9499 } catch (ArgumentNullException ex) {
9500 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9501 Assert.IsNull (ex.InnerException, "#A3");
9502 Assert.IsNotNull (ex.Message, "#A4");
9503 Assert.AreEqual ("names", ex.ParamName, "#A5");
9506 try {
9507 tb.DefineGenericParameters ("K", null, "V");
9508 Assert.Fail ("#B1");
9509 } catch (ArgumentNullException ex) {
9510 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9511 Assert.IsNull (ex.InnerException, "#B3");
9512 Assert.IsNotNull (ex.Message, "#B4");
9513 Assert.AreEqual ("names", ex.ParamName, "#B5");
9517 [Test]
9518 public void GenericType ()
9520 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9521 tb.DefineGenericParameters ("T");
9523 Assert.IsTrue (tb.IsGenericType, "#A1");
9524 Assert.IsTrue (tb.IsGenericTypeDefinition, "#A2");
9525 Assert.IsTrue (tb.ContainsGenericParameters, "#A3");
9526 Assert.IsFalse (tb.IsGenericParameter, "#A4");
9528 Type[] args = tb.GetGenericArguments ();
9529 Assert.IsFalse (args [0].IsGenericType, "#B1");
9530 Assert.IsFalse (args [0].IsGenericTypeDefinition, "#B2");
9531 Assert.IsTrue (args [0].ContainsGenericParameters, "#B3");
9532 Assert.IsTrue (args [0].IsGenericParameter, "#B4");
9535 [Test]
9536 public void MakeGenericType ()
9538 TypeBuilder tb;
9539 Type generic_type;
9541 tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9542 tb.DefineGenericParameters ("T");
9544 generic_type = tb.MakeGenericType (typeof (int));
9545 Assert.IsTrue (generic_type.IsGenericType, "#A1");
9546 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A2");
9547 Assert.IsFalse (generic_type.ContainsGenericParameters, "#A3");
9548 Assert.IsFalse (generic_type.IsGenericParameter, "#A4");
9550 generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9551 Assert.IsTrue (generic_type.IsGenericType, "#B1");
9552 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B2");
9553 Assert.IsTrue (generic_type.ContainsGenericParameters, "#B3");
9554 Assert.IsFalse (generic_type.IsGenericParameter, "#B4");
9556 tb = module.DefineType (genTypeName (), TypeAttributes.Interface
9557 | TypeAttributes.Abstract | TypeAttributes.Public);
9558 tb.DefineGenericParameters ("T");
9560 generic_type = tb.MakeGenericType (typeof (int));
9561 Assert.IsTrue (generic_type.IsGenericType, "#C1");
9562 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#C2");
9563 Assert.IsFalse (generic_type.ContainsGenericParameters, "#C3");
9564 Assert.IsFalse (generic_type.IsGenericParameter, "#C4");
9566 generic_type = tb.MakeGenericType (typeof (List<>).GetGenericArguments ());
9567 Assert.IsTrue (generic_type.IsGenericType, "#D1");
9568 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#D2");
9569 Assert.IsTrue (generic_type.ContainsGenericParameters, "#D3");
9570 Assert.IsFalse (generic_type.IsGenericParameter, "#D4");
9573 [Test]
9574 public void MakeGenericType_NoGenericTypeDefinition ()
9576 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9577 try {
9578 tb.MakeGenericType (typeof (int));
9579 Assert.Fail ("#1");
9580 } catch (InvalidOperationException ex) {
9581 // Operation is not valid due to the current
9582 // state of the object
9583 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9584 Assert.IsNull (ex.InnerException, "#3");
9585 Assert.IsNotNull (ex.Message, "#4");
9589 [Test]
9590 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9591 public void MakeGenericType_TypeArguments_Null_Mono ()
9593 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9594 tb.DefineGenericParameters ("K", "V");
9596 try {
9597 tb.MakeGenericType ((Type []) null);
9598 Assert.Fail ("#A1");
9599 } catch (ArgumentNullException ex) {
9600 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
9601 Assert.IsNull (ex.InnerException, "#A3");
9602 Assert.IsNotNull (ex.Message, "#A4");
9603 Assert.AreEqual ("typeArguments", ex.ParamName, "#A5");
9606 try {
9607 tb.MakeGenericType (typeof (string), (Type) null);
9608 Assert.Fail ("#B1");
9609 } catch (ArgumentNullException ex) {
9610 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
9611 Assert.IsNull (ex.InnerException, "#B3");
9612 Assert.IsNotNull (ex.Message, "#B4");
9613 Assert.AreEqual ("typeArguments", ex.ParamName, "#B5");
9617 [Test]
9618 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351169
9619 public void MakeGenericType_TypeArguments_Null_MS ()
9621 Type generic_type;
9622 Type [] type_args;
9624 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9625 tb.DefineGenericParameters ("K", "V");
9627 generic_type = tb.MakeGenericType ((Type []) null);
9628 Assert.IsNotNull (generic_type, "#A1");
9629 Assert.IsTrue (generic_type.IsGenericType, "#A2");
9630 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#A3");
9631 type_args = generic_type.GetGenericArguments ();
9632 Assert.IsNull (type_args, "#A4");
9634 generic_type = tb.MakeGenericType (typeof (string), (Type) null);
9635 Assert.IsNotNull (generic_type, "#B1");
9636 Assert.IsTrue (generic_type.IsGenericType, "#B2");
9637 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#B3");
9638 type_args = generic_type.GetGenericArguments ();
9639 Assert.IsNotNull (type_args, "#B4");
9640 Assert.AreEqual (2, type_args.Length, "#B5");
9641 Assert.AreEqual (typeof (string), type_args [0], "#B6");
9642 Assert.IsNull (type_args [1], "#B7");
9645 [Test]
9646 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9647 public void MakeGenericType_TypeArguments_Mismatch_Mono ()
9649 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9650 tb.DefineGenericParameters ("K", "V");
9651 try {
9652 tb.MakeGenericType (typeof (int));
9653 Assert.Fail ("#1");
9654 } catch (ArgumentException ex) {
9655 // The type or method has 2 generic prarameter(s)
9656 // but 1 generic argument(s) were provided. A
9657 // generic argument must be provided for each
9658 // generic parameter
9659 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
9660 Assert.IsNull (ex.InnerException, "#3");
9661 Assert.IsNotNull (ex.Message, "#4");
9662 Assert.AreEqual ("typeArguments", ex.ParamName, "#5");
9666 [Test]
9667 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351143
9668 public void MakeGenericType_TypeArguments_Mismatch_MS ()
9670 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9671 tb.DefineGenericParameters ("K", "V");
9673 Type generic_type = tb.MakeGenericType (typeof (int));
9674 Assert.IsTrue (generic_type.IsGenericType, "#1");
9675 Assert.IsFalse (generic_type.IsGenericTypeDefinition, "#2");
9676 Type [] type_args = generic_type.GetGenericArguments ();
9677 Assert.IsNotNull (type_args, "#3");
9678 Assert.AreEqual (1, type_args.Length, "#4");
9679 Assert.AreEqual (typeof (int), type_args [0], "#5");
9682 [Test]
9683 public void MakeArrayType_Complete ()
9685 // reference type
9686 TypeBuilder tb = module.DefineType (genTypeName (),
9687 TypeAttributes.Sealed | TypeAttributes.Serializable,
9688 typeof (ContextBoundObject));
9689 Type emittedType = tb.CreateType ();
9690 Type arrayType = tb.MakeArrayType ();
9691 Assert.IsTrue (arrayType.IsArray, "#A1");
9692 Assert.IsTrue (arrayType.HasElementType, "#A2");
9693 Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9694 Assert.IsFalse (tb.HasElementType, "#A4");
9695 Assert.IsTrue (tb.IsCreated (), "#A5");
9697 // value type
9698 tb = module.DefineType (genTypeName (),
9699 TypeAttributes.Sealed | TypeAttributes.Serializable,
9700 typeof (ValueType));
9701 emittedType = tb.CreateType ();
9702 arrayType = tb.MakeArrayType ();
9703 Assert.IsTrue (arrayType.IsArray, "#B1");
9704 Assert.IsTrue (arrayType.HasElementType, "#B2");
9705 Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9706 Assert.IsFalse (tb.HasElementType, "#B4");
9707 Assert.IsTrue (tb.IsCreated (), "#B5");
9709 tb = module.DefineType (genTypeName (),
9710 TypeAttributes.Sealed | TypeAttributes.Serializable,
9711 typeof (Enum));
9712 tb.DefineField ("value__", typeof (int), FieldAttributes.SpecialName |
9713 FieldAttributes.Private | FieldAttributes.RTSpecialName);
9714 emittedType = tb.CreateType ();
9715 arrayType = tb.MakeArrayType ();
9716 Assert.IsTrue (arrayType.IsArray, "#C1");
9717 Assert.IsTrue (arrayType.HasElementType, "#C2");
9718 Assert.AreEqual (tb, arrayType.GetElementType (), "#C3");
9719 Assert.IsFalse (tb.HasElementType, "#C4");
9720 Assert.IsTrue (tb.IsCreated (), "#C5");
9723 [Test] // bug #82015
9724 public void MakeArrayType_Incomplete ()
9726 // reference type
9727 TypeBuilder tb = module.DefineType (genTypeName (),
9728 TypeAttributes.Sealed | TypeAttributes.Serializable,
9729 typeof (ContextBoundObject));
9730 Type arrayType = tb.MakeArrayType ();
9731 Assert.IsTrue (arrayType.IsArray, "#A1");
9732 Assert.IsTrue (arrayType.HasElementType, "#A2");
9733 Assert.AreEqual (tb, arrayType.GetElementType (), "#A3");
9734 Assert.IsFalse (tb.HasElementType, "#A4");
9735 Assert.IsFalse (tb.IsCreated (), "#A5");
9737 // value type
9738 tb = module.DefineType (genTypeName (),
9739 TypeAttributes.Sealed | TypeAttributes.Serializable,
9740 typeof (ValueType));
9741 arrayType = tb.MakeArrayType ();
9742 Assert.IsTrue (arrayType.IsArray, "#B1");
9743 Assert.IsTrue (arrayType.HasElementType, "#B2");
9744 Assert.AreEqual (tb, arrayType.GetElementType (), "#B3");
9745 Assert.IsFalse (tb.HasElementType, "#B4");
9746 Assert.IsFalse (tb.IsCreated (), "#B5");
9748 // enum
9749 tb = module.DefineType (genTypeName (),
9750 TypeAttributes.Sealed | TypeAttributes.Serializable,
9751 typeof (Enum));
9752 arrayType = tb.MakeArrayType ();
9753 Assert.IsTrue (arrayType.IsArray, "#C1");
9754 Assert.IsTrue (arrayType.HasElementType, "#C2");
9755 Assert.IsFalse (tb.HasElementType, "#C3");
9756 Assert.IsFalse (tb.IsCreated (), "#C4");
9759 [Test]
9760 public void GetCustomAttributes_InflatedType ()
9762 TypeBuilder tb = module.DefineType (genTypeName ());
9763 tb.DefineGenericParameters (new string[] { "FOO" });
9765 ConstructorInfo guidCtor = typeof (GuidAttribute).GetConstructor (
9766 new Type [] { typeof (string) });
9768 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (guidCtor,
9769 new object [] { Guid.NewGuid ().ToString ("D") }, new FieldInfo [0], new object [0]);
9771 tb.SetCustomAttribute (caBuilder);
9772 Type t = tb.CreateType ();
9774 Type inflated = t.MakeGenericType (new Type [] { typeof (int) });
9776 Assert.AreEqual (1, inflated.GetCustomAttributes (false).Length);
9779 [Test]
9780 public void GetField ()
9782 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
9783 GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");
9785 ConstructorBuilder cb = tb.DefineDefaultConstructor (MethodAttributes.Public);
9787 FieldBuilder fb1 = tb.DefineField ("field1", typeParams [0], FieldAttributes.Public);
9789 Type t = tb.MakeGenericType (typeof (int));
9791 // Chect that calling MakeArrayType () does not initialize the class
9792 // (bug #351172)
9793 t.MakeArrayType ();
9795 // Check that the instantiation of a type builder contains live data
9796 TypeBuilder.GetField (t, fb1);
9797 FieldBuilder fb2 = tb.DefineField ("field2", typeParams [0], FieldAttributes.Public);
9798 FieldInfo fi2 = TypeBuilder.GetField (t, fb1);
9800 MethodBuilder mb = tb.DefineMethod ("get_int", MethodAttributes.Public|MethodAttributes.Static, typeof (int), Type.EmptyTypes);
9801 ILGenerator ilgen = mb.GetILGenerator ();
9802 ilgen.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t, cb));
9803 ilgen.Emit (OpCodes.Dup);
9804 ilgen.Emit (OpCodes.Ldc_I4, 42);
9805 ilgen.Emit (OpCodes.Stfld, fi2);
9806 ilgen.Emit (OpCodes.Ldfld, fi2);
9807 ilgen.Emit (OpCodes.Ret);
9809 // Check GetField on a type instantiated with type parameters
9810 Type t3 = tb.MakeGenericType (typeParams [0]);
9811 FieldBuilder fb3 = tb.DefineField ("field3", typeParams [0], FieldAttributes.Public);
9812 FieldInfo fi3 = TypeBuilder.GetField (t3, fb3);
9814 MethodBuilder mb3 = tb.DefineMethod ("get_T", MethodAttributes.Public|MethodAttributes.Static, typeParams [0], Type.EmptyTypes);
9815 ILGenerator ilgen3 = mb3.GetILGenerator ();
9816 ilgen3.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (t3, cb));
9817 ilgen3.Emit (OpCodes.Ldfld, fi3);
9818 ilgen3.Emit (OpCodes.Ret);
9820 Type created = tb.CreateType ();
9822 Type inst = created.MakeGenericType (typeof (object));
9824 Assert.AreEqual (42, inst.GetMethod ("get_int").Invoke (null, null));
9826 Assert.AreEqual (null, inst.GetMethod ("get_T").Invoke (null, null));
9829 [Test] //bug #354047
9830 public void CreatedTypeInstantiationOverTypeBuilderArgsIsNotAGenericTypeDefinition ()
9832 TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9833 GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9834 Type t = tb.CreateType ();
9836 Type inst = tb.MakeGenericType (typeParams [0]);
9837 Assert.IsFalse (inst.IsGenericTypeDefinition, "#1 create type instance is not a generic type definition");
9840 [Test] //bug #354047
9841 public void CreatedTypeAndTypeBuilderOwnTheirGenericArguments ()
9843 TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9844 GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9845 Type t = tb.CreateType ();
9847 Assert.IsTrue (tb.GetGenericArguments()[0].DeclaringType == tb, "#1 TypeBuilder owns its arguments");
9848 Assert.IsTrue (t.GetGenericArguments()[0].DeclaringType == t, "#1 create type owns its arguments");
9851 [Test] //bug #354047
9852 public void CreatedTypeAndTypeBuilderDontShareGenericArguments ()
9854 TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9855 GenericTypeParameterBuilder[] typeParams = tb.DefineGenericParameters (new String[] { "T" });
9856 Type t = tb.CreateType ();
9858 Assert.IsTrue (tb.GetGenericArguments()[0] != t.GetGenericArguments()[0], "#1 TypeBuilder and create type arguments are diferent");
9861 [Test] //bug #399047
9862 public void FieldOnTypeBuilderInstDontInflateWhenEncoded () {
9863 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9865 module = assembly.DefineDynamicModule ("Instance.exe");
9867 TypeBuilder G = module.DefineType ("G", TypeAttributes.Public);
9868 Type T = G.DefineGenericParameters ("T") [0];
9869 ConstructorInfo ctor = G.DefineDefaultConstructor (MethodAttributes.Public);
9870 Type GObj = G.MakeGenericType (new Type [] { T });
9872 FieldBuilder F = G.DefineField ("F", T, FieldAttributes.Public);
9874 TypeBuilder P = module.DefineType ("P", TypeAttributes.Public);
9876 MethodBuilder Test = P.DefineMethod ("Test", MethodAttributes.Public);
9877 Type TATest = Test.DefineGenericParameters ("TA") [0];
9879 Type TestGObj = G.MakeGenericType (new Type [] { TATest });
9881 ILGenerator il = Test.GetILGenerator ();
9883 il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (TestGObj, ctor));
9884 il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (TestGObj, F));
9885 il.Emit (OpCodes.Pop);
9887 il.Emit (OpCodes.Ret);
9890 MethodBuilder main = P.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static);
9892 ILGenerator il = main.GetILGenerator ();
9893 il.Emit(OpCodes.Newobj, P.DefineDefaultConstructor (MethodAttributes.Public));
9894 il.Emit(OpCodes.Call, Test.MakeGenericMethod (typeof (int)));
9895 il.Emit (OpCodes.Ret);
9898 assembly.SetEntryPoint (main);
9899 G.CreateType ();
9900 P.CreateType ();
9902 assembly.Save ("Instance.exe");
9903 Thread.GetDomain ().ExecuteAssembly(Path.GetTempPath () + Path.DirectorySeparatorChar + "Instance.exe");
9906 [Test]
9907 public void FieldWithInitializedDataWorksWithCompilerRuntimeHelpers ()
9909 TypeBuilder tb = module.DefineType ("Type1", TypeAttributes.Public);
9910 FieldBuilder fb = tb.DefineInitializedData ("Foo", new byte [] {1,2,3,4}, FieldAttributes.Static|FieldAttributes.Public);
9911 tb.CreateType ();
9913 assembly = Thread.GetDomain ().DefineDynamicAssembly (new AssemblyName (ASSEMBLY_NAME+"2"), AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
9914 module = assembly.DefineDynamicModule ("Instance.exe");
9916 TypeBuilder tb2 = module.DefineType ("Type2", TypeAttributes.Public);
9917 MethodBuilder mb = tb2.DefineMethod ("Test", MethodAttributes.Public | MethodAttributes.Static, typeof (object), new Type [0]);
9918 ILGenerator il = mb.GetILGenerator ();
9920 il.Emit (OpCodes.Ldc_I4_1);
9921 il.Emit (OpCodes.Newarr, typeof (int));
9922 il.Emit (OpCodes.Dup);
9923 il.Emit (OpCodes.Ldtoken, fb);
9924 il.Emit (OpCodes.Call, typeof (RuntimeHelpers).GetMethod ("InitializeArray"));
9925 il.Emit (OpCodes.Ret);
9927 Type t = tb2.CreateType ();
9928 int[] res = (int[])t.GetMethod ("Test").Invoke (null, new object[0]);
9929 //Console.WriteLine (res[0]);
9931 #endif
9933 public interface IDelegateFactory
9935 Delegate Create (Delegate del);
9938 [Test]
9939 public void CreateType_Ctor_NoBody ()
9941 TypeBuilder tb = module.DefineType (genTypeName ());
9942 tb.DefineConstructor (MethodAttributes.Public,
9943 CallingConventions.Standard,
9944 new Type [] { typeof (string) });
9945 try {
9946 tb.CreateType ();
9947 Assert.Fail ("#1");
9948 } catch (InvalidOperationException ex) {
9949 // Method '.ctor' does not have a method body
9950 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
9951 Assert.IsNull (ex.InnerException, "#3");
9952 Assert.IsNotNull (ex.Message, "#4");
9953 Assert.IsTrue (ex.Message.IndexOf (".ctor") != -1, "#5");
9957 [Test] //bug #361689
9958 public void CreateTypeFailsWithInvalidMethodOverride ()
9960 TypeBuilder tb = module.DefineType ("TheType", TypeAttributes.Public, typeof (object), new Type [] {typeof (IDelegateFactory)});
9962 MethodBuilder mc = tb.DefineMethod ("Create", MethodAttributes.Public, typeof (Delegate), new Type[] {typeof (Delegate)});
9963 ILGenerator gen = mc.GetILGenerator ();
9964 gen.Emit (OpCodes.Ldarg_0);
9965 gen.Emit (OpCodes.Ret);
9966 tb.DefineMethodOverride (mc, typeof (IDelegateFactory).GetMethod ("Create"));
9967 try {
9968 tb.CreateType ();
9969 Assert.Fail ("#1 create type did not throw TypeLoadException");
9970 } catch (TypeLoadException) {
9975 [Test] //bug #349194
9976 public void IsAssignableToWorksWithInterfacesOnParent ()
9978 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9979 TypeBuilder tb2 = module.DefineType (genTypeName (), TypeAttributes.Public, tb);
9981 Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb));
9982 Type t = tb.CreateType ();
9983 Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb));
9984 Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t));
9987 Assert.IsFalse (typeof (EmptyInterface).IsAssignableFrom (tb2));
9988 Type t2 = tb2.CreateType ();
9989 Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (tb2));
9990 Assert.IsTrue (typeof (EmptyInterface).IsAssignableFrom (t2));
9993 #if NET_2_0
9995 [Test] //bug #430508
9996 public void MakeGenericTypeRespectBaseType ()
9998 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (EmptyIfaceImpl));
9999 EnumBuilder eb = module.DefineEnum (genTypeName (), TypeAttributes.Public, typeof (int));
10001 MethodBuilder mb = tb.DefineMethod ("Test",
10002 MethodAttributes.Public,
10003 typeof (Tuple<,>).MakeGenericType (typeof (int), eb),
10004 new Type [0]);
10005 ILGenerator il = mb.GetILGenerator();
10006 il.Emit (OpCodes.Ldnull);
10007 il.Emit (OpCodes.Ret);
10009 Type e = eb.CreateType ();
10010 Type c = tb.CreateType ();
10012 Assert.AreEqual (c.GetMethod ("Test").ReturnType.GetGenericArguments ()[1], e, "#1");
10015 [Test]
10016 public void GetCustomAttrOnFieldOfInflatedType ()
10018 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
10019 tb.DefineGenericParameters ("T");
10021 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10022 typeof (SimpleTestAttribute).GetConstructors ()[0],
10023 new object [0]);
10025 FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
10026 field.SetCustomAttribute (caBuilder);
10028 Type t = tb.CreateType ();
10030 FieldInfo fi = t.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10031 object[] cattrs = fi.GetCustomAttributes (false);
10032 Assert.AreEqual (1, cattrs.Length);
10034 fi = t.MakeGenericType (typeof (int)).GetFields (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10035 cattrs = fi.GetCustomAttributes (false);
10036 Assert.AreEqual (1, cattrs.Length);
10039 [Test]
10040 public void GetCustomAttrOnPropertyOfInflatedType ()
10042 TypeBuilder tb = module.DefineType (genTypeName ());
10043 tb.DefineGenericParameters ("T");
10045 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10046 typeof (SimpleTestAttribute).GetConstructors ()[0],
10047 new object [0]);
10049 PropertyBuilder property = DefineStringProperty (tb, "Name", "name", MethodAttributes.Public);
10050 property.SetCustomAttribute (caBuilder);
10052 Type t = tb.CreateType ();
10054 PropertyInfo pi = t.GetProperties ()[0];
10055 object[] cattrs = pi.GetCustomAttributes (false);
10056 Assert.AreEqual (1, cattrs.Length);
10058 pi = t.MakeGenericType (typeof (int)).GetProperties ()[0];
10059 cattrs = pi.GetCustomAttributes (false);
10060 Assert.AreEqual (1, cattrs.Length);
10063 [Test]
10064 public void GetCustomAttrOnEventOfInflatedType ()
10066 TypeBuilder tb = module.DefineType (genTypeName ());
10067 tb.DefineGenericParameters ("T");
10069 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10070 typeof (SimpleTestAttribute).GetConstructors ()[0],
10071 new object [0]);
10073 EventBuilder evt = tb.DefineEvent ("OI", 0, typeof (int));
10074 evt.SetCustomAttribute (caBuilder);
10076 Type t = tb.CreateType ();
10078 EventInfo ei = t.GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10079 object[] cattrs = ei.GetCustomAttributes (false);
10080 Assert.AreEqual (1, cattrs.Length);
10082 ei = t.MakeGenericType (typeof (int)).GetEvents (BindingFlags.NonPublic | BindingFlags.Instance)[0];
10083 cattrs = ei.GetCustomAttributes (false);
10084 Assert.AreEqual (1, cattrs.Length);
10087 public void TestDoubleInitializationOfMonoGenericClass () //bug #400643
10089 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public);
10090 tb.DefineGenericParameters ("T");
10092 CustomAttributeBuilder caBuilder = new CustomAttributeBuilder (
10093 typeof (SimpleTestAttribute).GetConstructors ()[0],
10094 new object [0]);
10096 FieldBuilder field = tb.DefineField ("OI", typeof (int), 0);
10097 field.SetCustomAttribute (caBuilder);
10100 tb.MakeGenericType (typeof (int)).GetMethods ();
10101 tb.MakeGenericType (typeof (double)).GetMethods ();
10103 Type t = tb.CreateType ();
10105 t.MakeGenericType (typeof (int)).GetMethods ();
10106 t.MakeGenericType (typeof (double)).GetMethods ();
10109 [Test]
10110 public void TestGenericFieldAccess () // bug #467415
10112 AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
10113 AppDomain domain = AppDomain.CurrentDomain;
10114 AssemblyBuilder demoAssembly =
10115 domain.DefineDynamicAssembly(asmName,
10116 AssemblyBuilderAccess.RunAndSave);
10118 // Define the module that contains the code. For an
10119 // assembly with one module, the module name is the
10120 // assembly name plus a file extension.
10121 ModuleBuilder demoModule =
10122 demoAssembly.DefineDynamicModule(asmName.Name,
10123 asmName.Name+".dll");
10125 TypeBuilder demoType =
10126 demoModule.DefineType("DemoType", TypeAttributes.Public);
10128 MethodBuilder factory =
10129 demoType.DefineMethod("Factory",
10130 MethodAttributes.Public | MethodAttributes.Static);
10132 string[] typeParameterNames = {"T"};
10133 GenericTypeParameterBuilder[] typeParameters =
10134 factory.DefineGenericParameters(typeParameterNames);
10136 GenericTypeParameterBuilder T = typeParameters[0];
10138 Type[] parms = {};
10139 factory.SetParameters(parms);
10141 factory.SetReturnType(T);
10143 ILGenerator ilgen = factory.GetILGenerator();
10145 Type G = typeof(Gen<>);
10146 Type GT = G.MakeGenericType (T);
10147 FieldInfo GF = G.GetField("field");
10148 FieldInfo GTF = TypeBuilder.GetField(GT, GF);
10150 ilgen.Emit(OpCodes.Ldsfld, GTF);
10151 ilgen.Emit(OpCodes.Ret);
10153 // Complete the type.
10154 Type dt = demoType.CreateType();
10155 // Save the assembly, so it can be examined with Ildasm.exe.
10156 //demoAssembly.Save(asmName.Name+".dll");
10158 MethodInfo m = dt.GetMethod("Factory");
10159 MethodInfo bound = m.MakeGenericMethod(typeof(int));
10161 // Display a string representing the bound method.
10162 //Console.WriteLine(bound);
10164 object[] parameters = {};
10165 int result = (int)(bound.Invoke(null, parameters));
10167 Assert.AreEqual (0, result, "#1");
10169 #endif
10171 static MethodInfo GetMethodByName (MethodInfo [] methods, string name)
10173 foreach (MethodInfo mi in methods)
10174 if (mi.Name == name)
10175 return mi;
10176 return null;
10179 void CreateMembers (TypeBuilder tb, string suffix, bool defineCtors)
10181 ConstructorBuilder cb;
10182 MethodBuilder mb;
10183 PropertyBuilder pb;
10184 EventBuilder eb;
10185 ILGenerator ilgen;
10187 if (defineCtors) {
10189 // instance constructors
10191 cb = tb.DefineConstructor (MethodAttributes.Private,
10192 CallingConventions.Standard,
10193 new Type [] { typeof (int), typeof (int) });
10194 cb.GetILGenerator ().Emit (OpCodes.Ret);
10196 cb = tb.DefineConstructor (MethodAttributes.Family,
10197 CallingConventions.Standard,
10198 new Type [] { typeof (string) });
10199 cb.GetILGenerator ().Emit (OpCodes.Ret);
10201 cb = tb.DefineConstructor (MethodAttributes.FamANDAssem,
10202 CallingConventions.Standard,
10203 new Type [] { typeof (string), typeof (string) });
10204 cb.GetILGenerator ().Emit (OpCodes.Ret);
10206 cb = tb.DefineConstructor (MethodAttributes.FamORAssem,
10207 CallingConventions.Standard,
10208 new Type [] { typeof (int) });
10209 cb.GetILGenerator ().Emit (OpCodes.Ret);
10211 cb = tb.DefineConstructor (MethodAttributes.Public,
10212 CallingConventions.Standard,
10213 new Type [] { typeof (int), typeof (bool) });
10214 cb.GetILGenerator ().Emit (OpCodes.Ret);
10216 cb = tb.DefineConstructor (MethodAttributes.Assembly,
10217 CallingConventions.Standard,
10218 new Type [] { typeof (string), typeof (int) });
10219 cb.GetILGenerator ().Emit (OpCodes.Ret);
10222 // static constructors
10225 cb = tb.DefineConstructor (MethodAttributes.Private |
10226 MethodAttributes.Static,
10227 CallingConventions.Standard,
10228 Type.EmptyTypes);
10229 cb.GetILGenerator ().Emit (OpCodes.Ret);
10233 // instance methods
10236 mb = tb.DefineMethod ("GetPrivateInstance" + suffix,
10237 MethodAttributes.Private, typeof (void),
10238 Type.EmptyTypes);
10239 mb.GetILGenerator ().Emit (OpCodes.Ret);
10241 mb = tb.DefineMethod ("GetFamilyInstance" + suffix,
10242 MethodAttributes.Family, typeof (void),
10243 Type.EmptyTypes);
10244 mb.GetILGenerator ().Emit (OpCodes.Ret);
10246 mb = tb.DefineMethod ("GetFamANDAssemInstance" + suffix,
10247 MethodAttributes.FamANDAssem, typeof (void),
10248 Type.EmptyTypes);
10249 mb.GetILGenerator ().Emit (OpCodes.Ret);
10251 mb = tb.DefineMethod ("GetFamORAssemInstance" + suffix,
10252 MethodAttributes.FamORAssem, typeof (void),
10253 Type.EmptyTypes);
10254 mb.GetILGenerator ().Emit (OpCodes.Ret);
10256 mb = tb.DefineMethod ("GetPublicInstance" + suffix,
10257 MethodAttributes.Public, typeof (void),
10258 Type.EmptyTypes);
10259 mb.GetILGenerator ().Emit (OpCodes.Ret);
10261 mb = tb.DefineMethod ("GetAssemblyInstance" + suffix,
10262 MethodAttributes.Assembly, typeof (void),
10263 Type.EmptyTypes);
10264 mb.GetILGenerator ().Emit (OpCodes.Ret);
10267 // static methods
10270 mb = tb.DefineMethod ("GetPrivateStatic" + suffix,
10271 MethodAttributes.Private | MethodAttributes.Static,
10272 typeof (void), Type.EmptyTypes);
10273 mb.GetILGenerator ().Emit (OpCodes.Ret);
10275 mb = tb.DefineMethod ("GetFamilyStatic" + suffix,
10276 MethodAttributes.Family | MethodAttributes.Static,
10277 typeof (void), Type.EmptyTypes);
10278 mb.GetILGenerator ().Emit (OpCodes.Ret);
10280 mb = tb.DefineMethod ("GetFamANDAssemStatic" + suffix,
10281 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10282 typeof (void), Type.EmptyTypes);
10283 mb.GetILGenerator ().Emit (OpCodes.Ret);
10285 mb = tb.DefineMethod ("GetFamORAssemStatic" + suffix,
10286 MethodAttributes.FamORAssem | MethodAttributes.Static,
10287 typeof (void), Type.EmptyTypes);
10288 mb.GetILGenerator ().Emit (OpCodes.Ret);
10290 mb = tb.DefineMethod ("GetPublicStatic" + suffix,
10291 MethodAttributes.Public | MethodAttributes.Static,
10292 typeof (void), Type.EmptyTypes);
10293 mb.GetILGenerator ().Emit (OpCodes.Ret);
10295 mb = tb.DefineMethod ("GetAssemblyStatic" + suffix,
10296 MethodAttributes.Assembly | MethodAttributes.Static,
10297 typeof (void), Type.EmptyTypes);
10298 mb.GetILGenerator ().Emit (OpCodes.Ret);
10301 // instance fields
10304 tb.DefineField ("privateInstance" + suffix,
10305 typeof (string), FieldAttributes.Private);
10306 tb.DefineField ("familyInstance" + suffix,
10307 typeof (string), FieldAttributes.Family);
10308 tb.DefineField ("famANDAssemInstance" + suffix,
10309 typeof (string), FieldAttributes.FamANDAssem);
10310 tb.DefineField ("famORAssemInstance" + suffix,
10311 typeof (string), FieldAttributes.FamORAssem);
10312 tb.DefineField ("publicInstance" + suffix,
10313 typeof (string), FieldAttributes.Public);
10314 tb.DefineField ("assemblyInstance" + suffix,
10315 typeof (string), FieldAttributes.Assembly);
10318 // static fields
10321 tb.DefineField ("privateStatic" + suffix,
10322 typeof (string), FieldAttributes.Private |
10323 FieldAttributes.Static);
10324 tb.DefineField ("familyStatic" + suffix,
10325 typeof (string), FieldAttributes.Family |
10326 FieldAttributes.Static);
10327 tb.DefineField ("famANDAssemStatic" + suffix,
10328 typeof (string), FieldAttributes.FamANDAssem |
10329 FieldAttributes.Static);
10330 tb.DefineField ("famORAssemStatic" + suffix,
10331 typeof (string), FieldAttributes.FamORAssem |
10332 FieldAttributes.Static);
10333 tb.DefineField ("publicStatic" + suffix,
10334 typeof (string), FieldAttributes.Public |
10335 FieldAttributes.Static);
10336 tb.DefineField ("assemblyStatic" + suffix,
10337 typeof (string), FieldAttributes.Assembly |
10338 FieldAttributes.Static);
10341 // instance properties
10344 pb = tb.DefineProperty ("PrivateInstance" + suffix,
10345 PropertyAttributes.None, typeof (string),
10346 Type.EmptyTypes);
10347 mb = tb.DefineMethod ("get_PrivateInstance" + suffix,
10348 MethodAttributes.Private, typeof (string),
10349 Type.EmptyTypes);
10350 ilgen = mb.GetILGenerator ();
10351 ilgen.Emit (OpCodes.Ldnull);
10352 ilgen.Emit (OpCodes.Ret);
10353 pb.SetGetMethod (mb);
10355 pb = tb.DefineProperty ("FamilyInstance" + suffix,
10356 PropertyAttributes.None, typeof (string),
10357 Type.EmptyTypes);
10358 mb = tb.DefineMethod ("get_FamilyInstance" + suffix,
10359 MethodAttributes.Family, typeof (string),
10360 Type.EmptyTypes);
10361 ilgen = mb.GetILGenerator ();
10362 ilgen.Emit (OpCodes.Ldnull);
10363 ilgen.Emit (OpCodes.Ret);
10364 pb.SetGetMethod (mb);
10366 pb = tb.DefineProperty ("FamANDAssemInstance" + suffix,
10367 PropertyAttributes.None, typeof (string),
10368 Type.EmptyTypes);
10369 mb = tb.DefineMethod ("get_FamANDAssemInstance" + suffix,
10370 MethodAttributes.FamANDAssem, typeof (string),
10371 Type.EmptyTypes);
10372 ilgen = mb.GetILGenerator ();
10373 ilgen.Emit (OpCodes.Ldnull);
10374 ilgen.Emit (OpCodes.Ret);
10375 pb.SetGetMethod (mb);
10377 pb = tb.DefineProperty ("FamORAssemInstance" + suffix,
10378 PropertyAttributes.None, typeof (string),
10379 Type.EmptyTypes);
10380 mb = tb.DefineMethod ("get_FamORAssemInstance" + suffix,
10381 MethodAttributes.FamORAssem, typeof (string),
10382 Type.EmptyTypes);
10383 ilgen = mb.GetILGenerator ();
10384 ilgen.Emit (OpCodes.Ldnull);
10385 ilgen.Emit (OpCodes.Ret);
10386 pb.SetGetMethod (mb);
10388 pb = tb.DefineProperty ("PublicInstance" + suffix,
10389 PropertyAttributes.None, typeof (string),
10390 Type.EmptyTypes);
10391 mb = tb.DefineMethod ("get_PublicInstance" + suffix,
10392 MethodAttributes.Public, typeof (string),
10393 Type.EmptyTypes);
10394 ilgen = mb.GetILGenerator ();
10395 ilgen.Emit (OpCodes.Ldnull);
10396 ilgen.Emit (OpCodes.Ret);
10397 pb.SetGetMethod (mb);
10399 pb = tb.DefineProperty ("AssemblyInstance" + suffix,
10400 PropertyAttributes.None, typeof (string),
10401 Type.EmptyTypes);
10402 mb = tb.DefineMethod ("get_AssemblyInstance" + suffix,
10403 MethodAttributes.Assembly, typeof (string),
10404 Type.EmptyTypes);
10405 ilgen = mb.GetILGenerator ();
10406 ilgen.Emit (OpCodes.Ldnull);
10407 ilgen.Emit (OpCodes.Ret);
10408 pb.SetGetMethod (mb);
10411 // static properties
10414 pb = tb.DefineProperty ("PrivateStatic" + suffix,
10415 PropertyAttributes.None, typeof (string),
10416 Type.EmptyTypes);
10417 mb = tb.DefineMethod ("get_PrivateStatic" + suffix,
10418 MethodAttributes.Private | MethodAttributes.Static,
10419 typeof (string), Type.EmptyTypes);
10420 ilgen = mb.GetILGenerator ();
10421 ilgen.Emit (OpCodes.Ldnull);
10422 ilgen.Emit (OpCodes.Ret);
10423 pb.SetGetMethod (mb);
10425 pb = tb.DefineProperty ("FamilyStatic" + suffix,
10426 PropertyAttributes.None, typeof (string),
10427 Type.EmptyTypes);
10428 mb = tb.DefineMethod ("get_FamilyStatic" + suffix,
10429 MethodAttributes.Family | MethodAttributes.Static,
10430 typeof (string), Type.EmptyTypes);
10431 ilgen = mb.GetILGenerator ();
10432 ilgen.Emit (OpCodes.Ldnull);
10433 ilgen.Emit (OpCodes.Ret);
10434 pb.SetGetMethod (mb);
10436 pb = tb.DefineProperty ("FamANDAssemStatic" + suffix,
10437 PropertyAttributes.None, typeof (string),
10438 Type.EmptyTypes);
10439 mb = tb.DefineMethod ("get_FamANDAssemStatic" + suffix,
10440 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10441 typeof (string), Type.EmptyTypes);
10442 ilgen = mb.GetILGenerator ();
10443 ilgen.Emit (OpCodes.Ldnull);
10444 ilgen.Emit (OpCodes.Ret);
10445 pb.SetGetMethod (mb);
10447 pb = tb.DefineProperty ("FamORAssemStatic" + suffix,
10448 PropertyAttributes.None, typeof (string),
10449 Type.EmptyTypes);
10450 mb = tb.DefineMethod ("get_FamORAssemStatic" + suffix,
10451 MethodAttributes.FamORAssem | MethodAttributes.Static,
10452 typeof (string), Type.EmptyTypes);
10453 ilgen = mb.GetILGenerator ();
10454 ilgen.Emit (OpCodes.Ldnull);
10455 ilgen.Emit (OpCodes.Ret);
10456 pb.SetGetMethod (mb);
10458 pb = tb.DefineProperty ("PublicStatic" + suffix,
10459 PropertyAttributes.None, typeof (string),
10460 Type.EmptyTypes);
10461 mb = tb.DefineMethod ("get_PublicStatic" + suffix,
10462 MethodAttributes.Public | MethodAttributes.Static,
10463 typeof (string), Type.EmptyTypes);
10464 ilgen = mb.GetILGenerator ();
10465 ilgen.Emit (OpCodes.Ldnull);
10466 ilgen.Emit (OpCodes.Ret);
10467 pb.SetGetMethod (mb);
10469 pb = tb.DefineProperty ("AssemblyStatic" + suffix,
10470 PropertyAttributes.None, typeof (string),
10471 Type.EmptyTypes);
10472 mb = tb.DefineMethod ("get_AssemblyStatic" + suffix,
10473 MethodAttributes.Assembly | MethodAttributes.Static,
10474 typeof (string), Type.EmptyTypes);
10475 ilgen = mb.GetILGenerator ();
10476 ilgen.Emit (OpCodes.Ldnull);
10477 ilgen.Emit (OpCodes.Ret);
10478 pb.SetGetMethod (mb);
10481 // instance events
10484 eb = tb.DefineEvent ("OnPrivateInstance" + suffix,
10485 EventAttributes.None, typeof (EventHandler));
10486 mb = tb.DefineMethod ("add_OnPrivateInstance" + suffix,
10487 MethodAttributes.Private, typeof (void),
10488 Type.EmptyTypes);
10489 mb.GetILGenerator ().Emit (OpCodes.Ret);
10490 eb.SetAddOnMethod (mb);
10492 eb = tb.DefineEvent ("OnFamilyInstance" + suffix,
10493 EventAttributes.None, typeof (EventHandler));
10494 mb = tb.DefineMethod ("add_OnFamilyInstance" + suffix,
10495 MethodAttributes.Family, typeof (void),
10496 Type.EmptyTypes);
10497 mb.GetILGenerator ().Emit (OpCodes.Ret);
10498 eb.SetAddOnMethod (mb);
10500 eb = tb.DefineEvent ("OnFamANDAssemInstance" + suffix,
10501 EventAttributes.None, typeof (EventHandler));
10502 mb = tb.DefineMethod ("add_OnFamANDAssemInstance" + suffix,
10503 MethodAttributes.FamANDAssem, typeof (void),
10504 Type.EmptyTypes);
10505 mb.GetILGenerator ().Emit (OpCodes.Ret);
10506 eb.SetAddOnMethod (mb);
10508 eb = tb.DefineEvent ("OnFamORAssemInstance" + suffix,
10509 EventAttributes.None, typeof (EventHandler));
10510 mb = tb.DefineMethod ("add_OnFamORAssemInstance" + suffix,
10511 MethodAttributes.FamORAssem, typeof (void),
10512 Type.EmptyTypes);
10513 mb.GetILGenerator ().Emit (OpCodes.Ret);
10514 eb.SetAddOnMethod (mb);
10516 eb = tb.DefineEvent ("OnPublicInstance" + suffix,
10517 EventAttributes.None, typeof (EventHandler));
10518 mb = tb.DefineMethod ("add_OnPublicInstance" + suffix,
10519 MethodAttributes.Public, typeof (void),
10520 Type.EmptyTypes);
10521 mb.GetILGenerator ().Emit (OpCodes.Ret);
10522 eb.SetAddOnMethod (mb);
10524 eb = tb.DefineEvent ("OnAssemblyInstance" + suffix,
10525 EventAttributes.None, typeof (EventHandler));
10526 mb = tb.DefineMethod ("add_OnAssemblyInstance" + suffix,
10527 MethodAttributes.Family, typeof (void),
10528 Type.EmptyTypes);
10529 mb.GetILGenerator ().Emit (OpCodes.Ret);
10530 eb.SetAddOnMethod (mb);
10533 // static events
10536 eb = tb.DefineEvent ("OnPrivateStatic" + suffix,
10537 EventAttributes.None, typeof (EventHandler));
10538 mb = tb.DefineMethod ("add_OnPrivateStatic" + suffix,
10539 MethodAttributes.Private | MethodAttributes.Static,
10540 typeof (void), Type.EmptyTypes);
10541 mb.GetILGenerator ().Emit (OpCodes.Ret);
10542 eb.SetAddOnMethod (mb);
10544 eb = tb.DefineEvent ("OnFamilyStatic" + suffix,
10545 EventAttributes.None, typeof (EventHandler));
10546 mb = tb.DefineMethod ("add_OnFamilyStatic" + suffix,
10547 MethodAttributes.Family | MethodAttributes.Static,
10548 typeof (void), Type.EmptyTypes);
10549 mb.GetILGenerator ().Emit (OpCodes.Ret);
10550 eb.SetAddOnMethod (mb);
10552 eb = tb.DefineEvent ("OnFamANDAssemStatic" + suffix,
10553 EventAttributes.None, typeof (EventHandler));
10554 mb = tb.DefineMethod ("add_OnFamANDAssemStatic" + suffix,
10555 MethodAttributes.FamANDAssem | MethodAttributes.Static,
10556 typeof (void), Type.EmptyTypes);
10557 mb.GetILGenerator ().Emit (OpCodes.Ret);
10558 eb.SetAddOnMethod (mb);
10560 eb = tb.DefineEvent ("OnFamORAssemStatic" + suffix,
10561 EventAttributes.None, typeof (EventHandler));
10562 mb = tb.DefineMethod ("add_OnFamORAssemStatic" + suffix,
10563 MethodAttributes.FamORAssem | MethodAttributes.Static,
10564 typeof (void), Type.EmptyTypes);
10565 mb.GetILGenerator ().Emit (OpCodes.Ret);
10566 eb.SetAddOnMethod (mb);
10568 eb = tb.DefineEvent ("OnPublicStatic" + suffix,
10569 EventAttributes.None, typeof (EventHandler));
10570 mb = tb.DefineMethod ("add_OnPublicStatic" + suffix,
10571 MethodAttributes.Public | MethodAttributes.Static,
10572 typeof (void), Type.EmptyTypes);
10573 mb.GetILGenerator ().Emit (OpCodes.Ret);
10574 eb.SetAddOnMethod (mb);
10576 eb = tb.DefineEvent ("OnAssemblyStatic" + suffix,
10577 EventAttributes.None, typeof (EventHandler));
10578 mb = tb.DefineMethod ("add_OnAssemblyStatic" + suffix,
10579 MethodAttributes.Family | MethodAttributes.Static,
10580 typeof (void), Type.EmptyTypes);
10581 mb.GetILGenerator ().Emit (OpCodes.Ret);
10582 eb.SetAddOnMethod (mb);
10585 #if NET_2_0
10586 #if !WINDOWS
10588 * Tests for passing user types to Ref.Emit. Currently these only test
10589 * whenever the runtime code can handle them without crashing, since we
10590 * don't support user types yet.
10591 * These tests are disabled for windows since the MS runtime trips on them.
10593 [Test]
10594 public void UserTypes () {
10595 TypeDelegator t = new TypeDelegator (typeof (int));
10597 try {
10598 /* Parent */
10599 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, t);
10600 } catch {
10603 try {
10604 /* Interfaces */
10605 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object), new Type [] { t });
10606 tb.CreateType ();
10607 } catch {
10610 try {
10611 /* Fields */
10612 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10613 tb.DefineField ("Foo", t, FieldAttributes.Public);
10614 tb.CreateType ();
10615 } catch {
10618 try {
10619 /* Custom modifiers on fields */
10620 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10621 tb.DefineField ("Foo", typeof (int), new Type [] { t }, new Type [] { t }, FieldAttributes.Public);
10622 tb.CreateType ();
10623 } catch {
10626 #if !WINDOWS
10627 try {
10628 /* This is mono only */
10629 UnmanagedMarshal m = UnmanagedMarshal.DefineCustom (t, "foo", "bar", Guid.Empty);
10630 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10631 FieldBuilder fb = tb.DefineField ("Foo", typeof (int), FieldAttributes.Public);
10632 fb.SetMarshal (m);
10633 tb.CreateType ();
10634 } catch {
10636 #endif
10638 try {
10639 /* Properties */
10640 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10641 tb.DefineProperty ("Foo", PropertyAttributes.None, t, null);
10642 tb.CreateType ();
10643 } catch {
10646 try {
10647 /* Custom modifiers on properties */
10648 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10649 // FIXME: These seems to be ignored
10650 tb.DefineProperty ("Foo", PropertyAttributes.None, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10651 tb.CreateType ();
10652 } catch {
10655 try {
10656 /* Method return types */
10657 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10658 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, t, null);
10659 mb.GetILGenerator ().Emit (OpCodes.Ret);
10660 tb.CreateType ();
10661 } catch {
10664 try {
10665 /* Custom modifiers on method return types */
10666 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10667 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { t }, new Type [] { t }, null, null, null);
10668 mb.GetILGenerator ().Emit (OpCodes.Ret);
10669 tb.CreateType ();
10670 } catch {
10673 try {
10674 /* Method parameters */
10675 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10676 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, typeof (int), new Type [] { t });
10677 mb.GetILGenerator ().Emit (OpCodes.Ret);
10678 tb.CreateType ();
10679 } catch {
10682 try {
10683 /* Custom modifiers on method parameters */
10684 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10685 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 }});
10686 mb.GetILGenerator ().Emit (OpCodes.Ret);
10687 tb.CreateType ();
10688 } catch {
10691 try {
10692 /* Ctor parameters */
10693 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10694 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { t });
10695 mb.GetILGenerator ().Emit (OpCodes.Ret);
10696 tb.CreateType ();
10697 } catch {
10700 try {
10701 /* Custom modifiers on ctor parameters */
10702 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10703 ConstructorBuilder mb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (int) }, new Type [][] { new Type [] { t }}, new Type[][] { new Type [] { t }});
10704 mb.GetILGenerator ().Emit (OpCodes.Ret);
10705 tb.CreateType ();
10706 } catch {
10709 try {
10710 /* SignatureHelper arguments */
10711 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10712 sighelper.AddArgument (t, false);
10713 byte[] arr = sighelper.GetSignature ();
10714 } catch {
10717 try {
10718 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10719 sighelper.AddArgument (t, false);
10720 byte[] arr = sighelper.GetSignature ();
10721 } catch {
10724 try {
10725 /* Custom modifiers on SignatureHelper arguments */
10726 SignatureHelper sighelper = SignatureHelper.GetFieldSigHelper (module);
10727 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10728 byte[] arr = sighelper.GetSignature ();
10729 } catch {
10732 try {
10733 /* Custom modifiers on SignatureHelper arguments */
10734 SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
10735 sighelper.AddArgument (typeof (int), new Type [] { t }, new Type [] { t });
10736 byte[] arr = sighelper.GetSignature ();
10737 } catch {
10740 /* Arguments to ILGenerator methods */
10741 try {
10742 /* Emit () */
10743 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10744 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10745 ILGenerator ig = mb.GetILGenerator ();
10746 ig.Emit (OpCodes.Ldnull);
10747 ig.Emit (OpCodes.Castclass, t);
10748 ig.Emit (OpCodes.Pop);
10749 ig.Emit (OpCodes.Ret);
10750 tb.CreateType ();
10751 } catch {
10754 try {
10755 /* DeclareLocal () */
10756 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10757 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10758 ILGenerator ig = mb.GetILGenerator ();
10759 ig.DeclareLocal (t);
10760 ig.Emit (OpCodes.Ret);
10761 tb.CreateType ();
10762 } catch {
10765 try {
10766 /* BeginExceptionCatchBlock () */
10767 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10768 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10769 ILGenerator ig = mb.GetILGenerator ();
10770 ig.BeginExceptionBlock ();
10771 ig.BeginCatchBlock (t);
10772 ig.Emit (OpCodes.Ret);
10773 tb.CreateType ();
10774 } catch {
10777 try {
10778 /* EmitCalli () */
10779 TypeBuilder tb = module.DefineType (genTypeName (), TypeAttributes.Public, typeof (object));
10780 MethodBuilder mb = tb.DefineMethod ("foo", MethodAttributes.Public, CallingConventions.Standard, typeof (int), new Type [] { });
10781 ILGenerator ig = mb.GetILGenerator ();
10782 ig.EmitCalli (OpCodes.Call, CallingConventions.Standard, typeof (void), new Type [] { t }, null);
10783 ig.Emit (OpCodes.Ret);
10784 tb.CreateType ();
10785 } catch {
10788 #endif
10789 #endif