2007-10-05 Alp Toker <alp@atoker.com>
[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                 [Test]
501                 public void TestAssemblyQualifiedName ()
502                 {
503                         Type t = Type.GetType ("System.Byte[]&");
504                         Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte[]&"));
505                         
506                         t = Type.GetType ("System.Byte*&");
507                         Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte*&"));
508                         
509                         t = Type.GetType ("System.Byte&");
510                         Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte&"));
511                 }
512
513                 struct B
514                 {
515                         int value;
516                 }
517
518                 [Test]
519                 public void CreateValueTypeNoCtor () {
520                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
521                 }
522
523                 [Test]
524                 [ExpectedException (typeof (MissingMethodException))]
525                 public void CreateValueTypeNoCtorArgs () {
526                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
527                 }
528
529                 class X
530                 {
531                         public static int Value;
532                 }
533
534                 class Y  : X
535                 {
536                 }
537
538                 [Test]
539                 public void InvokeMemberGetSetField () {
540                         typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
541
542                         Assert.AreEqual (5, X.Value);
543                         Assert.AreEqual (5, typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
544                         Assert.AreEqual (5, Y.Value);
545                         Assert.AreEqual (5, typeof (Y).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
546                 }                       
547
548                 class Z {
549                         public Z (IComparable value) {}
550                 }
551         
552                 [Test]
553                 public void InvokeMemberMatchPrimitiveTypeWithInterface () {
554                         object[] invokeargs = {1};
555                         typeof (Z).InvokeMember( "", 
556                                                                                         BindingFlags.DeclaredOnly |
557                                                                                         BindingFlags.Public |
558                                                                                         BindingFlags.NonPublic |
559                                                                                         BindingFlags.Instance |
560                                                                                         BindingFlags.CreateInstance,
561                                                                                         null, null, invokeargs 
562                                                                                         );
563                 }
564
565                 class TakesInt {
566                         private int i;
567
568                         public TakesInt (int x)
569                         {
570                                 i = x;
571                         }
572
573                         public int Integer {
574                                 get { return i; }
575                         }
576                 }
577
578                 class TakesObject {
579                         public TakesObject (object x) {}
580                 }
581
582                 // Filed as bug #75241
583                 [Test]
584                 public void GetConstructorNullInTypes ()
585                 {
586                         // This ends up calling type.GetConstructor ()
587                         Activator.CreateInstance (typeof (TakesInt), new object [] { null });
588                         Activator.CreateInstance (typeof (TakesObject), new object [] { null });
589                 }
590
591                 [Test]
592                 [ExpectedException (typeof (ArgumentNullException))]
593                 public void GetConstructorNullInTypes_Bug71300 ()
594                 {
595                         typeof (TakesInt).GetConstructor (new Type[1] { null });
596                         // so null in types isn't valid for GetConstructor!
597                 }
598
599                 [Test]
600                 public void GetConstructor_TakeInt_Object ()
601                 {
602                         Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
603                 }
604
605                 [Test]
606                 public void GetCustomAttributes_All ()
607                 {
608                         object [] attrs = typeof (A).GetCustomAttributes (false);
609                         Assert.AreEqual (2, attrs.Length, "#A1");
610                         Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
611                         Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
612
613                         attrs = typeof (BA).GetCustomAttributes (false);
614                         Assert.AreEqual (1, attrs.Length, "#B1");
615                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
616
617                         attrs = typeof (BA).GetCustomAttributes (true);
618                         Assert.AreEqual (2, attrs.Length, "#C1");
619                         Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
620                         Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
621
622                         attrs = typeof (CA).GetCustomAttributes (false);
623                         Assert.AreEqual (0, attrs.Length, "#D");
624
625                         attrs = typeof (CA).GetCustomAttributes (true);
626                         Assert.AreEqual (1, attrs.Length, "#E1");
627                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
628                 }
629
630                 static bool HasAttribute (object [] attrs, Type attributeType)
631                 {
632                         foreach (object attr in attrs)
633                                 if (attr.GetType () == attributeType)
634                                         return true;
635                         return false;
636                 }
637
638                 [Test]
639                 public void GetCustomAttributes_Type ()
640                 {
641                         object [] attrs = null;
642
643                         attrs = typeof (A).GetCustomAttributes (
644                                 typeof (VolatileModifier), false);
645                         Assert.AreEqual (1, attrs.Length, "#A1");
646                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
647                         attrs = typeof (A).GetCustomAttributes (
648                                 typeof (VolatileModifier), true);
649                         Assert.AreEqual (1, attrs.Length, "#A3");
650                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
651
652                         attrs = typeof (A).GetCustomAttributes (
653                                 typeof (NemerleAttribute), false);
654                         Assert.AreEqual (1, attrs.Length, "#B1");
655                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
656                         attrs = typeof (A).GetCustomAttributes (
657                                 typeof (NemerleAttribute), true);
658                         Assert.AreEqual (1, attrs.Length, "#B3");
659                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
660
661                         attrs = typeof (A).GetCustomAttributes (
662                                 typeof (FooAttribute), false);
663                         Assert.AreEqual (1, attrs.Length, "#C1");
664                         Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
665                         attrs = typeof (A).GetCustomAttributes (
666                                 typeof (FooAttribute), false);
667                         Assert.AreEqual (1, attrs.Length, "#C3");
668                         Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
669
670                         attrs = typeof (BA).GetCustomAttributes (
671                                 typeof (VolatileModifier), false);
672                         Assert.AreEqual (0, attrs.Length, "#D1");
673                         attrs = typeof (BA).GetCustomAttributes (
674                                 typeof (VolatileModifier), true);
675                         Assert.AreEqual (1, attrs.Length, "#D2");
676                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
677
678                         attrs = typeof (BA).GetCustomAttributes (
679                                 typeof (NemerleAttribute), false);
680                         Assert.AreEqual (0, attrs.Length, "#E1");
681                         attrs = typeof (BA).GetCustomAttributes (
682                                 typeof (NemerleAttribute), true);
683                         Assert.AreEqual (1, attrs.Length, "#E2");
684                         Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
685
686                         attrs = typeof (BA).GetCustomAttributes (
687                                 typeof (FooAttribute), false);
688                         Assert.AreEqual (1, attrs.Length, "#F1");
689                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
690                         attrs = typeof (BA).GetCustomAttributes (
691                                 typeof (FooAttribute), true);
692                         Assert.AreEqual (1, attrs.Length, "#F3");
693                         Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
694
695                         attrs = typeof (bug82431A1).GetCustomAttributes (
696                                 typeof (InheritAttribute), false);
697                         Assert.AreEqual (1, attrs.Length, "#G1");
698                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
699                         attrs = typeof (bug82431A1).GetCustomAttributes (
700                                 typeof (InheritAttribute), true);
701                         Assert.AreEqual (1, attrs.Length, "#G3");
702                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
703
704                         attrs = typeof (bug82431A1).GetCustomAttributes (
705                                 typeof (NotInheritAttribute), false);
706                         Assert.AreEqual (1, attrs.Length, "#H1");
707                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
708                         attrs = typeof (bug82431A1).GetCustomAttributes (
709                                 typeof (InheritAttribute), true);
710                         Assert.AreEqual (1, attrs.Length, "#H3");
711                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
712
713                         attrs = typeof (bug82431A2).GetCustomAttributes (
714                                 typeof (InheritAttribute), false);
715                         Assert.AreEqual (0, attrs.Length, "#I1");
716                         attrs = typeof (bug82431A2).GetCustomAttributes (
717                                 typeof (InheritAttribute), true);
718                         Assert.AreEqual (0, attrs.Length, "#I2");
719
720                         attrs = typeof (bug82431A2).GetCustomAttributes (
721                                 typeof (NotInheritAttribute), false);
722                         Assert.AreEqual (0, attrs.Length, "#J1");
723                         attrs = typeof (bug82431A2).GetCustomAttributes (
724                                 typeof (NotInheritAttribute), true);
725                         Assert.AreEqual (0, attrs.Length, "#J2");
726
727                         attrs = typeof (bug82431A3).GetCustomAttributes (
728                                 typeof (InheritAttribute), false);
729                         Assert.AreEqual (2, attrs.Length, "#K1");
730                         Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
731                         Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
732                         attrs = typeof (bug82431A3).GetCustomAttributes (
733                                 typeof (InheritAttribute), true);
734                         Assert.AreEqual (2, attrs.Length, "#K4");
735                         Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
736                         Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
737
738                         attrs = typeof (bug82431A3).GetCustomAttributes (
739                                 typeof (NotInheritAttribute), false);
740                         Assert.AreEqual (1, attrs.Length, "#L1");
741                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
742                         attrs = typeof (bug82431A3).GetCustomAttributes (
743                                 typeof (NotInheritAttribute), true);
744                         Assert.AreEqual (1, attrs.Length, "#L3");
745                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
746
747                         attrs = typeof (bug82431B1).GetCustomAttributes (
748                                 typeof (InheritAttribute), false);
749                         Assert.AreEqual (1, attrs.Length, "#M1");
750                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
751                         attrs = typeof (bug82431B1).GetCustomAttributes (
752                                 typeof (InheritAttribute), true);
753                         Assert.AreEqual (1, attrs.Length, "#M3");
754                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
755
756                         attrs = typeof (bug82431B1).GetCustomAttributes (
757                                 typeof (NotInheritAttribute), false);
758                         Assert.AreEqual (0, attrs.Length, "#N1");
759                         attrs = typeof (bug82431B1).GetCustomAttributes (
760                                 typeof (NotInheritAttribute), true);
761                         Assert.AreEqual (0, attrs.Length, "#N2");
762
763                         attrs = typeof (bug82431B2).GetCustomAttributes (
764                                 typeof (InheritAttribute), false);
765                         Assert.AreEqual (0, attrs.Length, "#O1");
766                         attrs = typeof (bug82431B2).GetCustomAttributes (
767                                 typeof (InheritAttribute), true);
768                         Assert.AreEqual (1, attrs.Length, "#O2");
769                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
770
771                         attrs = typeof (bug82431B2).GetCustomAttributes (
772                                 typeof (NotInheritAttribute), false);
773                         Assert.AreEqual (0, attrs.Length, "#P1");
774                         attrs = typeof (bug82431B2).GetCustomAttributes (
775                                 typeof (NotInheritAttribute), true);
776                         Assert.AreEqual (0, attrs.Length, "#P2");
777
778                         attrs = typeof (bug82431B3).GetCustomAttributes (
779                                 typeof (InheritAttribute), false);
780                         Assert.AreEqual (1, attrs.Length, "#Q1");
781                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
782                         attrs = typeof (bug82431B3).GetCustomAttributes (
783                                 typeof (InheritAttribute), true);
784                         Assert.AreEqual (2, attrs.Length, "#Q3");
785                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
786                         Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
787
788                         attrs = typeof (bug82431B3).GetCustomAttributes (
789                                 typeof (NotInheritAttribute), false);
790                         Assert.AreEqual (1, attrs.Length, "#R1");
791                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
792                         attrs = typeof (bug82431B3).GetCustomAttributes (
793                                 typeof (NotInheritAttribute), true);
794                         Assert.AreEqual (1, attrs.Length, "#R3");
795                         Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
796
797                         attrs = typeof (bug82431B4).GetCustomAttributes (
798                                 typeof (InheritAttribute), false);
799                         Assert.AreEqual (0, attrs.Length, "#S1");
800                         attrs = typeof (bug82431B4).GetCustomAttributes (
801                                 typeof (InheritAttribute), true);
802                         Assert.AreEqual (1, attrs.Length, "#S2");
803                         Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
804
805                         attrs = typeof (bug82431B4).GetCustomAttributes (
806                                 typeof (NotInheritAttribute), false);
807                         Assert.AreEqual (0, attrs.Length, "#T1");
808                         attrs = typeof (bug82431B4).GetCustomAttributes (
809                                 typeof (NotInheritAttribute), true);
810                         Assert.AreEqual (0, attrs.Length, "#T2");
811
812                         attrs = typeof (A).GetCustomAttributes (
813                                 typeof (string), false);
814                         Assert.AreEqual (0, attrs.Length, "#U1");
815                         attrs = typeof (A).GetCustomAttributes (
816                                 typeof (string), true);
817                         Assert.AreEqual (0, attrs.Length, "#U2");
818                 }
819
820                 [Test] // bug #76150
821                 public void IsDefined ()
822                 {
823                         Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
824                         Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#A2");
825                         Assert.IsTrue (typeof (A).IsDefined (typeof (FooAttribute), false), "#A3");
826                         Assert.IsFalse (typeof (A).IsDefined (typeof (BarAttribute), false), "#A4");
827
828                         Assert.IsFalse (typeof (BA).IsDefined (typeof (NemerleAttribute), false), "#B1");
829                         Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
830                         Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
831                         Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
832                         Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
833                         Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
834                         Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
835                         Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
836                         Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
837                         Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
838                         Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
839                         Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
840                 }
841
842                 [Test]
843                 public void IsDefined_AttributeType_Null ()
844                 {
845                         try {
846                                 typeof (BA).IsDefined ((Type) null, false);
847                                 Assert.Fail ("#1");
848                         } catch (ArgumentNullException ex) {
849                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
850                                 Assert.IsNull (ex.InnerException, "#3");
851                                 Assert.IsNotNull (ex.Message, "#4");
852                                 Assert.IsNotNull (ex.ParamName, "#5");
853                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
854                         }
855                 }
856
857                 [Test] // bug #82431
858 #if NET_2_0
859                 [Category ("NotWorking")]
860 #endif
861                 public void IsDefined_Inherited ()
862                 {
863                         Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
864                         Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
865                         Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
866                         Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), false), "#C4");
867                         Assert.IsTrue (typeof (CA).IsDefined (typeof (NemerleAttribute), true), "#C5");
868                         Assert.IsTrue (typeof (CA).IsDefined (typeof (VolatileModifier), true), "#C6");
869                         Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), true), "#C7");
870                         Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), true), "#C8");
871
872                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (NemerleAttribute), false), "#D1");
873                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (VolatileModifier), false), "#D2");
874                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), false), "#D3");
875                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
876                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
877                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
878 #if NET_2_0
879                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
880                         Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
881 #else
882                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
883                         Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
884 #endif
885
886                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
887                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
888                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
889                         Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
890
891                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
892                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
893 #if NET_2_0
894                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
895 #else
896                         Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
897 #endif
898                         Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
899
900                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
901                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
902                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
903                         Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
904
905                         Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
906                         Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
907                         Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
908                         Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
909
910                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
911                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
912                         Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
913                         Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
914
915                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
916                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
917                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
918                         Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
919
920                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
921                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
922                         Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
923                         Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
924                 }
925
926                 [Test]
927                 public void GetTypeCode ()
928                 {
929                         Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
930                         Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
931                         Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
932                         Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
933                         Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
934                         Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
935                         Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
936                         Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
937                         Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
938                         Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
939                         Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
940                         Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
941                         Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
942                         Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
943                         Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
944                         Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
945                         Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
946                         Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
947                 }
948
949                 [Test]
950                 [ExpectedException (typeof (ArgumentNullException))]
951                 public void GetConstructor1a_Bug71300 ()
952                 {
953                         typeof (BindingFlags).GetConstructor (null);
954                 }
955
956                 [Test]
957                 [ExpectedException (typeof (ArgumentNullException))]
958                 public void GetConstructor1b_Bug71300 ()
959                 {
960                         typeof (BindingFlags).GetConstructor (new Type[1] { null });
961                 }
962
963                 [Test]
964                 [ExpectedException (typeof (ArgumentNullException))]
965                 public void GetConstructor4_Bug71300 ()
966                 {
967                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
968                 }
969
970                 [Test]
971                 [ExpectedException (typeof (ArgumentNullException))]
972                 public void GetConstructor5_Bug71300 ()
973                 {
974                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
975                 }
976
977                 [Test]
978                 public void GetMethod_Bug77367 ()
979                 {
980                         MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
981                         Assert.IsNull (i);
982                 }
983
984 #if !TARGET_JVM // Reflection.Emit is not supported for TARGET_JVM
985                 [Test]
986                 public void EqualsUnderlyingType ()
987                 {
988                         AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
989                         TypeAttributes attribs = TypeAttributes.Public;
990
991                         AssemblyName name = new AssemblyName ();
992                         name.Name = "enumtest";
993                         AssemblyBuilder assembly = 
994                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
995                                         name, access);
996
997                         ModuleBuilder module = assembly.DefineDynamicModule 
998                                 ("m", "enumtest.dll");
999                         EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
1000
1001                         Assert.IsTrue (typeof (int).Equals (e));
1002                 }
1003 #endif // TARGET_JVM
1004
1005                 [Test]
1006                 public void Equals_Type_Null ()
1007                 {
1008                         Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
1009                         Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
1010                 }
1011
1012                 [Test]
1013                 public void GetElementType_Bug63841 ()
1014                 {
1015                         Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
1016                 }
1017
1018 #if NET_2_0
1019                 [Test]
1020                 public void FullNameGenerics ()
1021                 {
1022                         Type fooType = typeof (Foo<>);
1023                         FieldInfo [] fields = fooType.GetFields ();
1024
1025                         Assert.AreEqual (1, fields.Length, "#0");
1026
1027                         Assert.IsNotNull (fooType.FullName, "#1");
1028                         Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
1029
1030                         FieldInfo field = fooType.GetField ("Whatever");
1031                         Assert.IsNotNull (field, "#2");
1032                         Assert.AreEqual (field, fields [0], "#2a");
1033                         Assert.IsNull (field.FieldType.FullName, "#3");
1034                         Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
1035                         Assert.IsNotNull (field.FieldType.ToString (), "#4");
1036
1037                         PropertyInfo prop = fooType.GetProperty ("Test");
1038                         Assert.IsNotNull (prop, "#5");
1039                         Assert.IsNull (prop.PropertyType.FullName, "#6");
1040                         Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
1041                         Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
1042
1043                         MethodInfo method = fooType.GetMethod("Execute");
1044                         Assert.IsNotNull (method, "#8");
1045                         Assert.IsNull (method.ReturnType.FullName, "#9");
1046                         Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
1047                         Assert.IsNotNull (method.ReturnType.ToString (), "#10");
1048
1049                         ParameterInfo[] parameters = method.GetParameters();
1050                         Assert.AreEqual (1, parameters.Length, "#11");
1051                         Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
1052                         Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
1053                         Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
1054                 }
1055
1056                 [Test]
1057                 public void TypeParameterIsNotGeneric ()
1058                 {
1059                         Type fooType = typeof (Foo<>);
1060                         Type type_param = fooType.GetGenericArguments () [0];
1061                         Assert.IsTrue (type_param.IsGenericParameter);
1062                         Assert.IsFalse (type_param.IsGenericType);
1063                         Assert.IsFalse (type_param.IsGenericTypeDefinition);
1064
1065                         // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
1066                         // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
1067                         Assert.IsTrue (type_param.ContainsGenericParameters);
1068                 }
1069
1070                 [Test]
1071                 public void IsAssignable ()
1072                 {
1073                         Type foo_type = typeof (Foo<>);
1074                         Type foo_int_type = typeof (Foo<int>);
1075                         Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
1076                         Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
1077
1078                         Type ibar_short_type = typeof (IBar<short>);
1079                         Type ibar_int_type = typeof (IBar<int>);
1080                         Type baz_short_type = typeof (Baz<short>);
1081                         Type baz_int_type = typeof (Baz<int>);
1082
1083                         Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
1084                         Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
1085
1086                         Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
1087                         Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
1088
1089                         // Nullable tests
1090                         Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
1091                         Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
1092                         Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
1093                 }
1094
1095                 [Test]
1096                 public void IsInstanceOf ()
1097                 {
1098                         Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
1099                 }
1100
1101                 [Test]
1102                 public void ByrefType ()
1103                 {
1104                         Type foo_type = typeof (Foo<>);
1105                         Type type_param = foo_type.GetGenericArguments () [0];
1106                         Type byref_type_param = type_param.MakeByRefType ();
1107                         Assert.IsFalse (byref_type_param.IsGenericParameter);
1108                         Assert.IsNull (byref_type_param.DeclaringType);
1109                 }
1110
1111                 [Test]
1112                 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
1113                 public void Bug79023 ()
1114                 {
1115                         ArrayList list = new ArrayList();
1116                         list.Add("foo");
1117
1118                         // The next line used to throw because we had SetProperty
1119                         list.GetType().InvokeMember("Item",
1120                                                     BindingFlags.SetField|BindingFlags.SetProperty|
1121                                                     BindingFlags.Instance|BindingFlags.Public,
1122                                                     null, list, new object[] { 0, "bar" });
1123                         Assert.AreEqual ("bar", list[0]);
1124                 }
1125                 
1126                 [ComVisible (true)]
1127                 public class ComFoo<T> {
1128                 }
1129
1130                 [Test]
1131                 public void GetCustomAttributesGenericInstance ()
1132                 {
1133                         Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
1134                 }
1135
1136                 interface ByRef1<T> { void f (ref T t); }
1137                 interface ByRef2 { void f<T> (ref T t); }
1138
1139                 interface ByRef3<T> where T:struct { void f (ref T? t); }
1140                 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
1141
1142                 void CheckGenericByRef (Type t)
1143                 {
1144                         string name = t.Name;
1145                         t = t.GetMethod ("f").GetParameters () [0].ParameterType;
1146
1147                         Assert.IsFalse (t.IsGenericType, name);
1148                         Assert.IsFalse (t.IsGenericTypeDefinition, name);
1149                         Assert.IsFalse (t.IsGenericParameter, name);
1150                 }
1151
1152                 [Test]
1153                 public void GenericByRef ()
1154                 {
1155                         CheckGenericByRef (typeof (ByRef1<>));
1156                         CheckGenericByRef (typeof (ByRef2));
1157                         CheckGenericByRef (typeof (ByRef3<>));
1158                         CheckGenericByRef (typeof (ByRef4));
1159                 }
1160
1161                 public class Bug80242<T> {
1162                         public interface IFoo { }
1163                         public class Bar : IFoo { }
1164                         public class Baz : Bar { }
1165                 }
1166
1167                 [Test]
1168                 public void TestNestedTypes ()
1169                 {
1170                         Type t = typeof (Bug80242<object>);
1171                         Assert.IsFalse (t.IsGenericTypeDefinition);
1172                         foreach (Type u in t.GetNestedTypes ()) {
1173                                 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
1174                                 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
1175                         }
1176                 }
1177
1178                 [Test] // bug #82211
1179                 public void GetMembers_GenericArgument ()
1180                 {
1181                         Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
1182                         MemberInfo [] members = argType.GetMembers ();
1183                         Assert.IsNotNull (members, "#1");
1184                         Assert.AreEqual (4, members.Length, "#2");
1185                 }
1186 #endif
1187
1188                 public class NemerleAttribute : Attribute
1189                 { }
1190
1191                 public class VolatileModifier : NemerleAttribute
1192                 { }
1193
1194                 [VolatileModifier]
1195                 [FooAttribute]
1196                 class A { }
1197
1198                 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1199                 public class FooAttribute : Attribute
1200                 {
1201                 }
1202
1203                 public class BarAttribute : FooAttribute
1204                 {
1205                 }
1206
1207                 [BarAttribute]
1208                 class BA : A
1209                 {
1210                 }
1211
1212                 class BBA : BA
1213                 {
1214                 }
1215
1216                 class CA : A
1217                 {
1218                 }
1219
1220                 [AttributeUsage (AttributeTargets.Class, Inherited=true)]
1221                 public class InheritAttribute : Attribute
1222                 {
1223                 }
1224
1225                 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1226                 public class NotInheritAttribute : InheritAttribute
1227                 {
1228                 }
1229
1230                 [NotInheritAttribute]
1231                 public class bug82431A1
1232                 {
1233                 }
1234
1235                 public class bug82431A2 : bug82431A1
1236                 {
1237                 }
1238
1239                 [NotInheritAttribute]
1240                 [InheritAttribute]
1241                 public class bug82431A3 : bug82431A1
1242                 {
1243                 }
1244
1245                 [InheritAttribute]
1246                 public class bug82431B1
1247                 {
1248                 }
1249
1250                 public class bug82431B2 : bug82431B1
1251                 {
1252                 }
1253
1254                 [NotInheritAttribute]
1255                 public class bug82431B3 : bug82431B2
1256                 {
1257                 }
1258
1259                 public class bug82431B4 : bug82431B3
1260                 {
1261                 }
1262
1263                 struct FooStruct {
1264                 }
1265
1266                 public class Bug77367
1267                 {
1268                         public void Run (bool b)
1269                         {
1270                         }
1271                 }
1272
1273         }
1274 }