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"));
506 public void CreateValueTypeNoCtor () {
507 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
511 [ExpectedException (typeof (MissingMethodException))]
512 public void CreateValueTypeNoCtorArgs () {
513 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
518 public static int Value;
526 public void InvokeMemberGetSetField () {
527 typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.SetField, null, null, new object [] { 5 });
529 Assert.AreEqual (5, X.Value);
530 Assert.AreEqual (5, typeof (X).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
531 Assert.AreEqual (5, Y.Value);
532 Assert.AreEqual (5, typeof (Y).InvokeMember ("Value", BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy|BindingFlags.GetField, null, null, new object [0]));
536 public Z (IComparable value) {}
540 public void InvokeMemberMatchPrimitiveTypeWithInterface () {
541 object[] invokeargs = {1};
542 typeof (Z).InvokeMember( "",
543 BindingFlags.DeclaredOnly |
544 BindingFlags.Public |
545 BindingFlags.NonPublic |
546 BindingFlags.Instance |
547 BindingFlags.CreateInstance,
548 null, null, invokeargs
555 public TakesInt (int x)
566 public TakesObject (object x) {}
569 // Filed as bug #75241
571 public void GetConstructorNullInTypes ()
573 // This ends up calling type.GetConstructor ()
574 Activator.CreateInstance (typeof (TakesInt), new object [] { null });
575 Activator.CreateInstance (typeof (TakesObject), new object [] { null });
579 [ExpectedException (typeof (ArgumentNullException))]
580 public void GetConstructorNullInTypes_Bug71300 ()
582 typeof (TakesInt).GetConstructor (new Type[1] { null });
583 // so null in types isn't valid for GetConstructor!
587 public void GetConstructor_TakeInt_Object ()
589 Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
593 public void GetCustomAttributes_All ()
595 object [] attrs = typeof (A).GetCustomAttributes (false);
596 Assert.AreEqual (2, attrs.Length, "#A1");
597 Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
598 Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
600 attrs = typeof (BA).GetCustomAttributes (false);
601 Assert.AreEqual (1, attrs.Length, "#B1");
602 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
604 attrs = typeof (BA).GetCustomAttributes (true);
605 Assert.AreEqual (2, attrs.Length, "#C1");
606 Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
607 Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
609 attrs = typeof (CA).GetCustomAttributes (false);
610 Assert.AreEqual (0, attrs.Length, "#D");
612 attrs = typeof (CA).GetCustomAttributes (true);
613 Assert.AreEqual (1, attrs.Length, "#E1");
614 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
617 static bool HasAttribute (object [] attrs, Type attributeType)
619 foreach (object attr in attrs)
620 if (attr.GetType () == attributeType)
626 public void GetCustomAttributes_Type ()
628 object [] attrs = null;
630 attrs = typeof (A).GetCustomAttributes (
631 typeof (VolatileModifier), false);
632 Assert.AreEqual (1, attrs.Length, "#A1");
633 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
634 attrs = typeof (A).GetCustomAttributes (
635 typeof (VolatileModifier), true);
636 Assert.AreEqual (1, attrs.Length, "#A3");
637 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
639 attrs = typeof (A).GetCustomAttributes (
640 typeof (NemerleAttribute), false);
641 Assert.AreEqual (1, attrs.Length, "#B1");
642 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
643 attrs = typeof (A).GetCustomAttributes (
644 typeof (NemerleAttribute), true);
645 Assert.AreEqual (1, attrs.Length, "#B3");
646 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
648 attrs = typeof (A).GetCustomAttributes (
649 typeof (FooAttribute), false);
650 Assert.AreEqual (1, attrs.Length, "#C1");
651 Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
652 attrs = typeof (A).GetCustomAttributes (
653 typeof (FooAttribute), false);
654 Assert.AreEqual (1, attrs.Length, "#C3");
655 Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
657 attrs = typeof (BA).GetCustomAttributes (
658 typeof (VolatileModifier), false);
659 Assert.AreEqual (0, attrs.Length, "#D1");
660 attrs = typeof (BA).GetCustomAttributes (
661 typeof (VolatileModifier), true);
662 Assert.AreEqual (1, attrs.Length, "#D2");
663 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
665 attrs = typeof (BA).GetCustomAttributes (
666 typeof (NemerleAttribute), false);
667 Assert.AreEqual (0, attrs.Length, "#E1");
668 attrs = typeof (BA).GetCustomAttributes (
669 typeof (NemerleAttribute), true);
670 Assert.AreEqual (1, attrs.Length, "#E2");
671 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
673 attrs = typeof (BA).GetCustomAttributes (
674 typeof (FooAttribute), false);
675 Assert.AreEqual (1, attrs.Length, "#F1");
676 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
677 attrs = typeof (BA).GetCustomAttributes (
678 typeof (FooAttribute), true);
679 Assert.AreEqual (1, attrs.Length, "#F3");
680 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
682 attrs = typeof (bug82431A1).GetCustomAttributes (
683 typeof (InheritAttribute), false);
684 Assert.AreEqual (1, attrs.Length, "#G1");
685 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
686 attrs = typeof (bug82431A1).GetCustomAttributes (
687 typeof (InheritAttribute), true);
688 Assert.AreEqual (1, attrs.Length, "#G3");
689 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
691 attrs = typeof (bug82431A1).GetCustomAttributes (
692 typeof (NotInheritAttribute), false);
693 Assert.AreEqual (1, attrs.Length, "#H1");
694 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
695 attrs = typeof (bug82431A1).GetCustomAttributes (
696 typeof (InheritAttribute), true);
697 Assert.AreEqual (1, attrs.Length, "#H3");
698 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
700 attrs = typeof (bug82431A2).GetCustomAttributes (
701 typeof (InheritAttribute), false);
702 Assert.AreEqual (0, attrs.Length, "#I1");
703 attrs = typeof (bug82431A2).GetCustomAttributes (
704 typeof (InheritAttribute), true);
705 Assert.AreEqual (0, attrs.Length, "#I2");
707 attrs = typeof (bug82431A2).GetCustomAttributes (
708 typeof (NotInheritAttribute), false);
709 Assert.AreEqual (0, attrs.Length, "#J1");
710 attrs = typeof (bug82431A2).GetCustomAttributes (
711 typeof (NotInheritAttribute), true);
712 Assert.AreEqual (0, attrs.Length, "#J2");
714 attrs = typeof (bug82431A3).GetCustomAttributes (
715 typeof (InheritAttribute), false);
716 Assert.AreEqual (2, attrs.Length, "#K1");
717 Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
718 Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
719 attrs = typeof (bug82431A3).GetCustomAttributes (
720 typeof (InheritAttribute), true);
721 Assert.AreEqual (2, attrs.Length, "#K4");
722 Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
723 Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
725 attrs = typeof (bug82431A3).GetCustomAttributes (
726 typeof (NotInheritAttribute), false);
727 Assert.AreEqual (1, attrs.Length, "#L1");
728 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
729 attrs = typeof (bug82431A3).GetCustomAttributes (
730 typeof (NotInheritAttribute), true);
731 Assert.AreEqual (1, attrs.Length, "#L3");
732 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
734 attrs = typeof (bug82431B1).GetCustomAttributes (
735 typeof (InheritAttribute), false);
736 Assert.AreEqual (1, attrs.Length, "#M1");
737 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
738 attrs = typeof (bug82431B1).GetCustomAttributes (
739 typeof (InheritAttribute), true);
740 Assert.AreEqual (1, attrs.Length, "#M3");
741 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
743 attrs = typeof (bug82431B1).GetCustomAttributes (
744 typeof (NotInheritAttribute), false);
745 Assert.AreEqual (0, attrs.Length, "#N1");
746 attrs = typeof (bug82431B1).GetCustomAttributes (
747 typeof (NotInheritAttribute), true);
748 Assert.AreEqual (0, attrs.Length, "#N2");
750 attrs = typeof (bug82431B2).GetCustomAttributes (
751 typeof (InheritAttribute), false);
752 Assert.AreEqual (0, attrs.Length, "#O1");
753 attrs = typeof (bug82431B2).GetCustomAttributes (
754 typeof (InheritAttribute), true);
755 Assert.AreEqual (1, attrs.Length, "#O2");
756 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
758 attrs = typeof (bug82431B2).GetCustomAttributes (
759 typeof (NotInheritAttribute), false);
760 Assert.AreEqual (0, attrs.Length, "#P1");
761 attrs = typeof (bug82431B2).GetCustomAttributes (
762 typeof (NotInheritAttribute), true);
763 Assert.AreEqual (0, attrs.Length, "#P2");
765 attrs = typeof (bug82431B3).GetCustomAttributes (
766 typeof (InheritAttribute), false);
767 Assert.AreEqual (1, attrs.Length, "#Q1");
768 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
769 attrs = typeof (bug82431B3).GetCustomAttributes (
770 typeof (InheritAttribute), true);
771 Assert.AreEqual (2, attrs.Length, "#Q3");
772 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
773 Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
775 attrs = typeof (bug82431B3).GetCustomAttributes (
776 typeof (NotInheritAttribute), false);
777 Assert.AreEqual (1, attrs.Length, "#R1");
778 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
779 attrs = typeof (bug82431B3).GetCustomAttributes (
780 typeof (NotInheritAttribute), true);
781 Assert.AreEqual (1, attrs.Length, "#R3");
782 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
784 attrs = typeof (bug82431B4).GetCustomAttributes (
785 typeof (InheritAttribute), false);
786 Assert.AreEqual (0, attrs.Length, "#S1");
787 attrs = typeof (bug82431B4).GetCustomAttributes (
788 typeof (InheritAttribute), true);
789 Assert.AreEqual (1, attrs.Length, "#S2");
790 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
792 attrs = typeof (bug82431B4).GetCustomAttributes (
793 typeof (NotInheritAttribute), false);
794 Assert.AreEqual (0, attrs.Length, "#T1");
795 attrs = typeof (bug82431B4).GetCustomAttributes (
796 typeof (NotInheritAttribute), true);
797 Assert.AreEqual (0, attrs.Length, "#T2");
799 attrs = typeof (A).GetCustomAttributes (
800 typeof (string), false);
801 Assert.AreEqual (0, attrs.Length, "#U1");
802 attrs = typeof (A).GetCustomAttributes (
803 typeof (string), true);
804 Assert.AreEqual (0, attrs.Length, "#U2");
808 public void IsDefined ()
810 Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
811 Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#A2");
812 Assert.IsTrue (typeof (A).IsDefined (typeof (FooAttribute), false), "#A3");
813 Assert.IsFalse (typeof (A).IsDefined (typeof (BarAttribute), false), "#A4");
815 Assert.IsFalse (typeof (BA).IsDefined (typeof (NemerleAttribute), false), "#B1");
816 Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
817 Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
818 Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
819 Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
820 Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
821 Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
822 Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
823 Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
824 Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
825 Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
826 Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
830 public void IsDefined_AttributeType_Null ()
833 typeof (BA).IsDefined ((Type) null, false);
835 } catch (ArgumentNullException ex) {
836 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
837 Assert.IsNull (ex.InnerException, "#3");
838 Assert.IsNotNull (ex.Message, "#4");
839 Assert.IsNotNull (ex.ParamName, "#5");
840 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
846 [Category ("NotWorking")]
848 public void IsDefined_Inherited ()
850 Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
851 Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
852 Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
853 Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), false), "#C4");
854 Assert.IsTrue (typeof (CA).IsDefined (typeof (NemerleAttribute), true), "#C5");
855 Assert.IsTrue (typeof (CA).IsDefined (typeof (VolatileModifier), true), "#C6");
856 Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), true), "#C7");
857 Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), true), "#C8");
859 Assert.IsFalse (typeof (BBA).IsDefined (typeof (NemerleAttribute), false), "#D1");
860 Assert.IsFalse (typeof (BBA).IsDefined (typeof (VolatileModifier), false), "#D2");
861 Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), false), "#D3");
862 Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
863 Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
864 Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
866 Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
867 Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
869 Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
870 Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
873 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
874 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
875 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
876 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
878 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
879 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
881 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
883 Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
885 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
887 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
888 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
889 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
890 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
892 Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
893 Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
894 Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
895 Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
897 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
898 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
899 Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
900 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
902 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
903 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
904 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
905 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
907 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
908 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
909 Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
910 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
914 public void GetTypeCode ()
916 Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
917 Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
918 Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
919 Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
920 Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
921 Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
922 Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
923 Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
924 Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
925 Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
926 Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
927 Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
928 Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
929 Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
930 Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
931 Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
932 Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
933 Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
937 [ExpectedException (typeof (ArgumentNullException))]
938 public void GetConstructor1a_Bug71300 ()
940 typeof (BindingFlags).GetConstructor (null);
944 [ExpectedException (typeof (ArgumentNullException))]
945 public void GetConstructor1b_Bug71300 ()
947 typeof (BindingFlags).GetConstructor (new Type[1] { null });
951 [ExpectedException (typeof (ArgumentNullException))]
952 public void GetConstructor4_Bug71300 ()
954 typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, new Type[1] { null }, null);
958 [ExpectedException (typeof (ArgumentNullException))]
959 public void GetConstructor5_Bug71300 ()
961 typeof (BindingFlags).GetConstructor (BindingFlags.Default, null, CallingConventions.Any, new Type[1] { null }, null);
965 public void GetMethod_Bug77367 ()
967 MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
971 #if !TARGET_JVM // Reflection.Emit is not supported for TARGET_JVM
973 public void EqualsUnderlyingType ()
975 AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
976 TypeAttributes attribs = TypeAttributes.Public;
978 AssemblyName name = new AssemblyName ();
979 name.Name = "enumtest";
980 AssemblyBuilder assembly =
981 AppDomain.CurrentDomain.DefineDynamicAssembly (
984 ModuleBuilder module = assembly.DefineDynamicModule
985 ("m", "enumtest.dll");
986 EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
988 Assert.IsTrue (typeof (int).Equals (e));
993 public void Equals_Type_Null ()
995 Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
996 Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
1000 [Category("NotWorking")]
1001 public void GetElementType_Bug63841 ()
1003 Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
1008 public void FullNameGenerics ()
1010 Type fooType = typeof (Foo<>);
1011 FieldInfo [] fields = fooType.GetFields ();
1013 Assert.AreEqual (1, fields.Length, "#0");
1015 Assert.IsNotNull (fooType.FullName, "#1");
1016 Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
1018 FieldInfo field = fooType.GetField ("Whatever");
1019 Assert.IsNotNull (field, "#2");
1020 Assert.AreEqual (field, fields [0], "#2a");
1021 Assert.IsNull (field.FieldType.FullName, "#3");
1022 Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
1023 Assert.IsNotNull (field.FieldType.ToString (), "#4");
1025 PropertyInfo prop = fooType.GetProperty ("Test");
1026 Assert.IsNotNull (prop, "#5");
1027 Assert.IsNull (prop.PropertyType.FullName, "#6");
1028 Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
1029 Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
1031 MethodInfo method = fooType.GetMethod("Execute");
1032 Assert.IsNotNull (method, "#8");
1033 Assert.IsNull (method.ReturnType.FullName, "#9");
1034 Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
1035 Assert.IsNotNull (method.ReturnType.ToString (), "#10");
1037 ParameterInfo[] parameters = method.GetParameters();
1038 Assert.AreEqual (1, parameters.Length, "#11");
1039 Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
1040 Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
1041 Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
1045 public void TypeParameterIsNotGeneric ()
1047 Type fooType = typeof (Foo<>);
1048 Type type_param = fooType.GetGenericArguments () [0];
1049 Assert.IsTrue (type_param.IsGenericParameter);
1050 Assert.IsFalse (type_param.IsGenericType);
1051 Assert.IsFalse (type_param.IsGenericTypeDefinition);
1053 // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
1054 // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
1055 Assert.IsTrue (type_param.ContainsGenericParameters);
1059 public void IsAssignable ()
1061 Type foo_type = typeof (Foo<>);
1062 Type foo_int_type = typeof (Foo<int>);
1063 Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
1064 Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
1066 Type ibar_short_type = typeof (IBar<short>);
1067 Type ibar_int_type = typeof (IBar<int>);
1068 Type baz_short_type = typeof (Baz<short>);
1069 Type baz_int_type = typeof (Baz<int>);
1071 Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
1072 Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
1074 Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
1075 Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
1078 Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
1079 Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
1080 Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
1084 public void IsInstanceOf ()
1086 Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
1090 public void ByrefType ()
1092 Type foo_type = typeof (Foo<>);
1093 Type type_param = foo_type.GetGenericArguments () [0];
1094 Type byref_type_param = type_param.MakeByRefType ();
1095 Assert.IsFalse (byref_type_param.IsGenericParameter);
1096 Assert.IsNull (byref_type_param.DeclaringType);
1100 [Category ("NotWorking")] // BindingFlags.SetField throws since args.Length != 1, even though we have SetProperty
1101 public void Bug79023 ()
1103 ArrayList list = new ArrayList();
1106 // The next line used to throw because we had SetProperty
1107 list.GetType().InvokeMember("Item",
1108 BindingFlags.SetField|BindingFlags.SetProperty|
1109 BindingFlags.Instance|BindingFlags.Public,
1110 null, list, new object[] { 0, "bar" });
1111 Assert.AreEqual ("bar", list[0]);
1115 public class ComFoo<T> {
1119 public void GetCustomAttributesGenericInstance ()
1121 Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
1124 interface ByRef1<T> { void f (ref T t); }
1125 interface ByRef2 { void f<T> (ref T t); }
1127 interface ByRef3<T> where T:struct { void f (ref T? t); }
1128 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
1130 void CheckGenericByRef (Type t)
1132 string name = t.Name;
1133 t = t.GetMethod ("f").GetParameters () [0].ParameterType;
1135 Assert.IsFalse (t.IsGenericType, name);
1136 Assert.IsFalse (t.IsGenericTypeDefinition, name);
1137 Assert.IsFalse (t.IsGenericParameter, name);
1141 public void GenericByRef ()
1143 CheckGenericByRef (typeof (ByRef1<>));
1144 CheckGenericByRef (typeof (ByRef2));
1145 CheckGenericByRef (typeof (ByRef3<>));
1146 CheckGenericByRef (typeof (ByRef4));
1149 public class Bug80242<T> {
1150 public interface IFoo { }
1151 public class Bar : IFoo { }
1152 public class Baz : Bar { }
1156 public void TestNestedTypes ()
1158 Type t = typeof (Bug80242<object>);
1159 Assert.IsFalse (t.IsGenericTypeDefinition);
1160 foreach (Type u in t.GetNestedTypes ()) {
1161 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
1162 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
1166 [Test] // bug #82211
1167 public void GetMembers_GenericArgument ()
1169 Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
1170 MemberInfo [] members = argType.GetMembers ();
1171 Assert.IsNotNull (members, "#1");
1172 Assert.AreEqual (4, members.Length, "#2");
1176 public class NemerleAttribute : Attribute
1179 public class VolatileModifier : NemerleAttribute
1186 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1187 public class FooAttribute : Attribute
1191 public class BarAttribute : FooAttribute
1208 [AttributeUsage (AttributeTargets.Class, Inherited=true)]
1209 public class InheritAttribute : Attribute
1213 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
1214 public class NotInheritAttribute : InheritAttribute
1218 [NotInheritAttribute]
1219 public class bug82431A1
1223 public class bug82431A2 : bug82431A1
1227 [NotInheritAttribute]
1229 public class bug82431A3 : bug82431A1
1234 public class bug82431B1
1238 public class bug82431B2 : bug82431B1
1242 [NotInheritAttribute]
1243 public class bug82431B3 : bug82431B2
1247 public class bug82431B4 : bug82431B3
1254 public class Bug77367
1256 public void Run (bool b)