1 // TypeTest.cs - NUnit Test Cases for the System.Type class
4 // Zoltan Varga (vargaz@freemail.hu)
6 // Aleksey Kliger (aleksey@xamarin.com)
8 // (C) 2003 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2015 Xamarin, Inc. (http://www.xamarin.com)
12 using NUnit.Framework;
14 using System.Threading;
15 using System.Collections;
16 using System.Collections.Generic;
18 using System.Reflection;
19 #if !MONOTOUCH && !MOBILE_STATIC
20 using System.Reflection.Emit;
22 using System.Runtime.InteropServices;
24 using System.Globalization;
26 class NoNamespaceClass {
29 namespace MonoTests.System
31 class Super : ICloneable
33 public virtual object Clone ()
48 interface IFace2 : IFace1
53 interface IFace3 : IFace2
68 public abstract int this [byte i] {
72 public abstract int this [int i] {
76 public abstract void TestVoid ();
77 public abstract void TestInt (int i);
80 class DeriveVTable : Base
82 public override int this [byte i] {
86 public override int this [int i] {
90 public override void TestVoid ()
95 public override void TestInt (int i)
101 class NewVTable : DeriveVTable
103 public new int this [byte i] {
107 public new int this [int i] {
111 public new void TestVoid ()
116 public new void TestInt (int i)
121 public void Overload ()
125 public void Overload (int i)
129 public NewVTable (out int i)
134 public void byref_method (out int i)
142 public virtual int Foo {
147 public event EventHandler E;
154 class Derived1 : Base1
156 public override int Foo {
161 class Derived2 : Base1
168 public new event Action E;
169 public new void Dummy ()
180 get { throw new NotImplementedException (); }
183 public T Execute (T a)
188 public class Nested<K> {}
195 public interface IBar<T>
199 public class Baz<T> : IBar<T>
205 public static void Bang<S> () {}
208 public class Bug348522
210 public void Test (int __argument)
215 public class GenericIndexers<T, U>
217 // This class has two indexers that take different
218 // arguments. GetProperties on all instances of this
219 // generic type should still have 2 properties, even
220 // if T and U are instantiated with the same types.
221 public T this[T t] { get { return t; } }
222 public U this[U u] { get { return u; } }
225 public class FirstMethodBinder : Binder
227 public override MethodBase BindToMethod (BindingFlags bindingAttr, MethodBase [] match, ref object [] args,
228 ParameterModifier [] modifiers, CultureInfo culture, string [] names,
235 public override object ChangeType (object value, Type type1, CultureInfo culture)
240 // The rest is just to please the compiler
241 public override FieldInfo BindToField (BindingFlags a, FieldInfo[] b, object c, CultureInfo d)
246 public override void ReorderArgumentArray(ref object[] a, object b)
250 public override MethodBase SelectMethod(BindingFlags a, MethodBase[] b, Type[] c, ParameterModifier[] d)
255 public override PropertyInfo SelectProperty(BindingFlags a, PropertyInfo[] b, Type c, Type[] d, ParameterModifier[] e)
262 public class TypeTest
264 #if !MONOTOUCH && !MOBILE_STATIC
265 private ModuleBuilder module;
267 const string ASSEMBLY_NAME = "MonoTests.System.TypeTest";
268 static int typeIndexer = 0;
273 AssemblyName assemblyName = new AssemblyName ();
274 assemblyName.Name = ASSEMBLY_NAME;
275 #if !MONOTOUCH && !MOBILE_STATIC
276 var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (
277 assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
278 module = assembly.DefineDynamicModule ("module1");
282 private string genTypeName ()
284 return "t" + (typeIndexer++);
287 private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k)
291 public interface IFace {
294 private void GenericMethod<Q, T1> (Q q, T1 t) where T1 : IFace
304 public void TestIsAssignableFrom ()
306 // Simple tests for inheritance
307 Assert.AreEqual (typeof (Super).IsAssignableFrom (typeof (Duper)) , true, "#01");
308 Assert.AreEqual (typeof (Duper).IsAssignableFrom (typeof (Duper)), true, "#02");
309 Assert.AreEqual (typeof (Object).IsAssignableFrom (typeof (Duper)), true, "#03");
310 Assert.AreEqual (typeof (ICloneable).IsAssignableFrom (typeof (Duper)), true, "#04");
313 Assert.AreEqual (typeof (Super[]).IsAssignableFrom (typeof (Duper[])), true, "#05");
314 Assert.AreEqual (typeof (Duper[]).IsAssignableFrom (typeof (Super[])), false, "#06");
315 Assert.AreEqual (typeof (Object[]).IsAssignableFrom (typeof (Duper[])), true, "#07");
316 Assert.AreEqual (typeof (ICloneable[]).IsAssignableFrom (typeof (Duper[])), true, "#08");
318 // Tests for multiple dimensional arrays
319 Assert.AreEqual (typeof (Super[][]).IsAssignableFrom (typeof (Duper[][])), true, "#09");
320 Assert.AreEqual (typeof (Duper[][]).IsAssignableFrom (typeof (Super[][])), false, "#10");
321 Assert.AreEqual (typeof (Object[][]).IsAssignableFrom (typeof (Duper[][])), true, "#11");
322 Assert.AreEqual (typeof (ICloneable[][]).IsAssignableFrom (typeof (Duper[][])), true, "#12");
324 // Tests for vectors<->one dimensional arrays */
325 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
326 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
328 Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
329 Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
331 // Test that arrays of enums can be cast to their base types
332 Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
334 // Test that arrays of valuetypes can't be cast to arrays of
336 Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TypeCode[])), false, "#16");
337 Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TypeCode[])), false, "#17");
338 Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TypeCode[])), false, "#18");
340 // Test that arrays of enums can't be cast to arrays of references
341 Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TheEnum[])), false, "#19");
342 Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TheEnum[])), false, "#20");
343 Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TheEnum[])), false, "#21");
345 // Check that ValueType and Enum are recognized as reference types
346 Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (ValueType)), true, "#22");
347 Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (Enum)), true, "#23");
348 Assert.AreEqual (typeof (ValueType).IsAssignableFrom (typeof (Enum)), true, "#24");
350 Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (ValueType[])), true, "#25");
351 Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (ValueType[])), true, "#26");
352 Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (ValueType[])), false, "#27");
354 Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (Enum[])), true, "#28");
355 Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (Enum[])), true, "#29");
356 Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (Enum[])), true, "#30");
358 // Tests for byref types
359 MethodInfo mi = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic);
360 Assert.IsTrue (mi.GetParameters ()[2].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
361 Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
363 // Tests for type parameters
364 mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
365 Assert.IsTrue (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (mi.GetParameters ()[0].ParameterType));
366 Assert.IsFalse (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (typeof (int)));
368 // Tests for parameters with generic constraints
369 mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
370 Assert.IsTrue (typeof (IFace).IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
374 [ExpectedException (typeof (ArgumentException))]
375 public void GetInterfaceMapOnInterface ()
377 typeof (IList).GetInterfaceMap (typeof (ICollection));
381 public void TestIsSubclassOf ()
383 Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
385 // Tests for byref types
386 Type paramType = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic).GetParameters () [0].ParameterType;
387 Assert.IsFalse (paramType.IsSubclassOf (typeof(ValueType)), "#02");
388 Assert.IsNull (paramType.BaseType, "#02-b");
389 Assert.IsTrue (paramType.IsSubclassOf (typeof (Object)), "#03");
390 Assert.IsFalse (paramType.IsSubclassOf (paramType), "#04");
394 public void TestGetMethodImpl ()
396 // Test binding of new slot methods (using no types)
397 Assert.AreEqual (typeof (Base), typeof (Base).GetMethod("TestVoid").DeclaringType, "#01");
398 Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestVoid").DeclaringType, "#02");
400 // Test binding of new slot methods (using types)
401 Assert.AreEqual (typeof (Base), typeof (Base).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#03");
402 Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#04");
404 // Test overload resolution
405 Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
407 // Test byref parameters
408 Assert.AreEqual (null, typeof (NewVTable).GetMethod ("byref_method", new Type[] { typeof (int) }), "#06");
409 Type byrefInt = typeof (NewVTable).GetMethod ("byref_method").GetParameters ()[0].ParameterType;
410 Assert.IsNotNull (typeof (NewVTable).GetMethod ("byref_method", new Type[] { byrefInt }), "#07");
414 public void TestGetPropertyImpl ()
416 // Test getting property that is exact
417 Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int32) }).DeclaringType, "#01");
419 // Test getting property that is not exact
420 Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
422 // Test overriding of properties when only the set accessor is overriden
423 Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
427 public void GetEvents ()
430 Assert.AreEqual (1, typeof (Derived2).GetEvents ().Length);
431 Assert.AreEqual (typeof (Derived2), typeof (Derived2).GetEvents ()[0].DeclaringType);
435 public void GetProperties ()
437 // Test hide-by-name-and-signature
438 Assert.AreEqual (1, typeof (Derived2).GetProperties ().Length, "#1");
439 Assert.AreEqual (typeof (Derived2), typeof (Derived2).GetProperties ()[0].DeclaringType, "#2");
441 // For generics, hide-by-name-and-signature works on the unexpanded types. The
442 // GenericIndexers<T,U> class has two indexers that take different arguments.
443 // GetProperties on all instances of this generic type should still have 2 properties,
444 // even if T and U are instantiated with the same types.
446 var ps = typeof (GenericIndexers<int,int>).GetProperties ();
447 Assert.AreEqual (2, ps.Length, "#3");
448 for (int i = 0; i < ps.Length; i++) {
451 var getterResultType = p.GetGetMethod ().ReturnType;
453 var msg = String.Format ("#4-{0}", i);
454 Assert.AreEqual (typeof (int), getterResultType, msg);
459 [Test] // GetProperties (BindingFlags)
460 public void GetProperties_Flags ()
462 PropertyInfo [] props;
463 Type type = typeof (Bar);
466 flags = BindingFlags.Instance | BindingFlags.NonPublic;
467 props = type.GetProperties (flags);
469 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#A1");
470 Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#A2");
471 Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#A3");
472 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#A4");
473 Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#A5");
474 Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#A6");
475 Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#A7");
476 Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#A8");
477 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#A9");
478 Assert.IsTrue (ContainsProperty (props, "IntInst"), "#A10");
479 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#A11");
480 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#A12");
481 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#A13");
482 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#A14");
483 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#A15");
484 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#A16");
485 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#A17");
486 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#A18");
487 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#A19");
488 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#A20");
489 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#A21");
490 Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#A22");
491 Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#A23");
492 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#A24");
493 Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#A25");
494 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#A26");
495 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#A27");
496 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#A28");
497 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#A29");
498 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#A30");
500 flags = BindingFlags.Instance | BindingFlags.Public;
501 props = type.GetProperties (flags);
503 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#B1");
504 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#B2");
505 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#B3");
506 Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#B4");
507 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#B5");
508 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#B6");
509 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#B7");
510 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#B8");
511 Assert.IsTrue (ContainsProperty (props, "PubInst"), "#B9");
512 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#B10");
513 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#B11");
514 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#B12");
515 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#B13");
516 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#B14");
517 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#B15");
518 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#B16");
519 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#B17");
520 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#B18");
521 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#B19");
522 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#B20");
523 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#B21");
524 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#B22");
525 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#B23");
526 Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#B24");
527 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#B25");
528 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#B26");
529 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#B27");
530 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#B28");
531 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#B29");
532 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#B30");
534 flags = BindingFlags.Static | BindingFlags.Public;
535 props = type.GetProperties (flags);
537 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#C1");
538 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#C2");
539 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#C3");
540 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#C4");
541 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#C5");
542 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#C6");
543 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#C7");
544 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#C8");
545 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#C9");
546 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#C10");
547 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#C11");
548 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#C12");
549 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#C13");
550 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#C14");
551 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#C15");
552 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#C16");
553 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#C17");
554 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#C18");
555 Assert.IsTrue (ContainsProperty (props, "PubStat"), "#C19");
556 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#C20");
557 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#C21");
558 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#C22");
559 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#C23");
560 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#C24");
561 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#C25");
562 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#C26");
563 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#C27");
564 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#C28");
565 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#C29");
566 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#C30");
568 flags = BindingFlags.Static | BindingFlags.NonPublic;
569 props = type.GetProperties (flags);
571 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#D1");
572 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#D2");
573 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#D3");
574 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#D4");
575 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#D5");
576 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#D6");
577 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#D7");
578 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#D8");
579 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#D9");
580 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#D10");
581 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#D11");
582 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#D12");
583 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#D13");
584 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#D14");
585 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#D15");
586 Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#D16");
587 Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#D17");
588 Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#D18");
589 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#D19");
590 Assert.IsTrue (ContainsProperty (props, "IntStat"), "#D20");
591 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#D21");
592 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#D22");
593 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#D23");
594 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#D24");
595 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#D25");
596 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#D26");
597 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#D27");
598 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#D28");
599 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#D29");
600 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#D30");
602 flags = BindingFlags.Instance | BindingFlags.NonPublic |
603 BindingFlags.FlattenHierarchy;
604 props = type.GetProperties (flags);
606 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#E1");
607 Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#E2");
608 Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#E3");
609 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#E4");
610 Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#E5");
611 Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#E6");
612 Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#E7");
613 Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#E8");
614 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#E9");
615 Assert.IsTrue (ContainsProperty (props, "IntInst"), "#E10");
616 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#E11");
617 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#E12");
618 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#E13");
619 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#E14");
620 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#E15");
621 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#E16");
622 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#E17");
623 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#E18");
624 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#E19");
625 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#E20");
626 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#E21");
627 Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#E22");
628 Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#E23");
629 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#E24");
630 Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#E25");
631 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#E26");
632 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#E27");
633 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#E28");
634 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#E29");
635 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#E30");
637 flags = BindingFlags.Instance | BindingFlags.Public |
638 BindingFlags.FlattenHierarchy;
639 props = type.GetProperties (flags);
641 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#F1");
642 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#F2");
643 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#F3");
644 Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#F4");
645 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#F5");
646 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#F6");
647 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#F7");
648 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#F8");
649 Assert.IsTrue (ContainsProperty (props, "PubInst"), "#F9");
650 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#F10");
651 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#F11");
652 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#F12");
653 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#F13");
654 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#F14");
655 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#F15");
656 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#F16");
657 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#F17");
658 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#F18");
659 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#F19");
660 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#F20");
661 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#F21");
662 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#F22");
663 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#F23");
664 Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#F24");
665 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#F25");
666 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#F26");
667 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#F27");
668 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#F28");
669 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#F29");
670 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#F30");
672 flags = BindingFlags.Static | BindingFlags.Public |
673 BindingFlags.FlattenHierarchy;
674 props = type.GetProperties (flags);
676 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#G1");
677 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#G2");
678 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#G3");
679 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#G4");
680 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#G5");
681 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#G6");
682 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#G7");
683 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#G8");
684 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#G9");
685 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#G10");
686 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#G11");
687 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#G12");
688 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#G13");
689 Assert.IsTrue (ContainsProperty (props, "PubStatBase"), "#G14");
690 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#G15");
691 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#G16");
692 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#G17");
693 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#G18");
694 Assert.IsTrue (ContainsProperty (props, "PubStat"), "#G19");
695 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#G20");
696 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#G21");
697 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#G22");
698 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#G23");
699 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#G24");
700 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#G25");
701 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#G26");
702 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#G27");
703 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#G28");
704 Assert.IsTrue (ContainsProperty (props, "PubStatBlue"), "#G29");
705 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#G30");
707 flags = BindingFlags.Static | BindingFlags.NonPublic |
708 BindingFlags.FlattenHierarchy;
709 props = type.GetProperties (flags);
711 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#H1");
712 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#H2");
713 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#H3");
714 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#H4");
715 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#H5");
716 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#H6");
717 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#H7");
718 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#H8");
719 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#H9");
720 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#H10");
721 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#H11");
722 Assert.IsTrue (ContainsProperty (props, "ProtStatBase"), "#H12");
723 Assert.IsTrue (ContainsProperty (props, "ProIntStatBase"), "#H13");
724 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#H14");
725 Assert.IsTrue (ContainsProperty (props, "IntStatBase"), "#H15");
726 Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#H16");
727 Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#H17");
728 Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#H18");
729 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#H19");
730 Assert.IsTrue (ContainsProperty (props, "IntStat"), "#H20");
731 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#H21");
732 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#H22");
733 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#H23");
734 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#H24");
735 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#H25");
736 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#H26");
737 Assert.IsTrue (ContainsProperty (props, "ProtStatBlue"), "#H27");
738 Assert.IsTrue (ContainsProperty (props, "ProIntStatBlue"), "#H28");
739 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#H29");
740 Assert.IsTrue (ContainsProperty (props, "IntStatBlue"), "#H30");
742 flags = BindingFlags.Instance | BindingFlags.NonPublic |
743 BindingFlags.DeclaredOnly;
744 props = type.GetProperties (flags);
746 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#I1");
747 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#I2");
748 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#I3");
749 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#I4");
750 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#I5");
751 Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#I6");
752 Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#I7");
753 Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#I8");
754 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#I9");
755 Assert.IsTrue (ContainsProperty (props, "IntInst"), "#I10");
756 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#I11");
757 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#I12");
758 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#I13");
759 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#I14");
760 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#I15");
761 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#I16");
762 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#I17");
763 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#I18");
764 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#I19");
765 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#I20");
766 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#I21");
767 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#I22");
768 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#I23");
769 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#I24");
770 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#I25");
771 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#I26");
772 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#I27");
773 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#I28");
774 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#I29");
775 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#I30");
777 flags = BindingFlags.Instance | BindingFlags.Public |
778 BindingFlags.DeclaredOnly;
779 props = type.GetProperties (flags);
781 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#J1");
782 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#J2");
783 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#J3");
784 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#J4");
785 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#J5");
786 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#J6");
787 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#J7");
788 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#J8");
789 Assert.IsTrue (ContainsProperty (props, "PubInst"), "#J9");
790 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#J10");
791 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#J11");
792 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#J12");
793 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#J13");
794 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#J14");
795 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#J15");
796 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#J16");
797 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#J17");
798 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#J18");
799 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#J19");
800 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#J20");
801 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#J21");
802 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#J22");
803 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#J23");
804 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#J24");
805 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#J25");
806 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#J26");
807 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#J27");
808 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#J28");
809 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#J29");
810 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#J30");
812 flags = BindingFlags.Static | BindingFlags.Public |
813 BindingFlags.DeclaredOnly;
814 props = type.GetProperties (flags);
816 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#K1");
817 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#K2");
818 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#K3");
819 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#K4");
820 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#K5");
821 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#K6");
822 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#K7");
823 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#K8");
824 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#K9");
825 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#K10");
826 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#K11");
827 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#K12");
828 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#K13");
829 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#K14");
830 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#K15");
831 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#K16");
832 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#K17");
833 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#K18");
834 Assert.IsTrue (ContainsProperty (props, "PubStat"), "#K19");
835 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#K20");
836 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#K21");
837 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#K22");
838 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#K23");
839 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#K24");
840 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#K25");
841 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#K26");
842 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#K27");
843 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#K28");
844 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#K29");
845 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#K30");
847 flags = BindingFlags.Static | BindingFlags.NonPublic |
848 BindingFlags.DeclaredOnly;
849 props = type.GetProperties (flags);
851 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#L1");
852 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#L2");
853 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#L3");
854 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#L4");
855 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#L5");
856 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#L6");
857 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#L7");
858 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#L8");
859 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#L9");
860 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#L10");
861 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#L11");
862 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#L12");
863 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#L13");
864 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#L14");
865 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#L15");
866 Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#L16");
867 Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#L17");
868 Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#L18");
869 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#L19");
870 Assert.IsTrue (ContainsProperty (props, "IntStat"), "#L20");
871 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#L21");
872 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#L22");
873 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#L23");
874 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#L24");
875 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#L25");
876 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#L26");
877 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#L27");
878 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#L28");
879 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#L29");
880 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#L30");
882 flags = BindingFlags.Instance | BindingFlags.NonPublic |
884 props = type.GetProperties (flags);
886 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#M1");
887 Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#M2");
888 Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#M3");
889 Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#M4");
890 Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#M5");
891 Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#M6");
892 Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#M7");
893 Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#M8");
894 Assert.IsTrue (ContainsProperty (props, "PubInst"), "#M9");
895 Assert.IsTrue (ContainsProperty (props, "IntInst"), "#M10");
896 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#M11");
897 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#M12");
898 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#M13");
899 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#M14");
900 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#M15");
901 Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#M16");
902 Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#M17");
903 Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#M18");
904 Assert.IsFalse (ContainsProperty (props, "PubStat"), "#M19");
905 Assert.IsFalse (ContainsProperty (props, "IntStat"), "#M20");
906 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#M21");
907 Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#M22");
908 Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#M23");
909 Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#M24");
910 Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#M25");
911 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#M26");
912 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#M27");
913 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#M28");
914 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#M29");
915 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#M30");
917 flags = BindingFlags.Static | BindingFlags.NonPublic |
919 props = type.GetProperties (flags);
921 Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#N1");
922 Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#N2");
923 Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#N3");
924 Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#N4");
925 Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#N5");
926 Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#N6");
927 Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#N7");
928 Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#N8");
929 Assert.IsFalse (ContainsProperty (props, "PubInst"), "#N9");
930 Assert.IsFalse (ContainsProperty (props, "IntInst"), "#N10");
931 Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#N11");
932 Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#N12");
933 Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#N13");
934 Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#N14");
935 Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#N15");
936 Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#N16");
937 Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#N17");
938 Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#N18");
939 Assert.IsTrue (ContainsProperty (props, "PubStat"), "#N19");
940 Assert.IsTrue (ContainsProperty (props, "IntStat"), "#N20");
941 Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#N21");
942 Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#N22");
943 Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#N23");
944 Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#N24");
945 Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#N25");
946 Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#N26");
947 Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#N27");
948 Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#N28");
949 Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#N29");
950 Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#N30");
953 [Test] // GetProperty (String)
954 public void GetProperty1_Name_Null ()
956 Type type = typeof (Bar);
958 type.GetProperty ((string) null);
960 } catch (ArgumentNullException ex) {
961 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
962 Assert.IsNull (ex.InnerException, "#3");
963 Assert.IsNotNull (ex.Message, "#4");
964 Assert.IsNotNull (ex.ParamName, "#5");
965 Assert.AreEqual ("name", ex.ParamName, "#6");
969 [Test] // GetProperty (String, BindingFlags)
970 public void GetProperty2 ()
972 Type type = typeof (Bar);
975 flags = BindingFlags.Instance | BindingFlags.NonPublic;
977 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#A1");
978 Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#A2");
979 Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#A3");
980 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#A4");
981 Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#A5");
982 Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#A6");
983 Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#A7");
984 Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#A8");
985 Assert.IsNull (type.GetProperty ("PubInst", flags), "#A9");
986 Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#A10");
987 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#A11");
988 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#A12");
989 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#A13");
990 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#A14");
991 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#A15");
992 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#A16");
993 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#A17");
994 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#A18");
995 Assert.IsNull (type.GetProperty ("PubStat", flags), "#A19");
996 Assert.IsNull (type.GetProperty ("IntStat", flags), "#A20");
997 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#A21");
998 Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#A22");
999 Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#A23");
1000 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#A24");
1001 Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#A25");
1002 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#A26");
1003 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#A27");
1004 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#A28");
1005 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#A29");
1006 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#A30");
1008 flags = BindingFlags.Instance | BindingFlags.Public;
1010 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#B1");
1011 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#B2");
1012 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#B3");
1013 Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#B4");
1014 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#B5");
1015 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#B6");
1016 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#B7");
1017 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#B8");
1018 Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#B9");
1019 Assert.IsNull (type.GetProperty ("IntInst", flags), "#B10");
1020 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#B11");
1021 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#B12");
1022 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#B13");
1023 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#B14");
1024 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#B15");
1025 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#B16");
1026 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#B17");
1027 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#B18");
1028 Assert.IsNull (type.GetProperty ("PubStat", flags), "#B19");
1029 Assert.IsNull (type.GetProperty ("IntStat", flags), "#B20");
1030 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#B21");
1031 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#B22");
1032 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#B23");
1033 Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#B24");
1034 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#B25");
1035 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#B26");
1036 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#B27");
1037 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#B28");
1038 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#B29");
1039 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#B30");
1041 flags = BindingFlags.Static | BindingFlags.Public;
1043 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#C1");
1044 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#C2");
1045 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#C3");
1046 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#C4");
1047 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#C5");
1048 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#C6");
1049 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#C7");
1050 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#C8");
1051 Assert.IsNull (type.GetProperty ("PubInst", flags), "#C9");
1052 Assert.IsNull (type.GetProperty ("IntInst", flags), "#C10");
1053 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#C11");
1054 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#C12");
1055 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#C13");
1056 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#C14");
1057 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#C15");
1058 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#C16");
1059 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#C17");
1060 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#C18");
1061 Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#C19");
1062 Assert.IsNull (type.GetProperty ("IntStat", flags), "#C20");
1063 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#C21");
1064 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#C22");
1065 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#C23");
1066 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#C24");
1067 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#C25");
1068 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#C26");
1069 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#C27");
1070 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#C28");
1071 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#C29");
1072 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#C30");
1074 flags = BindingFlags.Static | BindingFlags.NonPublic;
1076 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#D1");
1077 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#D2");
1078 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#D3");
1079 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#D4");
1080 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#D5");
1081 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#D6");
1082 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#D7");
1083 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#D8");
1084 Assert.IsNull (type.GetProperty ("PubInst", flags), "#D9");
1085 Assert.IsNull (type.GetProperty ("IntInst", flags), "#D10");
1086 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#D11");
1087 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#D12");
1088 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#D13");
1089 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#D14");
1090 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#D15");
1091 Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#D16");
1092 Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#D17");
1093 Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#D18");
1094 Assert.IsNull (type.GetProperty ("PubStat", flags), "#D19");
1095 Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#D20");
1096 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#D21");
1097 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#D22");
1098 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#D23");
1099 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#D24");
1100 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#D25");
1101 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#D26");
1102 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#D27");
1103 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#D28");
1104 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#D29");
1105 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#D30");
1107 flags = BindingFlags.Instance | BindingFlags.NonPublic |
1108 BindingFlags.FlattenHierarchy;
1110 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#E1");
1111 Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#E2");
1112 Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#E3");
1113 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#E4");
1114 Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#E5");
1115 Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#E6");
1116 Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#E7");
1117 Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#E8");
1118 Assert.IsNull (type.GetProperty ("PubInst", flags), "#E9");
1119 Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#E10");
1120 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#E11");
1121 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#E12");
1122 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#E13");
1123 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#E14");
1124 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#E15");
1125 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#E16");
1126 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#E17");
1127 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#E18");
1128 Assert.IsNull (type.GetProperty ("PubStat", flags), "#E19");
1129 Assert.IsNull (type.GetProperty ("IntStat", flags), "#E20");
1130 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#E21");
1131 Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#E22");
1132 Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#E23");
1133 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#E24");
1134 Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#E25");
1135 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#E26");
1136 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#E27");
1137 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#E28");
1138 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#E29");
1139 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#E30");
1141 flags = BindingFlags.Instance | BindingFlags.Public |
1142 BindingFlags.FlattenHierarchy;
1144 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#F1");
1145 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#F2");
1146 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#F3");
1147 Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#F4");
1148 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#F5");
1149 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#F6");
1150 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#F7");
1151 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#F8");
1152 Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#F9");
1153 Assert.IsNull (type.GetProperty ("IntInst", flags), "#F10");
1154 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#F11");
1155 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#F12");
1156 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#F13");
1157 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#F14");
1158 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#F15");
1159 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#F16");
1160 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#F17");
1161 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#F18");
1162 Assert.IsNull (type.GetProperty ("PubStat", flags), "#F19");
1163 Assert.IsNull (type.GetProperty ("IntStat", flags), "#F20");
1164 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#F21");
1165 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#F22");
1166 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#F23");
1167 Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#F24");
1168 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#F25");
1169 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#F26");
1170 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#F27");
1171 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#F28");
1172 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#F29");
1173 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#F30");
1175 flags = BindingFlags.Static | BindingFlags.Public |
1176 BindingFlags.FlattenHierarchy;
1178 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#G1");
1179 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#G2");
1180 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#G3");
1181 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#G4");
1182 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#G5");
1183 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#G6");
1184 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#G7");
1185 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#G8");
1186 Assert.IsNull (type.GetProperty ("PubInst", flags), "#G9");
1187 Assert.IsNull (type.GetProperty ("IntInst", flags), "#G10");
1188 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#G11");
1189 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#G12");
1190 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#G13");
1191 Assert.IsNotNull (type.GetProperty ("PubStatBase", flags), "#G14");
1192 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#G15");
1193 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#G16");
1194 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#G17");
1195 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#G18");
1196 Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#G19");
1197 Assert.IsNull (type.GetProperty ("IntStat", flags), "#G20");
1198 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#G21");
1199 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#G22");
1200 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#G23");
1201 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#G24");
1202 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#G25");
1203 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#G26");
1204 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#G27");
1205 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#G28");
1206 Assert.IsNotNull (type.GetProperty ("PubStatBlue", flags), "#G29");
1207 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#G30");
1209 flags = BindingFlags.Static | BindingFlags.NonPublic |
1210 BindingFlags.FlattenHierarchy;
1212 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#H1");
1213 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#H2");
1214 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#H3");
1215 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#H4");
1216 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#H5");
1217 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#H6");
1218 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#H7");
1219 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#H8");
1220 Assert.IsNull (type.GetProperty ("PubInst", flags), "#H9");
1221 Assert.IsNull (type.GetProperty ("IntInst", flags), "#H10");
1222 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#H11");
1223 Assert.IsNotNull (type.GetProperty ("ProtStatBase", flags), "#H12");
1224 Assert.IsNotNull (type.GetProperty ("ProIntStatBase", flags), "#H13");
1225 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#H14");
1226 Assert.IsNotNull (type.GetProperty ("IntStatBase", flags), "#H15");
1227 Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#H16");
1228 Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#H17");
1229 Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#H18");
1230 Assert.IsNull (type.GetProperty ("PubStat", flags), "#H19");
1231 Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#H20");
1232 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#H21");
1233 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#H22");
1234 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#H23");
1235 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#H24");
1236 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#H25");
1237 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#H26");
1238 Assert.IsNotNull (type.GetProperty ("ProtStatBlue", flags), "#H27");
1239 Assert.IsNotNull (type.GetProperty ("ProIntStatBlue", flags), "#H28");
1240 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#H29");
1241 Assert.IsNotNull (type.GetProperty ("IntStatBlue", flags), "#H30");
1243 flags = BindingFlags.Instance | BindingFlags.NonPublic |
1244 BindingFlags.DeclaredOnly;
1246 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#I1");
1247 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#I2");
1248 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#I3");
1249 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#I4");
1250 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#I5");
1251 Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#I6");
1252 Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#I7");
1253 Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#I8");
1254 Assert.IsNull (type.GetProperty ("PubInst", flags), "#I9");
1255 Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#I10");
1256 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#I11");
1257 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#I12");
1258 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#I13");
1259 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#I14");
1260 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#I15");
1261 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#I16");
1262 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#I17");
1263 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#I18");
1264 Assert.IsNull (type.GetProperty ("PubStat", flags), "#I19");
1265 Assert.IsNull (type.GetProperty ("IntStat", flags), "#I20");
1266 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#I21");
1267 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#I22");
1268 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#I23");
1269 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#I24");
1270 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#I25");
1271 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#I26");
1272 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#I27");
1273 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#I28");
1274 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#I29");
1275 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#I30");
1277 flags = BindingFlags.Instance | BindingFlags.Public |
1278 BindingFlags.DeclaredOnly;
1280 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#J1");
1281 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#J2");
1282 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#J3");
1283 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#J4");
1284 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#J5");
1285 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#J6");
1286 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#J7");
1287 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#J8");
1288 Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#J9");
1289 Assert.IsNull (type.GetProperty ("IntInst", flags), "#J10");
1290 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#J11");
1291 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#J12");
1292 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#J13");
1293 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#J14");
1294 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#J15");
1295 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#J16");
1296 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#J17");
1297 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#J18");
1298 Assert.IsNull (type.GetProperty ("PubStat", flags), "#J19");
1299 Assert.IsNull (type.GetProperty ("IntStat", flags), "#J20");
1300 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#J21");
1301 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#J22");
1302 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#J23");
1303 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#J24");
1304 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#J25");
1305 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#J26");
1306 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#J27");
1307 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#J28");
1308 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#J29");
1309 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#J30");
1311 flags = BindingFlags.Static | BindingFlags.Public |
1312 BindingFlags.DeclaredOnly;
1314 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#K1");
1315 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#K2");
1316 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#K3");
1317 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#K4");
1318 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#K5");
1319 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#K6");
1320 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#K7");
1321 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#K8");
1322 Assert.IsNull (type.GetProperty ("PubInst", flags), "#K9");
1323 Assert.IsNull (type.GetProperty ("IntInst", flags), "#K10");
1324 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#K11");
1325 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#K12");
1326 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#K13");
1327 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#K14");
1328 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#K15");
1329 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#K16");
1330 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#K17");
1331 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#K18");
1332 Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#K19");
1333 Assert.IsNull (type.GetProperty ("IntStat", flags), "#K20");
1334 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#K21");
1335 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#K22");
1336 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#K23");
1337 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#K24");
1338 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#K25");
1339 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#K26");
1340 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#K27");
1341 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#K28");
1342 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#K29");
1343 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#K30");
1345 flags = BindingFlags.Static | BindingFlags.NonPublic |
1346 BindingFlags.DeclaredOnly;
1348 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#L1");
1349 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#L2");
1350 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#L3");
1351 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#L4");
1352 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#L5");
1353 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#L6");
1354 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#L7");
1355 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#L8");
1356 Assert.IsNull (type.GetProperty ("PubInst", flags), "#L9");
1357 Assert.IsNull (type.GetProperty ("IntInst", flags), "#L10");
1358 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#L11");
1359 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#L12");
1360 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#L13");
1361 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#L14");
1362 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#L15");
1363 Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#L16");
1364 Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#L17");
1365 Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#L18");
1366 Assert.IsNull (type.GetProperty ("PubStat", flags), "#L19");
1367 Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#L20");
1368 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#L21");
1369 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#L22");
1370 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#L23");
1371 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#L24");
1372 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#L25");
1373 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#L26");
1374 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#L27");
1375 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#L28");
1376 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#L29");
1377 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#L30");
1379 flags = BindingFlags.Instance | BindingFlags.NonPublic |
1380 BindingFlags.Public;
1382 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#M1");
1383 Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#M2");
1384 Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#M3");
1385 Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#M4");
1386 Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#M5");
1387 Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#M6");
1388 Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#M7");
1389 Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#M8");
1390 Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#M9");
1391 Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#M10");
1392 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#M11");
1393 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#M12");
1394 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#M13");
1395 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#M14");
1396 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#M15");
1397 Assert.IsNull (type.GetProperty ("PrivStat", flags), "#M16");
1398 Assert.IsNull (type.GetProperty ("ProtStat", flags), "#M17");
1399 Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#M18");
1400 Assert.IsNull (type.GetProperty ("PubStat", flags), "#M19");
1401 Assert.IsNull (type.GetProperty ("IntStat", flags), "#M20");
1402 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#M21");
1403 Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#M22");
1404 Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#M23");
1405 Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#M24");
1406 Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#M25");
1407 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#M26");
1408 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#M27");
1409 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#M28");
1410 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#M29");
1411 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#M30");
1413 flags = BindingFlags.Static | BindingFlags.NonPublic |
1414 BindingFlags.Public;
1416 Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#N1");
1417 Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#N2");
1418 Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#N3");
1419 Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#N4");
1420 Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#N5");
1421 Assert.IsNull (type.GetProperty ("PrivInst", flags), "#N6");
1422 Assert.IsNull (type.GetProperty ("ProtInst", flags), "#N7");
1423 Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#N8");
1424 Assert.IsNull (type.GetProperty ("PubInst", flags), "#N9");
1425 Assert.IsNull (type.GetProperty ("IntInst", flags), "#N10");
1426 Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#N11");
1427 Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#N12");
1428 Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#N13");
1429 Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#N14");
1430 Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#N15");
1431 Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#N16");
1432 Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#N17");
1433 Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#N18");
1434 Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#N19");
1435 Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#N20");
1436 Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#N21");
1437 Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#N22");
1438 Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#N23");
1439 Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#N24");
1440 Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#N25");
1441 Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#N26");
1442 Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#N27");
1443 Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#N28");
1444 Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#N29");
1445 Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#N30");
1448 [Test] // GetProperty (String, BindingFlags)
1449 public void GetProperty2_Name_Null ()
1451 Type type = typeof (Bar);
1453 type.GetProperty ((string) null);
1455 } catch (ArgumentNullException ex) {
1456 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1457 Assert.IsNull (ex.InnerException, "#3");
1458 Assert.IsNotNull (ex.Message, "#4");
1459 Assert.IsNotNull (ex.ParamName, "#5");
1460 Assert.AreEqual ("name", ex.ParamName, "#6");
1464 [Test] // GetProperty (String, Type)
1465 public void GetProperty3_Name_Null ()
1467 Type type = typeof (Bar);
1469 type.GetProperty ((string) null, typeof (int));
1471 } catch (ArgumentNullException ex) {
1472 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1473 Assert.IsNull (ex.InnerException, "#3");
1474 Assert.IsNotNull (ex.Message, "#4");
1475 Assert.IsNotNull (ex.ParamName, "#5");
1476 Assert.AreEqual ("name", ex.ParamName, "#6");
1480 [Test] // GetProperty (String, Type [])
1481 public void GetProperty4_Name_Null ()
1483 Type type = typeof (Bar);
1485 type.GetProperty ((string) null, Type.EmptyTypes);
1487 } catch (ArgumentNullException ex) {
1488 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1489 Assert.IsNull (ex.InnerException, "#3");
1490 Assert.IsNotNull (ex.Message, "#4");
1491 Assert.IsNotNull (ex.ParamName, "#5");
1492 Assert.AreEqual ("name", ex.ParamName, "#6");
1496 [Test] // GetProperty (String, Type, Type [])
1497 public void GetProperty5_Name_Null ()
1499 Type type = typeof (Bar);
1501 type.GetProperty ((string) null, typeof (int),
1504 } catch (ArgumentNullException ex) {
1505 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1506 Assert.IsNull (ex.InnerException, "#3");
1507 Assert.IsNotNull (ex.Message, "#4");
1508 Assert.IsNotNull (ex.ParamName, "#5");
1509 Assert.AreEqual ("name", ex.ParamName, "#6");
1513 [Test] // GetProperty (String, Type, Type [], ParameterModifier [])
1514 public void GetProperty6_Name_Null ()
1516 Type type = typeof (Bar);
1518 type.GetProperty ((string) null, typeof (int),
1519 Type.EmptyTypes, null);
1521 } catch (ArgumentNullException ex) {
1522 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1523 Assert.IsNull (ex.InnerException, "#3");
1524 Assert.IsNotNull (ex.Message, "#4");
1525 Assert.IsNotNull (ex.ParamName, "#5");
1526 Assert.AreEqual ("name", ex.ParamName, "#6");
1530 [Test] // GetProperty (String, BindingFlags, Binder, Type, Type [], ParameterModifier [])
1531 public void GetProperty7_Name_Null ()
1533 Type type = typeof (Bar);
1535 type.GetProperty ((string) null, BindingFlags.Public,
1536 null, typeof (int), Type.EmptyTypes, null);
1538 } catch (ArgumentNullException ex) {
1539 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1540 Assert.IsNull (ex.InnerException, "#3");
1541 Assert.IsNotNull (ex.Message, "#4");
1542 Assert.IsNotNull (ex.ParamName, "#5");
1543 Assert.AreEqual ("name", ex.ParamName, "#6");
1548 public void GetProperty8_PropertyType ()
1550 Type type = typeof (Bar);
1551 Assert.IsNull (type.GetProperty ("PubInst", BindingFlags.Public | BindingFlags.Instance,
1552 null, typeof (int), Type.EmptyTypes, null), "#1");
1553 Assert.IsNotNull (type.GetProperty ("PubInst", BindingFlags.Public | BindingFlags.Instance, null,
1554 typeof (long), new Type[0], null), "#2");
1558 public void GetProperty9_Indexers ()
1561 var bindingFlags = BindingFlags.Public | BindingFlags.Instance;
1563 Type type1 = typeof (List<byte>);
1564 var p1 = type1.GetProperty ("Item", bindingFlags, null, typeof (byte), new Type[] { typeof (int) }, null);
1565 Assert.IsNotNull (p1, "#1");
1567 Type type2 = typeof (List<string>);
1568 var p2 = type2.GetProperty ("Item", bindingFlags, null, typeof (string), new Type[] { typeof (int) }, null);
1569 Assert.IsNotNull (p2, "#2");
1571 Type type3 = typeof (List<Type>);
1572 // result type not convertible, make sure we fail.
1573 var p3 = type3.GetProperty ("Item", bindingFlags, null, typeof (string) /*!*/,
1574 new Type[] { typeof (int) }, null);
1575 Assert.IsNull (p3, "#3");
1578 [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
1583 [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
1589 public void StructLayoutAttribute ()
1591 StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
1592 Assert.AreEqual (LayoutKind.Auto, attr1.Value);
1594 StructLayoutAttribute attr2 = typeof (Class1).StructLayoutAttribute;
1595 Assert.AreEqual (LayoutKind.Explicit, attr2.Value);
1596 Assert.AreEqual (4, attr2.Pack);
1597 Assert.AreEqual (64, attr2.Size);
1599 StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
1600 Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
1601 Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
1605 public void Namespace ()
1607 Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
1611 public void GenericParameterNamespace ()
1613 var t = typeof (Foo<>).GetGenericArguments () [0];
1615 Assert.AreEqual ("T", t.Name);
1616 Assert.AreEqual ("MonoTests.System", t.Namespace);
1618 var s = typeof (Gazonk).GetMethod ("Bang").GetGenericArguments () [0];
1620 Assert.AreEqual ("S", s.Name);
1621 Assert.AreEqual ("MonoTests.System", s.Namespace);
1624 public static void Reflected (ref int a)
1631 Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
1632 Assert.AreEqual ("String[*]", Array.CreateInstance (typeof(string), new int[] { 1 }, new int[] { 1 }).GetType ().Name);
1636 public void GetInterfaces ()
1638 Type[] t = typeof (Duper).GetInterfaces ();
1639 Assert.AreEqual (1, t.Length);
1640 Assert.AreEqual (typeof (ICloneable), t[0]);
1642 Type[] t2 = typeof (IFace3).GetInterfaces ();
1643 Assert.AreEqual (2, t2.Length);
1647 public void GetInterfacesGenericVarWithConstraints ()
1649 var a = typeof (TypeTest).GetMethod ("GenericMethod");
1651 var p = a.GetParameters ();
1652 var i = p[0].ParameterType.GetElementType ();
1656 public static void GenericMethod<T, T2> (T[] arr) where T: IComparable<T> {
1662 public void GetFieldIgnoreCase ()
1664 Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
1677 public void GetPropertyAccessorModifiers ()
1679 Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
1680 Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
1684 public void IsAbstract ()
1686 Assert.IsFalse (typeof (string).IsAbstract, "#1");
1687 Assert.IsTrue (typeof (ICloneable).IsAbstract, "#2");
1688 Assert.IsTrue (typeof (ValueType).IsAbstract, "#3");
1689 Assert.IsTrue (typeof (Enum).IsAbstract, "#4");
1690 Assert.IsFalse (typeof (TimeSpan).IsAbstract, "#5");
1691 Assert.IsTrue (typeof (TextReader).IsAbstract, "#6");
1694 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=286308
1695 Type [] typeArgs = typeof (List<>).GetGenericArguments ();
1696 Assert.IsFalse (typeArgs [0].IsAbstract, "#7");
1700 public void IsCOMObject ()
1702 Type type = typeof (string);
1703 Assert.IsFalse (type.IsCOMObject, "#1");
1705 TypeBuilder tb = module.DefineType (genTypeName ());
1706 type = tb.CreateType ();
1707 Assert.IsFalse (type.IsCOMObject, "#2");
1711 public void IsImport ()
1713 Type type = typeof (string);
1714 Assert.IsFalse (type.IsImport, "#1");
1716 TypeBuilder tb = module.DefineType (genTypeName ());
1717 type = tb.CreateType ();
1718 Assert.IsFalse (type.IsImport, "#2");
1720 tb = module.DefineType (genTypeName (), TypeAttributes.Import |
1721 TypeAttributes.Interface | TypeAttributes.Abstract);
1722 type = tb.CreateType ();
1723 Assert.IsTrue (type.IsImport, "#3");
1727 public void IsInterface ()
1729 Assert.IsFalse (typeof (string).IsInterface, "#1");
1730 Assert.IsTrue (typeof (ICloneable).IsInterface, "#2");
1734 public void IsPrimitive () {
1735 Assert.IsTrue (typeof (IntPtr).IsPrimitive, "#1");
1736 Assert.IsTrue (typeof (int).IsPrimitive, "#2");
1737 Assert.IsFalse (typeof (string).IsPrimitive, "#2");
1741 public void IsValueType ()
1743 Assert.IsTrue (typeof (int).IsValueType, "#1");
1744 Assert.IsFalse (typeof (Enum).IsValueType, "#2");
1745 Assert.IsFalse (typeof (ValueType).IsValueType, "#3");
1746 Assert.IsTrue (typeof (AttributeTargets).IsValueType, "#4");
1747 Assert.IsFalse (typeof (string).IsValueType, "#5");
1748 Assert.IsTrue (typeof (TimeSpan).IsValueType, "#6");
1752 public void IsVisible ()
1754 Assert.IsTrue (typeof (int).IsVisible, "#1");
1755 Assert.IsTrue (typeof (Nested).IsVisible, "#2");
1759 public void GetTypeNonVectorArray ()
1761 Type t = Type.GetType ("System.String[*]");
1762 Assert.AreEqual ("System.String[*]", t.ToString ());
1767 public void TypeFromCLSID ()
1769 Guid CLSID_ShellDesktop = new Guid("00021400-0000-0000-c000-000000000046");
1770 Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
1772 Type t1 = Type.GetTypeFromCLSID (CLSID_ShellDesktop);
1774 Type t2 = Type.GetTypeFromCLSID (CLSID_Bogus);
1776 Assert.AreEqual (t1.FullName, "System.__ComObject");
1778 if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
1779 Environment.OSVersion.Platform == PlatformID.Win32NT)
1780 Activator.CreateInstance(t1);
1782 Assert.AreEqual (t2.FullName, "System.__ComObject");
1784 Assert.AreNotEqual (t1, t2);
1788 [Category("NotWorking")] // Mono throws TargetInvokationException
1789 [ExpectedException("System.Runtime.InteropServices.COMException")]
1790 public void TypeFromCLSIDBogus ()
1792 Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
1793 Type t = Type.GetTypeFromCLSID (CLSID_Bogus);
1794 if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
1795 Environment.OSVersion.Platform == PlatformID.Win32NT)
1796 Activator.CreateInstance(t);
1798 throw new COMException ();
1802 public void ExerciseFilterName ()
1804 MemberInfo[] mi = typeof(Base).FindMembers(
1806 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1807 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1808 Type.FilterName, "*");
1809 Assert.AreEqual (4, mi.Length);
1810 mi = typeof(Base).FindMembers(
1812 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1813 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1814 Type.FilterName, "Test*");
1815 Assert.AreEqual (2, mi.Length);
1816 mi = typeof(Base).FindMembers(
1818 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1819 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1820 Type.FilterName, "TestVoid");
1821 Assert.AreEqual (1, mi.Length);
1822 mi = typeof(Base).FindMembers(
1824 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1825 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1826 Type.FilterName, "NonExistingMethod");
1827 Assert.AreEqual (0, mi.Length);
1831 public void ExerciseFilterNameIgnoreCase ()
1833 MemberInfo[] mi = typeof(Base).FindMembers(
1835 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1836 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1837 Type.FilterNameIgnoreCase, "*");
1838 Assert.AreEqual (4, mi.Length);
1839 mi = typeof(Base).FindMembers(
1841 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1842 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1843 Type.FilterNameIgnoreCase, "test*");
1844 Assert.AreEqual (2, mi.Length);
1845 mi = typeof(Base).FindMembers(
1847 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1848 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1849 Type.FilterNameIgnoreCase, "TESTVOID");
1850 Assert.AreEqual (1, mi.Length);
1851 mi = typeof(Base).FindMembers(
1853 BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
1854 BindingFlags.Instance | BindingFlags.DeclaredOnly,
1855 Type.FilterNameIgnoreCase, "NonExistingMethod");
1856 Assert.AreEqual (0, mi.Length);
1860 [ExpectedException (typeof (InvalidFilterCriteriaException))]
1861 public void FilterAttribute_Invalid ()
1863 Type.FilterAttribute (MethodBase.GetCurrentMethod (), (byte) 1);
1867 public void GenericParameterMemberType ()
1869 var t = typeof (Foo<>).GetGenericArguments () [0];
1870 Assert.IsNotNull (t);
1872 Assert.AreEqual (MemberTypes.TypeInfo, t.MemberType);
1878 public int property {
1881 public ByRef0 (int i) {}
1882 public void f (int i) {}
1886 public void ByrefTypes ()
1888 Type t = Type.GetType ("MonoTests.System.TypeTest+ByRef0&");
1889 Assert.IsNotNull (t);
1890 Assert.IsTrue (t.IsByRef);
1891 Assert.AreEqual (0, t.GetMethods (BindingFlags.Public | BindingFlags.Instance).Length);
1892 Assert.AreEqual (0, t.GetConstructors (BindingFlags.Public | BindingFlags.Instance).Length);
1893 Assert.AreEqual (0, t.GetEvents (BindingFlags.Public | BindingFlags.Instance).Length);
1894 Assert.AreEqual (0, t.GetProperties (BindingFlags.Public | BindingFlags.Instance).Length);
1896 Assert.IsNull (t.GetMethod ("f"));
1897 Assert.IsNull (t.GetField ("field"));
1898 Assert.IsNull (t.GetProperty ("property"));
1902 public void TestAssemblyQualifiedName ()
1904 Type t = Type.GetType ("System.Byte[]&");
1905 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte[]&"));
1907 t = Type.GetType ("System.Byte*&");
1908 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte*&"));
1910 t = Type.GetType ("System.Byte&");
1911 Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte&"));
1916 #pragma warning disable 169
1918 #pragma warning restore 169
1922 public void CreateValueTypeNoCtor ()
1924 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
1928 [ExpectedException (typeof (MissingMethodException))]
1929 public void CreateValueTypeNoCtorArgs ()
1931 typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
1935 [ExpectedException (typeof (MissingMethodException))]
1936 public void InvokeGetPropertyMissing ()
1938 typeof(B).InvokeMember ("", BindingFlags.GetProperty, null, null, new object [] { 1 });
1942 [ExpectedException (typeof (MissingMethodException))]
1943 public void InvokeSetPropertyMissing ()
1945 typeof(B).InvokeMember ("", BindingFlags.SetProperty, null, null, new object [] { 1 });
1948 internal static string bug336841 (string param1, params string [] param2)
1950 StringBuilder sb = new StringBuilder ();
1954 for (int i = 0; i < param2.Length; i++) {
1957 sb.Append (param2 [i]);
1959 return sb.ToString ();
1962 internal static string bug336841 (string param1)
1964 return "#B:" + param1;
1967 internal static string bug336841 (params string [] param1)
1969 StringBuilder sb = new StringBuilder ();
1971 for (int i = 0; i < param1.Length; i++) {
1974 sb.Append (param1 [i]);
1976 return sb.ToString ();
1980 public void InvokeMember_GetSetField ()
1982 typeof (X).InvokeMember ("Value", BindingFlags.Public |
1983 BindingFlags.Static | BindingFlags.FlattenHierarchy |
1984 BindingFlags.SetField, null, null, new object [] { 5 });
1986 Assert.AreEqual (5, X.Value, "#A1");
1987 Assert.AreEqual (5, typeof (X).InvokeMember ("Value",
1988 BindingFlags.Public | BindingFlags.Static |
1989 BindingFlags.FlattenHierarchy | BindingFlags.GetField,
1990 null, null, new object [0]), "#A2");
1991 Assert.AreEqual (5, Y.Value, "#A3");
1992 Assert.AreEqual (5, typeof (Y).InvokeMember ("Value",
1993 BindingFlags.Public | BindingFlags.Static |
1994 BindingFlags.FlattenHierarchy | BindingFlags.GetField,
1995 null, null, new object [0]), "#A4");
1998 typeof (X).InvokeMember ("Value", BindingFlags.Public |
1999 BindingFlags.Static | BindingFlags.FlattenHierarchy |
2000 BindingFlags.GetField | BindingFlags.SetField,
2001 null, null, new object [] { 5 });
2002 Assert.Fail ("#B1");
2003 } catch (ArgumentException ex) {
2004 // Cannot specify both Get and Set on a field
2005 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
2006 Assert.IsNull (ex.InnerException, "#B3");
2007 Assert.IsNotNull (ex.Message, "#B4");
2008 Assert.IsNotNull (ex.ParamName, "#B5");
2009 Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
2014 public void InvokeMember_GetSetProperty ()
2017 typeof (ArrayList).InvokeMember ("Item",
2018 BindingFlags.GetProperty | BindingFlags.SetProperty |
2019 BindingFlags.Instance | BindingFlags.Public,
2020 null, new ArrayList (), new object [] { 0, "bar" });
2022 } catch (ArgumentException ex) {
2023 // Cannot specify both Get and Set on a property
2024 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2025 Assert.IsNull (ex.InnerException, "#3");
2026 Assert.IsNotNull (ex.Message, "#4");
2027 Assert.IsNotNull (ex.ParamName, "#5");
2028 Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
2034 public void InvokeMember_InvokeMethod_Set ()
2037 typeof (ArrayList).InvokeMember ("ToString",
2038 BindingFlags.InvokeMethod | BindingFlags.SetField |
2039 BindingFlags.Instance | BindingFlags.Public,
2040 null, new ArrayList (), new object [0]);
2041 Assert.Fail ("#A1");
2042 } catch (ArgumentException ex) {
2043 // Cannot specify Set on a field and Invoke on a method
2044 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
2045 Assert.IsNull (ex.InnerException, "#A3");
2046 Assert.IsNotNull (ex.Message, "#A4");
2047 Assert.IsNotNull (ex.ParamName, "#A5");
2048 Assert.AreEqual ("bindingFlags", ex.ParamName, "#A6");
2052 typeof (ArrayList).InvokeMember ("ToString",
2053 BindingFlags.InvokeMethod | BindingFlags.SetProperty |
2054 BindingFlags.Instance | BindingFlags.Public,
2055 null, new ArrayList (), new object [0]);
2056 Assert.Fail ("#B1");
2057 } catch (ArgumentException ex) {
2058 // Cannot specify Set on a property and Invoke on a method
2059 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
2060 Assert.IsNull (ex.InnerException, "#B3");
2061 Assert.IsNotNull (ex.Message, "#B4");
2062 Assert.IsNotNull (ex.ParamName, "#B5");
2063 Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
2068 public void InvokeMember_MatchPrimitiveTypeWithInterface ()
2070 object [] invokeargs = { 1 };
2071 typeof (Z).InvokeMember ("", BindingFlags.DeclaredOnly |
2072 BindingFlags.Public | BindingFlags.NonPublic |
2073 BindingFlags.Instance | BindingFlags.CreateInstance,
2074 null, null, invokeargs);
2078 public void InvokeMember_Name_Null ()
2081 typeof (X).InvokeMember ((string) null,
2082 BindingFlags.Public | BindingFlags.Static |
2083 BindingFlags.FlattenHierarchy | BindingFlags.SetField,
2084 null, null, new object [] { 5 });
2086 } catch (ArgumentNullException ex) {
2087 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2088 Assert.IsNull (ex.InnerException, "#3");
2089 Assert.IsNotNull (ex.Message, "#4");
2090 Assert.IsNotNull (ex.ParamName, "#5");
2091 Assert.AreEqual ("name", ex.ParamName, "#6");
2096 public void InvokeMember_NoOperation ()
2099 typeof (TypeTest).InvokeMember ("Run", BindingFlags.Public |
2100 BindingFlags.Static, null, null, new object [0]);
2102 } catch (ArgumentException ex) {
2103 // Must specify binding flags describing the
2104 // invoke operation required
2105 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2106 Assert.IsNull (ex.InnerException, "#3");
2107 Assert.IsNotNull (ex.Message, "#4");
2108 Assert.IsNotNull (ex.ParamName, "#5");
2109 Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
2113 [Test] // bug #321735
2114 public void InvokeMember_SetFieldProperty ()
2116 ArrayList list = new ArrayList ();
2118 list.GetType ().InvokeMember ("Item",
2119 BindingFlags.SetField | BindingFlags.SetProperty |
2120 BindingFlags.Instance | BindingFlags.Public,
2121 null, list, new object [] { 0, "bar" });
2122 Assert.AreEqual ("bar", list [0]);
2126 public void InvokeMember_SetField_ProvidedArgs ()
2129 typeof (X).InvokeMember ("Value", BindingFlags.Public |
2130 BindingFlags.Static | BindingFlags.SetField,
2131 null, null, new object [0]);
2132 Assert.Fail ("#A1");
2133 } catch (ArgumentException ex) {
2134 // Only the field value can be specified to set
2136 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
2137 Assert.IsNull (ex.InnerException, "#A3");
2138 Assert.IsNotNull (ex.Message, "#A4");
2139 Assert.IsNotNull (ex.ParamName, "#A5");
2140 Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
2144 typeof (X).InvokeMember ("Value", BindingFlags.Public |
2145 BindingFlags.Static | BindingFlags.SetField,
2147 Assert.Fail ("#B1");
2148 } catch (ArgumentNullException ex) {
2149 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
2150 Assert.IsNull (ex.InnerException, "#B3");
2151 Assert.IsNotNull (ex.Message, "#B4");
2152 Assert.IsNotNull (ex.ParamName, "#B5");
2153 Assert.AreEqual ("providedArgs", ex.ParamName, "#B6");
2157 [Test] // bug #336841
2158 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=306797
2159 public void InvokeMember_VarArgs ()
2161 BindingFlags flags = BindingFlags.InvokeMethod | BindingFlags.Public |
2162 BindingFlags.NonPublic | BindingFlags.OptionalParamBinding |
2163 BindingFlags.Static | BindingFlags.FlattenHierarchy |
2164 BindingFlags.Instance;
2166 Type type = typeof (TypeTest);
2167 string result = (string) type.InvokeMember ("bug336841",
2168 flags, null, null, new object [] { "1" });
2169 Assert.IsNotNull (result, "#A1");
2170 Assert.AreEqual ("#B:1", result, "#A2");
2172 result = (string) type.InvokeMember ("bug336841", flags,
2173 null, null, new object [] { "1", "2", "3", "4" });
2174 Assert.IsNotNull (result, "#B1");
2175 Assert.AreEqual ("#A:1|2,3,4", result, "#B2");
2179 [Test] // bug #348522
2180 public void InvokeMember_WithoutDefaultValue ()
2182 BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;
2184 typeof (Bug348522).InvokeMember ("Test", flags, new FirstMethodBinder (), new Bug348522(),
2185 new object [] {Missing.Value}, null, null, null);
2187 } catch (ArgumentException ex) {
2188 // Missing parameter does not have a default value
2189 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2190 Assert.IsNull (ex.InnerException, "#3");
2191 Assert.IsNotNull (ex.Message, "#4");
2192 Assert.IsNotNull (ex.ParamName, "#5");
2193 Assert.AreEqual ("parameters", ex.ParamName, "#6");
2198 public void TestMissing () {
2199 Assert.AreEqual (Type.Missing, Missing.Value);
2203 public void GetGenericMethodDefinitionOverInflatedMethodOnGTD () {
2204 var l = typeof (List<>);
2205 var m = l.GetMethod ("ConvertAll");
2206 var infl = m.MakeGenericMethod (typeof (int));
2207 var res = m.GetGenericMethodDefinition ();
2208 Assert.AreEqual (m, res, "#1");
2212 public void InvokeMember_OutParam ()
2214 object[] args = new object[] { new string [0] };
2215 typeof (TypeTest).InvokeMember ("OutTest", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, args);
2216 Assert.IsTrue (args [0] is string[]);
2217 Assert.AreEqual (10, ((string[])args[0]).Length);
2220 public static void OutTest (out string[] a1)
2222 a1 = new string [10];
2227 public static int Value;
2236 public Z (IComparable value)
2241 public static void Run ()
2249 public TakesInt (int x)
2254 public int Integer {
2261 public TakesObject (object x) {}
2264 [Test] // bug #75241
2265 public void GetConstructorNullInTypes ()
2267 // This ends up calling type.GetConstructor ()
2268 Activator.CreateInstance (typeof (TakesInt), new object [] { null });
2269 Activator.CreateInstance (typeof (TakesObject), new object [] { null });
2273 public void GetConstructor_TakeInt_Object ()
2275 Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
2279 public void GetCustomAttributes_All ()
2281 object [] attrs = typeof (A).GetCustomAttributes (false);
2282 Assert.AreEqual (2, attrs.Length, "#A1");
2283 Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
2284 Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
2286 attrs = typeof (BA).GetCustomAttributes (false);
2287 Assert.AreEqual (1, attrs.Length, "#B1");
2288 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
2290 attrs = typeof (BA).GetCustomAttributes (true);
2291 Assert.AreEqual (2, attrs.Length, "#C1");
2292 Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
2293 Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
2295 attrs = typeof (CA).GetCustomAttributes (false);
2296 Assert.AreEqual (0, attrs.Length, "#D");
2298 attrs = typeof (CA).GetCustomAttributes (true);
2299 Assert.AreEqual (1, attrs.Length, "#E1");
2300 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
2303 static bool HasAttribute (object [] attrs, Type attributeType)
2305 foreach (object attr in attrs)
2306 if (attr.GetType () == attributeType)
2312 public void GetCustomAttributes_Type ()
2314 object [] attrs = null;
2316 attrs = typeof (A).GetCustomAttributes (
2317 typeof (VolatileModifier), false);
2318 Assert.AreEqual (1, attrs.Length, "#A1");
2319 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
2320 attrs = typeof (A).GetCustomAttributes (
2321 typeof (VolatileModifier), true);
2322 Assert.AreEqual (1, attrs.Length, "#A3");
2323 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
2325 attrs = typeof (A).GetCustomAttributes (
2326 typeof (NemerleAttribute), false);
2327 Assert.AreEqual (1, attrs.Length, "#B1");
2328 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
2329 attrs = typeof (A).GetCustomAttributes (
2330 typeof (NemerleAttribute), true);
2331 Assert.AreEqual (1, attrs.Length, "#B3");
2332 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
2334 attrs = typeof (A).GetCustomAttributes (
2335 typeof (FooAttribute), false);
2336 Assert.AreEqual (1, attrs.Length, "#C1");
2337 Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
2338 attrs = typeof (A).GetCustomAttributes (
2339 typeof (FooAttribute), false);
2340 Assert.AreEqual (1, attrs.Length, "#C3");
2341 Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
2343 attrs = typeof (BA).GetCustomAttributes (
2344 typeof (VolatileModifier), false);
2345 Assert.AreEqual (0, attrs.Length, "#D1");
2346 attrs = typeof (BA).GetCustomAttributes (
2347 typeof (VolatileModifier), true);
2348 Assert.AreEqual (1, attrs.Length, "#D2");
2349 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
2351 attrs = typeof (BA).GetCustomAttributes (
2352 typeof (NemerleAttribute), false);
2353 Assert.AreEqual (0, attrs.Length, "#E1");
2354 attrs = typeof (BA).GetCustomAttributes (
2355 typeof (NemerleAttribute), true);
2356 Assert.AreEqual (1, attrs.Length, "#E2");
2357 Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
2359 attrs = typeof (BA).GetCustomAttributes (
2360 typeof (FooAttribute), false);
2361 Assert.AreEqual (1, attrs.Length, "#F1");
2362 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
2363 attrs = typeof (BA).GetCustomAttributes (
2364 typeof (FooAttribute), true);
2365 Assert.AreEqual (1, attrs.Length, "#F3");
2366 Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
2368 attrs = typeof (bug82431A1).GetCustomAttributes (
2369 typeof (InheritAttribute), false);
2370 Assert.AreEqual (1, attrs.Length, "#G1");
2371 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
2372 attrs = typeof (bug82431A1).GetCustomAttributes (
2373 typeof (InheritAttribute), true);
2374 Assert.AreEqual (1, attrs.Length, "#G3");
2375 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
2377 attrs = typeof (bug82431A1).GetCustomAttributes (
2378 typeof (NotInheritAttribute), false);
2379 Assert.AreEqual (1, attrs.Length, "#H1");
2380 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
2381 attrs = typeof (bug82431A1).GetCustomAttributes (
2382 typeof (InheritAttribute), true);
2383 Assert.AreEqual (1, attrs.Length, "#H3");
2384 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
2386 attrs = typeof (bug82431A2).GetCustomAttributes (
2387 typeof (InheritAttribute), false);
2388 Assert.AreEqual (0, attrs.Length, "#I1");
2389 attrs = typeof (bug82431A2).GetCustomAttributes (
2390 typeof (InheritAttribute), true);
2391 Assert.AreEqual (0, attrs.Length, "#I2");
2393 attrs = typeof (bug82431A2).GetCustomAttributes (
2394 typeof (NotInheritAttribute), false);
2395 Assert.AreEqual (0, attrs.Length, "#J1");
2396 attrs = typeof (bug82431A2).GetCustomAttributes (
2397 typeof (NotInheritAttribute), true);
2398 Assert.AreEqual (0, attrs.Length, "#J2");
2400 attrs = typeof (bug82431A3).GetCustomAttributes (
2401 typeof (InheritAttribute), false);
2402 Assert.AreEqual (2, attrs.Length, "#K1");
2403 Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
2404 Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
2405 attrs = typeof (bug82431A3).GetCustomAttributes (
2406 typeof (InheritAttribute), true);
2407 Assert.AreEqual (2, attrs.Length, "#K4");
2408 Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
2409 Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
2411 attrs = typeof (bug82431A3).GetCustomAttributes (
2412 typeof (NotInheritAttribute), false);
2413 Assert.AreEqual (1, attrs.Length, "#L1");
2414 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
2415 attrs = typeof (bug82431A3).GetCustomAttributes (
2416 typeof (NotInheritAttribute), true);
2417 Assert.AreEqual (1, attrs.Length, "#L3");
2418 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
2420 attrs = typeof (bug82431B1).GetCustomAttributes (
2421 typeof (InheritAttribute), false);
2422 Assert.AreEqual (1, attrs.Length, "#M1");
2423 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
2424 attrs = typeof (bug82431B1).GetCustomAttributes (
2425 typeof (InheritAttribute), true);
2426 Assert.AreEqual (1, attrs.Length, "#M3");
2427 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
2429 attrs = typeof (bug82431B1).GetCustomAttributes (
2430 typeof (NotInheritAttribute), false);
2431 Assert.AreEqual (0, attrs.Length, "#N1");
2432 attrs = typeof (bug82431B1).GetCustomAttributes (
2433 typeof (NotInheritAttribute), true);
2434 Assert.AreEqual (0, attrs.Length, "#N2");
2436 attrs = typeof (bug82431B2).GetCustomAttributes (
2437 typeof (InheritAttribute), false);
2438 Assert.AreEqual (0, attrs.Length, "#O1");
2439 attrs = typeof (bug82431B2).GetCustomAttributes (
2440 typeof (InheritAttribute), true);
2441 Assert.AreEqual (1, attrs.Length, "#O2");
2442 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
2444 attrs = typeof (bug82431B2).GetCustomAttributes (
2445 typeof (NotInheritAttribute), false);
2446 Assert.AreEqual (0, attrs.Length, "#P1");
2447 attrs = typeof (bug82431B2).GetCustomAttributes (
2448 typeof (NotInheritAttribute), true);
2449 Assert.AreEqual (0, attrs.Length, "#P2");
2451 attrs = typeof (bug82431B3).GetCustomAttributes (
2452 typeof (InheritAttribute), false);
2453 Assert.AreEqual (1, attrs.Length, "#Q1");
2454 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
2455 attrs = typeof (bug82431B3).GetCustomAttributes (
2456 typeof (InheritAttribute), true);
2457 Assert.AreEqual (2, attrs.Length, "#Q3");
2458 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
2459 Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
2461 attrs = typeof (bug82431B3).GetCustomAttributes (
2462 typeof (NotInheritAttribute), false);
2463 Assert.AreEqual (1, attrs.Length, "#R1");
2464 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
2465 attrs = typeof (bug82431B3).GetCustomAttributes (
2466 typeof (NotInheritAttribute), true);
2467 Assert.AreEqual (1, attrs.Length, "#R3");
2468 Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
2470 attrs = typeof (bug82431B4).GetCustomAttributes (
2471 typeof (InheritAttribute), false);
2472 Assert.AreEqual (0, attrs.Length, "#S1");
2473 attrs = typeof (bug82431B4).GetCustomAttributes (
2474 typeof (InheritAttribute), true);
2475 Assert.AreEqual (1, attrs.Length, "#S2");
2476 Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
2478 attrs = typeof (bug82431B4).GetCustomAttributes (
2479 typeof (NotInheritAttribute), false);
2480 Assert.AreEqual (0, attrs.Length, "#T1");
2481 attrs = typeof (bug82431B4).GetCustomAttributes (
2482 typeof (NotInheritAttribute), true);
2483 Assert.AreEqual (0, attrs.Length, "#T2");
2485 attrs = typeof (A).GetCustomAttributes (
2486 typeof (string), false);
2487 Assert.AreEqual (0, attrs.Length, "#U1");
2488 attrs = typeof (A).GetCustomAttributes (
2489 typeof (string), true);
2490 Assert.AreEqual (0, attrs.Length, "#U2");
2493 [Test] // bug #76150
2494 public void IsDefined ()
2496 Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
2497 Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#A2");
2498 Assert.IsTrue (typeof (A).IsDefined (typeof (FooAttribute), false), "#A3");
2499 Assert.IsFalse (typeof (A).IsDefined (typeof (BarAttribute), false), "#A4");
2501 Assert.IsFalse (typeof (BA).IsDefined (typeof (NemerleAttribute), false), "#B1");
2502 Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
2503 Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
2504 Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
2505 Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
2506 Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
2507 Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
2508 Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
2509 Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
2510 Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
2511 Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
2512 Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
2516 public void IsDefined_AttributeType_Null ()
2519 typeof (BA).IsDefined ((Type) null, false);
2521 } catch (ArgumentNullException ex) {
2522 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2523 Assert.IsNull (ex.InnerException, "#3");
2524 Assert.IsNotNull (ex.Message, "#4");
2525 Assert.IsNotNull (ex.ParamName, "#5");
2526 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
2530 [Test] // bug #82431
2531 [Category ("NotWorking")]
2532 public void IsDefined_Inherited ()
2534 Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
2535 Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
2536 Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
2537 Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), false), "#C4");
2538 Assert.IsTrue (typeof (CA).IsDefined (typeof (NemerleAttribute), true), "#C5");
2539 Assert.IsTrue (typeof (CA).IsDefined (typeof (VolatileModifier), true), "#C6");
2540 Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), true), "#C7");
2541 Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), true), "#C8");
2543 Assert.IsFalse (typeof (BBA).IsDefined (typeof (NemerleAttribute), false), "#D1");
2544 Assert.IsFalse (typeof (BBA).IsDefined (typeof (VolatileModifier), false), "#D2");
2545 Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), false), "#D3");
2546 Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
2547 Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
2548 Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
2549 Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
2550 Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
2552 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
2553 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
2554 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
2555 Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
2557 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
2558 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
2559 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
2560 Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
2562 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
2563 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
2564 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
2565 Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
2567 Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
2568 Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
2569 Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
2570 Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
2572 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
2573 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
2574 Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
2575 Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
2577 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
2578 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
2579 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
2580 Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
2582 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
2583 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
2584 Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
2585 Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
2588 class Bug13767Attribute : Attribute
2590 public object[] field;
2592 public Bug13767Attribute (params object[] args)
2598 public enum Bug13767Enum
2604 [Bug13767("Demo", new[] { Bug13767Enum.Value1, Bug13767Enum.Value0 })]
2605 public void Bug13767Method(string attributeName, Bug13767Enum[]options)
2611 public void CustomAttributeWithNestedArrayOfEnum ()
2613 var m = GetType ().GetMethod ("Bug13767Method");
2615 var attr = m.GetCustomAttributes (false);
2616 Assert.AreEqual (1, attr.Length, "#1");
2618 var tc = (Bug13767Attribute)attr[0];
2619 Assert.AreEqual (2, tc.field.Length, "#2");
2620 Assert.AreEqual ("Demo", tc.field[0], "#3");
2621 Assert.IsNotNull (tc.field[1], "#4");
2623 var arr = (Bug13767Enum[])tc.field [1];
2624 Assert.AreEqual (2, arr.Length, "#5");
2625 Assert.AreEqual (Bug13767Enum.Value1, arr [0], "#6");
2626 Assert.AreEqual (Bug13767Enum.Value0, arr [1], "#7");
2629 [Test] // GetType (String)
2630 public void GetType1_TypeName_Null ()
2633 Type.GetType ((string) null);
2635 } catch (ArgumentNullException ex) {
2636 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2637 Assert.IsNull (ex.InnerException, "#3");
2638 Assert.IsNotNull (ex.Message, "#4");
2639 Assert.AreEqual ("TypeName", ex.ParamName, "#5");
2643 [Test] // GetType (String, Boolean)
2644 public void GetType2_TypeName_Null ()
2647 Type.GetType ((string) null, false);
2649 } catch (ArgumentNullException ex) {
2650 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2651 Assert.IsNull (ex.InnerException, "#3");
2652 Assert.IsNotNull (ex.Message, "#4");
2653 Assert.AreEqual ("TypeName", ex.ParamName, "#5");
2657 [Test] // GetType (String, Boolean, Boolean)
2658 public void GetType3_TypeName_Null ()
2661 Type.GetType ((string) null, false, false);
2663 } catch (ArgumentNullException ex) {
2664 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2665 Assert.IsNull (ex.InnerException, "#3");
2666 Assert.IsNotNull (ex.Message, "#4");
2667 Assert.AreEqual ("TypeName", ex.ParamName, "#5");
2672 public void GetTypeArray_Args_Null ()
2675 Type.GetTypeArray ((object []) null);
2677 } catch (ArgumentNullException ex) {
2678 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2679 Assert.IsNull (ex.InnerException, "#3");
2680 Assert.IsNotNull (ex.Message, "#4");
2681 Assert.AreEqual ("args", ex.ParamName, "#5");
2686 public void GetTypeCode ()
2688 Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
2689 Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
2690 Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
2691 Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
2692 Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
2693 Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
2694 Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
2695 Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
2696 Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
2697 Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
2698 Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
2699 Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
2700 Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
2701 Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
2702 Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
2703 Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
2704 Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
2705 Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
2709 public void GetTypeFromHandle_Handle_Zero ()
2711 RuntimeTypeHandle handle = new RuntimeTypeHandle ();
2713 Assert.IsNull (Type.GetTypeFromHandle (handle));
2717 public void GetTypeHandle_O_Null ()
2720 Type.GetTypeHandle (null);
2722 } catch (ArgumentNullException ex) {
2723 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2724 Assert.IsNull (ex.InnerException, "#3");
2725 Assert.IsNotNull (ex.Message, "#4");
2726 Assert.IsNull (ex.ParamName, "#5");
2730 [Test] // GetConstructor (Type [])
2731 public void GetConstructor1 ()
2734 ConstructorInfo ctor;
2736 type = typeof (CtorsA);
2737 ctor = type.GetConstructor (Type.EmptyTypes);
2738 Assert.IsNotNull (ctor, "#A1");
2739 Assert.AreEqual (0, ctor.GetParameters ().Length, "#A2");
2740 Assert.IsFalse (ctor.IsStatic, "#A3");
2741 Assert.IsTrue (ctor.IsPublic, "#A4");
2742 Assert.AreEqual (".ctor", ctor.Name, "#A5");
2744 type = typeof (CtorsB);
2745 ctor = type.GetConstructor (Type.EmptyTypes);
2746 Assert.IsNotNull (ctor, "#B1");
2747 Assert.AreEqual (0, ctor.GetParameters ().Length, "#B2");
2748 Assert.IsFalse (ctor.IsStatic, "#B3");
2749 Assert.IsTrue (ctor.IsPublic, "#B4");
2750 Assert.AreEqual (".ctor", ctor.Name, "#B5");
2752 type = typeof (CtorsC);
2753 ctor = type.GetConstructor (Type.EmptyTypes);
2754 Assert.IsNull (ctor, "#C");
2756 type = typeof (CtorsC);
2757 ctor = type.GetConstructor (new Type [] { typeof (int) });
2758 Assert.IsNotNull (ctor, "#D1");
2759 Assert.AreEqual (1, ctor.GetParameters ().Length, "#D2");
2760 Assert.IsFalse (ctor.IsStatic, "#D3");
2761 Assert.IsTrue (ctor.IsPublic, "#D4");
2762 Assert.AreEqual (".ctor", ctor.Name, "#D5");
2765 [Test] // GetConstructor (Type [])
2766 public void GetConstructor1_Types_Null ()
2769 typeof (BindingFlags).GetConstructor (null);
2771 } catch (ArgumentNullException ex) {
2772 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2773 Assert.IsNull (ex.InnerException, "#3");
2774 Assert.IsNotNull (ex.Message, "#4");
2775 Assert.IsNotNull (ex.ParamName, "#5");
2776 Assert.AreEqual ("types", ex.ParamName, "#6");
2780 [Test] // GetConstructor (Type [])
2781 public void GetConstructor1_Types_ItemNull ()
2783 Type type = typeof (BindingFlags);
2785 type.GetConstructor (new Type[1] { null });
2786 Assert.Fail ("#A1");
2787 } catch (ArgumentNullException ex) {
2788 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2789 Assert.IsNull (ex.InnerException, "#A3");
2790 Assert.IsNotNull (ex.Message, "#A4");
2791 Assert.IsNotNull (ex.ParamName, "#A5");
2792 Assert.AreEqual ("types", ex.ParamName, "#A6");
2795 type = typeof (TakesInt);
2797 type.GetConstructor (new Type [1] { null });
2798 Assert.Fail ("#B1");
2799 } catch (ArgumentNullException ex) {
2800 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
2801 Assert.IsNull (ex.InnerException, "#B3");
2802 Assert.IsNotNull (ex.Message, "#B4");
2803 Assert.IsNotNull (ex.ParamName, "#B5");
2804 Assert.AreEqual ("types", ex.ParamName, "#B6");
2808 [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
2809 public void GetConstructor2_Types_ItemNull ()
2811 Type type = typeof (BindingFlags);
2813 type.GetConstructor (BindingFlags.Default, null,
2814 new Type[1] { null }, null);
2816 } catch (ArgumentNullException ex) {
2817 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2818 Assert.IsNull (ex.InnerException, "#3");
2819 Assert.IsNotNull (ex.Message, "#4");
2820 Assert.IsNotNull (ex.ParamName, "#5");
2821 Assert.AreEqual ("types", ex.ParamName, "#6");
2825 [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
2826 public void GetConstructor3_Types_ItemNull ()
2828 Type type = typeof (BindingFlags);
2830 type.GetConstructor (BindingFlags.Default,
2831 null, CallingConventions.Any,
2832 new Type[1] { null }, null);
2834 } catch (ArgumentNullException ex) {
2835 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2836 Assert.IsNull (ex.InnerException, "#3");
2837 Assert.IsNotNull (ex.Message, "#4");
2838 Assert.IsNotNull (ex.ParamName, "#5");
2839 Assert.AreEqual ("types", ex.ParamName, "#6");
2844 public void GetMethod_Bug77367 ()
2846 MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
2852 public void EqualsUnderlyingType ()
2854 AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
2855 TypeAttributes attribs = TypeAttributes.Public;
2857 AssemblyName name = new AssemblyName ();
2858 name.Name = "enumtest";
2859 AssemblyBuilder assembly =
2860 AppDomain.CurrentDomain.DefineDynamicAssembly (
2863 ModuleBuilder module = assembly.DefineDynamicModule
2864 ("m", "enumtest.dll");
2865 EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
2867 Assert.IsTrue (typeof (int).Equals (e));
2872 public void Equals_Type_Null ()
2874 Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
2875 Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
2879 public void GetElementType_Bug63841 ()
2881 Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
2885 public void FullNameGenerics ()
2887 Type fooType = typeof (Foo<>);
2888 FieldInfo [] fields = fooType.GetFields ();
2890 Assert.AreEqual (1, fields.Length, "#0");
2892 Assert.IsNotNull (fooType.FullName, "#1");
2893 Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
2895 FieldInfo field = fooType.GetField ("Whatever");
2896 Assert.IsNotNull (field, "#2");
2897 Assert.AreEqual (field, fields [0], "#2a");
2898 Assert.IsNull (field.FieldType.FullName, "#3");
2899 Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
2900 Assert.IsNotNull (field.FieldType.ToString (), "#4");
2902 PropertyInfo prop = fooType.GetProperty ("Test");
2903 Assert.IsNotNull (prop, "#5");
2904 Assert.IsNull (prop.PropertyType.FullName, "#6");
2905 Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
2906 Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
2908 MethodInfo method = fooType.GetMethod("Execute");
2909 Assert.IsNotNull (method, "#8");
2910 Assert.IsNull (method.ReturnType.FullName, "#9");
2911 Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
2912 Assert.IsNotNull (method.ReturnType.ToString (), "#10");
2914 ParameterInfo[] parameters = method.GetParameters();
2915 Assert.AreEqual (1, parameters.Length, "#11");
2916 Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
2917 Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
2918 Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
2922 public void TypeParameterIsNotGeneric ()
2924 Type fooType = typeof (Foo<>);
2925 Type type_param = fooType.GetGenericArguments () [0];
2926 Assert.IsTrue (type_param.IsGenericParameter);
2927 Assert.IsFalse (type_param.IsGenericType);
2928 Assert.IsFalse (type_param.IsGenericTypeDefinition);
2930 // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
2931 // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
2932 Assert.IsTrue (type_param.ContainsGenericParameters);
2936 public void IsAssignable ()
2938 Type foo_type = typeof (Foo<>);
2939 Type foo_int_type = typeof (Foo<int>);
2940 Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
2941 Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
2943 Type ibar_short_type = typeof (IBar<short>);
2944 Type ibar_int_type = typeof (IBar<int>);
2945 Type baz_short_type = typeof (Baz<short>);
2946 Type baz_int_type = typeof (Baz<int>);
2948 Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
2949 Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
2951 Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
2952 Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
2955 Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
2956 Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
2957 Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
2961 public void IsInstanceOf ()
2963 Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
2967 public void IsInstanceOfArrayOfNullable ()
2969 Assert.IsTrue (typeof (Nullable<int>[]).IsInstanceOfType (new Nullable<int> [0]));
2973 public void IsInstanceOfType_Null ()
2975 Assert.IsFalse (typeof (int).IsInstanceOfType (null), "int");
2976 Assert.IsFalse (typeof (object).IsInstanceOfType (null), "object");
2977 Assert.IsFalse (typeof (int?).IsInstanceOfType (null), "int?");
2981 public void ByrefType ()
2983 Type foo_type = typeof (Foo<>);
2984 Type type_param = foo_type.GetGenericArguments () [0];
2985 Type byref_type_param = type_param.MakeByRefType ();
2986 Assert.IsFalse (byref_type_param.IsGenericParameter);
2987 Assert.IsNull (byref_type_param.DeclaringType);
2991 [ExpectedException (typeof (TypeLoadException))]
2992 public void MakeByRefByRef ()
2994 typeof (int).MakeByRefType ().MakeByRefType ();
2998 public void MakeArrayTypeTest ()
3000 // This should not crash:
3001 typeof (void).MakeArrayType ();
3006 public class ComFoo<T> {
3010 public void GetCustomAttributesGenericInstance ()
3012 Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
3015 interface ByRef1<T> { void f (ref T t); }
3016 interface ByRef2 { void f<T> (ref T t); }
3018 interface ByRef3<T> where T:struct { void f (ref T? t); }
3019 interface ByRef4 { void f<T> (ref T? t) where T:struct; }
3021 void CheckGenericByRef (Type t)
3023 string name = t.Name;
3024 t = t.GetMethod ("f").GetParameters () [0].ParameterType;
3026 Assert.IsFalse (t.IsGenericType, name);
3027 Assert.IsFalse (t.IsGenericTypeDefinition, name);
3028 Assert.IsFalse (t.IsGenericParameter, name);
3032 public void GenericByRef ()
3034 CheckGenericByRef (typeof (ByRef1<>));
3035 CheckGenericByRef (typeof (ByRef2));
3036 CheckGenericByRef (typeof (ByRef3<>));
3037 CheckGenericByRef (typeof (ByRef4));
3040 public class Bug80242<T> {
3041 public interface IFoo { }
3042 public class Bar : IFoo { }
3043 public class Baz : Bar { }
3047 public void TestNestedTypes ()
3049 Type t = typeof (Bug80242<object>);
3050 Assert.IsFalse (t.IsGenericTypeDefinition);
3051 foreach (Type u in t.GetNestedTypes ()) {
3052 Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
3053 Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
3057 [Test] // bug #82211
3058 public void GetMembers_GenericArgument ()
3060 Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
3061 MemberInfo [] members = argType.GetMembers ();
3062 Assert.IsNotNull (members, "#1");
3063 Assert.AreEqual (4, members.Length, "#2");
3067 [ExpectedException (typeof (ArgumentNullException))]
3068 public void ReflectionOnlyGetTypeNullTypeName ()
3070 Type.ReflectionOnlyGetType (null, false, false);
3074 public void ReflectionOnlyGetTypeDoNotThrow ()
3076 Assert.IsNull (Type.ReflectionOnlyGetType ("a, nonexistent.dll", false, false));
3080 [ExpectedException (typeof (FileNotFoundException))]
3081 public void ReflectionOnlyGetTypeThrow ()
3083 Type.ReflectionOnlyGetType ("a, nonexistent.dll", true, false);
3087 public void ReflectionOnlyGetType ()
3089 Type t = Type.ReflectionOnlyGetType (typeof (int).AssemblyQualifiedName.ToString (), true, true);
3090 Assert.AreEqual ("System.Int32", t.FullName);
3094 #if MONOTOUCH || MOBILE_STATIC
3095 [ExpectedException (typeof (NotSupportedException))]
3097 public void MakeGenericType_UserDefinedType ()
3099 Type ut = new UserType (typeof (int));
3100 Type t = typeof (Foo<>).MakeGenericType (ut);
3101 Assert.IsTrue (t.IsGenericType, "#A1");
3102 Assert.AreEqual (1, t.GetGenericArguments ().Length, "#A2");
3104 Type arg = t.GetGenericArguments () [0];
3105 Assert.IsNotNull (arg, "#B1");
3106 Assert.IsFalse (arg.IsGenericType, "#B2");
3107 Assert.AreEqual (ut, arg, "#B3");
3111 #if MONOTOUCH || MOBILE_STATIC
3112 [ExpectedException (typeof (NotSupportedException))]
3114 public void MakeGenericType_NestedUserDefinedType ()
3116 Type ut = new UserType (new UserType (typeof (int)));
3117 Type t = typeof (Foo<>).MakeGenericType (ut);
3118 Assert.IsTrue (t.IsGenericType, "#A1");
3119 Assert.AreEqual (1, t.GetGenericArguments ().Length, "#A2");
3121 Type arg = t.GetGenericArguments () [0];
3122 Assert.IsNotNull (arg, "#B1");
3123 Assert.IsFalse (arg.IsGenericType, "#B2");
3124 Assert.AreEqual (ut, arg, "#B3");
3128 #if MONOTOUCH || MOBILE_STATIC
3129 [ExpectedException (typeof (NotSupportedException))]
3131 public void TestMakeGenericType_UserDefinedType_DotNet20SP1 ()
3133 Type ut = new UserType(typeof(int));
3134 Type t = typeof(Foo<>).MakeGenericType(ut);
3135 Assert.IsTrue (t.IsGenericType, "#1");
3137 Assert.AreEqual (ut, t.GetGenericArguments()[0], "#2");
3141 #if MONOTOUCH || MOBILE_STATIC
3142 [ExpectedException (typeof (NotSupportedException))]
3144 public void MakeGenericType_BadUserType ()
3146 Type ut = new UserType (null);
3147 Type t = typeof (Foo<>).MakeGenericType (ut);
3148 var g0 = t.GetGenericArguments () [0];
3149 Assert.AreSame (g0, ut, "#1");
3153 public void MakeGenericType_WrongNumOfArguments ()
3156 Type t = typeof (Foo<,>).MakeGenericType (new Type [] { typeof (int) });
3158 } catch (ArgumentException) {
3162 [AttributeUsage (AttributeTargets.All)]
3163 public class DocAttribute : Attribute {
3164 public DocAttribute (string docs) {}
3167 class GenericClassWithAttributes<[Doc ("T")] T, [Doc ("B")] B>
3168 where T : class, new ()
3171 public T Bar { get{return null;}}
3173 public void M<[Doc ("X")] X> (X x)
3178 [Test] //bug #377596
3179 public void GetGenericArguments_ArgumentsHaveAttributes ()
3181 Type type = typeof(GenericClassWithAttributes<,>);
3182 Type[] tArgs = type.GetGenericArguments ();
3183 MethodInfo m = type.GetMethod ("M");
3184 Type[] mArgs = m.GetGenericArguments ();
3185 Assert.AreEqual(1, tArgs[0].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
3186 Assert.AreEqual(1, tArgs[1].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
3187 Assert.AreEqual(1, mArgs[0].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
3190 [Test] //bug #471255
3191 public void GetTypeCalledUsingReflection ()
3193 Type expectedType = Type.GetType ("NoNamespaceClass");
3194 Assert.IsNotNull (expectedType, "#1");
3195 MethodInfo m = typeof (Type).GetMethod ("GetType", BindingFlags.Public | BindingFlags.Static, null, new Type [] { typeof (string) }, null);
3196 object r = m.Invoke (null, BindingFlags.Default, null, new object [] { "NoNamespaceClass" }, CultureInfo.InvariantCulture);
3197 Assert.AreSame (expectedType, r, "#2");
3201 public void EqualsUserType () {
3202 UserType2 t1 = new UserType2(null);
3203 UserType2 t2 = new UserType2(t1);
3204 Assert.IsTrue (t1.Equals(t2));
3208 public void GetHashCodeUserType () {
3209 UserType2 t1 = new UserType2(null);
3210 UserType2 t2 = new UserType2(t1);
3211 Assert.AreEqual (42, t2.GetHashCode());
3215 public void IsGenericTypeDefinitionUserType () {
3216 Assert.IsFalse (new UserType(null).IsGenericTypeDefinition);
3220 public void IsGenericTypeUserType () {
3221 Assert.IsFalse (new UserType(null).IsGenericType);
3225 [ExpectedException (typeof (NotSupportedException))]
3226 public void GetGenericTypeDefinitionUserType () {
3227 new UserType(null).GetGenericTypeDefinition ();
3230 [ExpectedException (typeof (NotSupportedException))]
3231 public void GetGenericArgumentsUserType () {
3232 new UserType(null).GetGenericArguments ();
3236 [ExpectedException (typeof (InvalidOperationException))]
3237 public void GenericParameterPositionUserType () {
3238 Assert.IsTrue (new UserType(null).GenericParameterPosition == 0);
3242 public void TypeGetMemberReturnTypeTest ()
3245 MemberTypes memtype;
3247 object [] flagsandtypes = new object [] {
3248 MemberTypes.All, typeof (MemberInfo []),
3249 MemberTypes.Constructor, typeof (ConstructorInfo []),
3250 MemberTypes.Custom, typeof (MemberInfo []),
3251 MemberTypes.Event, typeof (EventInfo []),
3252 MemberTypes.Field, typeof (FieldInfo []),
3253 MemberTypes.Method, typeof (MethodInfo []),
3254 MemberTypes.NestedType, typeof (Type []),
3255 MemberTypes.Property, typeof (PropertyInfo []),
3256 MemberTypes.TypeInfo, typeof (Type [])};
3258 for (int i=0; i < flagsandtypes.Length; i+=2) {
3259 memtype = (MemberTypes)flagsandtypes [i];
3260 testtype = (Type)flagsandtypes [i+1];
3261 obj = GetType ().GetMember ("DummyMember", memtype,
3262 BindingFlags.Public | BindingFlags.Instance);
3263 Assert.AreEqual (testtype.GetHashCode (), obj.GetType ().GetHashCode (),
3264 "Expected #" + i + " " + testtype.FullName);
3270 public void TypeNameStartsWithSpace ()
3272 Type t1 = Type.GetType ("System.Type, mscorlib");
3273 Type t2 = Type.GetType (" System.Type, mscorlib");
3274 Assert.AreEqual (t1, t2);
3277 #if !MONOTOUCH && !MOBILE_STATIC
3279 public void SpaceAfterComma () {
3280 string strType = "System.Collections.Generic.Dictionary`2[[System.Int32,mscorlib], [System.String,mscorlib]],mscorlib";
3281 Assert.IsTrue (Type.GetType (strType) != null);
3285 #if !MONOTOUCH && !MOBILE_STATIC
3287 public void Bug506757 ()
3289 AssemblyName assemblyName = new AssemblyName ();
3290 assemblyName.Name = "customMod";
3291 assemblyName.Version = new Version (1, 2, 3, 4);
3293 AssemblyBuilder assembly
3294 = Thread.GetDomain().DefineDynamicAssembly(
3295 assemblyName, AssemblyBuilderAccess.RunAndSave);
3297 ModuleBuilder module = assembly.DefineDynamicModule("res.exe", "res.exe");
3299 TypeBuilder type0 = module.DefineType ("Base", TypeAttributes.Public, typeof (object));
3300 TypeBuilder type1 = module.DefineType ("Middle", TypeAttributes.Public, type0);
3301 TypeBuilder type2 = module.DefineType ("End", TypeAttributes.Public, type1);
3303 MethodAttributes attrs0 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
3304 MethodAttributes.NewSlot | MethodAttributes.FamORAssem;
3306 MethodAttributes attrs1 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
3307 MethodAttributes.FamORAssem;
3309 MethodAttributes attrs2 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
3310 MethodAttributes.Public;
3313 MethodBuilder m0 = type0.DefineMethod ("Tst", attrs0, typeof (void), null);
3314 m0.GetILGenerator ().Emit (OpCodes.Ret);
3316 MethodBuilder m1 = type1.DefineMethod ("Tst", attrs1, typeof (void), null);
3317 m1.GetILGenerator ().Emit (OpCodes.Ret);
3319 MethodBuilder m2 = type2.DefineMethod ("Tst", attrs2, typeof (void), null);
3320 m2.GetILGenerator ().Emit (OpCodes.Ret);
3323 type0.CreateType ();
3324 type1.CreateType ();
3325 Type t2 = type2.CreateType ();
3327 foreach (var m in t2.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic))
3328 Assert.IsTrue (m.DeclaringType == typeof (object), String.Format ("{0}::{1}", m.DeclaringType, m.Name));
3332 public void MakeArrayTypeOfOneDimension ()
3334 Type vector = typeof (int).MakeArrayType ();
3335 Type szarray = typeof (int).MakeArrayType (1);
3337 Assert.AreNotEqual (vector, szarray, "#1");
3338 Assert.AreEqual ("Int32[]", vector.Name, "#2");
3339 Assert.AreEqual ("Int32[*]", szarray.Name, "#3");
3342 public class DeclaringMethodFoo {
3343 public void Test<T> (T t) {}
3344 public void Test2<T> (ref T t) {}
3347 public class DeclaringMethodBar<T> {
3348 public void Test2 (ref T t) {}
3352 public void DeclaringMethodOnlyWorksWithGenericArgs ()
3354 MethodInfo testMethod = typeof (DeclaringMethodFoo).GetMethod ("Test");
3355 MethodBase otherMethod = testMethod.GetParameters ()[0].ParameterType.DeclaringMethod;
3357 Assert.AreEqual (testMethod, otherMethod,"#1");
3359 Assert.IsNull (typeof (DeclaringMethodBar<>).GetGenericArguments ()[0].DeclaringMethod, "#2");
3362 var x = typeof (int).DeclaringMethod;
3364 } catch (InvalidOperationException) {}
3367 var x = typeof (DeclaringMethodFoo).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
3369 } catch (InvalidOperationException) {}
3372 var x = typeof (DeclaringMethodBar<>).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
3374 } catch (InvalidOperationException) {}
3379 public void GetArrayRankThrowsForNonArrayType ()
3381 Assert.AreEqual (1, typeof (int[]).GetArrayRank (), "#1");
3382 Assert.AreEqual (2, typeof (int[,]).GetArrayRank (), "#2");
3384 typeof (int).GetArrayRank ();
3386 } catch (ArgumentException) {}
3389 [Test] //Bug #564379
3390 public void GetMethodsReturnPublicMethodsInInterfaces ()
3392 Type t = typeof (NonClosingStream);
3393 MethodInfo[] methods = t.GetMethods (BindingFlags.Public | BindingFlags.Instance);
3395 Assert.AreEqual (5, methods.Length, "#1");
3398 foreach (var m in methods) {
3399 if (m.Name.Equals ("ToString"))
3400 Assert.IsTrue (m.DeclaringType == typeof (NonClosingStream), "#" + id);
3401 else if (m.Name.Equals ("Dispose") && m.GetParameters ().Length == 0)
3402 Assert.IsTrue (m.DeclaringType == typeof (Stream), "#" + id);
3403 else if (m.Name.Equals ("Equals") || m.Name.Equals ("GetHashCode") || m.Name.Equals ("GetType"))
3404 Assert.IsTrue (m.DeclaringType == typeof (object), "#" + id);
3406 Assert.Fail ("invalid method " + m);
3411 [Test] // Bug #574696
3412 public void GetMember_DoesntReturnPrivatePropOfParent ()
3414 BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
3415 Assert.AreEqual (1, typeof (Bar).GetMember ("PrivInst", flags).Length);
3416 Assert.AreEqual (0, typeof (Bar).GetMember ("PrivInstBase", flags).Length);
3417 Assert.AreEqual (1, typeof (Foo).GetMember ("PrivInstBase", flags).Length);
3420 [Test] // Bug #484246
3421 public void GetInterfaceCompareAgainstGTDNames ()
3423 var t = typeof (Dictionary<string,string>);
3424 var iface = typeof (IDictionary<string,string>);
3426 Assert.AreSame (iface, t.GetInterface ("System.Collections.Generic.IDictionary`2"), "#1");
3428 string name = "System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]";
3430 Assert.IsNull (t.GetInterface (name), "#2");
3434 public void RuntimeCorrectlyNormalizeGenericTypes ()
3436 Type lst = typeof (MList<>);
3437 Type arg = lst.GetGenericArguments ()[0];
3439 Type sup = lst.BaseType;
3440 Type sa0 = sup.GetGenericArguments ()[0];
3441 Type sa1 = sup.GetGenericArguments ()[1];
3443 Assert.IsTrue (sa1 == lst, "#1");
3444 Assert.IsTrue (sa0 == arg, "#2");
3446 Type inst = typeof (Cons<,>).MakeGenericType (arg, lst.MakeGenericType (arg));
3447 Assert.IsTrue (inst == sup, "#3");
3455 class MList<A> : Cons<A, MList<A>>
3460 [Test] // Bug #331126
3461 public void IsAssignableFromWorksCorrectlyWithByRefs ()
3463 Type int_byref = typeof (int).MakeByRefType ();
3464 Type obj_byref = typeof (object).MakeByRefType ();
3465 Type long_byref = typeof (long).MakeByRefType ();
3466 Type enum1_byref = typeof (AttributeTargets).MakeByRefType ();
3467 Type enum2_byref = typeof (PlatformID).MakeByRefType ();
3468 Type uint_byref = typeof (uint).MakeByRefType ();
3469 Type string_byref = typeof (object).MakeByRefType ();
3470 Type struct0_byref = typeof (Size4).MakeByRefType ();
3471 Type struct1_byref = typeof (Size4b).MakeByRefType ();
3472 Type mvar0_byref = typeof (TypeTest).GetMethod ("Bug331126").GetGenericArguments ()[0].MakeByRefType ();
3473 Type mvar1_byref = typeof (TypeTest).GetMethod ("Bug331126").GetGenericArguments ()[1].MakeByRefType ();
3475 Assert.IsFalse (typeof (int).IsAssignableFrom (int_byref), "#1");
3476 Assert.IsFalse (int_byref.IsAssignableFrom (typeof (int)), "#2");
3477 Assert.IsFalse (obj_byref.IsAssignableFrom (long_byref), "#3");
3478 Assert.IsFalse (long_byref.IsAssignableFrom (obj_byref), "#4");
3479 Assert.IsTrue (enum1_byref.IsAssignableFrom (enum2_byref), "#5");
3480 Assert.IsTrue (enum2_byref.IsAssignableFrom (enum1_byref), "#6");
3481 Assert.IsTrue (int_byref.IsAssignableFrom (enum2_byref), "#7");
3482 Assert.IsTrue (enum2_byref.IsAssignableFrom (int_byref), "#8");
3483 Assert.IsTrue (enum2_byref.IsAssignableFrom (uint_byref), "#9");
3484 Assert.IsTrue (uint_byref.IsAssignableFrom (enum2_byref), "#10");
3485 Assert.IsTrue (int_byref.IsAssignableFrom (uint_byref), "#11");
3486 Assert.IsTrue (uint_byref.IsAssignableFrom (int_byref), "#12");
3488 Assert.IsTrue (typeof (object).IsAssignableFrom (typeof (long)), "#13");
3490 Assert.IsTrue (obj_byref.IsAssignableFrom (string_byref), "#14");
3491 Assert.IsTrue (string_byref.IsAssignableFrom (obj_byref), "#15");
3493 Assert.IsFalse (uint_byref.IsAssignableFrom (struct0_byref), "#16");
3494 Assert.IsFalse (struct0_byref.IsAssignableFrom (int_byref), "#17");
3495 Assert.IsFalse (struct0_byref.IsAssignableFrom (struct1_byref), "#18");
3497 Assert.IsFalse (obj_byref.IsAssignableFrom (mvar0_byref), "#19");
3498 Assert.IsFalse (mvar0_byref.IsAssignableFrom (mvar1_byref), "#20");
3499 Assert.IsTrue (mvar0_byref.IsAssignableFrom (mvar0_byref), "#21");
3500 Assert.IsFalse (mvar0_byref.IsAssignableFrom (obj_byref), "#22");
3503 public void Bug331126<T,K> () {}
3505 public struct Size4 {
3509 public struct Size4b {
3513 [Test] // Bug #612780
3514 public void CannotMakeDerivedTypesFromTypedByRef ()
3517 typeof (global::System.TypedReference).MakeArrayType ();
3519 } catch (TypeLoadException) { }
3522 typeof (global::System.TypedReference).MakeByRefType ();
3524 } catch (TypeLoadException) { }
3527 typeof (global::System.TypedReference).MakePointerType ();
3529 } catch (TypeLoadException) { }
3534 public void DeclaringTypeOfGenericNestedTypeInstanceIsOpen ()
3536 var type = typeof (Foo<int>.Nested<string>);
3537 Assert.AreSame (typeof (Foo<>), type.DeclaringType, "#1");
3540 interface IGetInterfaceMap<in T>
3545 class GetInterfaceMap : IGetInterfaceMap<object>
3547 public string Bar (object t)
3549 return t.GetType ().FullName;
3554 public void GetInterfaceMapWorksWithVariantIfaces ()
3556 InterfaceMapping res = typeof (GetInterfaceMap).GetInterfaceMap (typeof (IGetInterfaceMap <object>));
3557 Assert.AreEqual (typeof (IGetInterfaceMap <object>), res.InterfaceType);
3558 Assert.AreEqual (typeof (object), res.InterfaceMethods [0].GetParameters () [0].ParameterType);
3560 res = typeof (GetInterfaceMap).GetInterfaceMap (typeof (IGetInterfaceMap <string>));
3561 Assert.AreEqual (typeof (IGetInterfaceMap <string>), res.InterfaceType);
3562 Assert.AreEqual (typeof (string), res.InterfaceMethods [0].GetParameters () [0].ParameterType);
3566 public class MyType : TypeDelegator {
3569 public override bool Equals (Type t) {
3571 return base.Equals (t);
3574 public override Type UnderlyingSystemType {
3577 return typeof (int);
3583 public void NewV4EqualsBehavior ()
3585 var ta = new MyType ();
3586 var tb = new MyType ();
3587 object a = ta, b = tb;
3590 Assert.AreEqual (1, ta.eq, "#1");
3591 Assert.AreEqual (2, ta.ust, "#2");
3593 Assert.AreEqual (2, ta.eq, "#3");
3594 Assert.AreEqual (3, ta.ust, "#4");
3595 Assert.AreEqual (0, tb.eq, "#5");
3596 Assert.AreEqual (1, tb.ust, "#6");
3599 public enum MyRealEnum : short {
3604 public enum MyRealEnum2 : byte {
3608 public enum MyRealEnum3 : short {
3612 public class MyEnum : TypeDelegator {
3613 public bool is_enum { get; set; }
3614 public int fields { get; set; }
3616 public override bool IsSubclassOf (Type c) {
3617 return c == typeof (Enum) && is_enum;
3620 public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
3623 FieldInfo[] res = new FieldInfo [fields];
3624 for (int i = 0; i < fields; ++i) {
3625 if ((bindingAttr & BindingFlags.Instance) != 0)
3626 res [i] = typeof (MyRealEnum).GetField ("value__");
3628 res [i] = typeof (MyRealEnum).GetField ("A");
3635 public void GetEnumUnderlyingType () {
3638 new MyEnum () { is_enum = false }.GetEnumUnderlyingType ();
3640 } catch (ArgumentException) {}
3643 new MyEnum () { is_enum = true, fields = 0 }.GetEnumUnderlyingType ();
3645 } catch (ArgumentException) {}
3648 new MyEnum () { is_enum = true, fields = 2 }.GetEnumUnderlyingType ();
3650 } catch (ArgumentException) {}
3652 Assert.AreSame (typeof (short), new MyEnum () { is_enum = true, fields = 1 }.GetEnumUnderlyingType ());
3656 public void GetEnumNames () {
3658 new MyEnum () { is_enum = false }.GetEnumNames ();
3660 } catch (ArgumentException) {}
3662 var res = new MyEnum () { is_enum = true, fields = 1 }.GetEnumNames ();
3663 Assert.AreEqual (1, res.Length, "#2");
3664 Assert.AreEqual ("A", res [0], "#3");
3666 res = typeof (MyRealEnum).GetEnumNames ();
3667 Assert.AreEqual (3, res.Length, "#4");
3668 Assert.AreEqual ("A", res [0], "#5");
3669 Assert.AreEqual ("B", res [1], "#6");
3670 Assert.AreEqual ("C", res [2], "#7");
3673 public enum OutOfOrderEnum : sbyte
3675 D = -1, C = 2, B = 1, A = 0
3679 public void GetEnumNamesSortsByUnsignedValue ()
3681 string[] names = typeof (OutOfOrderEnum).GetEnumNames ();
3682 Assert.AreEqual (4, names.Length);
3683 Assert.AreEqual ("A", names [0]);
3684 Assert.AreEqual ("B", names [1]);
3685 Assert.AreEqual ("C", names [2]);
3686 Assert.AreEqual ("D", names [3]);
3690 public void GetEnumValues () {
3692 new MyEnum () { is_enum = false }.GetEnumValues ();
3694 } catch (ArgumentException) {}
3697 new MyEnum () { is_enum = true }.GetEnumValues ();
3699 } catch (NotImplementedException) {}
3701 var array = typeof (MyRealEnum).GetEnumValues ();
3702 Assert.AreEqual (typeof (MyRealEnum[]), array.GetType (), "#3");
3703 MyRealEnum[] res = (MyRealEnum[])array;
3705 Assert.AreEqual (3, res.Length, "#4");
3706 Assert.AreEqual (MyRealEnum.A, res [0], "#5");
3707 Assert.AreEqual (MyRealEnum.B, res [1], "#6");
3708 Assert.AreEqual (MyRealEnum.C, res [2], "#7");
3712 public void GetEnumValue () {
3714 typeof (MyRealEnum).GetEnumName (null);
3716 } catch (ArgumentException) { }
3719 new MyEnum () { is_enum = false }.GetEnumName (99);
3721 } catch (ArgumentException) { }
3724 Assert.IsNull (new MyEnum () { fields = 1, is_enum = true }.GetEnumName (77), "#3");
3725 Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (0), "#4");
3726 Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (MyRealEnum.A), "#5");
3727 Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (MyRealEnum2.A), "#6");
3729 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName (MyRealEnum.A), "#7");
3730 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((short)0), "#8");
3731 Assert.AreEqual ("C", typeof (MyRealEnum).GetEnumName (2), "#9");
3732 Assert.IsNull (typeof (MyRealEnum).GetEnumName (9), "#10");
3734 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((byte)0), "#11");
3735 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((sbyte)0), "#12");
3736 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName (false), "#13");
3737 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((short)0), "#14");
3738 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((ushort)0), "#15");
3739 Assert.IsNull (typeof (MyRealEnum).GetEnumName ('c'), "#16");
3741 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((int)0), "#17");
3742 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((uint)0), "#18");
3744 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((long)0), "#19");
3745 Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((ulong)0), "#20");
3748 typeof (MyRealEnum).GetEnumName ((float)0);
3749 Assert.Fail ("#21");
3750 } catch (ArgumentException) { }
3752 typeof (MyRealEnum).GetEnumName ((double)0);
3753 Assert.Fail ("#22");
3754 } catch (ArgumentException) { }
3757 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((byte)0), "#23");
3758 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((sbyte)0), "#24");
3759 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName (false), "#25");
3761 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((short)0), "#26");
3762 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((ushort)0), "#27");
3764 Assert.IsNull (typeof (MyRealEnum2).GetEnumName ('c'), "#28");
3766 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((int)0), "#29");
3767 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((uint)0), "#30");
3769 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((long)0), "#31");
3770 Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((ulong)0), "#32");
3773 typeof (MyRealEnum2).GetEnumName ((float)0);
3774 Assert.Fail ("#33");
3775 } catch (ArgumentException) { }
3777 typeof (MyRealEnum2).GetEnumName ((double)0);
3778 Assert.Fail ("#34");
3779 } catch (ArgumentException) { }
3781 Assert.IsNull (typeof (MyRealEnum2).GetEnumName (12345), "#35");
3785 public void IsEnumDefined () {
3787 typeof (MyRealEnum).IsEnumDefined (null);
3789 } catch (ArgumentException) { }
3792 new MyEnum () { is_enum = false }.IsEnumDefined (99);
3794 } catch (ArgumentException) { }
3797 typeof (MyRealEnum).IsEnumDefined (0);
3799 } catch (ArgumentException) { }
3802 typeof (MyRealEnum).IsEnumDefined ((ushort)0);
3804 } catch (ArgumentException) { }
3807 typeof (MyRealEnum).IsEnumDefined (MyRealEnum3.A);
3809 } catch (ArgumentException) { }
3812 typeof (MyRealEnum).IsEnumDefined (true);
3814 } catch (ArgumentException) { }
3817 typeof (MyRealEnum).IsEnumDefined (MyRealEnum2.A);
3819 } catch (ArgumentException) { }
3822 typeof (MyRealEnum).IsEnumDefined (typeof (MyRealEnum));
3824 } catch (InvalidOperationException) { }
3826 Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined ((short)0), "#9");
3827 Assert.IsFalse (typeof (MyRealEnum).IsEnumDefined ((short)88), "#10");
3828 Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined (MyRealEnum.A), "#11");
3829 Assert.IsFalse (typeof (MyRealEnum).IsEnumDefined ("d"), "#12");
3830 Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined ("A"), "#13");
3831 Assert.IsFalse (new MyEnum () { is_enum = true, fields = 1 }.IsEnumDefined ((short)99), "#14");
3836 public class Outer {
3837 public class Inner {}
3841 public class Outer<T> {
3842 public class Inner {}
3846 public void GetTypeWithDelegates () {
3847 var tname = typeof (MyRealEnum).AssemblyQualifiedName;
3848 var res = Type.GetType (tname, name => {
3849 return Assembly.Load (name);
3850 },(asm,name,ignore) => {
3851 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3853 Assert.AreEqual (typeof (MyRealEnum), res, "#1");
3856 tname = typeof (Dictionary<int, string>).AssemblyQualifiedName;
3857 res = Type.GetType (tname, name => {
3858 return Assembly.Load (name);
3859 },(asm,name,ignore) => {
3860 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3862 Assert.AreEqual (typeof (Dictionary<int, string>), res, "#2");
3865 tname = typeof (Foo<int>).AssemblyQualifiedName;
3866 res = Type.GetType (tname, name => {
3867 return Assembly.Load (name);
3868 },(asm,name,ignore) => {
3869 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3871 Assert.AreEqual (typeof (Foo<int>), res, "#3");
3874 tname = typeof (Outer.Inner).AssemblyQualifiedName;
3875 res = Type.GetType (tname, name => {
3876 return Assembly.Load (name);
3877 },(asm,name,ignore) => {
3878 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3880 Assert.AreEqual (typeof (Outer.Inner), res, "#4");
3883 tname = typeof (Outer<double>.Inner).AssemblyQualifiedName;
3884 res = Type.GetType (tname, name => {
3885 return Assembly.Load (name);
3886 },(asm,name,ignore) => {
3887 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3889 Assert.AreEqual (typeof (Outer<double>.Inner), res, "#5");
3892 tname = "System.Collections.Generic.List`1[System.Int32]";
3893 res = Type.GetType (tname, name => {
3894 return Assembly.Load (name);
3895 },(asm,name,ignore) => {
3896 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3898 Assert.AreEqual (typeof (List<int>), res, "#6");
3901 tname = typeof (Foo<>).FullName + "[,][]";
3902 res = Type.GetType (tname, name => {
3903 Console.WriteLine ("resolve-asm name {0}", name);
3904 return Assembly.Load (name);
3905 },(asm,name,ignore) => {
3906 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3908 Assert.AreEqual (typeof (Foo<>).MakeArrayType (2).MakeArrayType (), res, "#7");
3910 tname = string.Format("{0}[{1}][]*&", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName);
3911 res = Type.GetType (tname, name => {
3912 return Assembly.Load (name);
3913 },(asm,name,ignore) => {
3914 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3916 Assert.AreEqual (typeof (Foo<MyRealEnum>[]).MakePointerType ().MakeByRefType (), res, "#8");
3919 tname = typeof (MyRealEnum).FullName + "[][]";
3920 res = Type.GetType (tname, name => {
3921 return Assembly.Load (name);
3922 },(asm,name,ignore) => {
3923 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3925 Assert.AreEqual (typeof (MyRealEnum[][]), res, "#9");
3928 tname = typeof (MyRealEnum).FullName + "[*]";
3929 res = Type.GetType (tname, name => {
3930 return Assembly.Load (name);
3931 },(asm,name,ignore) => {
3932 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3934 Assert.AreEqual (typeof (MyRealEnum).MakeArrayType (1), res, "#10");
3937 tname = typeof (MyRealEnum).FullName + "&";
3938 res = Type.GetType (tname, name => {
3939 return Assembly.Load (name);
3940 },(asm,name,ignore) => {
3941 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3943 Assert.AreEqual (typeof (MyRealEnum).MakeByRefType (), res, "#11");
3946 tname = typeof (MyRealEnum).FullName + "*";
3947 res = Type.GetType (tname, name => {
3948 return Assembly.Load (name);
3949 },(asm,name,ignore) => {
3950 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3952 Assert.AreEqual (typeof (MyRealEnum).MakePointerType (), res, "#12");
3954 tname = typeof (MyRealEnum).FullName + "*&";
3955 res = Type.GetType (tname, name => {
3956 return Assembly.Load (name);
3957 },(asm,name,ignore) => {
3958 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3960 Assert.AreEqual (typeof (MyRealEnum).MakePointerType ().MakeByRefType(),
3963 tname = typeof (MyRealEnum).FullName + "[,]&";
3964 res = Type.GetType (tname, name => {
3965 return Assembly.Load (name);
3966 },(asm,name,ignore) => {
3967 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3969 Assert.AreEqual (typeof (MyRealEnum).MakeArrayType (2).MakeByRefType (),
3972 tname = typeof (MyRealEnum).FullName + "*[]";
3973 res = Type.GetType (tname, name => {
3974 return Assembly.Load (name);
3975 },(asm,name,ignore) => {
3976 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3978 Assert.AreEqual (typeof (MyRealEnum).MakePointerType().MakeArrayType(),
3981 // not a very useful type, but ought to be parsed correctly
3982 tname = typeof (MyRealEnum).FullName + "[]**[]*&";
3983 res = Type.GetType (tname, name => {
3984 return Assembly.Load (name);
3985 },(asm,name,ignore) => {
3986 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
3988 Assert.AreEqual (typeof (MyRealEnum).MakeArrayType().MakePointerType().MakePointerType().MakeArrayType().MakePointerType().MakeByRefType(),
3991 // assembly resolve without type resolve
3992 res = Type.GetType ("System.String,mscorlib", delegate (AssemblyName aname) { return typeof (int).Assembly; }, null);
3993 Assert.AreEqual (typeof (string), res);
3997 public class CustomGetType : TypeDelegator {
4000 public CustomGetType (string name) { this.name = name; }
4002 public override Type MakeGenericType (Type[] args) {
4003 return new CustomGetType ("GINST");
4006 public override Type GetNestedType(String name, BindingFlags bidingAttr) {
4007 return new CustomGetType ("NESTED");
4010 public override string ToString () { return "UT_" + name; }
4012 public override string Name {
4013 get { return "UT_" + name; }
4018 public void GetTypeWithDelegatesAndUserTypes ()
4020 var tname = "Magic[System.Int32]";
4021 var res = Type.GetType (tname, name => {
4022 return Assembly.Load (name);
4023 },(asm,name,ignore) => {
4024 if (name == "Magic") return new CustomGetType ("MAGIC");
4025 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4027 Assert.AreEqual ("UT_GINST", res.Name, "#1");
4030 tname = "Magic+MyRealEnum";
4031 res = Type.GetType (tname, name => {
4032 return Assembly.Load (name);
4033 },(asm,name,ignore) => {
4034 if (name == "Magic") return new CustomGetType ("MAGIC");
4035 return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4037 Assert.AreEqual ("UT_NESTED", res.Name, "#2");
4040 void MustTLE (string tname) {
4042 var res = Type.GetType (tname, name => {
4043 return Assembly.Load (name);
4044 },(asm,name,ignore) => {
4045 return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4047 Assert.Fail (tname);
4048 } catch (TypeLoadException) {}
4051 void MustANE (string tname) {
4053 var res = Type.GetType (tname, name => {
4054 return Assembly.Load (name);
4055 },(asm,name,ignore) => {
4056 return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4058 Assert.Fail (tname);
4059 } catch (ArgumentNullException) {}
4062 void MustAE_general (string tname, Func<string,Type> getType) {
4064 var res = getType (tname);
4065 Assert.Fail (tname);
4066 } catch (ArgumentException) {}
4069 void MustAE (string typename) {
4070 MustAE_general (typename, tname => {
4071 return Type.GetType (tname, name => {
4072 return Assembly.Load (name);
4073 },(asm,name,ignore) => {
4074 return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4079 void MustAEnn (string typename) {
4080 MustAE_general (typename, tname => Type.GetType (tname, null, null));
4083 void MustFNFE (string tname) {
4085 var res = Type.GetType (tname, name => {
4086 return Assembly.Load (name);
4087 },(asm,name,ignore) => {
4088 return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
4090 Assert.Fail (tname);
4091 } catch (FileNotFoundException) {}
4095 public void NewGetTypeErrors () {
4097 MustAE ("!@#$%^&*");
4098 MustAE (string.Format ("{0}[{1}&]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4099 MustAE (string.Format ("{0}[{1}*]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4100 MustAE (string.Format ("{0}&&", typeof (MyRealEnum).FullName));
4101 MustAE (string.Format ("{0}&*", typeof (MyRealEnum).FullName));
4102 MustAE (string.Format ("{0}&[{1}]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4103 MustAE (string.Format ("{0}[,", typeof (MyRealEnum).FullName));
4104 MustAE (string.Format ("{0}[*", typeof (MyRealEnum).FullName));
4106 MustAE (string.Format ("{0}[[{1},", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4107 MustAE (string.Format ("{0}[[{1}]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4108 MustAE (string.Format ("{0}[[{1}],", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4109 MustAE (string.Format ("{0}[[{1}]_", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4111 MustAE (string.Format ("{0}[{1}", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4112 MustAE (string.Format ("{0}[{1},", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4113 MustAE (string.Format ("{0}[{1},,", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4114 MustAE (string.Format ("{0}[{1} (", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4115 MustAE (string.Format ("{0}[", typeof (Foo<>).FullName));
4117 MustAE (string.Format ("{0}[**]", typeof (MyRealEnum).FullName));
4118 MustAE (string.Format ("{0}[*,*]", typeof (MyRealEnum).FullName));
4119 MustAE (string.Format ("{0}[*,]", typeof (MyRealEnum).FullName));
4120 MustAE (string.Format ("{0}[,*]", typeof (MyRealEnum).FullName));
4121 MustAE (string.Format ("{0}[,-]", typeof (MyRealEnum).FullName));
4122 MustAE (string.Format ("{0}[,{0}]", typeof (MyRealEnum).FullName));
4124 MustAE (string.Format ("{0}[{1}]]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
4125 MustAE (string.Format ("{0}[,]]", typeof (MyRealEnum).FullName));
4128 string aqn = typeof (MyRealEnum).Assembly.FullName;
4129 MustFNFE (string.Format ("{0}, ZZZ{1}", typeof (MyRealEnum).FullName, aqn));
4130 MustTLE (string.Format ("{0}ZZZZ", typeof (MyRealEnum).FullName));
4131 MustTLE (string.Format ("{0}ZZZZ,{1}", typeof (MyRealEnum).FullName, aqn));
4134 delegate void MyAction<in T>(T ag);
4136 [Test] //bug #668506
4137 public void IsAssignableFromWithVariantDelegate () {
4138 Assert.IsFalse (typeof(MyAction<string>).IsAssignableFrom(typeof(MyAction<>)), "#1");
4142 public void IsAssignableFromWithNullable () {
4143 Console.WriteLine(typeof(IEnumerable<int?>).IsAssignableFrom(typeof(IEnumerable<int>)));
4147 public void GetTypeParseGenericCorrectly () { //Bug #15124
4148 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1"), typeof (Foo<>), "#1");
4149 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32]"), typeof (Foo<int>), "#2");
4150 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[System.Int32]]"), typeof (Foo<int>), "#3");
4151 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][]"), typeof (Foo<int>[]), "#4");
4152 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][System.Int32]"), null, "#5");
4153 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][,]"), typeof (Foo<int>[,]), "#6");
4154 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[]"), typeof (Foo<>).MakeArrayType(), "#7");
4155 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,]"), typeof (Foo<>).MakeArrayType (2), "#8");
4156 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][]"), typeof (Foo<>).MakeArrayType ().MakeArrayType (), "#9");
4157 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1["), null, "#10");
4158 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[["), null, "#11");
4159 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[]"), null, "#12");
4160 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,"), null, "#13");
4161 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[*"), null, "#14");
4162 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32"), null, "#15");
4166 public void GetTypeNullDelegatesParseGenericCorrectly () {
4167 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1", null, null), typeof (Foo<>), "#1");
4168 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32]", null, null), typeof (Foo<int>), "#2");
4169 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[System.Int32]]", null, null), typeof (Foo<int>), "#3");
4170 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][]", null, null), typeof (Foo<int>[]), "#4");
4171 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][,]", null, null), typeof (Foo<int>[,]), "#5");
4172 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[]", null, null), typeof (Foo<>).MakeArrayType(), "#6");
4173 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,]", null, null), typeof (Foo<>).MakeArrayType (2), "#7");
4174 Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][]", null, null), typeof (Foo<>).MakeArrayType ().MakeArrayType (), "#8");
4176 MustAEnn ("MonoTests.System.Foo`1[][System.Int32]");
4177 MustAEnn ("MonoTests.System.Foo`1[");
4178 MustAEnn ("MonoTests.System.Foo`1[[");
4179 MustAEnn ("MonoTests.System.Foo`1[[]");
4180 MustAEnn ("MonoTests.System.Foo`1[,");
4181 MustAEnn ("MonoTests.System.Foo`1[*");
4182 MustAEnn ("MonoTests.System.Foo`1[System.Int32");
4185 Dictionary<int, T> MakeDictHelper<T> (T[] arr) {
4186 return new Dictionary<int, T>();
4190 public void GetTypeAnonymousParseCorrectly () {
4191 var x = new { X = 1 };
4192 var a = new [] { x };
4193 var d = MakeDictHelper (a);
4195 var x_type = x.GetType ();
4196 var a_type = a.GetType ();
4197 var d_type = d.GetType ();
4199 Assert.AreEqual (Type.GetType (x_type.ToString ()), x_type, "#1");
4200 Assert.AreEqual (Type.GetType (x_type.ToString (), null, null), x_type, "#2");
4201 Assert.AreEqual (Type.GetType (a_type.ToString ()), a_type, "#3");
4202 Assert.AreEqual (Type.GetType (a_type.ToString (), null, null), a_type, "#4");
4203 Assert.AreEqual (Type.GetType (d_type.ToString ()), d_type, "#5");
4204 Assert.AreEqual (Type.GetType (d_type.ToString (), null, null), d_type, "#6");
4206 Assert.AreEqual (Type.GetType (x_type.FullName), x_type, "#7");
4207 Assert.AreEqual (Type.GetType (x_type.FullName, null, null), x_type, "#8");
4208 Assert.AreEqual (Type.GetType (a_type.FullName), a_type, "#9");
4209 Assert.AreEqual (Type.GetType (a_type.FullName, null, null), a_type, "#10");
4210 Assert.AreEqual (Type.GetType (d_type.FullName), d_type, "#11");
4211 Assert.AreEqual (Type.GetType (d_type.FullName, null, null), d_type, "#12");
4215 #if !MONOTOUCH && !MOBILE_STATIC
4217 [Category ("AndroidNotWorking")] // requires symbol writer
4218 public void FullNameGetTypeParseEscapeRoundtrip () // bug #26384
4220 var nm = new AssemblyName ("asm");
4221 var ab = AssemblyBuilder.DefineDynamicAssembly (nm,
4222 AssemblyBuilderAccess.Run);
4223 var mb = ab.DefineDynamicModule("m", true);
4224 var tb = mb.DefineType ("NameSpace,+*&[]\\.Type,+*&[]\\",
4225 TypeAttributes.Class | TypeAttributes.Public);
4227 var nestedTb = tb.DefineNestedType("Nested,+*&[]\\",
4228 TypeAttributes.Class | TypeAttributes.NestedPublic);
4230 var ty = tb.CreateType();
4232 var nestedTy = nestedTb.CreateType();
4234 var escapedNestedName =
4235 "NameSpace\\,\\+\\*\\&\\[\\]\\\\"
4237 + "Type\\,\\+\\*\\&\\[\\]\\\\"
4239 + "Nested\\,\\+\\*\\&\\[\\]\\\\";
4241 Assert.AreEqual(escapedNestedName, nestedTy.FullName);
4243 var lookupNestedTy =
4244 Type.GetType(escapedNestedName + "," + nm.FullName,
4246 if (asmName.FullName.Equals(nm.FullName)) return ab;
4247 else return Assembly.Load (asmName);
4249 (asm,name,ignore) => {
4251 return Type.GetType(name, true, ignore);
4252 else return asm.GetType(name, true, ignore);
4256 Assert.AreEqual(nestedTy, lookupNestedTy);
4261 public abstract class Stream : IDisposable
4263 public void Dispose ()
4265 Console.WriteLine ("stream::dispose");
4268 protected virtual void Dispose (bool disposing)
4273 public class NonClosingStream
4274 : Stream, IDisposable
4276 void IDisposable.Dispose()
4278 Console.WriteLine ("ncs::dispose");
4281 public override string ToString () { return ""; }
4284 static bool ContainsProperty (PropertyInfo [] props, string name)
4286 foreach (PropertyInfo p in props)
4292 public class NemerleAttribute : Attribute
4296 public class VolatileModifier : NemerleAttribute
4306 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
4307 public class FooAttribute : Attribute
4311 public class BarAttribute : FooAttribute
4328 [AttributeUsage (AttributeTargets.Class, Inherited=true)]
4329 public class InheritAttribute : Attribute
4333 [AttributeUsage (AttributeTargets.Class, Inherited=false)]
4334 public class NotInheritAttribute : InheritAttribute
4338 [NotInheritAttribute]
4339 public class bug82431A1
4343 public class bug82431A2 : bug82431A1
4347 [NotInheritAttribute]
4349 public class bug82431A3 : bug82431A1
4354 public class bug82431B1
4358 public class bug82431B2 : bug82431B1
4362 [NotInheritAttribute]
4363 public class bug82431B3 : bug82431B2
4367 public class bug82431B4 : bug82431B3
4375 public class Bug77367
4377 public void Run (bool b)
4384 private string PrivInstBlue
4386 get { return null; }
4389 protected string ProtInstBlue
4391 get { return null; }
4394 protected internal string ProIntInstBlue
4396 get { return null; }
4399 public long PubInstBlue
4403 if (PrivInstBlue == null)
4405 return long.MaxValue;
4409 internal int IntInstBlue
4414 private static string PrivStatBlue
4416 get { return null; }
4419 protected static string ProtStatBlue
4421 get { return null; }
4424 protected static internal string ProIntStatBlue
4426 get { return null; }
4429 public static long PubStatBlue
4433 if (PrivStatBlue == null)
4435 return long.MaxValue;
4439 internal static int IntStatBlue
4445 public class Foo : Blue
4447 private string PrivInstBase
4449 get { return null; }
4452 protected string ProtInstBase
4454 get { return null; }
4457 protected internal string ProIntInstBase
4459 get { return null; }
4462 public long PubInstBase
4466 if (PrivInstBase == null)
4468 return long.MaxValue;
4472 internal int IntInstBase
4477 private static string PrivStatBase
4479 get { return null; }
4482 protected static string ProtStatBase
4484 get { return null; }
4487 protected static internal string ProIntStatBase
4489 get { return null; }
4492 public static long PubStatBase
4496 if (PrivStatBase == null)
4498 return long.MaxValue;
4502 internal static int IntStatBase
4508 public class Bar : Foo
4510 private string PrivInst
4512 get { return null; }
4515 protected string ProtInst
4517 get { return null; }
4520 protected internal string ProIntInst
4522 get { return null; }
4529 if (PrivInst == null)
4531 return long.MaxValue;
4535 internal int IntInst
4540 private static string PrivStat
4542 get { return null; }
4545 protected static string ProtStat
4547 get { return null; }
4550 protected static internal string ProIntStat
4552 get { return null; }
4555 public static long PubStat
4559 if (PrivStat == null)
4561 return long.MaxValue;
4565 internal static int IntStat
4591 public CtorsC (int x)
4597 class UserType : Type
4599 protected Type type;
4601 public UserType(Type type) {
4605 public override Type UnderlyingSystemType { get { return this.type; } }
4607 public override Assembly Assembly { get { return this.type == null ? null : this.type.Assembly; } }
4609 public override string AssemblyQualifiedName { get { return null; } }
4611 public override Type BaseType { get { return null; } }
4613 public override Module Module { get { return this.type.Module; } }
4615 public override string Namespace { get { return null; } }
4617 public override bool IsGenericParameter { get { return true; } }
4619 public override RuntimeTypeHandle TypeHandle { get { throw new NotSupportedException(); } }
4621 public override bool ContainsGenericParameters { get { return true; } }
4623 public override string FullName { get { return this.type.Name; } }
4625 public override Guid GUID { get { throw new NotSupportedException(); } }
4628 protected override bool IsArrayImpl() {
4632 protected override bool IsByRefImpl()
4637 protected override bool IsCOMObjectImpl()
4642 protected override bool IsPointerImpl()
4647 protected override bool IsPrimitiveImpl()
4653 protected override TypeAttributes GetAttributeFlagsImpl()
4658 protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder,
4659 CallingConventions callConvention, Type[] types,
4660 ParameterModifier[] modifiers)
4665 public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
4670 public override Type GetElementType()
4675 public override EventInfo GetEvent(string name, BindingFlags bindingAttr)
4681 public override FieldInfo GetField(string name, BindingFlags bindingAttr)
4687 public override Type GetInterface(string name, bool ignoreCase)
4692 public override Type[] GetInterfaces()
4697 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
4702 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
4707 public override object[] GetCustomAttributes(bool inherit)
4712 public override bool IsDefined(Type attributeType, bool inherit)
4717 public override string Name { get { return this.type.Name; } }
4719 public override EventInfo[] GetEvents(BindingFlags bindingAttr)
4721 throw new NotImplementedException();
4724 public override FieldInfo[] GetFields(BindingFlags bindingAttr)
4726 throw new NotImplementedException();
4729 protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder,
4730 CallingConventions callConvention, Type[] types,
4731 ParameterModifier[] modifiers)
4736 public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
4741 public override Type GetNestedType(string name, BindingFlags bindingAttr)
4746 public override Type[] GetNestedTypes(BindingFlags bindingAttr)
4751 public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
4756 protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder,
4757 Type returnType, Type[] types, ParameterModifier[] modifiers)
4762 protected override bool HasElementTypeImpl()
4767 public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target,
4768 object[] args, ParameterModifier[] modifiers, CultureInfo culture,
4769 string[] namedParameters)
4771 throw new NotSupportedException();
4775 class UserType2 : UserType {
4776 public UserType2 (Type type) : base (type) {
4779 public override Type UnderlyingSystemType { get { return this.type ?? this; } }
4781 public override int GetHashCode()
4785 return type.GetHashCode();