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