* MonoCustomAttrs.cs: In IsDefined, throw ArgumentNullException if
[mono.git] / mcs / class / corlib / Test / System / TypeTest.cs
1 // TypeTest.cs - NUnit Test Cases for the System.Type class
2 //
3 // Authors:
4 //      Zoltan Varga (vargaz@freemail.hu)
5 //  Patrik Torstensson
6 //
7 // (C) 2003 Ximian, Inc.  http://www.ximian.com
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 #if NET_2_0
14 using System.Collections.Generic;
15 #endif
16 using System.IO;
17 using System.Reflection;
18 using System.Reflection.Emit;
19 using System.Runtime.InteropServices;
20
21 class NoNamespaceClass {
22 }
23
24 namespace MonoTests.System
25 {
26         class Super : ICloneable {
27                 public virtual object Clone () {
28                         return null;
29                 }
30         }
31         class Duper: Super {
32         }
33
34         interface IFace1 {
35                 void foo ();
36         }
37
38         interface IFace2 : IFace1 {
39                 void bar ();
40         }
41
42         interface IFace3 : IFace2 {
43         }
44
45         enum TheEnum { A, B, C };
46
47         abstract class Base {
48                 public int level;
49
50                 public abstract int this [byte i] { get; }
51                 public abstract int this [int i] { get; }
52                 public abstract void TestVoid();
53                 public abstract void TestInt(int i);
54         }
55
56         class DeriveVTable : Base {
57                 public override int this [byte i] { get { return 1; } }
58                 public override int this [int i] { get { return 1; } }
59                 public override void TestVoid() { level = 1; }
60                 public override void TestInt(int i) { level = 1; }
61         }
62
63         class NewVTable : DeriveVTable {
64                 public new int this [byte i] { get { return 2; } }
65                 public new int this [int i] { get { return 2; } }
66                 public new void TestVoid() { level = 2; }
67                 public new void TestInt(int i) { level = 2; }
68
69                 public void Overload () { }
70                 public void Overload (int i) { }
71
72                 public NewVTable (out int i) {
73                         i = 0;
74                 }
75
76                 public void byref_method (out int i) {
77                         i = 0;
78                 }
79
80         }
81
82         class Base1 {
83                 public virtual int Foo {
84                         get {
85                                 return 1;
86                         }
87                         set {
88                         }
89                 }
90         }
91
92         class Derived1 : Base1 {
93                 public override int Foo {
94                         set {
95                         }
96                 }
97         }
98
99 #if NET_2_0
100         public class Foo<T> {
101                 public T Whatever;
102         
103                 public T Test {
104                         get { throw new NotImplementedException (); }
105                 }
106
107                 public T Execute(T a) {
108                         return a;
109                 }
110         }
111
112         public interface IBar<T> { }
113         public class Baz<T> : IBar<T> { }
114 #endif
115
116         [TestFixture]
117         public class TypeTest
118         {
119                 private AssemblyBuilder assembly;
120                 private ModuleBuilder module;
121                 const string ASSEMBLY_NAME = "MonoTests.System.TypeTest";
122                 static int typeIndexer = 0;
123
124                 [SetUp]
125                 public void SetUp ()
126                 {
127                         AssemblyName assemblyName = new AssemblyName ();
128                         assemblyName.Name = ASSEMBLY_NAME;
129                         assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (
130                                         assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
131                         module = assembly.DefineDynamicModule ("module1");
132                 }
133
134                 private string genTypeName ()
135                 {
136                         return "t" + (typeIndexer++);
137                 }
138
139                 private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k) {
140                 }
141 #if NET_2_0
142                 private void GenericMethod<Q> (Q q) {
143                 }
144 #endif
145                 [Test]
146                 public void TestIsAssignableFrom () {
147                         // Simple tests for inheritance
148                         Assert.AreEqual (typeof (Super).IsAssignableFrom (typeof (Duper)) , true, "#01");
149                         Assert.AreEqual (typeof (Duper).IsAssignableFrom (typeof (Duper)), true, "#02");
150                         Assert.AreEqual (typeof (Object).IsAssignableFrom (typeof (Duper)), true, "#03");
151                         Assert.AreEqual (typeof (ICloneable).IsAssignableFrom (typeof (Duper)), true, "#04");
152
153                         // Tests for arrays
154                         Assert.AreEqual (typeof (Super[]).IsAssignableFrom (typeof (Duper[])), true, "#05");
155                         Assert.AreEqual (typeof (Duper[]).IsAssignableFrom (typeof (Super[])), false, "#06");
156                         Assert.AreEqual (typeof (Object[]).IsAssignableFrom (typeof (Duper[])), true, "#07");
157                         Assert.AreEqual (typeof (ICloneable[]).IsAssignableFrom (typeof (Duper[])), true, "#08");
158
159                         // Tests for multiple dimensional arrays
160                         Assert.AreEqual (typeof (Super[][]).IsAssignableFrom (typeof (Duper[][])), true, "#09");
161                         Assert.AreEqual (typeof (Duper[][]).IsAssignableFrom (typeof (Super[][])), false, "#10");
162                         Assert.AreEqual (typeof (Object[][]).IsAssignableFrom (typeof (Duper[][])), true, "#11");
163                         Assert.AreEqual (typeof (ICloneable[][]).IsAssignableFrom (typeof (Duper[][])), true, "#12");
164
165                         // Tests for vectors<->one dimensional arrays */
166 #if TARGET_JVM // Lower bounds arrays are not supported for TARGET_JVM.
167                         Array arr1 = Array.CreateInstance (typeof (int), new int[] {1});
168                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
169 #else
170                         Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
171                         Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
172
173                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
174                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
175 #endif // TARGET_JVM
176
177                         // Test that arrays of enums can be cast to their base types
178                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
179
180                         // Test that arrays of valuetypes can't be cast to arrays of
181                         // references
182                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TypeCode[])), false, "#16");
183                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TypeCode[])), false, "#17");
184                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TypeCode[])), false, "#18");
185
186                         // Test that arrays of enums can't be cast to arrays of references
187                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TheEnum[])), false, "#19");
188                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TheEnum[])), false, "#20");
189                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TheEnum[])), false, "#21");
190
191                         // Check that ValueType and Enum are recognized as reference types
192                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (ValueType)), true, "#22");
193                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (Enum)), true, "#23");
194                         Assert.AreEqual (typeof (ValueType).IsAssignableFrom (typeof (Enum)), true, "#24");
195
196                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (ValueType[])), true, "#25");
197                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (ValueType[])), true, "#26");
198                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (ValueType[])), false, "#27");
199
200                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (Enum[])), true, "#28");
201                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (Enum[])), true, "#29");
202                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (Enum[])), true, "#30");
203
204                         // Tests for byref types
205                         MethodInfo mi = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic);
206                         Assert.IsTrue (mi.GetParameters ()[2].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
207                         Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
208
209                         // Tests for type parameters
210 #if NET_2_0
211                         mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
212                         Assert.IsTrue (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (mi.GetParameters ()[0].ParameterType));
213                         Assert.IsFalse (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (typeof (int)));
214 #endif
215                 }
216
217                 [Test]
218                 public void TestIsSubclassOf () {
219                         Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
220
221                         // Tests for byref types
222                         Type paramType = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic).GetParameters () [0].ParameterType;
223                         Assert.IsTrue (!paramType.IsSubclassOf (typeof (ValueType)), "#02");
224                         //Assert.IsTrue (paramType.IsSubclassOf (typeof (Object)), "#03");
225                         Assert.IsTrue (!paramType.IsSubclassOf (paramType), "#04");
226                 }
227
228                 [Test]
229                 public void TestGetMethodImpl() {
230                         // Test binding of new slot methods (using no types)
231                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod("TestVoid").DeclaringType, "#01");
232                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestVoid").DeclaringType, "#02");
233
234                         // Test binding of new slot methods (using types)
235                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#03");
236                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#04");
237
238                         // Test overload resolution
239                         Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
240
241                         // Test byref parameters
242                         Assert.AreEqual (null, typeof (NewVTable).GetMethod ("byref_method", new Type[] { typeof (int) }), "#06");
243                         Type byrefInt = typeof (NewVTable).GetMethod ("byref_method").GetParameters ()[0].ParameterType;
244                         Assert.IsNotNull (typeof (NewVTable).GetMethod ("byref_method", new Type[] { byrefInt }), "#07");
245                 }
246
247                 [Test]
248                 [Category ("TargetJvmNotWorking")]
249                 public void TestGetPropertyImpl() {
250                         // Test getting property that is exact
251                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int32) }).DeclaringType, "#01");
252
253                         // Test getting property that is not exact
254                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
255
256                         // Test overriding of properties when only the set accessor is overriden
257                         Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
258                 }
259
260 #if !TARGET_JVM // StructLayout not supported for TARGET_JVM
261                 [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
262                 public class Class1 {
263                 }
264
265                 [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
266                 public class Class2 {
267                 }
268
269 #if NET_2_0
270                 [Test]
271                 public void StructLayoutAttribute () {
272                         StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
273                         Assert.AreEqual (LayoutKind.Auto, attr1.Value);
274
275                         StructLayoutAttribute attr2 = typeof (Class1).StructLayoutAttribute;
276                         Assert.AreEqual (LayoutKind.Explicit, attr2.Value);
277                         Assert.AreEqual (4, attr2.Pack);
278                         Assert.AreEqual (64, attr2.Size);
279
280                         StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
281                         Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
282                         Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
283                 }
284 #endif
285 #endif // TARGET_JVM
286
287                 [Test]
288                 public void Namespace () {
289                         Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
290                 }
291
292                 public static void Reflected (ref int a) {
293                 }
294
295                 [Test]
296                 public void Name ()
297                 {
298                         Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
299                 }
300
301                 [Test]
302                 public void GetInterfaces () {
303                         Type[] t = typeof (Duper).GetInterfaces ();
304                         Assert.AreEqual (1, t.Length);
305                         Assert.AreEqual (typeof (ICloneable), t[0]);
306
307                         Type[] t2 = typeof (IFace3).GetInterfaces ();
308                         Assert.AreEqual (2, t2.Length);
309                 }
310
311                 public int AField;
312
313                 [Test]
314                 public void GetFieldIgnoreCase () {
315                         Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
316                 }
317
318 #if NET_2_0
319                 public int Count {
320                         internal get {
321                                 return 0;
322                         }
323
324                         set {
325                         }
326                 }
327
328                 [Test]
329                 public void GetPropertyAccessorModifiers () {
330                         Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
331                         Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
332                 }
333 #endif
334
335                 [Test]
336                 public void IsAbstract ()
337                 {
338                         Assert.IsFalse (typeof (string).IsAbstract, "#1");
339                         Assert.IsTrue (typeof (ICloneable).IsAbstract, "#2");
340                         Assert.IsTrue (typeof (ValueType).IsAbstract, "#3");
341                         Assert.IsTrue (typeof (Enum).IsAbstract, "#4");
342                         Assert.IsFalse (typeof (TimeSpan).IsAbstract, "#5");
343                         Assert.IsTrue (typeof (TextReader).IsAbstract, "#6");
344
345 #if NET_2_0
346                         // LAMESPEC:
347                         // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=286308
348                         Type [] typeArgs = typeof (List<>).GetGenericArguments ();
349                         Assert.IsFalse (typeArgs [0].IsAbstract, "#7");
350 #endif
351                 }
352
353                 [Test]
354                 public void IsCOMObject ()
355                 {
356                         Type type = typeof (string);
357                         Assert.IsFalse (type.IsCOMObject, "#1");
358
359                         TypeBuilder tb = module.DefineType (genTypeName ());
360                         type = tb.CreateType ();
361                         Assert.IsFalse (type.IsCOMObject, "#2");
362                 }
363
364                 [Test]
365                 public void IsImport ()
366                 {
367                         Type type = typeof (string);
368                         Assert.IsFalse (type.IsImport, "#1");
369
370                         TypeBuilder tb = module.DefineType (genTypeName ());
371                         type = tb.CreateType ();
372                         Assert.IsFalse (type.IsImport, "#2");
373
374                         tb = module.DefineType (genTypeName (), TypeAttributes.Import |
375                                 TypeAttributes.Interface | TypeAttributes.Abstract);
376                         type = tb.CreateType ();
377                         Assert.IsTrue (type.IsImport, "#3");
378                 }
379
380                 [Test]
381                 public void IsInterface ()
382                 {
383                         Assert.IsFalse (typeof (string).IsInterface, "#1");
384                         Assert.IsTrue (typeof (ICloneable).IsInterface, "#2");
385                 }
386
387                 [Test]
388                 public void IsPrimitive () {
389                         Assert.IsTrue (typeof (IntPtr).IsPrimitive, "#1");
390                         Assert.IsTrue (typeof (int).IsPrimitive, "#2");
391                         Assert.IsFalse (typeof (string).IsPrimitive, "#2");
392                 }
393
394                 [Test]
395                 public void IsValueType ()
396                 {
397                         Assert.IsTrue (typeof (int).IsValueType, "#1");
398                         Assert.IsFalse (typeof (Enum).IsValueType, "#2");
399                         Assert.IsFalse (typeof (ValueType).IsValueType, "#3");
400                         Assert.IsTrue (typeof (AttributeTargets).IsValueType, "#4");
401                         Assert.IsFalse (typeof (string).IsValueType, "#5");
402                         Assert.IsTrue (typeof (TimeSpan).IsValueType, "#6");
403                 }
404
405                 [Test]
406                 [Category("NotDotNet")]
407                 // Depends on the GAC working, which it doesn't durring make distcheck.
408                 [Category ("NotWorking")]
409                 public void GetTypeWithWhitespace () {
410                         Assert.IsNotNull (Type.GetType
411                                                    (@"System.Configuration.NameValueSectionHandler,
412                         System,
413 Version=1.0.5000.0,
414 Culture=neutral
415 ,
416 PublicKeyToken=b77a5c561934e089"));
417                 }
418                 
419                 [Test]
420                 public void ExerciseFilterName() {
421                         MemberInfo[] mi = typeof(Base).FindMembers(
422                                 MemberTypes.Method, 
423                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
424                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
425                             Type.FilterName, "*");
426                         Assert.AreEqual (4, mi.Length);
427                         mi = typeof(Base).FindMembers(
428                                 MemberTypes.Method, 
429                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
430                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
431                             Type.FilterName, "Test*");
432                         Assert.AreEqual (2, mi.Length);
433                         mi = typeof(Base).FindMembers(
434                                 MemberTypes.Method, 
435                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
436                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
437                             Type.FilterName, "TestVoid");
438                         Assert.AreEqual (1, mi.Length);
439                         mi = typeof(Base).FindMembers(
440                                 MemberTypes.Method, 
441                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
442                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
443                             Type.FilterName, "NonExistingMethod");
444                         Assert.AreEqual (0, mi.Length);
445                 }
446                 
447                 [Test]
448                 public void ExerciseFilterNameIgnoreCase() {
449                         MemberInfo[] mi = typeof(Base).FindMembers(
450                                 MemberTypes.Method, 
451                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
452                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
453                             Type.FilterNameIgnoreCase, "*");
454                         Assert.AreEqual (4, mi.Length);
455                         mi = typeof(Base).FindMembers(
456                                 MemberTypes.Method, 
457                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
458                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
459                             Type.FilterNameIgnoreCase, "test*");
460                         Assert.AreEqual (2, mi.Length);
461                         mi = typeof(Base).FindMembers(
462                                 MemberTypes.Method, 
463                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
464                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
465                             Type.FilterNameIgnoreCase, "TESTVOID");
466                         Assert.AreEqual (1, mi.Length);
467                         mi = typeof(Base).FindMembers(
468                                 MemberTypes.Method, 
469                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
470                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
471                             Type.FilterNameIgnoreCase, "NonExistingMethod");
472                         Assert.AreEqual (0, mi.Length);
473                 }
474
475                 public class ByRef0 {
476                         public int field;
477                         public int property {
478                                 get { return 0; }
479                         }
480                         public ByRef0 (int i) {}
481                         public void f (int i) {}
482                 }
483
484                 [Test]
485                 public void ByrefTypes ()
486                 {
487                         Type t = Type.GetType ("MonoTests.System.TypeTest+ByRef0&");
488                         Assert.IsNotNull (t);
489                         Assert.IsTrue (t.IsByRef);
490                         Assert.AreEqual (0, t.GetMethods (BindingFlags.Public | BindingFlags.Instance).Length);
491                         Assert.AreEqual (0, t.GetConstructors (BindingFlags.Public | BindingFlags.Instance).Length);
492                         Assert.AreEqual (0, t.GetEvents (BindingFlags.Public | BindingFlags.Instance).Length);
493                         Assert.AreEqual (0, t.GetProperties (BindingFlags.Public | BindingFlags.Instance).Length);
494
495                         Assert.IsNull (t.GetMethod ("f"));
496                         Assert.IsNull (t.GetField ("field"));
497                         Assert.IsNull (t.GetProperty ("property"));
498                 }
499
500                 struct B
501                 {
502                         int value;
503                 }
504
505                 [Test]
506                 public void CreateValueTypeNoCtor () {
507                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
508                 }
509
510                 [Test]
511                 [ExpectedException (typeof (MissingMethodException))]
512                 public void CreateValueTypeNoCtorArgs () {
513                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
514                 }
515
516                 class X
517                 {
518                         public static int Value;
519                 }
520
521                 class Y  : X
522                 {
523                 }
524
525                 [Test]
526                 public void InvokeMemberGetSetField () {
527                         typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
528
529                         Assert.AreEqual (5, X.Value);
530                         Assert.AreEqual (5, typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
531                         Assert.AreEqual (5, Y.Value);
532                         Assert.AreEqual (5, typeof (Y).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
533                 }                       
534
535                 class Z {
536                         public Z (IComparable value) {}
537                 }
538         
539                 [Test]
540                 public void InvokeMemberMatchPrimitiveTypeWithInterface () {
541                         object[] invokeargs = {1};
542                         typeof (Z).InvokeMember( "", 
543                                                                                         BindingFlags.DeclaredOnly |
544                                                                                         BindingFlags.Public |
545                                                                                         BindingFlags.NonPublic |
546                                                                                         BindingFlags.Instance |
547                                                                                         BindingFlags.CreateInstance,
548                                                                                         null, null, invokeargs 
549                                                                                         );
550                 }
551
552                 class TakesInt {
553                         private int i;
554
555                         public TakesInt (int x)
556                         {
557                                 i = x;
558                         }
559
560                         public int Integer {
561                                 get { return i; }
562                         }
563                 }
564
565                 class TakesObject {
566                         public TakesObject (object x) {}
567                 }
568
569                 // Filed as bug #75241
570                 [Test]
571                 public void GetConstructorNullInTypes ()
572                 {
573                         // This ends up calling type.GetConstructor ()
574                         Activator.CreateInstance (typeof (TakesInt), new object [] { null });
575                         Activator.CreateInstance (typeof (TakesObject), new object [] { null });
576                 }
577
578                 [Test]
579                 [ExpectedException (typeof (ArgumentNullException))]
580                 public void GetConstructorNullInTypes_Bug71300 ()
581                 {
582                         typeof (TakesInt).GetConstructor (new Type[1] { null });
583                         // so null in types isn't valid for GetConstructor!
584                 }
585
586                 [Test]
587                 public void GetConstructor_TakeInt_Object ()
588                 {
589                         Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
590                 }
591
592                 [Test]
593                 public void GetCustomAttributes_All ()
594                 {
595                         object [] attrs = typeof (A).GetCustomAttributes (false);
596                         Assert.AreEqual (2, attrs.Length, "#A1");
597                         Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
598                         Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
599
600                         attrs = typeof (BA).GetCustomAttributes (false);
601                         Assert.AreEqual (1, attrs.Length, "#B1");
602                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
603
604                         attrs = typeof (BA).GetCustomAttributes (true);
605                         Assert.AreEqual (2, attrs.Length, "#C1");
606                         Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
607                         Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
608
609                         attrs = typeof (CA).GetCustomAttributes (false);
610                         Assert.AreEqual (0, attrs.Length, "#D");
611
612                         attrs = typeof (CA).GetCustomAttributes (true);
613                         Assert.AreEqual (1, attrs.Length, "#E1");
614                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
615                 }
616
617                 static bool HasAttribute (object [] attrs, Type attributeType)
618                 {
619                         foreach (object attr in attrs)
620                                 if (attr.GetType () == attributeType)
621                                         return true;
622                         return false;
623                 }
624
625                 [Test]
626                 public void GetCustomAttributes_Type ()
627                 {
628                         object [] attrs = null;
629
630                         attrs = typeof (A).GetCustomAttributes (
631                                 typeof (VolatileModifier), false);
632                         Assert.AreEqual (1, attrs.Length, "#A1");
633                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
634                         attrs = typeof (A).GetCustomAttributes (
635                                 typeof (VolatileModifier), true);
636                         Assert.AreEqual (1, attrs.Length, "#A3");
637                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
638
639                         attrs = typeof (A).GetCustomAttributes (
640                                 typeof (NemerleAttribute), false);
641                         Assert.AreEqual (1, attrs.Length, "#B1");
642                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
643                         attrs = typeof (A).GetCustomAttributes (
644                                 typeof (NemerleAttribute), true);
645                         Assert.AreEqual (1, attrs.Length, "#B3");
646                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
647
648                         attrs = typeof (A).GetCustomAttributes (
649                                 typeof (FooAttribute), false);
650                         Assert.AreEqual (1, attrs.Length, "#C1");
651                         Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
652                         attrs = typeof (A).GetCustomAttributes (
653                                 typeof (FooAttribute), false);
654                         Assert.AreEqual (1, attrs.Length, "#C3");
655                         Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
656
657                         attrs = typeof (BA).GetCustomAttributes (
658                                 typeof (VolatileModifier), false);
659                         Assert.AreEqual (0, attrs.Length, "#D1");
660                         attrs = typeof (BA).GetCustomAttributes (
661                                 typeof (VolatileModifier), true);
662                         Assert.AreEqual (1, attrs.Length, "#D2");
663                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
664
665                         attrs = typeof (BA).GetCustomAttributes (
666                                 typeof (NemerleAttribute), false);
667                         Assert.AreEqual (0, attrs.Length, "#E1");
668                         attrs = typeof (BA).GetCustomAttributes (
669                                 typeof (NemerleAttribute), true);
670                         Assert.AreEqual (1, attrs.Length, "#E2");
671                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
672
673                         attrs = typeof (BA).GetCustomAttributes (
674                                 typeof (FooAttribute), false);
675                         Assert.AreEqual (1, attrs.Length, "#F1");
676                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
677                         attrs = typeof (BA).GetCustomAttributes (
678                                 typeof (FooAttribute), true);
679                         Assert.AreEqual (1, attrs.Length, "#F3");
680                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
681
682                         attrs = typeof (bug82431A1).GetCustomAttributes (
683                                 typeof (InheritAttribute), false);
684                         Assert.AreEqual (1, attrs.Length, "#G1");
685                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
686                         attrs = typeof (bug82431A1).GetCustomAttributes (
687                                 typeof (InheritAttribute), true);
688                         Assert.AreEqual (1, attrs.Length, "#G3");
689                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
690
691                         attrs = typeof (bug82431A1).GetCustomAttributes (
692                                 typeof (NotInheritAttribute), false);
693                         Assert.AreEqual (1, attrs.Length, "#H1");
694                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
695                         attrs = typeof (bug82431A1).GetCustomAttributes (
696                                 typeof (InheritAttribute), true);
697                         Assert.AreEqual (1, attrs.Length, "#H3");
698                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
699
700                         attrs = typeof (bug82431A2).GetCustomAttributes (
701                                 typeof (InheritAttribute), false);
702                         Assert.AreEqual (0, attrs.Length, "#I1");
703                         attrs = typeof (bug82431A2).GetCustomAttributes (
704                                 typeof (InheritAttribute), true);
705                         Assert.AreEqual (0, attrs.Length, "#I2");
706
707                         attrs = typeof (bug82431A2).GetCustomAttributes (
708                                 typeof (NotInheritAttribute), false);
709                         Assert.AreEqual (0, attrs.Length, "#J1");
710                         attrs = typeof (bug82431A2).GetCustomAttributes (
711                                 typeof (NotInheritAttribute), true);
712                         Assert.AreEqual (0, attrs.Length, "#J2");
713
714                         attrs = typeof (bug82431A3).GetCustomAttributes (
715                                 typeof (InheritAttribute), false);
716                         Assert.AreEqual (2, attrs.Length, "#K1");
717                         Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
718                         Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
719                         attrs = typeof (bug82431A3).GetCustomAttributes (
720                                 typeof (InheritAttribute), true);
721                         Assert.AreEqual (2, attrs.Length, "#K4");
722                         Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
723                         Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
724
725                         attrs = typeof (bug82431A3).GetCustomAttributes (
726                                 typeof (NotInheritAttribute), false);
727                         Assert.AreEqual (1, attrs.Length, "#L1");
728                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
729                         attrs = typeof (bug82431A3).GetCustomAttributes (
730                                 typeof (NotInheritAttribute), true);
731                         Assert.AreEqual (1, attrs.Length, "#L3");
732                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
733
734                         attrs = typeof (bug82431B1).GetCustomAttributes (
735                                 typeof (InheritAttribute), false);
736                         Assert.AreEqual (1, attrs.Length, "#M1");
737                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
738                         attrs = typeof (bug82431B1).GetCustomAttributes (
739                                 typeof (InheritAttribute), true);
740                         Assert.AreEqual (1, attrs.Length, "#M3");
741                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
742
743                         attrs = typeof (bug82431B1).GetCustomAttributes (
744                                 typeof (NotInheritAttribute), false);
745                         Assert.AreEqual (0, attrs.Length, "#N1");
746                         attrs = typeof (bug82431B1).GetCustomAttributes (
747                                 typeof (NotInheritAttribute), true);
748                         Assert.AreEqual (0, attrs.Length, "#N2");
749
750                         attrs = typeof (bug82431B2).GetCustomAttributes (
751                                 typeof (InheritAttribute), false);
752                         Assert.AreEqual (0, attrs.Length, "#O1");
753                         attrs = typeof (bug82431B2).GetCustomAttributes (
754                                 typeof (InheritAttribute), true);
755                         Assert.AreEqual (1, attrs.Length, "#O2");
756                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
757
758                         attrs = typeof (bug82431B2).GetCustomAttributes (
759                                 typeof (NotInheritAttribute), false);
760                         Assert.AreEqual (0, attrs.Length, "#P1");
761                         attrs = typeof (bug82431B2).GetCustomAttributes (
762                                 typeof (NotInheritAttribute), true);
763                         Assert.AreEqual (0, attrs.Length, "#P2");
764
765                         attrs = typeof (bug82431B3).GetCustomAttributes (
766                                 typeof (InheritAttribute), false);
767                         Assert.AreEqual (1, attrs.Length, "#Q1");
768                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
769                         attrs = typeof (bug82431B3).GetCustomAttributes (
770                                 typeof (InheritAttribute), true);
771                         Assert.AreEqual (2, attrs.Length, "#Q3");
772                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
773                         Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
774
775                         attrs = typeof (bug82431B3).GetCustomAttributes (
776                                 typeof (NotInheritAttribute), false);
777                         Assert.AreEqual (1, attrs.Length, "#R1");
778                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
779                         attrs = typeof (bug82431B3).GetCustomAttributes (
780                                 typeof (NotInheritAttribute), true);
781                         Assert.AreEqual (1, attrs.Length, "#R3");
782                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
783
784                         attrs = typeof (bug82431B4).GetCustomAttributes (
785                                 typeof (InheritAttribute), false);
786                         Assert.AreEqual (0, attrs.Length, "#S1");
787                         attrs = typeof (bug82431B4).GetCustomAttributes (
788                                 typeof (InheritAttribute), true);
789                         Assert.AreEqual (1, attrs.Length, "#S2");
790                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
791
792                         attrs = typeof (bug82431B4).GetCustomAttributes (
793                                 typeof (NotInheritAttribute), false);
794                         Assert.AreEqual (0, attrs.Length, "#T1");
795                         attrs = typeof (bug82431B4).GetCustomAttributes (
796                                 typeof (NotInheritAttribute), true);
797                         Assert.AreEqual (0, attrs.Length, "#T2");
798
799                         attrs = typeof (A).GetCustomAttributes (
800                                 typeof (string), false);
801                         Assert.AreEqual (0, attrs.Length, "#U1");
802                         attrs = typeof (A).GetCustomAttributes (
803                                 typeof (string), true);
804                         Assert.AreEqual (0, attrs.Length, "#U2");
805                 }
806
807                 [Test] // bug #76150
808                 public void IsDefined ()
809                 {
810                         Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
811                         Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#A2");
812                         Assert.IsTrue (typeof (A).IsDefined (typeof (FooAttribute), false), "#A3");
813                         Assert.IsFalse (typeof (A).IsDefined (typeof (BarAttribute), false), "#A4");
814
815                         Assert.IsFalse (typeof (BA).IsDefined (typeof (NemerleAttribute), false), "#B1");
816                         Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
817                         Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
818                         Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
819                         Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
820                         Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
821                         Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
822                         Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
823                         Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
824                         Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
825                         Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
826                         Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
827                 }
828
829                 [Test]
830                 public void IsDefined_AttributeType_Null ()
831                 {
832                         try {
833                                 typeof (BA).IsDefined ((Type) null, false);
834                                 Assert.Fail ("#1");
835                         } catch (ArgumentNullException ex) {
836                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
837                                 Assert.IsNull (ex.InnerException, "#3");
838                                 Assert.IsNotNull (ex.Message, "#4");
839                                 Assert.IsNotNull (ex.ParamName, "#5");
840                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
841                         }
842                 }
843
844                 [Test] // bug #82431
845 #if NET_2_0
846                 [Category ("NotWorking")]
847 #endif
848                 public void IsDefined_Inherited ()
849                 {
850                         Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
851                         Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
852                         Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
853                         Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), false), "#C4");
854                         Assert.IsTrue (typeof (CA).IsDefined (typeof (NemerleAttribute), true), "#C5");
855                         Assert.IsTrue (typeof (CA).IsDefined (typeof (VolatileModifier), true), "#C6");
856                         Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), true), "#C7");
857                         Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), true), "#C8");
858
859                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (NemerleAttribute), false), "#D1");
860                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (VolatileModifier), false), "#D2");
861                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), false), "#D3");
862                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
863                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
864                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
865 #if NET_2_0
866                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
867                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
868 #else
869                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
870                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
871 #endif
872
873                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
874                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
875                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
876                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
877
878                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
879                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
880 #if NET_2_0
881                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
882 #else
883                         Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
884 #endif
885                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
886
887                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
888                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
889                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
890                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
891
892                         Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
893                         Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
894                         Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
895                         Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
896
897                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
898                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
899                         Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
900                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
901
902                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
903                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
904                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
905                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
906
907                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
908                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
909                         Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
910                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
911                 }
912
913                 [Test]
914                 public void GetTypeCode ()
915                 {
916                         Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
917                         Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
918                         Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
919                         Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
920                         Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
921                         Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
922                         Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
923                         Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
924                         Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
925                         Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
926                         Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
927                         Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
928                         Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
929                         Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
930                         Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
931                         Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
932                         Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
933                         Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
934                 }
935
936                 [Test]
937                 [ExpectedException (typeof (ArgumentNullException))]
938                 public void GetConstructor1a_Bug71300 ()
939                 {
940                         typeof (BindingFlags).GetConstructor (null);
941                 }
942
943                 [Test]
944                 [ExpectedException (typeof (ArgumentNullException))]
945                 public void GetConstructor1b_Bug71300 ()
946                 {
947                         typeof (BindingFlags).GetConstructor (new Type[1] { null });
948                 }
949
950                 [Test]
951                 [ExpectedException (typeof (ArgumentNullException))]
952                 public void GetConstructor4_Bug71300 ()
953                 {
954                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
955                 }
956
957                 [Test]
958                 [ExpectedException (typeof (ArgumentNullException))]
959                 public void GetConstructor5_Bug71300 ()
960                 {
961                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
962                 }
963
964                 [Test]
965                 public void GetMethod_Bug77367 ()
966                 {
967                         MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
968                         Assert.IsNull (i);
969                 }
970
971 #if !TARGET_JVM // Reflection.Emit is not supported for TARGET_JVM
972                 [Test]
973                 public void EqualsUnderlyingType ()
974                 {
975                         AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
976                         TypeAttributes attribs = TypeAttributes.Public;
977
978                         AssemblyName name = new AssemblyName ();
979                         name.Name = "enumtest";
980                         AssemblyBuilder assembly = 
981                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
982                                         name, access);
983
984                         ModuleBuilder module = assembly.DefineDynamicModule 
985                                 ("m", "enumtest.dll");
986                         EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
987
988                         Assert.IsTrue (typeof (int).Equals (e));
989                 }
990 #endif // TARGET_JVM
991
992                 [Test]
993                 public void Equals_Type_Null ()
994                 {
995                         Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
996                         Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
997                 }
998
999                 [Test]
1000                 [Category("NotWorking")]
1001                 public void GetElementType_Bug63841 ()
1002                 {
1003                         Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
1004                 }
1005
1006 #if NET_2_0
1007                 [Test]
1008                 public void FullNameGenerics ()
1009                 {
1010                         Type fooType = typeof (Foo<>);
1011                         FieldInfo [] fields = fooType.GetFields ();
1012
1013                         Assert.AreEqual (1, fields.Length, "#0");
1014
1015                         Assert.IsNotNull (fooType.FullName, "#1");
1016                         Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
1017
1018                         FieldInfo field = fooType.GetField ("Whatever");
1019                         Assert.IsNotNull (field, "#2");
1020                         Assert.AreEqual (field, fields [0], "#2a");
1021                         Assert.IsNull (field.FieldType.FullName, "#3");
1022                         Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
1023                         Assert.IsNotNull (field.FieldType.ToString (), "#4");
1024
1025                         PropertyInfo prop = fooType.GetProperty ("Test");
1026                         Assert.IsNotNull (prop, "#5");
1027                         Assert.IsNull (prop.PropertyType.FullName, "#6");
1028                         Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
1029                         Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
1030
1031                         MethodInfo method = fooType.GetMethod("Execute");
1032                         Assert.IsNotNull (method, "#8");
1033                         Assert.IsNull (method.ReturnType.FullName, "#9");
1034                         Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
1035                         Assert.IsNotNull (method.ReturnType.ToString (), "#10");
1036
1037                         ParameterInfo[] parameters = method.GetParameters();
1038                         Assert.AreEqual (1, parameters.Length, "#11");
1039                         Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
1040                         Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
1041                         Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
1042                 }
1043
1044                 [Test]
1045                 public void TypeParameterIsNotGeneric ()
1046                 {
1047                         Type fooType = typeof (Foo<>);
1048                         Type type_param = fooType.GetGenericArguments () [0];
1049                         Assert.IsTrue (type_param.IsGenericParameter);
1050                         Assert.IsFalse (type_param.IsGenericType);
1051                         Assert.IsFalse (type_param.IsGenericTypeDefinition);
1052
1053                         // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
1054                         // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
1055                         Assert.IsTrue (type_param.ContainsGenericParameters);
1056                 }
1057
1058                 [Test]
1059                 public void IsAssignable ()
1060                 {
1061                         Type foo_type = typeof (Foo<>);
1062                         Type foo_int_type = typeof (Foo<int>);
1063                         Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
1064                         Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
1065
1066                         Type ibar_short_type = typeof (IBar<short>);
1067                         Type ibar_int_type = typeof (IBar<int>);
1068                         Type baz_short_type = typeof (Baz<short>);
1069                         Type baz_int_type = typeof (Baz<int>);
1070
1071                         Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
1072                         Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
1073
1074                         Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
1075                         Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
1076
1077                         // Nullable tests
1078                         Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
1079                         Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
1080                         Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
1081                 }
1082
1083                 [Test]
1084                 public void IsInstanceOf ()
1085                 {
1086                         Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
1087                 }
1088
1089                 [Test]
1090                 public void ByrefType ()
1091                 {
1092                         Type foo_type = typeof (Foo<>);
1093                         Type type_param = foo_type.GetGenericArguments () [0];
1094                         Type byref_type_param = type_param.MakeByRefType ();
1095                         Assert.IsFalse (byref_type_param.IsGenericParameter);
1096                         Assert.IsNull (byref_type_param.DeclaringType);
1097                 }
1098
1099                 [Test]
1100                 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
1101                 public void Bug79023 ()
1102                 {
1103                         ArrayList list = new ArrayList();
1104                         list.Add("foo");
1105
1106                         // The next line used to throw because we had SetProperty
1107                         list.GetType().InvokeMember("Item",
1108                                                     BindingFlags.SetField|BindingFlags.SetProperty|
1109                                                     BindingFlags.Instance|BindingFlags.Public,
1110                                                     null, list, new object[] { 0, "bar" });
1111                         Assert.AreEqual ("bar", list[0]);
1112                 }
1113                 
1114                 [ComVisible (true)]
1115                 public class ComFoo<T> {
1116                 }
1117
1118                 [Test]
1119                 public void GetCustomAttributesGenericInstance ()
1120                 {
1121                         Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
1122                 }
1123
1124                 interface ByRef1<T> { void f (ref T t); }
1125                 interface ByRef2 { void f<T> (ref T t); }
1126
1127                 interface ByRef3<T> where T:struct { void f (ref T? t); }
1128                 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
1129
1130                 void CheckGenericByRef (Type t)
1131                 {
1132                         string name = t.Name;
1133                         t = t.GetMethod ("f").GetParameters () [0].ParameterType;
1134
1135                         Assert.IsFalse (t.IsGenericType, name);
1136                         Assert.IsFalse (t.IsGenericTypeDefinition, name);
1137                         Assert.IsFalse (t.IsGenericParameter, name);
1138                 }
1139
1140                 [Test]
1141                 public void GenericByRef ()
1142                 {
1143                         CheckGenericByRef (typeof (ByRef1<>));
1144                         CheckGenericByRef (typeof (ByRef2));
1145                         CheckGenericByRef (typeof (ByRef3<>));
1146                         CheckGenericByRef (typeof (ByRef4));
1147                 }
1148
1149                 public class Bug80242<T> {
1150                         public interface IFoo { }
1151                         public class Bar : IFoo { }
1152                         public class Baz : Bar { }
1153                 }
1154
1155                 [Test]
1156                 public void TestNestedTypes ()
1157                 {
1158                         Type t = typeof (Bug80242<object>);
1159                         Assert.IsFalse (t.IsGenericTypeDefinition);
1160                         foreach (Type u in t.GetNestedTypes ()) {
1161                                 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
1162                                 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
1163                         }
1164                 }
1165
1166                 [Test] // bug #82211
1167                 public void GetMembers_GenericArgument ()
1168                 {
1169                         Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
1170                         MemberInfo [] members = argType.GetMembers ();
1171                         Assert.IsNotNull (members, "#1");
1172                         Assert.AreEqual (4, members.Length, "#2");
1173                 }
1174 #endif
1175
1176                 public class NemerleAttribute : Attribute
1177                 { }
1178
1179                 public class VolatileModifier : NemerleAttribute
1180                 { }
1181
1182                 [VolatileModifier]
1183                 [FooAttribute]
1184                 class A { }
1185
1186                 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1187                 public class FooAttribute : Attribute
1188                 {
1189                 }
1190
1191                 public class BarAttribute : FooAttribute
1192                 {
1193                 }
1194
1195                 [BarAttribute]
1196                 class BA : A
1197                 {
1198                 }
1199
1200                 class BBA : BA
1201                 {
1202                 }
1203
1204                 class CA : A
1205                 {
1206                 }
1207
1208                 [AttributeUsage (AttributeTargets.Class, Inherited=true)]
1209                 public class InheritAttribute : Attribute
1210                 {
1211                 }
1212
1213                 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1214                 public class NotInheritAttribute : InheritAttribute
1215                 {
1216                 }
1217
1218                 [NotInheritAttribute]
1219                 public class bug82431A1
1220                 {
1221                 }
1222
1223                 public class bug82431A2 : bug82431A1
1224                 {
1225                 }
1226
1227                 [NotInheritAttribute]
1228                 [InheritAttribute]
1229                 public class bug82431A3 : bug82431A1
1230                 {
1231                 }
1232
1233                 [InheritAttribute]
1234                 public class bug82431B1
1235                 {
1236                 }
1237
1238                 public class bug82431B2 : bug82431B1
1239                 {
1240                 }
1241
1242                 [NotInheritAttribute]
1243                 public class bug82431B3 : bug82431B2
1244                 {
1245                 }
1246
1247                 public class bug82431B4 : bug82431B3
1248                 {
1249                 }
1250
1251                 struct FooStruct {
1252                 }
1253
1254                 public class Bug77367
1255                 {
1256                         public void Run (bool b)
1257                         {
1258                         }
1259                 }
1260
1261         }
1262 }