6387581c99ea8841425a52b701a817fb25f29529
[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 using System.IO;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Runtime.InteropServices;
17
18 class NoNamespaceClass {
19 }
20
21 namespace MonoTests.System
22 {
23         class Super : ICloneable {
24                 public virtual object Clone () {
25                         return null;
26                 }
27         }
28         class Duper: Super {
29         }
30
31         interface IFace1 {
32                 void foo ();
33         }
34
35         interface IFace2 : IFace1 {
36                 void bar ();
37         }
38
39         interface IFace3 : IFace2 {
40         }
41
42         enum TheEnum { A, B, C };
43
44         abstract class Base {
45                 public int level;
46
47                 public abstract int this [byte i] { get; }
48                 public abstract int this [int i] { get; }
49                 public abstract void TestVoid();
50                 public abstract void TestInt(int i);
51         }
52
53         class DeriveVTable : Base {
54                 public override int this [byte i] { get { return 1; } }
55                 public override int this [int i] { get { return 1; } }
56                 public override void TestVoid() { level = 1; }
57                 public override void TestInt(int i) { level = 1; }
58         }
59
60         class NewVTable : DeriveVTable {
61                 public new int this [byte i] { get { return 2; } }
62                 public new int this [int i] { get { return 2; } }
63                 public new void TestVoid() { level = 2; }
64                 public new void TestInt(int i) { level = 2; }
65
66                 public void Overload () { }
67                 public void Overload (int i) { }
68
69                 public NewVTable (out int i) {
70                         i = 0;
71                 }
72
73                 public void byref_method (out int i) {
74                         i = 0;
75                 }
76
77         }
78
79         class Base1 {
80                 public virtual int Foo {
81                         get {
82                                 return 1;
83                         }
84                         set {
85                         }
86                 }
87         }
88
89         class Derived1 : Base1 {
90                 public override int Foo {
91                         set {
92                         }
93                 }
94         }
95
96 #if NET_2_0
97         public class Foo<T> {
98                 public T Whatever;
99         
100                 public T Test {
101                         get { throw new NotImplementedException (); }
102                 }
103
104                 public T Execute(T a) {
105                         return a;
106                 }
107         }
108
109         public interface IBar<T> { }
110         public class Baz<T> : IBar<T> { }
111 #endif
112
113         [TestFixture]
114         public class TypeTest
115         {
116                 private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k) {
117                 }
118
119                 [Test]
120                 public void TestIsAssignableFrom () {
121                         // Simple tests for inheritance
122                         Assert.AreEqual (typeof (Super).IsAssignableFrom (typeof (Duper)) , true, "#01");
123                         Assert.AreEqual (typeof (Duper).IsAssignableFrom (typeof (Duper)), true, "#02");
124                         Assert.AreEqual (typeof (Object).IsAssignableFrom (typeof (Duper)), true, "#03");
125                         Assert.AreEqual (typeof (ICloneable).IsAssignableFrom (typeof (Duper)), true, "#04");
126
127                         // Tests for arrays
128                         Assert.AreEqual (typeof (Super[]).IsAssignableFrom (typeof (Duper[])), true, "#05");
129                         Assert.AreEqual (typeof (Duper[]).IsAssignableFrom (typeof (Super[])), false, "#06");
130                         Assert.AreEqual (typeof (Object[]).IsAssignableFrom (typeof (Duper[])), true, "#07");
131                         Assert.AreEqual (typeof (ICloneable[]).IsAssignableFrom (typeof (Duper[])), true, "#08");
132
133                         // Tests for multiple dimensional arrays
134                         Assert.AreEqual (typeof (Super[][]).IsAssignableFrom (typeof (Duper[][])), true, "#09");
135                         Assert.AreEqual (typeof (Duper[][]).IsAssignableFrom (typeof (Super[][])), false, "#10");
136                         Assert.AreEqual (typeof (Object[][]).IsAssignableFrom (typeof (Duper[][])), true, "#11");
137                         Assert.AreEqual (typeof (ICloneable[][]).IsAssignableFrom (typeof (Duper[][])), true, "#12");
138
139                         // Tests for vectors<->one dimensional arrays */
140                         Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
141                         Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
142
143                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
144                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
145
146                         // Test that arrays of enums can be cast to their base types
147                         Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
148
149                         // Test that arrays of valuetypes can't be cast to arrays of
150                         // references
151                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TypeCode[])), false, "#16");
152                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TypeCode[])), false, "#17");
153                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TypeCode[])), false, "#18");
154
155                         // Test that arrays of enums can't be cast to arrays of references
156                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TheEnum[])), false, "#19");
157                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TheEnum[])), false, "#20");
158                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TheEnum[])), false, "#21");
159
160                         // Check that ValueType and Enum are recognized as reference types
161                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (ValueType)), true, "#22");
162                         Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (Enum)), true, "#23");
163                         Assert.AreEqual (typeof (ValueType).IsAssignableFrom (typeof (Enum)), true, "#24");
164
165                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (ValueType[])), true, "#25");
166                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (ValueType[])), true, "#26");
167                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (ValueType[])), false, "#27");
168
169                         Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (Enum[])), true, "#28");
170                         Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (Enum[])), true, "#29");
171                         Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (Enum[])), true, "#30");
172
173                         // Tests for byref types
174                         MethodInfo mi = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic);
175                         Assert.IsTrue (mi.GetParameters ()[2].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
176                         Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
177                 }
178
179                 [Test]
180                 public void TestIsSubclassOf () {
181                         Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
182
183                         // Tests for byref types
184                         Type paramType = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic).GetParameters () [0].ParameterType;
185                         Assert.IsTrue (!paramType.IsSubclassOf (typeof (ValueType)), "#02");
186                         //Assert.IsTrue (paramType.IsSubclassOf (typeof (Object)), "#03");
187                         Assert.IsTrue (!paramType.IsSubclassOf (paramType), "#04");
188                 }
189
190                 [Test]
191                 public void TestGetMethodImpl() {
192                         // Test binding of new slot methods (using no types)
193                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod("TestVoid").DeclaringType, "#01");
194                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestVoid").DeclaringType, "#02");
195
196                         // Test binding of new slot methods (using types)
197                         Assert.AreEqual (typeof (Base), typeof (Base).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#03");
198                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#04");
199
200                         // Test overload resolution
201                         Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
202
203                         // Test byref parameters
204                         Assert.AreEqual (null, typeof (NewVTable).GetMethod ("byref_method", new Type[] { typeof (int) }), "#06");
205                         Type byrefInt = typeof (NewVTable).GetMethod ("byref_method").GetParameters ()[0].ParameterType;
206                         Assert.IsNotNull (typeof (NewVTable).GetMethod ("byref_method", new Type[] { byrefInt }), "#07");
207                 }
208
209                 [Test]
210                 public void TestGetPropertyImpl() {
211                         // Test getting property that is exact
212                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int32) }).DeclaringType, "#01");
213
214                         // Test getting property that is not exact
215                         Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
216
217                         // Test overriding of properties when only the set accessor is overriden
218                         Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
219                 }
220
221 #if !TARGET_JVM // StructLayout not supported for TARGET_JVM
222                 [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
223                 public class Class1 {
224                 }
225
226                 [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
227                 public class Class2 {
228                 }
229
230 #if NET_2_0
231                 [Test]
232                 public void StructLayoutAttribute () {
233                         StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
234                         Assert.AreEqual (LayoutKind.Auto, attr1.Value);
235
236                         StructLayoutAttribute attr2 = typeof (Class1).StructLayoutAttribute;
237                         Assert.AreEqual (LayoutKind.Explicit, attr2.Value);
238                         Assert.AreEqual (4, attr2.Pack);
239                         Assert.AreEqual (64, attr2.Size);
240
241                         StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
242                         Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
243                         Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
244                 }
245 #endif
246 #endif // TARGET_JVM
247
248                 [Test]
249                 public void Namespace () {
250                         Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
251                 }
252
253                 public static void Reflected (ref int a) {
254                 }
255
256                 [Test]
257                 public void Name ()
258                 {
259                         Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
260                 }
261
262                 [Test]
263                 public void GetInterfaces () {
264                         Type[] t = typeof (Duper).GetInterfaces ();
265                         Assert.AreEqual (1, t.Length);
266                         Assert.AreEqual (typeof (ICloneable), t[0]);
267
268                         Type[] t2 = typeof (IFace3).GetInterfaces ();
269                         Assert.AreEqual (2, t2.Length);
270                 }
271
272                 public int AField;
273
274                 [Test]
275                 public void GetFieldIgnoreCase () {
276                         Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
277                 }
278
279 #if NET_2_0
280                 public int Count {
281                         internal get {
282                                 return 0;
283                         }
284
285                         set {
286                         }
287                 }
288
289                 [Test]
290                 public void GetPropertyAccessorModifiers () {
291                         Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
292                         Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
293                 }
294 #endif
295
296                 [Test]
297                 public void IsPrimitive () {
298                         Assert.IsTrue (typeof (IntPtr).IsPrimitive);
299                 }
300
301                 [Test]
302                 [Category("NotDotNet")]
303                 // Depends on the GAC working, which it doesn't durring make distcheck.
304                 [Category ("NotWorking")]
305                 public void GetTypeWithWhitespace () {
306                         Assert.IsNotNull (Type.GetType
307                                                    (@"System.Configuration.NameValueSectionHandler,
308                         System,
309 Version=1.0.5000.0,
310 Culture=neutral
311 ,
312 PublicKeyToken=b77a5c561934e089"));
313                 }
314                 
315                 [Test]
316                 public void ExerciseFilterName() {
317                         MemberInfo[] mi = typeof(Base).FindMembers(
318                                 MemberTypes.Method, 
319                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
320                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
321                             Type.FilterName, "*");
322                         Assert.AreEqual (4, mi.Length);
323                         mi = typeof(Base).FindMembers(
324                                 MemberTypes.Method, 
325                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
326                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
327                             Type.FilterName, "Test*");
328                         Assert.AreEqual (2, mi.Length);
329                         mi = typeof(Base).FindMembers(
330                                 MemberTypes.Method, 
331                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
332                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
333                             Type.FilterName, "TestVoid");
334                         Assert.AreEqual (1, mi.Length);
335                         mi = typeof(Base).FindMembers(
336                                 MemberTypes.Method, 
337                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
338                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
339                             Type.FilterName, "NonExistingMethod");
340                         Assert.AreEqual (0, mi.Length);
341                 }
342                 
343                 [Test]
344                 public void ExerciseFilterNameIgnoreCase() {
345                         MemberInfo[] mi = typeof(Base).FindMembers(
346                                 MemberTypes.Method, 
347                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
348                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
349                             Type.FilterNameIgnoreCase, "*");
350                         Assert.AreEqual (4, mi.Length);
351                         mi = typeof(Base).FindMembers(
352                                 MemberTypes.Method, 
353                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
354                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
355                             Type.FilterNameIgnoreCase, "test*");
356                         Assert.AreEqual (2, mi.Length);
357                         mi = typeof(Base).FindMembers(
358                                 MemberTypes.Method, 
359                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
360                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
361                             Type.FilterNameIgnoreCase, "TESTVOID");
362                         Assert.AreEqual (1, mi.Length);
363                         mi = typeof(Base).FindMembers(
364                                 MemberTypes.Method, 
365                                 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
366                             BindingFlags.Instance | BindingFlags.DeclaredOnly,
367                             Type.FilterNameIgnoreCase, "NonExistingMethod");
368                         Assert.AreEqual (0, mi.Length);
369                 }
370
371                 public class ByRef0 {
372                         public int field;
373                         public int property {
374                                 get { return 0; }
375                         }
376                         public ByRef0 (int i) {}
377                         public void f (int i) {}
378                 }
379
380                 [Test]
381                 public void ByrefTypes ()
382                 {
383                         Type t = Type.GetType ("MonoTests.System.TypeTest+ByRef0&");
384                         Assert.IsNotNull (t);
385                         Assert.IsTrue (t.IsByRef);
386                         Assert.AreEqual (0, t.GetMethods (BindingFlags.Public | BindingFlags.Instance).Length);
387                         Assert.AreEqual (0, t.GetConstructors (BindingFlags.Public | BindingFlags.Instance).Length);
388                         Assert.AreEqual (0, t.GetEvents (BindingFlags.Public | BindingFlags.Instance).Length);
389                         Assert.AreEqual (0, t.GetProperties (BindingFlags.Public | BindingFlags.Instance).Length);
390
391                         Assert.IsNull (t.GetMethod ("f"));
392                         Assert.IsNull (t.GetField ("field"));
393                         Assert.IsNull (t.GetProperty ("property"));
394                 }
395
396                 struct B
397                 {
398                         int value;
399                 }
400
401                 [Test]
402                 public void CreateValueTypeNoCtor () {
403                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
404                 }
405
406                 [Test]
407                 [ExpectedException (typeof (MissingMethodException))]
408                 public void CreateValueTypeNoCtorArgs () {
409                         typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
410                 }
411
412                 class X
413                 {
414                         public static int Value;
415                 }
416
417                 class Y  : X
418                 {
419                 }
420
421                 [Test]
422                 public void InvokeMemberGetSetField () {
423                         typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
424
425                         Assert.AreEqual (5, X.Value);
426                         Assert.AreEqual (5, typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
427                         Assert.AreEqual (5, Y.Value);
428                         Assert.AreEqual (5, typeof (Y).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
429                 }                       
430
431                 class Z {
432                         public Z (IComparable value) {}
433                 }
434         
435                 [Test]
436                 public void InvokeMemberMatchPrimitiveTypeWithInterface () {
437                         object[] invokeargs = {1};
438                         typeof (Z).InvokeMember( "", 
439                                                                                         BindingFlags.DeclaredOnly |
440                                                                                         BindingFlags.Public |
441                                                                                         BindingFlags.NonPublic |
442                                                                                         BindingFlags.Instance |
443                                                                                         BindingFlags.CreateInstance,
444                                                                                         null, null, invokeargs 
445                                                                                         );
446                 }
447
448                 class TakesInt {
449                         private int i;
450
451                         public TakesInt (int x)
452                         {
453                                 i = x;
454                         }
455
456                         public int Integer {
457                                 get { return i; }
458                         }
459                 }
460
461                 class TakesObject {
462                         public TakesObject (object x) {}
463                 }
464
465                 // Filed as bug #75241
466                 [Test]
467                 public void GetConstructorNullInTypes ()
468                 {
469                         // This ends up calling type.GetConstructor ()
470                         Activator.CreateInstance (typeof (TakesInt), new object [] { null });
471                         Activator.CreateInstance (typeof (TakesObject), new object [] { null });
472                 }
473
474                 [Test]
475                 [ExpectedException (typeof (ArgumentNullException))]
476                 public void GetConstructorNullInTypes_Bug71300 ()
477                 {
478                         typeof (TakesInt).GetConstructor (new Type[1] { null });
479                         // so null in types isn't valid for GetConstructor!
480                 }
481
482                 [Test]
483                 public void GetConstructor_TakeInt_Object ()
484                 {
485                         Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
486                 }
487
488                 // bug #76150
489                 [Test]
490                 public void IsDefined ()
491                 {
492                         Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#1");
493                         Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#2");
494                 }
495
496                 [Test]
497                 public void GetTypeCode ()
498                 {
499                         Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
500                         Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
501                         Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
502                         Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
503                         Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
504                         Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
505                         Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
506                         Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
507                         Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
508                         Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
509                         Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
510                         Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
511                         Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
512                         Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
513                         Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
514                         Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
515                         Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
516                         Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
517                 }
518
519                 [Test]
520                 [ExpectedException (typeof (ArgumentNullException))]
521                 public void GetConstructor1a_Bug71300 ()
522                 {
523                         typeof (BindingFlags).GetConstructor (null);
524                 }
525
526                 [Test]
527                 [ExpectedException (typeof (ArgumentNullException))]
528                 public void GetConstructor1b_Bug71300 ()
529                 {
530                         typeof (BindingFlags).GetConstructor (new Type[1] { null });
531                 }
532
533                 [Test]
534                 [ExpectedException (typeof (ArgumentNullException))]
535                 public void GetConstructor4_Bug71300 ()
536                 {
537                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
538                 }
539
540                 [Test]
541                 [ExpectedException (typeof (ArgumentNullException))]
542                 public void GetConstructor5_Bug71300 ()
543                 {
544                         typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
545                 }
546
547                 [Test]
548                 public void GetMethod_Bug77367 ()
549                 {
550                         MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
551                         Assert.IsNull (i);
552                 }
553
554                 [Test]
555                 public void EqualsUnderlyingType ()
556                 {
557                         AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
558                         TypeAttributes attribs = TypeAttributes.Public;
559
560                         AssemblyName name = new AssemblyName ();
561                         name.Name = "enumtest";
562                         AssemblyBuilder assembly = 
563                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
564                                                                                                                            name, access);
565
566                         ModuleBuilder module = assembly.DefineDynamicModule 
567                                 ("m", "enumtest.dll");
568                         EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
569
570                         Assert.IsTrue (typeof (int).Equals (e));
571                 }
572
573                 [Test]
574                 public void GetElementType_Bug63841 ()
575                 {
576                         Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
577                 }
578
579 #if NET_2_0
580                 [Test]
581                 public void FullNameGenerics ()
582                 {
583                         Type fooType = typeof (Foo<>);
584                         FieldInfo [] fields = fooType.GetFields ();
585
586                         Assert.AreEqual (1, fields.Length, "#0");
587
588                         Assert.IsNotNull (fooType.FullName, "#1");
589                         Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
590
591                         FieldInfo field = fooType.GetField ("Whatever");
592                         Assert.IsNotNull (field, "#2");
593                         Assert.AreEqual (field, fields [0], "#2a");
594                         Assert.IsNull (field.FieldType.FullName, "#3");
595                         Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
596                         Assert.IsNotNull (field.FieldType.ToString (), "#4");
597
598                         PropertyInfo prop = fooType.GetProperty ("Test");
599                         Assert.IsNotNull (prop, "#5");
600                         Assert.IsNull (prop.PropertyType.FullName, "#6");
601                         Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
602                         Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
603
604                         MethodInfo method = fooType.GetMethod("Execute");
605                         Assert.IsNotNull (method, "#8");
606                         Assert.IsNull (method.ReturnType.FullName, "#9");
607                         Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
608                         Assert.IsNotNull (method.ReturnType.ToString (), "#10");
609
610                         ParameterInfo[] parameters = method.GetParameters();
611                         Assert.AreEqual (1, parameters.Length, "#11");
612                         Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
613                         Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
614                         Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
615                 }
616
617                 [Test]
618                 public void TypeParameterIsNotGeneric ()
619                 {
620                         Type fooType = typeof (Foo<>);
621                         Type type_param = fooType.GetGenericArguments () [0];
622                         Assert.IsTrue (type_param.IsGenericParameter);
623                         Assert.IsFalse (type_param.IsGenericType);
624                         Assert.IsFalse (type_param.IsGenericTypeDefinition);
625
626                         // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
627                         // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
628                         Assert.IsTrue (type_param.ContainsGenericParameters);
629                 }
630
631                 [Test]
632                 public void IsAssignable ()
633                 {
634                         Type foo_type = typeof (Foo<>);
635                         Type foo_int_type = typeof (Foo<int>);
636                         Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
637                         Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
638
639                         Type ibar_short_type = typeof (IBar<short>);
640                         Type ibar_int_type = typeof (IBar<int>);
641                         Type baz_short_type = typeof (Baz<short>);
642                         Type baz_int_type = typeof (Baz<int>);
643
644                         Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
645                         Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
646
647                         Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
648                         Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
649
650                         // Nullable tests
651                         Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
652                         Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
653                         Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
654                 }
655
656                 [Test]
657                 public void IsInstanceOf ()
658                 {
659                         Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
660                 }
661
662                 [Test]
663                 public void ByrefType ()
664                 {
665                         Type foo_type = typeof (Foo<>);
666                         Type type_param = foo_type.GetGenericArguments () [0];
667                         Type byref_type_param = type_param.MakeByRefType ();
668                         Assert.IsFalse (byref_type_param.IsGenericParameter);
669                         Assert.IsNull (byref_type_param.DeclaringType);
670                 }
671
672                 [Test]
673                 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
674                 public void Bug79023 ()
675                 {
676                         ArrayList list = new ArrayList();
677                         list.Add("foo");
678
679                         // The next line used to throw because we had SetProperty
680                         list.GetType().InvokeMember("Item",
681                                                     BindingFlags.SetField|BindingFlags.SetProperty|
682                                                     BindingFlags.Instance|BindingFlags.Public,
683                                                     null, list, new object[] { 0, "bar" });
684                         Assert.AreEqual ("bar", list[0]);
685                 }
686                 
687                 [ComVisible (true)]
688                 public class ComFoo<T> {
689                 }
690
691                 [Test]
692                 public void GetCustomAttributesGenericInstance ()
693                 {
694                         Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
695                 }
696
697                 interface ByRef1<T> { void f (ref T t); }
698                 interface ByRef2 { void f<T> (ref T t); }
699
700                 interface ByRef3<T> where T:struct { void f (ref T? t); }
701                 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
702
703                 void CheckGenericByRef (Type t)
704                 {
705                         string name = t.Name;
706                         t = t.GetMethod ("f").GetParameters () [0].ParameterType;
707
708                         Assert.IsFalse (t.IsGenericType, name);
709                         Assert.IsFalse (t.IsGenericTypeDefinition, name);
710                         Assert.IsFalse (t.IsGenericParameter, name);
711                 }
712
713                 [Test]
714                 public void GenericByRef ()
715                 {
716                         CheckGenericByRef (typeof (ByRef1<>));
717                         CheckGenericByRef (typeof (ByRef2));
718                         CheckGenericByRef (typeof (ByRef3<>));
719                         CheckGenericByRef (typeof (ByRef4));
720                 }
721
722                 public class Bug80242<T> {
723                         public interface IFoo { }
724                         public class Bar : IFoo { }
725                         public class Baz : Bar { }
726                 }
727
728                 [Test]
729                 public void TestNestedTypes ()
730                 {
731                         Type t = typeof (Bug80242<object>);
732                         Assert.IsFalse (t.IsGenericTypeDefinition);
733                         foreach (Type u in t.GetNestedTypes ()) {
734                                 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
735                                 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
736                         }
737                 }
738 #endif
739
740                 public class NemerleAttribute : Attribute
741                 { }
742
743                 public class VolatileModifier : NemerleAttribute
744                 { }
745
746                 [VolatileModifier]
747                 class A { }
748
749                 struct FooStruct {
750                 }
751
752                 public class Bug77367
753                 {
754                         public void Run (bool b)
755                         {
756                         }
757                 }
758
759         }
760 }