1 // TypeTest.cs - NUnit Test Cases for the System.Type class
4 // Zoltan Varga (vargaz@freemail.hu)
7 // (C) 2003 Ximian, Inc. http://www.ximian.com
10 using NUnit.Framework;
12 using System.Collections;
14 using System.Collections.Generic;
17 using System.Reflection;
18 using System.Reflection.Emit;
19 using System.Runtime.InteropServices;
21 class NoNamespaceClass {
24 namespace MonoTests.System
26 class Super : ICloneable {
27 public virtual object Clone () {
38 interface IFace2 : IFace1 {
42 interface IFace3 : IFace2 {
45 enum TheEnum { A, B, C };
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);
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; }
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; }
69 public void Overload () { }
70 public void Overload (int i) { }
72 public NewVTable (out int i) {
76 public void byref_method (out int i) {
83 public virtual int Foo {
92 class Derived1 : Base1 {
93 public override int Foo {
100 public class Foo<T> {
104 get { throw new NotImplementedException (); }
107 public T Execute(T a) {
112 public interface IBar<T> { }
113 public class Baz<T> : IBar<T> { }
117 public class TypeTest
119 private AssemblyBuilder assembly;
120 private ModuleBuilder module;
121 const string ASSEMBLY_NAME = "MonoTests.System.TypeTest";
122 static int typeIndexer = 0;
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");
134 private string genTypeName ()
136 return "t" + (typeIndexer++);
139 private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k) {
142 private void GenericMethod<Q> (Q q) {
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");
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");
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");
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");
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});
173 Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
174 Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
177 // Test that arrays of enums can be cast to their base types
178 Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
180 // Test that arrays of valuetypes can't be cast to arrays of
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");
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");
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");
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");
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");
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));
209 // Tests for type parameters
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)));
218 public void TestIsSubclassOf () {
219 Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
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");
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");
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");
238 // Test overload resolution
239 Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
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");
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");
253 // Test getting property that is not exact
254 Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
256 // Test overriding of properties when only the set accessor is overriden
257 Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
260 #if !TARGET_JVM // StructLayout not supported for TARGET_JVM
261 [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
262 public class Class1 {
265 [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
266 public class Class2 {
271 public void StructLayoutAttribute () {
272 StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
273 Assert.AreEqual (LayoutKind.Auto, attr1.Value);
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);
280 StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
281 Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
282 Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
288 public void Namespace () {
289 Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
292 public static void Reflected (ref int a) {
298 Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
302 public void GetInterfaces () {
303 Type[] t = typeof (Duper).GetInterfaces ();
304 Assert.AreEqual (1, t.Length);
305 Assert.AreEqual (typeof (ICloneable), t[0]);
307 Type[] t2 = typeof (IFace3).GetInterfaces ();
308 Assert.AreEqual (2, t2.Length);
314 public void GetFieldIgnoreCase () {
315 Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
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));
336 public void IsAbstract ()
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");
347 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=286308
348 Type [] typeArgs = typeof (List<>).GetGenericArguments ();
349 Assert.IsFalse (typeArgs [0].IsAbstract, "#7");
354 public void IsCOMObject ()
356 Type type = typeof (string);
357 Assert.IsFalse (type.IsCOMObject, "#1");
359 TypeBuilder tb = module.DefineType (genTypeName ());
360 type = tb.CreateType ();
361 Assert.IsFalse (type.IsCOMObject, "#2");
365 public void IsImport ()
367 Type type = typeof (string);
368 Assert.IsFalse (type.IsImport, "#1");
370 TypeBuilder tb = module.DefineType (genTypeName ());
371 type = tb.CreateType ();
372 Assert.IsFalse (type.IsImport, "#2");
374 tb = module.DefineType (genTypeName (), TypeAttributes.Import |
375 TypeAttributes.Interface | TypeAttributes.Abstract);
376 type = tb.CreateType ();
377 Assert.IsTrue (type.IsImport, "#3");
381 public void IsInterface ()
383 Assert.IsFalse (typeof (string).IsInterface, "#1");
384 Assert.IsTrue (typeof (ICloneable).IsInterface, "#2");
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");
395 public void IsValueType ()
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");
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,
416 PublicKeyToken=b77a5c561934e089"));
420 public void ExerciseFilterName() {
421 MemberInfo[] mi = typeof(Base).FindMembers(
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(
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(
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(
441 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
442 BindingFlags.Instance | BindingFlags.DeclaredOnly,
443 Type.FilterName, "NonExistingMethod");
444 Assert.AreEqual (0, mi.Length);
448 public void ExerciseFilterNameIgnoreCase() {
449 MemberInfo[] mi = typeof(Base).FindMembers(
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(
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(
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(
469 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
470 BindingFlags.Instance | BindingFlags.DeclaredOnly,
471 Type.FilterNameIgnoreCase, "NonExistingMethod");
472 Assert.AreEqual (0, mi.Length);
475 public class ByRef0 {
477 public int property {
480 public ByRef0 (int i) {}
481 public void f (int i) {}
485 public void ByrefTypes ()
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);
495 Assert.IsNull (t.GetMethod ("f"));
496 Assert.IsNull (t.GetField ("field"));
497 Assert.IsNull (t.GetProperty ("property"));
501 public void TestAssemblyQualifiedName ()
503 Type t = Type.GetType ("System.Byte[]&");
504 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte[]&"));
506 t = Type.GetType ("System.Byte*&");
507 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte*&"));
509 t = Type.GetType ("System.Byte&");
510 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte&"));
519 public void CreateValueTypeNoCtor () {
520 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
524 [ExpectedException (typeof (MissingMethodException))]
525 public void CreateValueTypeNoCtorArgs () {
526 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
531 public static int Value;
539 public void InvokeMemberGetSetField () {
540 typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
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]));
549 public Z (IComparable value) {}
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
568 public TakesInt (int x)
579 public TakesObject (object x) {}
582 // Filed as bug #75241
584 public void GetConstructorNullInTypes ()
586 // This ends up calling type.GetConstructor ()
587 Activator.CreateInstance (typeof (TakesInt), new object [] { null });
588 Activator.CreateInstance (typeof (TakesObject), new object [] { null });
592 [ExpectedException (typeof (ArgumentNullException))]
593 public void GetConstructorNullInTypes_Bug71300 ()
595 typeof (TakesInt).GetConstructor (new Type[1] { null });
596 // so null in types isn't valid for GetConstructor!
600 public void GetConstructor_TakeInt_Object ()
602 Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
606 public void GetCustomAttributes_All ()
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");
613 attrs = typeof (BA).GetCustomAttributes (false);
614 Assert.AreEqual (1, attrs.Length, "#B1");
615 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
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");
622 attrs = typeof (CA).GetCustomAttributes (false);
623 Assert.AreEqual (0, attrs.Length, "#D");
625 attrs = typeof (CA).GetCustomAttributes (true);
626 Assert.AreEqual (1, attrs.Length, "#E1");
627 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
630 static bool HasAttribute (object [] attrs, Type attributeType)
632 foreach (object attr in attrs)
633 if (attr.GetType () == attributeType)
639 public void GetCustomAttributes_Type ()
641 object [] attrs = null;
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
821 public void IsDefined ()
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");
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");
843 public void IsDefined_AttributeType_Null ()
846 typeof (BA).IsDefined ((Type) null, false);
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");
859 [Category ("NotWorking")]
861 public void IsDefined_Inherited ()
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");
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");
879 Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
880 Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
882 Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
883 Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
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");
891 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
892 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
894 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
896 Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
898 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
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");
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");
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");
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");
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");
927 public void GetTypeCode ()
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");
950 [ExpectedException (typeof (ArgumentNullException))]
951 public void GetConstructor1a_Bug71300 ()
953 typeof (BindingFlags).GetConstructor (null);
957 [ExpectedException (typeof (ArgumentNullException))]
958 public void GetConstructor1b_Bug71300 ()
960 typeof (BindingFlags).GetConstructor (new Type[1] { null });
964 [ExpectedException (typeof (ArgumentNullException))]
965 public void GetConstructor4_Bug71300 ()
967 typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
971 [ExpectedException (typeof (ArgumentNullException))]
972 public void GetConstructor5_Bug71300 ()
974 typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
978 public void GetMethod_Bug77367 ()
980 MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
984 #if !TARGET_JVM // Reflection.Emit is not supported for TARGET_JVM
986 public void EqualsUnderlyingType ()
988 AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
989 TypeAttributes attribs = TypeAttributes.Public;
991 AssemblyName name = new AssemblyName ();
992 name.Name = "enumtest";
993 AssemblyBuilder assembly =
994 AppDomain.CurrentDomain.DefineDynamicAssembly (
997 ModuleBuilder module = assembly.DefineDynamicModule
998 ("m", "enumtest.dll");
999 EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
1001 Assert.IsTrue (typeof (int).Equals (e));
1003 #endif // TARGET_JVM
1006 public void Equals_Type_Null ()
1008 Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
1009 Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
1013 public void GetElementType_Bug63841 ()
1015 Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
1020 public void FullNameGenerics ()
1022 Type fooType = typeof (Foo<>);
1023 FieldInfo [] fields = fooType.GetFields ();
1025 Assert.AreEqual (1, fields.Length, "#0");
1027 Assert.IsNotNull (fooType.FullName, "#1");
1028 Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
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");
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");
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");
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");
1057 public void TypeParameterIsNotGeneric ()
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);
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);
1071 public void IsAssignable ()
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>");
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>);
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>");
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>");
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)));
1096 public void IsInstanceOf ()
1098 Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
1102 public void ByrefType ()
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);
1112 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
1113 public void Bug79023 ()
1115 ArrayList list = new ArrayList();
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]);
1127 public class ComFoo<T> {
1131 public void GetCustomAttributesGenericInstance ()
1133 Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
1136 interface ByRef1<T> { void f (ref T t); }
1137 interface ByRef2 { void f<T> (ref T t); }
1139 interface ByRef3<T> where T:struct { void f (ref T? t); }
1140 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
1142 void CheckGenericByRef (Type t)
1144 string name = t.Name;
1145 t = t.GetMethod ("f").GetParameters () [0].ParameterType;
1147 Assert.IsFalse (t.IsGenericType, name);
1148 Assert.IsFalse (t.IsGenericTypeDefinition, name);
1149 Assert.IsFalse (t.IsGenericParameter, name);
1153 public void GenericByRef ()
1155 CheckGenericByRef (typeof (ByRef1<>));
1156 CheckGenericByRef (typeof (ByRef2));
1157 CheckGenericByRef (typeof (ByRef3<>));
1158 CheckGenericByRef (typeof (ByRef4));
1161 public class Bug80242<T> {
1162 public interface IFoo { }
1163 public class Bar : IFoo { }
1164 public class Baz : Bar { }
1168 public void TestNestedTypes ()
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);
1178 [Test] // bug #82211
1179 public void GetMembers_GenericArgument ()
1181 Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
1182 MemberInfo [] members = argType.GetMembers ();
1183 Assert.IsNotNull (members, "#1");
1184 Assert.AreEqual (4, members.Length, "#2");
1188 public class NemerleAttribute : Attribute
1191 public class VolatileModifier : NemerleAttribute
1198 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1199 public class FooAttribute : Attribute
1203 public class BarAttribute : FooAttribute
1220 [AttributeUsage (AttributeTargets.Class, Inherited=true)]
1221 public class InheritAttribute : Attribute
1225 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1226 public class NotInheritAttribute : InheritAttribute
1230 [NotInheritAttribute]
1231 public class bug82431A1
1235 public class bug82431A2 : bug82431A1
1239 [NotInheritAttribute]
1241 public class bug82431A3 : bug82431A1
1246 public class bug82431B1
1250 public class bug82431B2 : bug82431B1
1254 [NotInheritAttribute]
1255 public class bug82431B3 : bug82431B2
1259 public class bug82431B4 : bug82431B3
1266 public class Bug77367
1268 public void Run (bool b)