PageRenderTime 81ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/corlib/Test/System/TypeTest.cs

https://bitbucket.org/danipen/mono
C# | 4513 lines | 3837 code | 625 blank | 51 comment | 77 complexity | 2a5701da121846a8b9ef71f14a9b6932 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. // TypeTest.cs - NUnit Test Cases for the System.Type class
  2. //
  3. // Authors:
  4. // Zoltan Varga (vargaz@freemail.hu)
  5. // Patrik Torstensson
  6. //
  7. // (C) 2003 Ximian, Inc. http://www.ximian.com
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Threading;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Reflection;
  16. #if !MONOTOUCH
  17. using System.Reflection.Emit;
  18. #endif
  19. using System.Runtime.InteropServices;
  20. using System.Text;
  21. using System.Globalization;
  22. class NoNamespaceClass {
  23. }
  24. namespace MonoTests.System
  25. {
  26. class Super : ICloneable
  27. {
  28. public virtual object Clone ()
  29. {
  30. return null;
  31. }
  32. }
  33. class Duper: Super
  34. {
  35. }
  36. interface IFace1
  37. {
  38. void foo ();
  39. }
  40. interface IFace2 : IFace1
  41. {
  42. void bar ();
  43. }
  44. interface IFace3 : IFace2
  45. {
  46. }
  47. enum TheEnum
  48. {
  49. A,
  50. B,
  51. C
  52. };
  53. abstract class Base
  54. {
  55. public int level;
  56. public abstract int this [byte i] {
  57. get;
  58. }
  59. public abstract int this [int i] {
  60. get;
  61. }
  62. public abstract void TestVoid ();
  63. public abstract void TestInt (int i);
  64. }
  65. class DeriveVTable : Base
  66. {
  67. public override int this [byte i] {
  68. get { return 1; }
  69. }
  70. public override int this [int i] {
  71. get { return 1; }
  72. }
  73. public override void TestVoid ()
  74. {
  75. level = 1;
  76. }
  77. public override void TestInt (int i)
  78. {
  79. level = 1;
  80. }
  81. }
  82. class NewVTable : DeriveVTable
  83. {
  84. public new int this [byte i] {
  85. get { return 2; }
  86. }
  87. public new int this [int i] {
  88. get { return 2; }
  89. }
  90. public new void TestVoid ()
  91. {
  92. level = 2;
  93. }
  94. public new void TestInt (int i)
  95. {
  96. level = 2;
  97. }
  98. public void Overload ()
  99. {
  100. }
  101. public void Overload (int i)
  102. {
  103. }
  104. public NewVTable (out int i)
  105. {
  106. i = 0;
  107. }
  108. public void byref_method (out int i)
  109. {
  110. i = 0;
  111. }
  112. }
  113. class Base1
  114. {
  115. public virtual int Foo {
  116. get { return 1; }
  117. set { }
  118. }
  119. }
  120. class Derived1 : Base1
  121. {
  122. public override int Foo {
  123. set { }
  124. }
  125. }
  126. class Derived2 : Base1
  127. {
  128. public new int Foo {
  129. get { return 1; }
  130. set { }
  131. }
  132. }
  133. public class Foo<T>
  134. {
  135. public T Whatever;
  136. public T Test {
  137. get { throw new NotImplementedException (); }
  138. }
  139. public T Execute (T a)
  140. {
  141. return a;
  142. }
  143. public class Nested<K> {}
  144. }
  145. class Foo<T, U>
  146. {
  147. }
  148. public interface IBar<T>
  149. {
  150. }
  151. public class Baz<T> : IBar<T>
  152. {
  153. }
  154. class Gazonk {
  155. public static void Bang<S> () {}
  156. }
  157. public class Bug348522
  158. {
  159. public void Test (int __argument)
  160. {
  161. }
  162. }
  163. public class FirstMethodBinder : Binder
  164. {
  165. public override MethodBase BindToMethod (BindingFlags bindingAttr, MethodBase [] match, ref object [] args,
  166. ParameterModifier [] modifiers, CultureInfo culture, string [] names,
  167. out object state)
  168. {
  169. state = null;
  170. return match [0];
  171. }
  172. public override object ChangeType (object value, Type type1, CultureInfo culture)
  173. {
  174. return value;
  175. }
  176. // The rest is just to please the compiler
  177. public override FieldInfo BindToField (BindingFlags a, FieldInfo[] b, object c, CultureInfo d)
  178. {
  179. return null;
  180. }
  181. public override void ReorderArgumentArray(ref object[] a, object b)
  182. {
  183. }
  184. public override MethodBase SelectMethod(BindingFlags a, MethodBase[] b, Type[] c, ParameterModifier[] d)
  185. {
  186. return null;
  187. }
  188. public override PropertyInfo SelectProperty(BindingFlags a, PropertyInfo[] b, Type c, Type[] d, ParameterModifier[] e)
  189. {
  190. return null;
  191. }
  192. }
  193. [TestFixture]
  194. public class TypeTest
  195. {
  196. #if !MONOTOUCH
  197. private ModuleBuilder module;
  198. #endif
  199. const string ASSEMBLY_NAME = "MonoTests.System.TypeTest";
  200. static int typeIndexer = 0;
  201. [SetUp]
  202. public void SetUp ()
  203. {
  204. AssemblyName assemblyName = new AssemblyName ();
  205. assemblyName.Name = ASSEMBLY_NAME;
  206. #if !MONOTOUCH
  207. var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (
  208. assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
  209. module = assembly.DefineDynamicModule ("module1");
  210. #endif
  211. }
  212. private string genTypeName ()
  213. {
  214. return "t" + (typeIndexer++);
  215. }
  216. private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k)
  217. {
  218. }
  219. public interface IFace {
  220. }
  221. private void GenericMethod<Q, T1> (Q q, T1 t) where T1 : IFace
  222. {
  223. }
  224. [Test]
  225. public void TestIsAssignableFrom ()
  226. {
  227. // Simple tests for inheritance
  228. Assert.AreEqual (typeof (Super).IsAssignableFrom (typeof (Duper)) , true, "#01");
  229. Assert.AreEqual (typeof (Duper).IsAssignableFrom (typeof (Duper)), true, "#02");
  230. Assert.AreEqual (typeof (Object).IsAssignableFrom (typeof (Duper)), true, "#03");
  231. Assert.AreEqual (typeof (ICloneable).IsAssignableFrom (typeof (Duper)), true, "#04");
  232. // Tests for arrays
  233. Assert.AreEqual (typeof (Super[]).IsAssignableFrom (typeof (Duper[])), true, "#05");
  234. Assert.AreEqual (typeof (Duper[]).IsAssignableFrom (typeof (Super[])), false, "#06");
  235. Assert.AreEqual (typeof (Object[]).IsAssignableFrom (typeof (Duper[])), true, "#07");
  236. Assert.AreEqual (typeof (ICloneable[]).IsAssignableFrom (typeof (Duper[])), true, "#08");
  237. // Tests for multiple dimensional arrays
  238. Assert.AreEqual (typeof (Super[][]).IsAssignableFrom (typeof (Duper[][])), true, "#09");
  239. Assert.AreEqual (typeof (Duper[][]).IsAssignableFrom (typeof (Super[][])), false, "#10");
  240. Assert.AreEqual (typeof (Object[][]).IsAssignableFrom (typeof (Duper[][])), true, "#11");
  241. Assert.AreEqual (typeof (ICloneable[][]).IsAssignableFrom (typeof (Duper[][])), true, "#12");
  242. // Tests for vectors<->one dimensional arrays */
  243. #if TARGET_JVM // Lower bounds arrays are not supported for TARGET_JVM.
  244. Array arr1 = Array.CreateInstance (typeof (int), new int[] {1});
  245. Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
  246. #else
  247. Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
  248. Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
  249. Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr1.GetType ()), true, "#13");
  250. Assert.AreEqual (typeof (int[]).IsAssignableFrom (arr2.GetType ()), false, "#14");
  251. #endif // TARGET_JVM
  252. // Test that arrays of enums can be cast to their base types
  253. Assert.AreEqual (typeof (int[]).IsAssignableFrom (typeof (TypeCode[])), true, "#15");
  254. // Test that arrays of valuetypes can't be cast to arrays of
  255. // references
  256. Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TypeCode[])), false, "#16");
  257. Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TypeCode[])), false, "#17");
  258. Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TypeCode[])), false, "#18");
  259. // Test that arrays of enums can't be cast to arrays of references
  260. Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (TheEnum[])), false, "#19");
  261. Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (TheEnum[])), false, "#20");
  262. Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (TheEnum[])), false, "#21");
  263. // Check that ValueType and Enum are recognized as reference types
  264. Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (ValueType)), true, "#22");
  265. Assert.AreEqual (typeof (object).IsAssignableFrom (typeof (Enum)), true, "#23");
  266. Assert.AreEqual (typeof (ValueType).IsAssignableFrom (typeof (Enum)), true, "#24");
  267. Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (ValueType[])), true, "#25");
  268. Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (ValueType[])), true, "#26");
  269. Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (ValueType[])), false, "#27");
  270. Assert.AreEqual (typeof (object[]).IsAssignableFrom (typeof (Enum[])), true, "#28");
  271. Assert.AreEqual (typeof (ValueType[]).IsAssignableFrom (typeof (Enum[])), true, "#29");
  272. Assert.AreEqual (typeof (Enum[]).IsAssignableFrom (typeof (Enum[])), true, "#30");
  273. // Tests for byref types
  274. MethodInfo mi = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic);
  275. Assert.IsTrue (mi.GetParameters ()[2].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
  276. Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
  277. // Tests for type parameters
  278. mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
  279. Assert.IsTrue (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (mi.GetParameters ()[0].ParameterType));
  280. Assert.IsFalse (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (typeof (int)));
  281. // Tests for parameters with generic constraints
  282. mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
  283. Assert.IsTrue (typeof (IFace).IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
  284. }
  285. [Test]
  286. [ExpectedException (typeof (ArgumentException))]
  287. public void GetInterfaceMapOnInterface ()
  288. {
  289. typeof (IList).GetInterfaceMap (typeof (ICollection));
  290. }
  291. [Test]
  292. public void TestIsSubclassOf ()
  293. {
  294. Assert.IsTrue (typeof (ICloneable).IsSubclassOf (typeof (object)), "#01");
  295. // Tests for byref types
  296. Type paramType = typeof (TypeTest).GetMethod ("ByrefMethod", BindingFlags.Instance|BindingFlags.NonPublic).GetParameters () [0].ParameterType;
  297. Assert.IsTrue (!paramType.IsSubclassOf (typeof (ValueType)), "#02");
  298. //Assert.IsTrue (paramType.IsSubclassOf (typeof (Object)), "#03");
  299. Assert.IsTrue (!paramType.IsSubclassOf (paramType), "#04");
  300. }
  301. [Test]
  302. public void TestGetMethodImpl ()
  303. {
  304. // Test binding of new slot methods (using no types)
  305. Assert.AreEqual (typeof (Base), typeof (Base).GetMethod("TestVoid").DeclaringType, "#01");
  306. Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestVoid").DeclaringType, "#02");
  307. // Test binding of new slot methods (using types)
  308. Assert.AreEqual (typeof (Base), typeof (Base).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#03");
  309. Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetMethod ("TestInt", new Type[] { typeof (int) }).DeclaringType, "#04");
  310. // Test overload resolution
  311. Assert.AreEqual (0, typeof (NewVTable).GetMethod ("Overload", new Type[0]).GetParameters ().Length, "#05");
  312. // Test byref parameters
  313. Assert.AreEqual (null, typeof (NewVTable).GetMethod ("byref_method", new Type[] { typeof (int) }), "#06");
  314. Type byrefInt = typeof (NewVTable).GetMethod ("byref_method").GetParameters ()[0].ParameterType;
  315. Assert.IsNotNull (typeof (NewVTable).GetMethod ("byref_method", new Type[] { byrefInt }), "#07");
  316. }
  317. [Test]
  318. [Category ("TargetJvmNotWorking")]
  319. public void TestGetPropertyImpl ()
  320. {
  321. // Test getting property that is exact
  322. Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int32) }).DeclaringType, "#01");
  323. // Test getting property that is not exact
  324. Assert.AreEqual (typeof (NewVTable), typeof (NewVTable).GetProperty ("Item", new Type[1] { typeof (Int16) }).DeclaringType, "#02");
  325. // Test overriding of properties when only the set accessor is overriden
  326. Assert.AreEqual (1, typeof (Derived1).GetProperties ().Length, "#03");
  327. }
  328. [Test]
  329. public void GetProperties ()
  330. {
  331. // Test hide-by-name-and-signature
  332. Assert.AreEqual (1, typeof (Derived2).GetProperties ().Length);
  333. Assert.AreEqual (typeof (Derived2), typeof (Derived2).GetProperties ()[0].DeclaringType);
  334. }
  335. [Test] // GetProperties (BindingFlags)
  336. public void GetProperties_Flags ()
  337. {
  338. PropertyInfo [] props;
  339. Type type = typeof (Bar);
  340. BindingFlags flags;
  341. flags = BindingFlags.Instance | BindingFlags.NonPublic;
  342. props = type.GetProperties (flags);
  343. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#A1");
  344. Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#A2");
  345. Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#A3");
  346. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#A4");
  347. Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#A5");
  348. Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#A6");
  349. Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#A7");
  350. Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#A8");
  351. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#A9");
  352. Assert.IsTrue (ContainsProperty (props, "IntInst"), "#A10");
  353. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#A11");
  354. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#A12");
  355. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#A13");
  356. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#A14");
  357. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#A15");
  358. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#A16");
  359. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#A17");
  360. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#A18");
  361. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#A19");
  362. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#A20");
  363. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#A21");
  364. Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#A22");
  365. Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#A23");
  366. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#A24");
  367. Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#A25");
  368. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#A26");
  369. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#A27");
  370. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#A28");
  371. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#A29");
  372. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#A30");
  373. flags = BindingFlags.Instance | BindingFlags.Public;
  374. props = type.GetProperties (flags);
  375. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#B1");
  376. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#B2");
  377. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#B3");
  378. Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#B4");
  379. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#B5");
  380. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#B6");
  381. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#B7");
  382. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#B8");
  383. Assert.IsTrue (ContainsProperty (props, "PubInst"), "#B9");
  384. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#B10");
  385. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#B11");
  386. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#B12");
  387. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#B13");
  388. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#B14");
  389. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#B15");
  390. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#B16");
  391. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#B17");
  392. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#B18");
  393. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#B19");
  394. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#B20");
  395. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#B21");
  396. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#B22");
  397. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#B23");
  398. Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#B24");
  399. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#B25");
  400. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#B26");
  401. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#B27");
  402. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#B28");
  403. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#B29");
  404. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#B30");
  405. flags = BindingFlags.Static | BindingFlags.Public;
  406. props = type.GetProperties (flags);
  407. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#C1");
  408. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#C2");
  409. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#C3");
  410. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#C4");
  411. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#C5");
  412. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#C6");
  413. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#C7");
  414. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#C8");
  415. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#C9");
  416. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#C10");
  417. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#C11");
  418. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#C12");
  419. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#C13");
  420. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#C14");
  421. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#C15");
  422. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#C16");
  423. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#C17");
  424. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#C18");
  425. Assert.IsTrue (ContainsProperty (props, "PubStat"), "#C19");
  426. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#C20");
  427. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#C21");
  428. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#C22");
  429. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#C23");
  430. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#C24");
  431. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#C25");
  432. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#C26");
  433. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#C27");
  434. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#C28");
  435. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#C29");
  436. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#C30");
  437. flags = BindingFlags.Static | BindingFlags.NonPublic;
  438. props = type.GetProperties (flags);
  439. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#D1");
  440. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#D2");
  441. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#D3");
  442. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#D4");
  443. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#D5");
  444. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#D6");
  445. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#D7");
  446. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#D8");
  447. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#D9");
  448. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#D10");
  449. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#D11");
  450. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#D12");
  451. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#D13");
  452. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#D14");
  453. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#D15");
  454. Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#D16");
  455. Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#D17");
  456. Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#D18");
  457. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#D19");
  458. Assert.IsTrue (ContainsProperty (props, "IntStat"), "#D20");
  459. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#D21");
  460. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#D22");
  461. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#D23");
  462. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#D24");
  463. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#D25");
  464. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#D26");
  465. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#D27");
  466. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#D28");
  467. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#D29");
  468. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#D30");
  469. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  470. BindingFlags.FlattenHierarchy;
  471. props = type.GetProperties (flags);
  472. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#E1");
  473. Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#E2");
  474. Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#E3");
  475. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#E4");
  476. Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#E5");
  477. Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#E6");
  478. Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#E7");
  479. Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#E8");
  480. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#E9");
  481. Assert.IsTrue (ContainsProperty (props, "IntInst"), "#E10");
  482. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#E11");
  483. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#E12");
  484. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#E13");
  485. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#E14");
  486. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#E15");
  487. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#E16");
  488. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#E17");
  489. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#E18");
  490. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#E19");
  491. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#E20");
  492. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#E21");
  493. Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#E22");
  494. Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#E23");
  495. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#E24");
  496. Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#E25");
  497. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#E26");
  498. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#E27");
  499. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#E28");
  500. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#E29");
  501. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#E30");
  502. flags = BindingFlags.Instance | BindingFlags.Public |
  503. BindingFlags.FlattenHierarchy;
  504. props = type.GetProperties (flags);
  505. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#F1");
  506. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#F2");
  507. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#F3");
  508. Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#F4");
  509. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#F5");
  510. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#F6");
  511. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#F7");
  512. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#F8");
  513. Assert.IsTrue (ContainsProperty (props, "PubInst"), "#F9");
  514. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#F10");
  515. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#F11");
  516. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#F12");
  517. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#F13");
  518. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#F14");
  519. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#F15");
  520. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#F16");
  521. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#F17");
  522. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#F18");
  523. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#F19");
  524. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#F20");
  525. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#F21");
  526. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#F22");
  527. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#F23");
  528. Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#F24");
  529. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#F25");
  530. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#F26");
  531. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#F27");
  532. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#F28");
  533. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#F29");
  534. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#F30");
  535. flags = BindingFlags.Static | BindingFlags.Public |
  536. BindingFlags.FlattenHierarchy;
  537. props = type.GetProperties (flags);
  538. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#G1");
  539. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#G2");
  540. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#G3");
  541. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#G4");
  542. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#G5");
  543. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#G6");
  544. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#G7");
  545. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#G8");
  546. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#G9");
  547. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#G10");
  548. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#G11");
  549. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#G12");
  550. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#G13");
  551. Assert.IsTrue (ContainsProperty (props, "PubStatBase"), "#G14");
  552. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#G15");
  553. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#G16");
  554. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#G17");
  555. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#G18");
  556. Assert.IsTrue (ContainsProperty (props, "PubStat"), "#G19");
  557. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#G20");
  558. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#G21");
  559. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#G22");
  560. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#G23");
  561. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#G24");
  562. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#G25");
  563. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#G26");
  564. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#G27");
  565. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#G28");
  566. Assert.IsTrue (ContainsProperty (props, "PubStatBlue"), "#G29");
  567. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#G30");
  568. flags = BindingFlags.Static | BindingFlags.NonPublic |
  569. BindingFlags.FlattenHierarchy;
  570. props = type.GetProperties (flags);
  571. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#H1");
  572. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#H2");
  573. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#H3");
  574. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#H4");
  575. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#H5");
  576. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#H6");
  577. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#H7");
  578. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#H8");
  579. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#H9");
  580. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#H10");
  581. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#H11");
  582. Assert.IsTrue (ContainsProperty (props, "ProtStatBase"), "#H12");
  583. Assert.IsTrue (ContainsProperty (props, "ProIntStatBase"), "#H13");
  584. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#H14");
  585. Assert.IsTrue (ContainsProperty (props, "IntStatBase"), "#H15");
  586. Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#H16");
  587. Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#H17");
  588. Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#H18");
  589. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#H19");
  590. Assert.IsTrue (ContainsProperty (props, "IntStat"), "#H20");
  591. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#H21");
  592. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#H22");
  593. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#H23");
  594. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#H24");
  595. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#H25");
  596. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#H26");
  597. Assert.IsTrue (ContainsProperty (props, "ProtStatBlue"), "#H27");
  598. Assert.IsTrue (ContainsProperty (props, "ProIntStatBlue"), "#H28");
  599. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#H29");
  600. Assert.IsTrue (ContainsProperty (props, "IntStatBlue"), "#H30");
  601. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  602. BindingFlags.DeclaredOnly;
  603. props = type.GetProperties (flags);
  604. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#I1");
  605. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#I2");
  606. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#I3");
  607. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#I4");
  608. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#I5");
  609. Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#I6");
  610. Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#I7");
  611. Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#I8");
  612. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#I9");
  613. Assert.IsTrue (ContainsProperty (props, "IntInst"), "#I10");
  614. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#I11");
  615. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#I12");
  616. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#I13");
  617. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#I14");
  618. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#I15");
  619. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#I16");
  620. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#I17");
  621. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#I18");
  622. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#I19");
  623. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#I20");
  624. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#I21");
  625. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#I22");
  626. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#I23");
  627. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#I24");
  628. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#I25");
  629. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#I26");
  630. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#I27");
  631. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#I28");
  632. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#I29");
  633. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#I30");
  634. flags = BindingFlags.Instance | BindingFlags.Public |
  635. BindingFlags.DeclaredOnly;
  636. props = type.GetProperties (flags);
  637. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#J1");
  638. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#J2");
  639. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#J3");
  640. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#J4");
  641. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#J5");
  642. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#J6");
  643. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#J7");
  644. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#J8");
  645. Assert.IsTrue (ContainsProperty (props, "PubInst"), "#J9");
  646. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#J10");
  647. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#J11");
  648. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#J12");
  649. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#J13");
  650. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#J14");
  651. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#J15");
  652. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#J16");
  653. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#J17");
  654. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#J18");
  655. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#J19");
  656. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#J20");
  657. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#J21");
  658. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#J22");
  659. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#J23");
  660. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#J24");
  661. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#J25");
  662. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#J26");
  663. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#J27");
  664. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#J28");
  665. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#J29");
  666. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#J30");
  667. flags = BindingFlags.Static | BindingFlags.Public |
  668. BindingFlags.DeclaredOnly;
  669. props = type.GetProperties (flags);
  670. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#K1");
  671. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#K2");
  672. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#K3");
  673. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#K4");
  674. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#K5");
  675. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#K6");
  676. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#K7");
  677. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#K8");
  678. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#K9");
  679. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#K10");
  680. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#K11");
  681. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#K12");
  682. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#K13");
  683. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#K14");
  684. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#K15");
  685. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#K16");
  686. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#K17");
  687. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#K18");
  688. Assert.IsTrue (ContainsProperty (props, "PubStat"), "#K19");
  689. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#K20");
  690. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#K21");
  691. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#K22");
  692. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#K23");
  693. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#K24");
  694. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#K25");
  695. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#K26");
  696. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#K27");
  697. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#K28");
  698. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#K29");
  699. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#K30");
  700. flags = BindingFlags.Static | BindingFlags.NonPublic |
  701. BindingFlags.DeclaredOnly;
  702. props = type.GetProperties (flags);
  703. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#L1");
  704. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#L2");
  705. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#L3");
  706. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#L4");
  707. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#L5");
  708. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#L6");
  709. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#L7");
  710. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#L8");
  711. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#L9");
  712. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#L10");
  713. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#L11");
  714. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#L12");
  715. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#L13");
  716. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#L14");
  717. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#L15");
  718. Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#L16");
  719. Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#L17");
  720. Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#L18");
  721. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#L19");
  722. Assert.IsTrue (ContainsProperty (props, "IntStat"), "#L20");
  723. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#L21");
  724. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#L22");
  725. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#L23");
  726. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#L24");
  727. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#L25");
  728. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#L26");
  729. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#L27");
  730. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#L28");
  731. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#L29");
  732. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#L30");
  733. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  734. BindingFlags.Public;
  735. props = type.GetProperties (flags);
  736. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#M1");
  737. Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#M2");
  738. Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#M3");
  739. Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#M4");
  740. Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#M5");
  741. Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#M6");
  742. Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#M7");
  743. Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#M8");
  744. Assert.IsTrue (ContainsProperty (props, "PubInst"), "#M9");
  745. Assert.IsTrue (ContainsProperty (props, "IntInst"), "#M10");
  746. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#M11");
  747. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#M12");
  748. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#M13");
  749. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#M14");
  750. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#M15");
  751. Assert.IsFalse (ContainsProperty (props, "PrivStat"), "#M16");
  752. Assert.IsFalse (ContainsProperty (props, "ProtStat"), "#M17");
  753. Assert.IsFalse (ContainsProperty (props, "ProIntStat"), "#M18");
  754. Assert.IsFalse (ContainsProperty (props, "PubStat"), "#M19");
  755. Assert.IsFalse (ContainsProperty (props, "IntStat"), "#M20");
  756. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#M21");
  757. Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#M22");
  758. Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#M23");
  759. Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#M24");
  760. Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#M25");
  761. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#M26");
  762. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#M27");
  763. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#M28");
  764. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#M29");
  765. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#M30");
  766. flags = BindingFlags.Static | BindingFlags.NonPublic |
  767. BindingFlags.Public;
  768. props = type.GetProperties (flags);
  769. Assert.IsFalse (ContainsProperty (props, "PrivInstBase"), "#N1");
  770. Assert.IsFalse (ContainsProperty (props, "ProtInstBase"), "#N2");
  771. Assert.IsFalse (ContainsProperty (props, "ProIntInstBase"), "#N3");
  772. Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#N4");
  773. Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#N5");
  774. Assert.IsFalse (ContainsProperty (props, "PrivInst"), "#N6");
  775. Assert.IsFalse (ContainsProperty (props, "ProtInst"), "#N7");
  776. Assert.IsFalse (ContainsProperty (props, "ProIntInst"), "#N8");
  777. Assert.IsFalse (ContainsProperty (props, "PubInst"), "#N9");
  778. Assert.IsFalse (ContainsProperty (props, "IntInst"), "#N10");
  779. Assert.IsFalse (ContainsProperty (props, "PrivStatBase"), "#N11");
  780. Assert.IsFalse (ContainsProperty (props, "ProtStatBase"), "#N12");
  781. Assert.IsFalse (ContainsProperty (props, "ProIntStatBase"), "#N13");
  782. Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#N14");
  783. Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#N15");
  784. Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#N16");
  785. Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#N17");
  786. Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#N18");
  787. Assert.IsTrue (ContainsProperty (props, "PubStat"), "#N19");
  788. Assert.IsTrue (ContainsProperty (props, "IntStat"), "#N20");
  789. Assert.IsFalse (ContainsProperty (props, "PrivInstBlue"), "#N21");
  790. Assert.IsFalse (ContainsProperty (props, "ProtInstBlue"), "#N22");
  791. Assert.IsFalse (ContainsProperty (props, "ProIntInstBlue"), "#N23");
  792. Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#N24");
  793. Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#N25");
  794. Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#N26");
  795. Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#N27");
  796. Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#N28");
  797. Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#N29");
  798. Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#N30");
  799. }
  800. [Test] // GetProperty (String)
  801. public void GetProperty1_Name_Null ()
  802. {
  803. Type type = typeof (Bar);
  804. try {
  805. type.GetProperty ((string) null);
  806. Assert.Fail ("#1");
  807. } catch (ArgumentNullException ex) {
  808. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  809. Assert.IsNull (ex.InnerException, "#3");
  810. Assert.IsNotNull (ex.Message, "#4");
  811. Assert.IsNotNull (ex.ParamName, "#5");
  812. Assert.AreEqual ("name", ex.ParamName, "#6");
  813. }
  814. }
  815. [Test] // GetProperty (String, BindingFlags)
  816. public void GetProperty2 ()
  817. {
  818. Type type = typeof (Bar);
  819. BindingFlags flags;
  820. flags = BindingFlags.Instance | BindingFlags.NonPublic;
  821. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#A1");
  822. Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#A2");
  823. Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#A3");
  824. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#A4");
  825. Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#A5");
  826. Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#A6");
  827. Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#A7");
  828. Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#A8");
  829. Assert.IsNull (type.GetProperty ("PubInst", flags), "#A9");
  830. Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#A10");
  831. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#A11");
  832. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#A12");
  833. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#A13");
  834. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#A14");
  835. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#A15");
  836. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#A16");
  837. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#A17");
  838. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#A18");
  839. Assert.IsNull (type.GetProperty ("PubStat", flags), "#A19");
  840. Assert.IsNull (type.GetProperty ("IntStat", flags), "#A20");
  841. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#A21");
  842. Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#A22");
  843. Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#A23");
  844. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#A24");
  845. Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#A25");
  846. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#A26");
  847. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#A27");
  848. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#A28");
  849. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#A29");
  850. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#A30");
  851. flags = BindingFlags.Instance | BindingFlags.Public;
  852. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#B1");
  853. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#B2");
  854. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#B3");
  855. Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#B4");
  856. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#B5");
  857. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#B6");
  858. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#B7");
  859. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#B8");
  860. Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#B9");
  861. Assert.IsNull (type.GetProperty ("IntInst", flags), "#B10");
  862. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#B11");
  863. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#B12");
  864. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#B13");
  865. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#B14");
  866. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#B15");
  867. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#B16");
  868. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#B17");
  869. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#B18");
  870. Assert.IsNull (type.GetProperty ("PubStat", flags), "#B19");
  871. Assert.IsNull (type.GetProperty ("IntStat", flags), "#B20");
  872. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#B21");
  873. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#B22");
  874. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#B23");
  875. Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#B24");
  876. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#B25");
  877. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#B26");
  878. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#B27");
  879. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#B28");
  880. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#B29");
  881. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#B30");
  882. flags = BindingFlags.Static | BindingFlags.Public;
  883. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#C1");
  884. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#C2");
  885. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#C3");
  886. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#C4");
  887. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#C5");
  888. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#C6");
  889. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#C7");
  890. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#C8");
  891. Assert.IsNull (type.GetProperty ("PubInst", flags), "#C9");
  892. Assert.IsNull (type.GetProperty ("IntInst", flags), "#C10");
  893. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#C11");
  894. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#C12");
  895. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#C13");
  896. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#C14");
  897. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#C15");
  898. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#C16");
  899. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#C17");
  900. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#C18");
  901. Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#C19");
  902. Assert.IsNull (type.GetProperty ("IntStat", flags), "#C20");
  903. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#C21");
  904. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#C22");
  905. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#C23");
  906. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#C24");
  907. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#C25");
  908. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#C26");
  909. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#C27");
  910. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#C28");
  911. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#C29");
  912. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#C30");
  913. flags = BindingFlags.Static | BindingFlags.NonPublic;
  914. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#D1");
  915. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#D2");
  916. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#D3");
  917. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#D4");
  918. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#D5");
  919. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#D6");
  920. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#D7");
  921. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#D8");
  922. Assert.IsNull (type.GetProperty ("PubInst", flags), "#D9");
  923. Assert.IsNull (type.GetProperty ("IntInst", flags), "#D10");
  924. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#D11");
  925. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#D12");
  926. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#D13");
  927. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#D14");
  928. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#D15");
  929. Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#D16");
  930. Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#D17");
  931. Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#D18");
  932. Assert.IsNull (type.GetProperty ("PubStat", flags), "#D19");
  933. Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#D20");
  934. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#D21");
  935. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#D22");
  936. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#D23");
  937. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#D24");
  938. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#D25");
  939. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#D26");
  940. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#D27");
  941. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#D28");
  942. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#D29");
  943. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#D30");
  944. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  945. BindingFlags.FlattenHierarchy;
  946. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#E1");
  947. Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#E2");
  948. Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#E3");
  949. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#E4");
  950. Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#E5");
  951. Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#E6");
  952. Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#E7");
  953. Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#E8");
  954. Assert.IsNull (type.GetProperty ("PubInst", flags), "#E9");
  955. Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#E10");
  956. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#E11");
  957. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#E12");
  958. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#E13");
  959. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#E14");
  960. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#E15");
  961. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#E16");
  962. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#E17");
  963. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#E18");
  964. Assert.IsNull (type.GetProperty ("PubStat", flags), "#E19");
  965. Assert.IsNull (type.GetProperty ("IntStat", flags), "#E20");
  966. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#E21");
  967. Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#E22");
  968. Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#E23");
  969. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#E24");
  970. Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#E25");
  971. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#E26");
  972. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#E27");
  973. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#E28");
  974. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#E29");
  975. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#E30");
  976. flags = BindingFlags.Instance | BindingFlags.Public |
  977. BindingFlags.FlattenHierarchy;
  978. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#F1");
  979. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#F2");
  980. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#F3");
  981. Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#F4");
  982. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#F5");
  983. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#F6");
  984. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#F7");
  985. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#F8");
  986. Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#F9");
  987. Assert.IsNull (type.GetProperty ("IntInst", flags), "#F10");
  988. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#F11");
  989. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#F12");
  990. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#F13");
  991. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#F14");
  992. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#F15");
  993. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#F16");
  994. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#F17");
  995. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#F18");
  996. Assert.IsNull (type.GetProperty ("PubStat", flags), "#F19");
  997. Assert.IsNull (type.GetProperty ("IntStat", flags), "#F20");
  998. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#F21");
  999. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#F22");
  1000. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#F23");
  1001. Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#F24");
  1002. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#F25");
  1003. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#F26");
  1004. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#F27");
  1005. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#F28");
  1006. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#F29");
  1007. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#F30");
  1008. flags = BindingFlags.Static | BindingFlags.Public |
  1009. BindingFlags.FlattenHierarchy;
  1010. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#G1");
  1011. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#G2");
  1012. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#G3");
  1013. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#G4");
  1014. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#G5");
  1015. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#G6");
  1016. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#G7");
  1017. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#G8");
  1018. Assert.IsNull (type.GetProperty ("PubInst", flags), "#G9");
  1019. Assert.IsNull (type.GetProperty ("IntInst", flags), "#G10");
  1020. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#G11");
  1021. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#G12");
  1022. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#G13");
  1023. Assert.IsNotNull (type.GetProperty ("PubStatBase", flags), "#G14");
  1024. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#G15");
  1025. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#G16");
  1026. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#G17");
  1027. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#G18");
  1028. Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#G19");
  1029. Assert.IsNull (type.GetProperty ("IntStat", flags), "#G20");
  1030. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#G21");
  1031. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#G22");
  1032. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#G23");
  1033. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#G24");
  1034. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#G25");
  1035. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#G26");
  1036. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#G27");
  1037. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#G28");
  1038. Assert.IsNotNull (type.GetProperty ("PubStatBlue", flags), "#G29");
  1039. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#G30");
  1040. flags = BindingFlags.Static | BindingFlags.NonPublic |
  1041. BindingFlags.FlattenHierarchy;
  1042. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#H1");
  1043. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#H2");
  1044. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#H3");
  1045. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#H4");
  1046. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#H5");
  1047. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#H6");
  1048. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#H7");
  1049. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#H8");
  1050. Assert.IsNull (type.GetProperty ("PubInst", flags), "#H9");
  1051. Assert.IsNull (type.GetProperty ("IntInst", flags), "#H10");
  1052. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#H11");
  1053. Assert.IsNotNull (type.GetProperty ("ProtStatBase", flags), "#H12");
  1054. Assert.IsNotNull (type.GetProperty ("ProIntStatBase", flags), "#H13");
  1055. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#H14");
  1056. Assert.IsNotNull (type.GetProperty ("IntStatBase", flags), "#H15");
  1057. Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#H16");
  1058. Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#H17");
  1059. Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#H18");
  1060. Assert.IsNull (type.GetProperty ("PubStat", flags), "#H19");
  1061. Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#H20");
  1062. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#H21");
  1063. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#H22");
  1064. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#H23");
  1065. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#H24");
  1066. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#H25");
  1067. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#H26");
  1068. Assert.IsNotNull (type.GetProperty ("ProtStatBlue", flags), "#H27");
  1069. Assert.IsNotNull (type.GetProperty ("ProIntStatBlue", flags), "#H28");
  1070. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#H29");
  1071. Assert.IsNotNull (type.GetProperty ("IntStatBlue", flags), "#H30");
  1072. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  1073. BindingFlags.DeclaredOnly;
  1074. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#I1");
  1075. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#I2");
  1076. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#I3");
  1077. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#I4");
  1078. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#I5");
  1079. Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#I6");
  1080. Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#I7");
  1081. Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#I8");
  1082. Assert.IsNull (type.GetProperty ("PubInst", flags), "#I9");
  1083. Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#I10");
  1084. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#I11");
  1085. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#I12");
  1086. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#I13");
  1087. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#I14");
  1088. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#I15");
  1089. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#I16");
  1090. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#I17");
  1091. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#I18");
  1092. Assert.IsNull (type.GetProperty ("PubStat", flags), "#I19");
  1093. Assert.IsNull (type.GetProperty ("IntStat", flags), "#I20");
  1094. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#I21");
  1095. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#I22");
  1096. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#I23");
  1097. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#I24");
  1098. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#I25");
  1099. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#I26");
  1100. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#I27");
  1101. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#I28");
  1102. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#I29");
  1103. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#I30");
  1104. flags = BindingFlags.Instance | BindingFlags.Public |
  1105. BindingFlags.DeclaredOnly;
  1106. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#J1");
  1107. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#J2");
  1108. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#J3");
  1109. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#J4");
  1110. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#J5");
  1111. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#J6");
  1112. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#J7");
  1113. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#J8");
  1114. Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#J9");
  1115. Assert.IsNull (type.GetProperty ("IntInst", flags), "#J10");
  1116. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#J11");
  1117. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#J12");
  1118. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#J13");
  1119. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#J14");
  1120. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#J15");
  1121. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#J16");
  1122. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#J17");
  1123. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#J18");
  1124. Assert.IsNull (type.GetProperty ("PubStat", flags), "#J19");
  1125. Assert.IsNull (type.GetProperty ("IntStat", flags), "#J20");
  1126. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#J21");
  1127. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#J22");
  1128. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#J23");
  1129. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#J24");
  1130. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#J25");
  1131. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#J26");
  1132. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#J27");
  1133. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#J28");
  1134. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#J29");
  1135. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#J30");
  1136. flags = BindingFlags.Static | BindingFlags.Public |
  1137. BindingFlags.DeclaredOnly;
  1138. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#K1");
  1139. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#K2");
  1140. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#K3");
  1141. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#K4");
  1142. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#K5");
  1143. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#K6");
  1144. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#K7");
  1145. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#K8");
  1146. Assert.IsNull (type.GetProperty ("PubInst", flags), "#K9");
  1147. Assert.IsNull (type.GetProperty ("IntInst", flags), "#K10");
  1148. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#K11");
  1149. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#K12");
  1150. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#K13");
  1151. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#K14");
  1152. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#K15");
  1153. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#K16");
  1154. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#K17");
  1155. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#K18");
  1156. Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#K19");
  1157. Assert.IsNull (type.GetProperty ("IntStat", flags), "#K20");
  1158. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#K21");
  1159. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#K22");
  1160. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#K23");
  1161. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#K24");
  1162. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#K25");
  1163. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#K26");
  1164. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#K27");
  1165. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#K28");
  1166. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#K29");
  1167. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#K30");
  1168. flags = BindingFlags.Static | BindingFlags.NonPublic |
  1169. BindingFlags.DeclaredOnly;
  1170. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#L1");
  1171. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#L2");
  1172. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#L3");
  1173. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#L4");
  1174. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#L5");
  1175. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#L6");
  1176. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#L7");
  1177. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#L8");
  1178. Assert.IsNull (type.GetProperty ("PubInst", flags), "#L9");
  1179. Assert.IsNull (type.GetProperty ("IntInst", flags), "#L10");
  1180. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#L11");
  1181. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#L12");
  1182. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#L13");
  1183. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#L14");
  1184. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#L15");
  1185. Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#L16");
  1186. Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#L17");
  1187. Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#L18");
  1188. Assert.IsNull (type.GetProperty ("PubStat", flags), "#L19");
  1189. Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#L20");
  1190. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#L21");
  1191. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#L22");
  1192. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#L23");
  1193. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#L24");
  1194. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#L25");
  1195. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#L26");
  1196. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#L27");
  1197. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#L28");
  1198. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#L29");
  1199. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#L30");
  1200. flags = BindingFlags.Instance | BindingFlags.NonPublic |
  1201. BindingFlags.Public;
  1202. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#M1");
  1203. Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#M2");
  1204. Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#M3");
  1205. Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#M4");
  1206. Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#M5");
  1207. Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#M6");
  1208. Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#M7");
  1209. Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#M8");
  1210. Assert.IsNotNull (type.GetProperty ("PubInst", flags), "#M9");
  1211. Assert.IsNotNull (type.GetProperty ("IntInst", flags), "#M10");
  1212. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#M11");
  1213. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#M12");
  1214. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#M13");
  1215. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#M14");
  1216. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#M15");
  1217. Assert.IsNull (type.GetProperty ("PrivStat", flags), "#M16");
  1218. Assert.IsNull (type.GetProperty ("ProtStat", flags), "#M17");
  1219. Assert.IsNull (type.GetProperty ("ProIntStat", flags), "#M18");
  1220. Assert.IsNull (type.GetProperty ("PubStat", flags), "#M19");
  1221. Assert.IsNull (type.GetProperty ("IntStat", flags), "#M20");
  1222. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#M21");
  1223. Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#M22");
  1224. Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#M23");
  1225. Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#M24");
  1226. Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#M25");
  1227. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#M26");
  1228. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#M27");
  1229. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#M28");
  1230. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#M29");
  1231. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#M30");
  1232. flags = BindingFlags.Static | BindingFlags.NonPublic |
  1233. BindingFlags.Public;
  1234. Assert.IsNull (type.GetProperty ("PrivInstBase", flags), "#N1");
  1235. Assert.IsNull (type.GetProperty ("ProtInstBase", flags), "#N2");
  1236. Assert.IsNull (type.GetProperty ("ProIntInstBase", flags), "#N3");
  1237. Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#N4");
  1238. Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#N5");
  1239. Assert.IsNull (type.GetProperty ("PrivInst", flags), "#N6");
  1240. Assert.IsNull (type.GetProperty ("ProtInst", flags), "#N7");
  1241. Assert.IsNull (type.GetProperty ("ProIntInst", flags), "#N8");
  1242. Assert.IsNull (type.GetProperty ("PubInst", flags), "#N9");
  1243. Assert.IsNull (type.GetProperty ("IntInst", flags), "#N10");
  1244. Assert.IsNull (type.GetProperty ("PrivStatBase", flags), "#N11");
  1245. Assert.IsNull (type.GetProperty ("ProtStatBase", flags), "#N12");
  1246. Assert.IsNull (type.GetProperty ("ProIntStatBase", flags), "#N13");
  1247. Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#N14");
  1248. Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#N15");
  1249. Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#N16");
  1250. Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#N17");
  1251. Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#N18");
  1252. Assert.IsNotNull (type.GetProperty ("PubStat", flags), "#N19");
  1253. Assert.IsNotNull (type.GetProperty ("IntStat", flags), "#N20");
  1254. Assert.IsNull (type.GetProperty ("PrivInstBlue", flags), "#N21");
  1255. Assert.IsNull (type.GetProperty ("ProtInstBlue", flags), "#N22");
  1256. Assert.IsNull (type.GetProperty ("ProIntInstBlue", flags), "#N23");
  1257. Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#N24");
  1258. Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#N25");
  1259. Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#N26");
  1260. Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#N27");
  1261. Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#N28");
  1262. Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#N29");
  1263. Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#N30");
  1264. }
  1265. [Test] // GetProperty (String, BindingFlags)
  1266. public void GetProperty2_Name_Null ()
  1267. {
  1268. Type type = typeof (Bar);
  1269. try {
  1270. type.GetProperty ((string) null);
  1271. Assert.Fail ("#1");
  1272. } catch (ArgumentNullException ex) {
  1273. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1274. Assert.IsNull (ex.InnerException, "#3");
  1275. Assert.IsNotNull (ex.Message, "#4");
  1276. Assert.IsNotNull (ex.ParamName, "#5");
  1277. Assert.AreEqual ("name", ex.ParamName, "#6");
  1278. }
  1279. }
  1280. [Test] // GetProperty (String, Type)
  1281. public void GetProperty3_Name_Null ()
  1282. {
  1283. Type type = typeof (Bar);
  1284. try {
  1285. type.GetProperty ((string) null, typeof (int));
  1286. Assert.Fail ("#1");
  1287. } catch (ArgumentNullException ex) {
  1288. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1289. Assert.IsNull (ex.InnerException, "#3");
  1290. Assert.IsNotNull (ex.Message, "#4");
  1291. Assert.IsNotNull (ex.ParamName, "#5");
  1292. Assert.AreEqual ("name", ex.ParamName, "#6");
  1293. }
  1294. }
  1295. [Test] // GetProperty (String, Type [])
  1296. public void GetProperty4_Name_Null ()
  1297. {
  1298. Type type = typeof (Bar);
  1299. try {
  1300. type.GetProperty ((string) null, Type.EmptyTypes);
  1301. Assert.Fail ("#1");
  1302. } catch (ArgumentNullException ex) {
  1303. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1304. Assert.IsNull (ex.InnerException, "#3");
  1305. Assert.IsNotNull (ex.Message, "#4");
  1306. Assert.IsNotNull (ex.ParamName, "#5");
  1307. Assert.AreEqual ("name", ex.ParamName, "#6");
  1308. }
  1309. }
  1310. [Test] // GetProperty (String, Type, Type [])
  1311. public void GetProperty5_Name_Null ()
  1312. {
  1313. Type type = typeof (Bar);
  1314. try {
  1315. type.GetProperty ((string) null, typeof (int),
  1316. Type.EmptyTypes);
  1317. Assert.Fail ("#1");
  1318. } catch (ArgumentNullException ex) {
  1319. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1320. Assert.IsNull (ex.InnerException, "#3");
  1321. Assert.IsNotNull (ex.Message, "#4");
  1322. Assert.IsNotNull (ex.ParamName, "#5");
  1323. Assert.AreEqual ("name", ex.ParamName, "#6");
  1324. }
  1325. }
  1326. [Test] // GetProperty (String, Type, Type [], ParameterModifier [])
  1327. public void GetProperty6_Name_Null ()
  1328. {
  1329. Type type = typeof (Bar);
  1330. try {
  1331. type.GetProperty ((string) null, typeof (int),
  1332. Type.EmptyTypes, null);
  1333. Assert.Fail ("#1");
  1334. } catch (ArgumentNullException ex) {
  1335. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1336. Assert.IsNull (ex.InnerException, "#3");
  1337. Assert.IsNotNull (ex.Message, "#4");
  1338. Assert.IsNotNull (ex.ParamName, "#5");
  1339. Assert.AreEqual ("name", ex.ParamName, "#6");
  1340. }
  1341. }
  1342. [Test] // GetProperty (String, BindingFlags, Binder, Type, Type [], ParameterModifier [])
  1343. public void GetProperty7_Name_Null ()
  1344. {
  1345. Type type = typeof (Bar);
  1346. try {
  1347. type.GetProperty ((string) null, BindingFlags.Public,
  1348. null, typeof (int), Type.EmptyTypes, null);
  1349. Assert.Fail ("#1");
  1350. } catch (ArgumentNullException ex) {
  1351. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1352. Assert.IsNull (ex.InnerException, "#3");
  1353. Assert.IsNotNull (ex.Message, "#4");
  1354. Assert.IsNotNull (ex.ParamName, "#5");
  1355. Assert.AreEqual ("name", ex.ParamName, "#6");
  1356. }
  1357. }
  1358. [Test]
  1359. public void GetProperty8_PropertyType ()
  1360. {
  1361. Type type = typeof (Bar);
  1362. Assert.IsNull (type.GetProperty ("PubInst", BindingFlags.Public | BindingFlags.Instance,
  1363. null, typeof (int), Type.EmptyTypes, null), "#1");
  1364. Assert.IsNotNull (type.GetProperty ("PubInst", BindingFlags.Public | BindingFlags.Instance, null,
  1365. typeof (long), new Type[0], null), "#2");
  1366. }
  1367. #if !TARGET_JVM // StructLayout not supported for TARGET_JVM
  1368. [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
  1369. public class Class1
  1370. {
  1371. }
  1372. [StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
  1373. public class Class2
  1374. {
  1375. }
  1376. [Test]
  1377. public void StructLayoutAttribute ()
  1378. {
  1379. StructLayoutAttribute attr1 = typeof (TypeTest).StructLayoutAttribute;
  1380. Assert.AreEqual (LayoutKind.Auto, attr1.Value);
  1381. StructLayoutAttribute attr2 = typeof (Class1).StructLayoutAttribute;
  1382. Assert.AreEqual (LayoutKind.Explicit, attr2.Value);
  1383. Assert.AreEqual (4, attr2.Pack);
  1384. Assert.AreEqual (64, attr2.Size);
  1385. StructLayoutAttribute attr3 = typeof (Class2).StructLayoutAttribute;
  1386. Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
  1387. Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
  1388. }
  1389. #endif // TARGET_JVM
  1390. [Test]
  1391. public void Namespace ()
  1392. {
  1393. Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
  1394. }
  1395. [Test]
  1396. public void GenericParameterNamespace ()
  1397. {
  1398. var t = typeof (Foo<>).GetGenericArguments () [0];
  1399. Assert.AreEqual ("T", t.Name);
  1400. Assert.AreEqual ("MonoTests.System", t.Namespace);
  1401. var s = typeof (Gazonk).GetMethod ("Bang").GetGenericArguments () [0];
  1402. Assert.AreEqual ("S", s.Name);
  1403. Assert.AreEqual ("MonoTests.System", s.Namespace);
  1404. }
  1405. public static void Reflected (ref int a)
  1406. {
  1407. }
  1408. [Test]
  1409. public void Name ()
  1410. {
  1411. Assert.AreEqual ("Int32&", typeof (TypeTest).GetMethod ("Reflected").GetParameters () [0].ParameterType.Name);
  1412. Assert.AreEqual ("String[*]", Array.CreateInstance (typeof(string), new int[] { 1 }, new int[] { 1 }).GetType ().Name);
  1413. }
  1414. [Test]
  1415. public void GetInterfaces ()
  1416. {
  1417. Type[] t = typeof (Duper).GetInterfaces ();
  1418. Assert.AreEqual (1, t.Length);
  1419. Assert.AreEqual (typeof (ICloneable), t[0]);
  1420. Type[] t2 = typeof (IFace3).GetInterfaces ();
  1421. Assert.AreEqual (2, t2.Length);
  1422. }
  1423. [Test]
  1424. public void GetInterfacesGenericVarWithConstraints ()
  1425. {
  1426. var a = typeof (TypeTest).GetMethod ("GenericMethod");
  1427. var p = a.GetParameters ();
  1428. var i = p[0].ParameterType.GetElementType ();
  1429. i.GetInterfaces ();
  1430. }
  1431. public static void GenericMethod<T, T2> (T[] arr) where T: IComparable<T> {
  1432. }
  1433. public int AField;
  1434. [Test]
  1435. public void GetFieldIgnoreCase ()
  1436. {
  1437. Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
  1438. }
  1439. public int Count {
  1440. internal get {
  1441. return 0;
  1442. }
  1443. set {
  1444. }
  1445. }
  1446. [Test]
  1447. public void GetPropertyAccessorModifiers ()
  1448. {
  1449. Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
  1450. Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
  1451. }
  1452. [Test]
  1453. public void IsAbstract ()
  1454. {
  1455. Assert.IsFalse (typeof (string).IsAbstract, "#1");
  1456. Assert.IsTrue (typeof (ICloneable).IsAbstract, "#2");
  1457. Assert.IsTrue (typeof (ValueType).IsAbstract, "#3");
  1458. Assert.IsTrue (typeof (Enum).IsAbstract, "#4");
  1459. Assert.IsFalse (typeof (TimeSpan).IsAbstract, "#5");
  1460. Assert.IsTrue (typeof (TextReader).IsAbstract, "#6");
  1461. // LAMESPEC:
  1462. // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=286308
  1463. Type [] typeArgs = typeof (List<>).GetGenericArguments ();
  1464. Assert.IsFalse (typeArgs [0].IsAbstract, "#7");
  1465. }
  1466. #if !MOBILE
  1467. [Test]
  1468. public void IsCOMObject ()
  1469. {
  1470. Type type = typeof (string);
  1471. Assert.IsFalse (type.IsCOMObject, "#1");
  1472. TypeBuilder tb = module.DefineType (genTypeName ());
  1473. type = tb.CreateType ();
  1474. Assert.IsFalse (type.IsCOMObject, "#2");
  1475. }
  1476. [Test]
  1477. public void IsImport ()
  1478. {
  1479. Type type = typeof (string);
  1480. Assert.IsFalse (type.IsImport, "#1");
  1481. TypeBuilder tb = module.DefineType (genTypeName ());
  1482. type = tb.CreateType ();
  1483. Assert.IsFalse (type.IsImport, "#2");
  1484. tb = module.DefineType (genTypeName (), TypeAttributes.Import |
  1485. TypeAttributes.Interface | TypeAttributes.Abstract);
  1486. type = tb.CreateType ();
  1487. Assert.IsTrue (type.IsImport, "#3");
  1488. }
  1489. #endif
  1490. [Test]
  1491. public void IsInterface ()
  1492. {
  1493. Assert.IsFalse (typeof (string).IsInterface, "#1");
  1494. Assert.IsTrue (typeof (ICloneable).IsInterface, "#2");
  1495. }
  1496. [Test]
  1497. public void IsPrimitive () {
  1498. Assert.IsTrue (typeof (IntPtr).IsPrimitive, "#1");
  1499. Assert.IsTrue (typeof (int).IsPrimitive, "#2");
  1500. Assert.IsFalse (typeof (string).IsPrimitive, "#2");
  1501. }
  1502. [Test]
  1503. public void IsValueType ()
  1504. {
  1505. Assert.IsTrue (typeof (int).IsValueType, "#1");
  1506. Assert.IsFalse (typeof (Enum).IsValueType, "#2");
  1507. Assert.IsFalse (typeof (ValueType).IsValueType, "#3");
  1508. Assert.IsTrue (typeof (AttributeTargets).IsValueType, "#4");
  1509. Assert.IsFalse (typeof (string).IsValueType, "#5");
  1510. Assert.IsTrue (typeof (TimeSpan).IsValueType, "#6");
  1511. }
  1512. [Test]
  1513. [Category("NotDotNet")]
  1514. // Depends on the GAC working, which it doesn't durring make distcheck.
  1515. [Category ("NotWorking")]
  1516. public void GetTypeWithWhitespace ()
  1517. {
  1518. Assert.IsNotNull (Type.GetType
  1519. (@"System.Configuration.NameValueSectionHandler,
  1520. System,
  1521. Version=1.0.5000.0,
  1522. Culture=neutral
  1523. ,
  1524. PublicKeyToken=b77a5c561934e089"));
  1525. }
  1526. [Test]
  1527. public void GetTypeNonVectorArray ()
  1528. {
  1529. Type t = Type.GetType ("System.String[*]");
  1530. Assert.AreEqual ("System.String[*]", t.ToString ());
  1531. }
  1532. #if MONOTOUCH
  1533. // feature not available when compiled under FULL_AOT_RUNTIME
  1534. [ExpectedException (typeof (NotImplementedException))]
  1535. #endif
  1536. [Test]
  1537. public void TypeFromCLSID ()
  1538. {
  1539. Guid CLSID_ShellDesktop = new Guid("00021400-0000-0000-c000-000000000046");
  1540. Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
  1541. Type t1 = Type.GetTypeFromCLSID (CLSID_ShellDesktop);
  1542. Type t2 = Type.GetTypeFromCLSID (CLSID_Bogus);
  1543. Assert.AreEqual (t1.FullName, "System.__ComObject");
  1544. if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
  1545. Environment.OSVersion.Platform == PlatformID.Win32NT)
  1546. Activator.CreateInstance(t1);
  1547. Assert.AreEqual (t2.FullName, "System.__ComObject");
  1548. Assert.AreNotEqual (t1, t2);
  1549. }
  1550. [Test]
  1551. [Category("NotWorking")] // Mono throws TargetInvokationException
  1552. [ExpectedException("System.Runtime.InteropServices.COMException")]
  1553. public void TypeFromCLSIDBogus ()
  1554. {
  1555. Guid CLSID_Bogus = new Guid("1ea9d7a9-f7ab-443b-b486-30d285b21f1b");
  1556. Type t = Type.GetTypeFromCLSID (CLSID_Bogus);
  1557. if (Environment.OSVersion.Platform == PlatformID.Win32Windows ||
  1558. Environment.OSVersion.Platform == PlatformID.Win32NT)
  1559. Activator.CreateInstance(t);
  1560. else
  1561. throw new COMException ();
  1562. }
  1563. [Test]
  1564. public void ExerciseFilterName ()
  1565. {
  1566. MemberInfo[] mi = typeof(Base).FindMembers(
  1567. MemberTypes.Method,
  1568. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1569. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1570. Type.FilterName, "*");
  1571. Assert.AreEqual (4, mi.Length);
  1572. mi = typeof(Base).FindMembers(
  1573. MemberTypes.Method,
  1574. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1575. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1576. Type.FilterName, "Test*");
  1577. Assert.AreEqual (2, mi.Length);
  1578. mi = typeof(Base).FindMembers(
  1579. MemberTypes.Method,
  1580. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1581. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1582. Type.FilterName, "TestVoid");
  1583. Assert.AreEqual (1, mi.Length);
  1584. mi = typeof(Base).FindMembers(
  1585. MemberTypes.Method,
  1586. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1587. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1588. Type.FilterName, "NonExistingMethod");
  1589. Assert.AreEqual (0, mi.Length);
  1590. }
  1591. [Test]
  1592. public void ExerciseFilterNameIgnoreCase ()
  1593. {
  1594. MemberInfo[] mi = typeof(Base).FindMembers(
  1595. MemberTypes.Method,
  1596. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1597. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1598. Type.FilterNameIgnoreCase, "*");
  1599. Assert.AreEqual (4, mi.Length);
  1600. mi = typeof(Base).FindMembers(
  1601. MemberTypes.Method,
  1602. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1603. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1604. Type.FilterNameIgnoreCase, "test*");
  1605. Assert.AreEqual (2, mi.Length);
  1606. mi = typeof(Base).FindMembers(
  1607. MemberTypes.Method,
  1608. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1609. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1610. Type.FilterNameIgnoreCase, "TESTVOID");
  1611. Assert.AreEqual (1, mi.Length);
  1612. mi = typeof(Base).FindMembers(
  1613. MemberTypes.Method,
  1614. BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic |
  1615. BindingFlags.Instance | BindingFlags.DeclaredOnly,
  1616. Type.FilterNameIgnoreCase, "NonExistingMethod");
  1617. Assert.AreEqual (0, mi.Length);
  1618. }
  1619. [Test]
  1620. [ExpectedException (typeof (InvalidFilterCriteriaException))]
  1621. public void FilterAttribute_Invalid ()
  1622. {
  1623. Type.FilterAttribute (MethodBase.GetCurrentMethod (), (byte) 1);
  1624. }
  1625. [Test]
  1626. public void GenericParameterMemberType ()
  1627. {
  1628. var t = typeof (Foo<>).GetGenericArguments () [0];
  1629. Assert.IsNotNull (t);
  1630. Assert.AreEqual (MemberTypes.TypeInfo, t.MemberType);
  1631. }
  1632. public class ByRef0
  1633. {
  1634. public int field;
  1635. public int property {
  1636. get { return 0; }
  1637. }
  1638. public ByRef0 (int i) {}
  1639. public void f (int i) {}
  1640. }
  1641. [Test]
  1642. public void ByrefTypes ()
  1643. {
  1644. Type t = Type.GetType ("MonoTests.System.TypeTest+ByRef0&");
  1645. Assert.IsNotNull (t);
  1646. Assert.IsTrue (t.IsByRef);
  1647. Assert.AreEqual (0, t.GetMethods (BindingFlags.Public | BindingFlags.Instance).Length);
  1648. Assert.AreEqual (0, t.GetConstructors (BindingFlags.Public | BindingFlags.Instance).Length);
  1649. Assert.AreEqual (0, t.GetEvents (BindingFlags.Public | BindingFlags.Instance).Length);
  1650. Assert.AreEqual (0, t.GetProperties (BindingFlags.Public | BindingFlags.Instance).Length);
  1651. Assert.IsNull (t.GetMethod ("f"));
  1652. Assert.IsNull (t.GetField ("field"));
  1653. Assert.IsNull (t.GetProperty ("property"));
  1654. }
  1655. [Test]
  1656. public void TestAssemblyQualifiedName ()
  1657. {
  1658. Type t = Type.GetType ("System.Byte[]&");
  1659. Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte[]&"));
  1660. t = Type.GetType ("System.Byte*&");
  1661. Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte*&"));
  1662. t = Type.GetType ("System.Byte&");
  1663. Assert.IsTrue (t.AssemblyQualifiedName.StartsWith ("System.Byte&"));
  1664. }
  1665. struct B
  1666. {
  1667. int value;
  1668. }
  1669. [Test]
  1670. public void CreateValueTypeNoCtor ()
  1671. {
  1672. typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, null);
  1673. }
  1674. [Test]
  1675. [ExpectedException (typeof (MissingMethodException))]
  1676. public void CreateValueTypeNoCtorArgs ()
  1677. {
  1678. typeof(B).InvokeMember ("", BindingFlags.CreateInstance, null, null, new object [] { 1 });
  1679. }
  1680. internal static string bug336841 (string param1, params string [] param2)
  1681. {
  1682. StringBuilder sb = new StringBuilder ();
  1683. sb.Append ("#A:");
  1684. sb.Append (param1);
  1685. sb.Append ("|");
  1686. for (int i = 0; i < param2.Length; i++) {
  1687. if (i > 0)
  1688. sb.Append (",");
  1689. sb.Append (param2 [i]);
  1690. }
  1691. return sb.ToString ();
  1692. }
  1693. internal static string bug336841 (string param1)
  1694. {
  1695. return "#B:" + param1;
  1696. }
  1697. internal static string bug336841 (params string [] param1)
  1698. {
  1699. StringBuilder sb = new StringBuilder ();
  1700. sb.Append ("#C:");
  1701. for (int i = 0; i < param1.Length; i++) {
  1702. if (i > 0)
  1703. sb.Append (";");
  1704. sb.Append (param1 [i]);
  1705. }
  1706. return sb.ToString ();
  1707. }
  1708. [Test]
  1709. public void InvokeMember_GetSetField ()
  1710. {
  1711. typeof (X).InvokeMember ("Value", BindingFlags.Public |
  1712. BindingFlags.Static | BindingFlags.FlattenHierarchy |
  1713. BindingFlags.SetField, null, null, new object [] { 5 });
  1714. Assert.AreEqual (5, X.Value, "#A1");
  1715. Assert.AreEqual (5, typeof (X).InvokeMember ("Value",
  1716. BindingFlags.Public | BindingFlags.Static |
  1717. BindingFlags.FlattenHierarchy | BindingFlags.GetField,
  1718. null, null, new object [0]), "#A2");
  1719. Assert.AreEqual (5, Y.Value, "#A3");
  1720. Assert.AreEqual (5, typeof (Y).InvokeMember ("Value",
  1721. BindingFlags.Public | BindingFlags.Static |
  1722. BindingFlags.FlattenHierarchy | BindingFlags.GetField,
  1723. null, null, new object [0]), "#A4");
  1724. try {
  1725. typeof (X).InvokeMember ("Value", BindingFlags.Public |
  1726. BindingFlags.Static | BindingFlags.FlattenHierarchy |
  1727. BindingFlags.GetField | BindingFlags.SetField,
  1728. null, null, new object [] { 5 });
  1729. Assert.Fail ("#B1");
  1730. } catch (ArgumentException ex) {
  1731. // Cannot specify both Get and Set on a field
  1732. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1733. Assert.IsNull (ex.InnerException, "#B3");
  1734. Assert.IsNotNull (ex.Message, "#B4");
  1735. Assert.IsNotNull (ex.ParamName, "#B5");
  1736. Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
  1737. }
  1738. }
  1739. [Test]
  1740. public void InvokeMember_GetSetProperty ()
  1741. {
  1742. try {
  1743. typeof (ArrayList).InvokeMember ("Item",
  1744. BindingFlags.GetProperty | BindingFlags.SetProperty |
  1745. BindingFlags.Instance | BindingFlags.Public,
  1746. null, new ArrayList (), new object [] { 0, "bar" });
  1747. Assert.Fail ("#1");
  1748. } catch (ArgumentException ex) {
  1749. // Cannot specify both Get and Set on a property
  1750. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1751. Assert.IsNull (ex.InnerException, "#3");
  1752. Assert.IsNotNull (ex.Message, "#4");
  1753. Assert.IsNotNull (ex.ParamName, "#5");
  1754. Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
  1755. }
  1756. }
  1757. [Test]
  1758. public void InvokeMember_InvokeMethod_Set ()
  1759. {
  1760. try {
  1761. typeof (ArrayList).InvokeMember ("ToString",
  1762. BindingFlags.InvokeMethod | BindingFlags.SetField |
  1763. BindingFlags.Instance | BindingFlags.Public,
  1764. null, new ArrayList (), new object [0]);
  1765. Assert.Fail ("#A1");
  1766. } catch (ArgumentException ex) {
  1767. // Cannot specify Set on a field and Invoke on a method
  1768. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
  1769. Assert.IsNull (ex.InnerException, "#A3");
  1770. Assert.IsNotNull (ex.Message, "#A4");
  1771. Assert.IsNotNull (ex.ParamName, "#A5");
  1772. Assert.AreEqual ("bindingFlags", ex.ParamName, "#A6");
  1773. }
  1774. try {
  1775. typeof (ArrayList).InvokeMember ("ToString",
  1776. BindingFlags.InvokeMethod | BindingFlags.SetProperty |
  1777. BindingFlags.Instance | BindingFlags.Public,
  1778. null, new ArrayList (), new object [0]);
  1779. Assert.Fail ("#B1");
  1780. } catch (ArgumentException ex) {
  1781. // Cannot specify Set on a property and Invoke on a method
  1782. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1783. Assert.IsNull (ex.InnerException, "#B3");
  1784. Assert.IsNotNull (ex.Message, "#B4");
  1785. Assert.IsNotNull (ex.ParamName, "#B5");
  1786. Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
  1787. }
  1788. }
  1789. [Test]
  1790. public void InvokeMember_MatchPrimitiveTypeWithInterface ()
  1791. {
  1792. object [] invokeargs = { 1 };
  1793. typeof (Z).InvokeMember ("", BindingFlags.DeclaredOnly |
  1794. BindingFlags.Public | BindingFlags.NonPublic |
  1795. BindingFlags.Instance | BindingFlags.CreateInstance,
  1796. null, null, invokeargs);
  1797. }
  1798. [Test]
  1799. public void InvokeMember_Name_Null ()
  1800. {
  1801. try {
  1802. typeof (X).InvokeMember ((string) null,
  1803. BindingFlags.Public | BindingFlags.Static |
  1804. BindingFlags.FlattenHierarchy | BindingFlags.SetField,
  1805. null, null, new object [] { 5 });
  1806. Assert.Fail ("#1");
  1807. } catch (ArgumentNullException ex) {
  1808. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  1809. Assert.IsNull (ex.InnerException, "#3");
  1810. Assert.IsNotNull (ex.Message, "#4");
  1811. Assert.IsNotNull (ex.ParamName, "#5");
  1812. Assert.AreEqual ("name", ex.ParamName, "#6");
  1813. }
  1814. }
  1815. [Test]
  1816. public void InvokeMember_NoOperation ()
  1817. {
  1818. try {
  1819. typeof (TypeTest).InvokeMember ("Run", BindingFlags.Public |
  1820. BindingFlags.Static, null, null, new object [0]);
  1821. Assert.Fail ("#1");
  1822. } catch (ArgumentException ex) {
  1823. // Must specify binding flags describing the
  1824. // invoke operation required
  1825. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1826. Assert.IsNull (ex.InnerException, "#3");
  1827. Assert.IsNotNull (ex.Message, "#4");
  1828. Assert.IsNotNull (ex.ParamName, "#5");
  1829. Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
  1830. }
  1831. }
  1832. [Test] // bug #321735
  1833. public void InvokeMember_SetFieldProperty ()
  1834. {
  1835. ArrayList list = new ArrayList ();
  1836. list.Add ("foo");
  1837. list.GetType ().InvokeMember ("Item",
  1838. BindingFlags.SetField | BindingFlags.SetProperty |
  1839. BindingFlags.Instance | BindingFlags.Public,
  1840. null, list, new object [] { 0, "bar" });
  1841. Assert.AreEqual ("bar", list [0]);
  1842. }
  1843. [Test]
  1844. public void InvokeMember_SetField_ProvidedArgs ()
  1845. {
  1846. try {
  1847. typeof (X).InvokeMember ("Value", BindingFlags.Public |
  1848. BindingFlags.Static | BindingFlags.SetField,
  1849. null, null, new object [0]);
  1850. Assert.Fail ("#A1");
  1851. } catch (ArgumentException ex) {
  1852. // Only the field value can be specified to set
  1853. // a field value
  1854. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
  1855. Assert.IsNull (ex.InnerException, "#A3");
  1856. Assert.IsNotNull (ex.Message, "#A4");
  1857. Assert.IsNotNull (ex.ParamName, "#A5");
  1858. Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
  1859. }
  1860. try {
  1861. typeof (X).InvokeMember ("Value", BindingFlags.Public |
  1862. BindingFlags.Static | BindingFlags.SetField,
  1863. null, null, null);
  1864. Assert.Fail ("#B1");
  1865. } catch (ArgumentNullException ex) {
  1866. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
  1867. Assert.IsNull (ex.InnerException, "#B3");
  1868. Assert.IsNotNull (ex.Message, "#B4");
  1869. Assert.IsNotNull (ex.ParamName, "#B5");
  1870. Assert.AreEqual ("providedArgs", ex.ParamName, "#B6");
  1871. }
  1872. }
  1873. [Test] // bug #336841
  1874. [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=306797
  1875. public void InvokeMember_VarArgs ()
  1876. {
  1877. BindingFlags flags = BindingFlags.InvokeMethod | BindingFlags.Public |
  1878. BindingFlags.NonPublic | BindingFlags.OptionalParamBinding |
  1879. BindingFlags.Static | BindingFlags.FlattenHierarchy |
  1880. BindingFlags.Instance;
  1881. Type type = typeof (TypeTest);
  1882. string result = (string) type.InvokeMember ("bug336841",
  1883. flags, null, null, new object [] { "1" });
  1884. Assert.IsNotNull (result, "#A1");
  1885. Assert.AreEqual ("#B:1", result, "#A2");
  1886. result = (string) type.InvokeMember ("bug336841", flags,
  1887. null, null, new object [] { "1", "2", "3", "4" });
  1888. Assert.IsNotNull (result, "#B1");
  1889. Assert.AreEqual ("#A:1|2,3,4", result, "#B2");
  1890. }
  1891. [Test] // bug #348522
  1892. public void InvokeMember_WithoutDefaultValue ()
  1893. {
  1894. BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;
  1895. try {
  1896. typeof (Bug348522).InvokeMember ("Test", flags, new FirstMethodBinder (), new Bug348522(),
  1897. new object [] {Missing.Value}, null, null, null);
  1898. Assert.Fail ("#1");
  1899. } catch (ArgumentException ex) {
  1900. // Missing parameter does not have a default value
  1901. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1902. Assert.IsNull (ex.InnerException, "#3");
  1903. Assert.IsNotNull (ex.Message, "#4");
  1904. Assert.IsNotNull (ex.ParamName, "#5");
  1905. Assert.AreEqual ("parameters", ex.ParamName, "#6");
  1906. }
  1907. }
  1908. [Test]
  1909. public void TestMissing () {
  1910. Assert.AreEqual (Type.Missing, Missing.Value);
  1911. }
  1912. [Test]
  1913. public void GetGenericMethodDefinitionOverInflatedMethodOnGTD () {
  1914. var l = typeof (List<>);
  1915. var m = l.GetMethod ("ConvertAll");
  1916. var infl = m.MakeGenericMethod (typeof (int));
  1917. var res = m.GetGenericMethodDefinition ();
  1918. Assert.AreEqual (m, res, "#1");
  1919. }
  1920. [Test]
  1921. public void InvokeMember_OutParam ()
  1922. {
  1923. object[] args = new object[] { new string [0] };
  1924. typeof (TypeTest).InvokeMember ("OutTest", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, args);
  1925. Assert.IsTrue (args [0] is string[]);
  1926. Assert.AreEqual (10, ((string[])args[0]).Length);
  1927. }
  1928. public static void OutTest (out string[] a1)
  1929. {
  1930. a1 = new string [10];
  1931. }
  1932. class X
  1933. {
  1934. public static int Value;
  1935. }
  1936. class Y : X
  1937. {
  1938. }
  1939. class Z
  1940. {
  1941. public Z (IComparable value)
  1942. {
  1943. }
  1944. }
  1945. public static void Run ()
  1946. {
  1947. }
  1948. class TakesInt
  1949. {
  1950. private int i;
  1951. public TakesInt (int x)
  1952. {
  1953. i = x;
  1954. }
  1955. public int Integer {
  1956. get { return i; }
  1957. }
  1958. }
  1959. class TakesObject
  1960. {
  1961. public TakesObject (object x) {}
  1962. }
  1963. [Test] // bug #75241
  1964. public void GetConstructorNullInTypes ()
  1965. {
  1966. // This ends up calling type.GetConstructor ()
  1967. Activator.CreateInstance (typeof (TakesInt), new object [] { null });
  1968. Activator.CreateInstance (typeof (TakesObject), new object [] { null });
  1969. }
  1970. [Test]
  1971. public void GetConstructor_TakeInt_Object ()
  1972. {
  1973. Assert.IsNull (typeof (TakesInt).GetConstructor (new Type[1] { typeof (object) }));
  1974. }
  1975. [Test]
  1976. public void GetCustomAttributes_All ()
  1977. {
  1978. object [] attrs = typeof (A).GetCustomAttributes (false);
  1979. Assert.AreEqual (2, attrs.Length, "#A1");
  1980. Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
  1981. Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
  1982. attrs = typeof (BA).GetCustomAttributes (false);
  1983. Assert.AreEqual (1, attrs.Length, "#B1");
  1984. Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#B2");
  1985. attrs = typeof (BA).GetCustomAttributes (true);
  1986. Assert.AreEqual (2, attrs.Length, "#C1");
  1987. Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
  1988. Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
  1989. attrs = typeof (CA).GetCustomAttributes (false);
  1990. Assert.AreEqual (0, attrs.Length, "#D");
  1991. attrs = typeof (CA).GetCustomAttributes (true);
  1992. Assert.AreEqual (1, attrs.Length, "#E1");
  1993. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
  1994. }
  1995. static bool HasAttribute (object [] attrs, Type attributeType)
  1996. {
  1997. foreach (object attr in attrs)
  1998. if (attr.GetType () == attributeType)
  1999. return true;
  2000. return false;
  2001. }
  2002. [Test]
  2003. public void GetCustomAttributes_Type ()
  2004. {
  2005. object [] attrs = null;
  2006. attrs = typeof (A).GetCustomAttributes (
  2007. typeof (VolatileModifier), false);
  2008. Assert.AreEqual (1, attrs.Length, "#A1");
  2009. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
  2010. attrs = typeof (A).GetCustomAttributes (
  2011. typeof (VolatileModifier), true);
  2012. Assert.AreEqual (1, attrs.Length, "#A3");
  2013. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
  2014. attrs = typeof (A).GetCustomAttributes (
  2015. typeof (NemerleAttribute), false);
  2016. Assert.AreEqual (1, attrs.Length, "#B1");
  2017. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
  2018. attrs = typeof (A).GetCustomAttributes (
  2019. typeof (NemerleAttribute), true);
  2020. Assert.AreEqual (1, attrs.Length, "#B3");
  2021. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
  2022. attrs = typeof (A).GetCustomAttributes (
  2023. typeof (FooAttribute), false);
  2024. Assert.AreEqual (1, attrs.Length, "#C1");
  2025. Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
  2026. attrs = typeof (A).GetCustomAttributes (
  2027. typeof (FooAttribute), false);
  2028. Assert.AreEqual (1, attrs.Length, "#C3");
  2029. Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
  2030. attrs = typeof (BA).GetCustomAttributes (
  2031. typeof (VolatileModifier), false);
  2032. Assert.AreEqual (0, attrs.Length, "#D1");
  2033. attrs = typeof (BA).GetCustomAttributes (
  2034. typeof (VolatileModifier), true);
  2035. Assert.AreEqual (1, attrs.Length, "#D2");
  2036. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
  2037. attrs = typeof (BA).GetCustomAttributes (
  2038. typeof (NemerleAttribute), false);
  2039. Assert.AreEqual (0, attrs.Length, "#E1");
  2040. attrs = typeof (BA).GetCustomAttributes (
  2041. typeof (NemerleAttribute), true);
  2042. Assert.AreEqual (1, attrs.Length, "#E2");
  2043. Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
  2044. attrs = typeof (BA).GetCustomAttributes (
  2045. typeof (FooAttribute), false);
  2046. Assert.AreEqual (1, attrs.Length, "#F1");
  2047. Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
  2048. attrs = typeof (BA).GetCustomAttributes (
  2049. typeof (FooAttribute), true);
  2050. Assert.AreEqual (1, attrs.Length, "#F3");
  2051. Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
  2052. attrs = typeof (bug82431A1).GetCustomAttributes (
  2053. typeof (InheritAttribute), false);
  2054. Assert.AreEqual (1, attrs.Length, "#G1");
  2055. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
  2056. attrs = typeof (bug82431A1).GetCustomAttributes (
  2057. typeof (InheritAttribute), true);
  2058. Assert.AreEqual (1, attrs.Length, "#G3");
  2059. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
  2060. attrs = typeof (bug82431A1).GetCustomAttributes (
  2061. typeof (NotInheritAttribute), false);
  2062. Assert.AreEqual (1, attrs.Length, "#H1");
  2063. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
  2064. attrs = typeof (bug82431A1).GetCustomAttributes (
  2065. typeof (InheritAttribute), true);
  2066. Assert.AreEqual (1, attrs.Length, "#H3");
  2067. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
  2068. attrs = typeof (bug82431A2).GetCustomAttributes (
  2069. typeof (InheritAttribute), false);
  2070. Assert.AreEqual (0, attrs.Length, "#I1");
  2071. attrs = typeof (bug82431A2).GetCustomAttributes (
  2072. typeof (InheritAttribute), true);
  2073. Assert.AreEqual (0, attrs.Length, "#I2");
  2074. attrs = typeof (bug82431A2).GetCustomAttributes (
  2075. typeof (NotInheritAttribute), false);
  2076. Assert.AreEqual (0, attrs.Length, "#J1");
  2077. attrs = typeof (bug82431A2).GetCustomAttributes (
  2078. typeof (NotInheritAttribute), true);
  2079. Assert.AreEqual (0, attrs.Length, "#J2");
  2080. attrs = typeof (bug82431A3).GetCustomAttributes (
  2081. typeof (InheritAttribute), false);
  2082. Assert.AreEqual (2, attrs.Length, "#K1");
  2083. Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
  2084. Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
  2085. attrs = typeof (bug82431A3).GetCustomAttributes (
  2086. typeof (InheritAttribute), true);
  2087. Assert.AreEqual (2, attrs.Length, "#K4");
  2088. Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
  2089. Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
  2090. attrs = typeof (bug82431A3).GetCustomAttributes (
  2091. typeof (NotInheritAttribute), false);
  2092. Assert.AreEqual (1, attrs.Length, "#L1");
  2093. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
  2094. attrs = typeof (bug82431A3).GetCustomAttributes (
  2095. typeof (NotInheritAttribute), true);
  2096. Assert.AreEqual (1, attrs.Length, "#L3");
  2097. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
  2098. attrs = typeof (bug82431B1).GetCustomAttributes (
  2099. typeof (InheritAttribute), false);
  2100. Assert.AreEqual (1, attrs.Length, "#M1");
  2101. Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
  2102. attrs = typeof (bug82431B1).GetCustomAttributes (
  2103. typeof (InheritAttribute), true);
  2104. Assert.AreEqual (1, attrs.Length, "#M3");
  2105. Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
  2106. attrs = typeof (bug82431B1).GetCustomAttributes (
  2107. typeof (NotInheritAttribute), false);
  2108. Assert.AreEqual (0, attrs.Length, "#N1");
  2109. attrs = typeof (bug82431B1).GetCustomAttributes (
  2110. typeof (NotInheritAttribute), true);
  2111. Assert.AreEqual (0, attrs.Length, "#N2");
  2112. attrs = typeof (bug82431B2).GetCustomAttributes (
  2113. typeof (InheritAttribute), false);
  2114. Assert.AreEqual (0, attrs.Length, "#O1");
  2115. attrs = typeof (bug82431B2).GetCustomAttributes (
  2116. typeof (InheritAttribute), true);
  2117. Assert.AreEqual (1, attrs.Length, "#O2");
  2118. Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
  2119. attrs = typeof (bug82431B2).GetCustomAttributes (
  2120. typeof (NotInheritAttribute), false);
  2121. Assert.AreEqual (0, attrs.Length, "#P1");
  2122. attrs = typeof (bug82431B2).GetCustomAttributes (
  2123. typeof (NotInheritAttribute), true);
  2124. Assert.AreEqual (0, attrs.Length, "#P2");
  2125. attrs = typeof (bug82431B3).GetCustomAttributes (
  2126. typeof (InheritAttribute), false);
  2127. Assert.AreEqual (1, attrs.Length, "#Q1");
  2128. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
  2129. attrs = typeof (bug82431B3).GetCustomAttributes (
  2130. typeof (InheritAttribute), true);
  2131. Assert.AreEqual (2, attrs.Length, "#Q3");
  2132. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
  2133. Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
  2134. attrs = typeof (bug82431B3).GetCustomAttributes (
  2135. typeof (NotInheritAttribute), false);
  2136. Assert.AreEqual (1, attrs.Length, "#R1");
  2137. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
  2138. attrs = typeof (bug82431B3).GetCustomAttributes (
  2139. typeof (NotInheritAttribute), true);
  2140. Assert.AreEqual (1, attrs.Length, "#R3");
  2141. Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
  2142. attrs = typeof (bug82431B4).GetCustomAttributes (
  2143. typeof (InheritAttribute), false);
  2144. Assert.AreEqual (0, attrs.Length, "#S1");
  2145. attrs = typeof (bug82431B4).GetCustomAttributes (
  2146. typeof (InheritAttribute), true);
  2147. Assert.AreEqual (1, attrs.Length, "#S2");
  2148. Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
  2149. attrs = typeof (bug82431B4).GetCustomAttributes (
  2150. typeof (NotInheritAttribute), false);
  2151. Assert.AreEqual (0, attrs.Length, "#T1");
  2152. attrs = typeof (bug82431B4).GetCustomAttributes (
  2153. typeof (NotInheritAttribute), true);
  2154. Assert.AreEqual (0, attrs.Length, "#T2");
  2155. attrs = typeof (A).GetCustomAttributes (
  2156. typeof (string), false);
  2157. Assert.AreEqual (0, attrs.Length, "#U1");
  2158. attrs = typeof (A).GetCustomAttributes (
  2159. typeof (string), true);
  2160. Assert.AreEqual (0, attrs.Length, "#U2");
  2161. }
  2162. [Test] // bug #76150
  2163. public void IsDefined ()
  2164. {
  2165. Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
  2166. Assert.IsTrue (typeof (A).IsDefined (typeof (VolatileModifier), false), "#A2");
  2167. Assert.IsTrue (typeof (A).IsDefined (typeof (FooAttribute), false), "#A3");
  2168. Assert.IsFalse (typeof (A).IsDefined (typeof (BarAttribute), false), "#A4");
  2169. Assert.IsFalse (typeof (BA).IsDefined (typeof (NemerleAttribute), false), "#B1");
  2170. Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
  2171. Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
  2172. Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
  2173. Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
  2174. Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
  2175. Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
  2176. Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
  2177. Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
  2178. Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
  2179. Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
  2180. Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
  2181. }
  2182. [Test]
  2183. public void IsDefined_AttributeType_Null ()
  2184. {
  2185. try {
  2186. typeof (BA).IsDefined ((Type) null, false);
  2187. Assert.Fail ("#1");
  2188. } catch (ArgumentNullException ex) {
  2189. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2190. Assert.IsNull (ex.InnerException, "#3");
  2191. Assert.IsNotNull (ex.Message, "#4");
  2192. Assert.IsNotNull (ex.ParamName, "#5");
  2193. Assert.AreEqual ("attributeType", ex.ParamName, "#6");
  2194. }
  2195. }
  2196. [Test] // bug #82431
  2197. [Category ("NotWorking")]
  2198. public void IsDefined_Inherited ()
  2199. {
  2200. Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
  2201. Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
  2202. Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
  2203. Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), false), "#C4");
  2204. Assert.IsTrue (typeof (CA).IsDefined (typeof (NemerleAttribute), true), "#C5");
  2205. Assert.IsTrue (typeof (CA).IsDefined (typeof (VolatileModifier), true), "#C6");
  2206. Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), true), "#C7");
  2207. Assert.IsFalse (typeof (CA).IsDefined (typeof (BarAttribute), true), "#C8");
  2208. Assert.IsFalse (typeof (BBA).IsDefined (typeof (NemerleAttribute), false), "#D1");
  2209. Assert.IsFalse (typeof (BBA).IsDefined (typeof (VolatileModifier), false), "#D2");
  2210. Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), false), "#D3");
  2211. Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
  2212. Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
  2213. Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
  2214. Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
  2215. Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
  2216. Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
  2217. Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
  2218. Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
  2219. Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
  2220. Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
  2221. Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
  2222. Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
  2223. Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
  2224. Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
  2225. Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
  2226. Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
  2227. Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
  2228. Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
  2229. Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
  2230. Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
  2231. Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
  2232. Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
  2233. Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
  2234. Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
  2235. Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
  2236. Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
  2237. Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
  2238. Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
  2239. Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
  2240. Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
  2241. Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
  2242. Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
  2243. Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
  2244. }
  2245. [Test] // GetType (String)
  2246. public void GetType1_TypeName_Null ()
  2247. {
  2248. try {
  2249. Type.GetType ((string) null);
  2250. Assert.Fail ("#1");
  2251. } catch (ArgumentNullException ex) {
  2252. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2253. Assert.IsNull (ex.InnerException, "#3");
  2254. Assert.IsNotNull (ex.Message, "#4");
  2255. Assert.AreEqual ("TypeName", ex.ParamName, "#5");
  2256. }
  2257. }
  2258. [Test] // GetType (String, Boolean)
  2259. public void GetType2_TypeName_Null ()
  2260. {
  2261. try {
  2262. Type.GetType ((string) null, false);
  2263. Assert.Fail ("#1");
  2264. } catch (ArgumentNullException ex) {
  2265. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2266. Assert.IsNull (ex.InnerException, "#3");
  2267. Assert.IsNotNull (ex.Message, "#4");
  2268. Assert.AreEqual ("TypeName", ex.ParamName, "#5");
  2269. }
  2270. }
  2271. [Test] // GetType (String, Boolean, Boolean)
  2272. public void GetType3_TypeName_Null ()
  2273. {
  2274. try {
  2275. Type.GetType ((string) null, false, false);
  2276. Assert.Fail ("#1");
  2277. } catch (ArgumentNullException ex) {
  2278. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2279. Assert.IsNull (ex.InnerException, "#3");
  2280. Assert.IsNotNull (ex.Message, "#4");
  2281. Assert.AreEqual ("TypeName", ex.ParamName, "#5");
  2282. }
  2283. }
  2284. [Test]
  2285. public void GetTypeArray_Args_Null ()
  2286. {
  2287. try {
  2288. Type.GetTypeArray ((object []) null);
  2289. Assert.Fail ("#1");
  2290. } catch (ArgumentNullException ex) {
  2291. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2292. Assert.IsNull (ex.InnerException, "#3");
  2293. Assert.IsNotNull (ex.Message, "#4");
  2294. Assert.AreEqual ("args", ex.ParamName, "#5");
  2295. }
  2296. }
  2297. [Test]
  2298. public void GetTypeCode ()
  2299. {
  2300. Assert.AreEqual (TypeCode.Boolean, Type.GetTypeCode (typeof (bool)), "#1");
  2301. Assert.AreEqual (TypeCode.Byte, Type.GetTypeCode (typeof (byte)), "#2");
  2302. Assert.AreEqual (TypeCode.Char, Type.GetTypeCode (typeof (char)), "#3");
  2303. Assert.AreEqual (TypeCode.DateTime, Type.GetTypeCode (typeof (DateTime)), "#4");
  2304. Assert.AreEqual (TypeCode.DBNull, Type.GetTypeCode (typeof (DBNull)), "#5");
  2305. Assert.AreEqual (TypeCode.Decimal, Type.GetTypeCode (typeof (decimal)), "#6");
  2306. Assert.AreEqual (TypeCode.Double, Type.GetTypeCode (typeof (double)), "#7");
  2307. Assert.AreEqual (TypeCode.Empty, Type.GetTypeCode (null), "#8");
  2308. Assert.AreEqual (TypeCode.Int16, Type.GetTypeCode (typeof (short)), "#9");
  2309. Assert.AreEqual (TypeCode.Int32, Type.GetTypeCode (typeof (int)), "#10");
  2310. Assert.AreEqual (TypeCode.Int64, Type.GetTypeCode (typeof (long)), "#11");
  2311. Assert.AreEqual (TypeCode.Object, Type.GetTypeCode (typeof (TakesInt)), "#12");
  2312. Assert.AreEqual (TypeCode.SByte, Type.GetTypeCode (typeof (sbyte)), "#13");
  2313. Assert.AreEqual (TypeCode.Single, Type.GetTypeCode (typeof (float)), "#14");
  2314. Assert.AreEqual (TypeCode.String, Type.GetTypeCode (typeof (string)), "#15");
  2315. Assert.AreEqual (TypeCode.UInt16, Type.GetTypeCode (typeof (ushort)), "#16");
  2316. Assert.AreEqual (TypeCode.UInt32, Type.GetTypeCode (typeof (uint)), "#17");
  2317. Assert.AreEqual (TypeCode.UInt64, Type.GetTypeCode (typeof (ulong)), "#18");
  2318. }
  2319. [Test]
  2320. public void GetTypeFromHandle_Handle_Zero ()
  2321. {
  2322. RuntimeTypeHandle handle = new RuntimeTypeHandle ();
  2323. Assert.IsNull (Type.GetTypeFromHandle (handle));
  2324. }
  2325. [Test]
  2326. public void GetTypeHandle_O_Null ()
  2327. {
  2328. try {
  2329. Type.GetTypeHandle (null);
  2330. Assert.Fail ("#1");
  2331. } catch (ArgumentNullException ex) {
  2332. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2333. Assert.IsNull (ex.InnerException, "#3");
  2334. Assert.IsNotNull (ex.Message, "#4");
  2335. Assert.IsNull (ex.ParamName, "#5");
  2336. }
  2337. }
  2338. [Test] // GetConstructor (Type [])
  2339. public void GetConstructor1 ()
  2340. {
  2341. Type type;
  2342. ConstructorInfo ctor;
  2343. type = typeof (CtorsA);
  2344. ctor = type.GetConstructor (Type.EmptyTypes);
  2345. Assert.IsNotNull (ctor, "#A1");
  2346. Assert.AreEqual (0, ctor.GetParameters ().Length, "#A2");
  2347. Assert.IsFalse (ctor.IsStatic, "#A3");
  2348. Assert.IsTrue (ctor.IsPublic, "#A4");
  2349. Assert.AreEqual (".ctor", ctor.Name, "#A5");
  2350. type = typeof (CtorsB);
  2351. ctor = type.GetConstructor (Type.EmptyTypes);
  2352. Assert.IsNotNull (ctor, "#B1");
  2353. Assert.AreEqual (0, ctor.GetParameters ().Length, "#B2");
  2354. Assert.IsFalse (ctor.IsStatic, "#B3");
  2355. Assert.IsTrue (ctor.IsPublic, "#B4");
  2356. Assert.AreEqual (".ctor", ctor.Name, "#B5");
  2357. type = typeof (CtorsC);
  2358. ctor = type.GetConstructor (Type.EmptyTypes);
  2359. Assert.IsNull (ctor, "#C");
  2360. type = typeof (CtorsC);
  2361. ctor = type.GetConstructor (new Type [] { typeof (int) });
  2362. Assert.IsNotNull (ctor, "#D1");
  2363. Assert.AreEqual (1, ctor.GetParameters ().Length, "#D2");
  2364. Assert.IsFalse (ctor.IsStatic, "#D3");
  2365. Assert.IsTrue (ctor.IsPublic, "#D4");
  2366. Assert.AreEqual (".ctor", ctor.Name, "#D5");
  2367. }
  2368. [Test] // GetConstructor (Type [])
  2369. public void GetConstructor1_Types_Null ()
  2370. {
  2371. try {
  2372. typeof (BindingFlags).GetConstructor (null);
  2373. Assert.Fail ("#1");
  2374. } catch (ArgumentNullException ex) {
  2375. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2376. Assert.IsNull (ex.InnerException, "#3");
  2377. Assert.IsNotNull (ex.Message, "#4");
  2378. Assert.IsNotNull (ex.ParamName, "#5");
  2379. Assert.AreEqual ("types", ex.ParamName, "#6");
  2380. }
  2381. }
  2382. [Test] // GetConstructor (Type [])
  2383. public void GetConstructor1_Types_ItemNull ()
  2384. {
  2385. Type type = typeof (BindingFlags);
  2386. try {
  2387. type.GetConstructor (new Type[1] { null });
  2388. Assert.Fail ("#A1");
  2389. } catch (ArgumentNullException ex) {
  2390. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  2391. Assert.IsNull (ex.InnerException, "#A3");
  2392. Assert.IsNotNull (ex.Message, "#A4");
  2393. Assert.IsNotNull (ex.ParamName, "#A5");
  2394. Assert.AreEqual ("types", ex.ParamName, "#A6");
  2395. }
  2396. type = typeof (TakesInt);
  2397. try {
  2398. type.GetConstructor (new Type [1] { null });
  2399. Assert.Fail ("#B1");
  2400. } catch (ArgumentNullException ex) {
  2401. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
  2402. Assert.IsNull (ex.InnerException, "#B3");
  2403. Assert.IsNotNull (ex.Message, "#B4");
  2404. Assert.IsNotNull (ex.ParamName, "#B5");
  2405. Assert.AreEqual ("types", ex.ParamName, "#B6");
  2406. }
  2407. }
  2408. [Test] // GetConstructor (BindingFlags, Binder, Type [], ParameterModifier [])
  2409. public void GetConstructor2_Types_ItemNull ()
  2410. {
  2411. Type type = typeof (BindingFlags);
  2412. try {
  2413. type.GetConstructor (BindingFlags.Default, null,
  2414. new Type[1] { null }, null);
  2415. Assert.Fail ("#1");
  2416. } catch (ArgumentNullException ex) {
  2417. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2418. Assert.IsNull (ex.InnerException, "#3");
  2419. Assert.IsNotNull (ex.Message, "#4");
  2420. Assert.IsNotNull (ex.ParamName, "#5");
  2421. Assert.AreEqual ("types", ex.ParamName, "#6");
  2422. }
  2423. }
  2424. [Test] // GetConstructor (BindingFlags, Binder, CallingConventions, Type [], ParameterModifier [])
  2425. public void GetConstructor3_Types_ItemNull ()
  2426. {
  2427. Type type = typeof (BindingFlags);
  2428. try {
  2429. type.GetConstructor (BindingFlags.Default,
  2430. null, CallingConventions.Any,
  2431. new Type[1] { null }, null);
  2432. Assert.Fail ("#1");
  2433. } catch (ArgumentNullException ex) {
  2434. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  2435. Assert.IsNull (ex.InnerException, "#3");
  2436. Assert.IsNotNull (ex.Message, "#4");
  2437. Assert.IsNotNull (ex.ParamName, "#5");
  2438. Assert.AreEqual ("types", ex.ParamName, "#6");
  2439. }
  2440. }
  2441. [Test]
  2442. public void GetMethod_Bug77367 ()
  2443. {
  2444. MethodInfo i = typeof (Bug77367).GetMethod ("Run", Type.EmptyTypes);
  2445. Assert.IsNull (i);
  2446. }
  2447. #if !TARGET_JVM && !MOBILE // Reflection.Emit is not supported for TARGET_JVM
  2448. [Test]
  2449. public void EqualsUnderlyingType ()
  2450. {
  2451. AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
  2452. TypeAttributes attribs = TypeAttributes.Public;
  2453. AssemblyName name = new AssemblyName ();
  2454. name.Name = "enumtest";
  2455. AssemblyBuilder assembly =
  2456. AppDomain.CurrentDomain.DefineDynamicAssembly (
  2457. name, access);
  2458. ModuleBuilder module = assembly.DefineDynamicModule
  2459. ("m", "enumtest.dll");
  2460. EnumBuilder e = module.DefineEnum ("E", attribs, typeof (int));
  2461. Assert.IsTrue (typeof (int).Equals (e));
  2462. }
  2463. #endif // TARGET_JVM
  2464. [Test]
  2465. public void Equals_Type_Null ()
  2466. {
  2467. Assert.IsFalse (typeof (int).Equals ((Type) null), "#1");
  2468. Assert.IsFalse (typeof (int).Equals ((object) null), "#2");
  2469. }
  2470. [Test]
  2471. public void GetElementType_Bug63841 ()
  2472. {
  2473. Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
  2474. }
  2475. [Test]
  2476. public void FullNameGenerics ()
  2477. {
  2478. Type fooType = typeof (Foo<>);
  2479. FieldInfo [] fields = fooType.GetFields ();
  2480. Assert.AreEqual (1, fields.Length, "#0");
  2481. Assert.IsNotNull (fooType.FullName, "#1");
  2482. Assert.IsNotNull (fooType.AssemblyQualifiedName, "#1a");
  2483. FieldInfo field = fooType.GetField ("Whatever");
  2484. Assert.IsNotNull (field, "#2");
  2485. Assert.AreEqual (field, fields [0], "#2a");
  2486. Assert.IsNull (field.FieldType.FullName, "#3");
  2487. Assert.IsNull (field.FieldType.AssemblyQualifiedName, "#3a");
  2488. Assert.IsNotNull (field.FieldType.ToString (), "#4");
  2489. PropertyInfo prop = fooType.GetProperty ("Test");
  2490. Assert.IsNotNull (prop, "#5");
  2491. Assert.IsNull (prop.PropertyType.FullName, "#6");
  2492. Assert.IsNull (prop.PropertyType.AssemblyQualifiedName, "#6a");
  2493. Assert.IsNotNull (prop.PropertyType.ToString (), "#7");
  2494. MethodInfo method = fooType.GetMethod("Execute");
  2495. Assert.IsNotNull (method, "#8");
  2496. Assert.IsNull (method.ReturnType.FullName, "#9");
  2497. Assert.IsNull (method.ReturnType.AssemblyQualifiedName, "#9a");
  2498. Assert.IsNotNull (method.ReturnType.ToString (), "#10");
  2499. ParameterInfo[] parameters = method.GetParameters();
  2500. Assert.AreEqual (1, parameters.Length, "#11");
  2501. Assert.IsNull (parameters[0].ParameterType.FullName, "#12");
  2502. Assert.IsNull (parameters[0].ParameterType.AssemblyQualifiedName, "#12a");
  2503. Assert.IsNotNull (parameters[0].ParameterType.ToString (), "#13");
  2504. }
  2505. [Test]
  2506. public void TypeParameterIsNotGeneric ()
  2507. {
  2508. Type fooType = typeof (Foo<>);
  2509. Type type_param = fooType.GetGenericArguments () [0];
  2510. Assert.IsTrue (type_param.IsGenericParameter);
  2511. Assert.IsFalse (type_param.IsGenericType);
  2512. Assert.IsFalse (type_param.IsGenericTypeDefinition);
  2513. // LAMESPEC: MSDN claims that this should be false, but .NET v2.0.50727 says it's true
  2514. // http://msdn2.microsoft.com/en-us/library/system.type.isgenerictype.aspx
  2515. Assert.IsTrue (type_param.ContainsGenericParameters);
  2516. }
  2517. [Test]
  2518. public void IsAssignable ()
  2519. {
  2520. Type foo_type = typeof (Foo<>);
  2521. Type foo_int_type = typeof (Foo<int>);
  2522. Assert.IsFalse (foo_type.IsAssignableFrom (foo_int_type), "Foo<int> -!-> Foo<>");
  2523. Assert.IsFalse (foo_int_type.IsAssignableFrom (foo_type), "Foo<> -!-> Foo<int>");
  2524. Type ibar_short_type = typeof (IBar<short>);
  2525. Type ibar_int_type = typeof (IBar<int>);
  2526. Type baz_short_type = typeof (Baz<short>);
  2527. Type baz_int_type = typeof (Baz<int>);
  2528. Assert.IsTrue (ibar_int_type.IsAssignableFrom (baz_int_type), "Baz<int> -> IBar<int>");
  2529. Assert.IsTrue (ibar_short_type.IsAssignableFrom (baz_short_type), "Baz<short> -> IBar<short>");
  2530. Assert.IsFalse (ibar_int_type.IsAssignableFrom (baz_short_type), "Baz<short> -!-> IBar<int>");
  2531. Assert.IsFalse (ibar_short_type.IsAssignableFrom (baz_int_type), "Baz<int> -!-> IBar<short>");
  2532. // Nullable tests
  2533. Assert.IsTrue (typeof (Nullable<int>).IsAssignableFrom (typeof (int)));
  2534. Assert.IsFalse (typeof (int).IsAssignableFrom (typeof (Nullable<int>)));
  2535. Assert.IsTrue (typeof (Nullable<FooStruct>).IsAssignableFrom (typeof (FooStruct)));
  2536. }
  2537. [Test]
  2538. public void IsInstanceOf ()
  2539. {
  2540. Assert.IsTrue (typeof (Nullable<int>).IsInstanceOfType (5));
  2541. }
  2542. [Test]
  2543. public void IsInstanceOfArrayOfNullable ()
  2544. {
  2545. Assert.IsTrue (typeof (Nullable<int>[]).IsInstanceOfType (new Nullable<int> [0]));
  2546. }
  2547. [Test]
  2548. public void IsInstanceOfType_Null ()
  2549. {
  2550. Assert.IsFalse (typeof (int).IsInstanceOfType (null), "int");
  2551. Assert.IsFalse (typeof (object).IsInstanceOfType (null), "object");
  2552. Assert.IsFalse (typeof (int?).IsInstanceOfType (null), "int?");
  2553. }
  2554. [Test]
  2555. public void ByrefType ()
  2556. {
  2557. Type foo_type = typeof (Foo<>);
  2558. Type type_param = foo_type.GetGenericArguments () [0];
  2559. Type byref_type_param = type_param.MakeByRefType ();
  2560. Assert.IsFalse (byref_type_param.IsGenericParameter);
  2561. Assert.IsNull (byref_type_param.DeclaringType);
  2562. }
  2563. [Test]
  2564. [ExpectedException (typeof (TypeLoadException))]
  2565. public void MakeByRefByRef ()
  2566. {
  2567. typeof (int).MakeByRefType ().MakeByRefType ();
  2568. }
  2569. [Test]
  2570. public void MakeArrayTypeTest ()
  2571. {
  2572. // This should not crash:
  2573. typeof (void).MakeArrayType ();
  2574. }
  2575. [ComVisible (true)]
  2576. public class ComFoo<T> {
  2577. }
  2578. [Test]
  2579. public void GetCustomAttributesGenericInstance ()
  2580. {
  2581. Assert.AreEqual (1, typeof (ComFoo<int>).GetCustomAttributes (typeof (ComVisibleAttribute), true).Length);
  2582. }
  2583. interface ByRef1<T> { void f (ref T t); }
  2584. interface ByRef2 { void f<T> (ref T t); }
  2585. interface ByRef3<T> where T:struct { void f (ref T? t); }
  2586. interface ByRef4 { void f<T> (ref T? t) where T:struct; }
  2587. void CheckGenericByRef (Type t)
  2588. {
  2589. string name = t.Name;
  2590. t = t.GetMethod ("f").GetParameters () [0].ParameterType;
  2591. Assert.IsFalse (t.IsGenericType, name);
  2592. Assert.IsFalse (t.IsGenericTypeDefinition, name);
  2593. Assert.IsFalse (t.IsGenericParameter, name);
  2594. }
  2595. [Test]
  2596. public void GenericByRef ()
  2597. {
  2598. CheckGenericByRef (typeof (ByRef1<>));
  2599. CheckGenericByRef (typeof (ByRef2));
  2600. CheckGenericByRef (typeof (ByRef3<>));
  2601. CheckGenericByRef (typeof (ByRef4));
  2602. }
  2603. public class Bug80242<T> {
  2604. public interface IFoo { }
  2605. public class Bar : IFoo { }
  2606. public class Baz : Bar { }
  2607. }
  2608. [Test]
  2609. public void TestNestedTypes ()
  2610. {
  2611. Type t = typeof (Bug80242<object>);
  2612. Assert.IsFalse (t.IsGenericTypeDefinition);
  2613. foreach (Type u in t.GetNestedTypes ()) {
  2614. Assert.IsTrue (u.IsGenericTypeDefinition, "{0} isn't a generic definition", u);
  2615. Assert.AreEqual (u, u.GetGenericArguments () [0].DeclaringType);
  2616. }
  2617. }
  2618. [Test] // bug #82211
  2619. public void GetMembers_GenericArgument ()
  2620. {
  2621. Type argType = typeof (ComFoo<>).GetGenericArguments () [0];
  2622. MemberInfo [] members = argType.GetMembers ();
  2623. Assert.IsNotNull (members, "#1");
  2624. Assert.AreEqual (4, members.Length, "#2");
  2625. }
  2626. [Test]
  2627. [ExpectedException (typeof (ArgumentNullException))]
  2628. public void ReflectionOnlyGetTypeNullTypeName ()
  2629. {
  2630. Type.ReflectionOnlyGetType (null, false, false);
  2631. }
  2632. [Test]
  2633. public void ReflectionOnlyGetTypeDoNotThrow ()
  2634. {
  2635. Assert.IsNull (Type.ReflectionOnlyGetType ("a, nonexistent.dll", false, false));
  2636. }
  2637. [Test]
  2638. [ExpectedException (typeof (FileNotFoundException))]
  2639. public void ReflectionOnlyGetTypeThrow ()
  2640. {
  2641. Type.ReflectionOnlyGetType ("a, nonexistent.dll", true, false);
  2642. }
  2643. [Test]
  2644. public void ReflectionOnlyGetType ()
  2645. {
  2646. Type t = Type.ReflectionOnlyGetType (typeof (int).AssemblyQualifiedName.ToString (), true, true);
  2647. Assert.AreEqual ("System.Int32", t.FullName);
  2648. }
  2649. [Test]
  2650. #if MONOTOUCH
  2651. [ExpectedException (typeof (NotSupportedException))]
  2652. #endif
  2653. public void MakeGenericType_UserDefinedType ()
  2654. {
  2655. Type ut = new UserType (typeof (int));
  2656. Type t = typeof (Foo<>).MakeGenericType (ut);
  2657. Assert.IsTrue (t.IsGenericType, "#A1");
  2658. Assert.AreEqual (1, t.GetGenericArguments ().Length, "#A2");
  2659. Type arg = t.GetGenericArguments () [0];
  2660. Assert.IsNotNull (arg, "#B1");
  2661. Assert.IsFalse (arg.IsGenericType, "#B2");
  2662. Assert.AreEqual (ut, arg, "#B3");
  2663. }
  2664. [Category ("NotWorking")]
  2665. //We dont support instantiating a user type
  2666. public void MakeGenericType_NestedUserDefinedType ()
  2667. {
  2668. Type ut = new UserType (new UserType (typeof (int)));
  2669. Type t = typeof (Foo<>).MakeGenericType (ut);
  2670. Assert.IsTrue (t.IsGenericType, "#A1");
  2671. Assert.AreEqual (1, t.GetGenericArguments ().Length, "#A2");
  2672. Type arg = t.GetGenericArguments () [0];
  2673. Assert.IsNotNull (arg, "#B1");
  2674. Assert.IsFalse (arg.IsGenericType, "#B2");
  2675. Assert.AreEqual (ut, arg, "#B3");
  2676. }
  2677. [Test]
  2678. [Category ("NotWorking")]
  2679. public void TestMakeGenericType_UserDefinedType_DotNet20SP1 ()
  2680. {
  2681. Type ut = new UserType(typeof(int));
  2682. Type t = typeof(Foo<>).MakeGenericType(ut);
  2683. Assert.IsTrue (t.IsGenericType, "#1");
  2684. Assert.AreEqual (ut, t.GetGenericArguments()[0], "#2");
  2685. }
  2686. [Test]
  2687. #if MONOTOUCH
  2688. [ExpectedException (typeof (NotSupportedException))]
  2689. #endif
  2690. public void MakeGenericType_BadUserType ()
  2691. {
  2692. Type ut = new UserType (null);
  2693. Type t = typeof (Foo<>).MakeGenericType (ut);
  2694. var g0 = t.GetGenericArguments () [0];
  2695. Assert.AreSame (g0, ut, "#1");
  2696. }
  2697. [Test]
  2698. public void MakeGenericType_WrongNumOfArguments ()
  2699. {
  2700. try {
  2701. Type t = typeof (Foo<,>).MakeGenericType (new Type [] { typeof (int) });
  2702. Assert.Fail ("#1");
  2703. } catch (ArgumentException) {
  2704. }
  2705. }
  2706. [AttributeUsage (AttributeTargets.All)]
  2707. public class DocAttribute : Attribute {
  2708. public DocAttribute (string docs) {}
  2709. }
  2710. class GenericClassWithAttributes<[Doc ("T")] T, [Doc ("B")] B>
  2711. where T : class, new ()
  2712. where B : Attribute
  2713. {
  2714. public T Bar { get{return null;}}
  2715. public void M<[Doc ("X")] X> (X x)
  2716. {
  2717. }
  2718. }
  2719. [Test] //bug #377596
  2720. public void GetGenericArguments_ArgumentsHaveAttributes ()
  2721. {
  2722. Type type = typeof(GenericClassWithAttributes<,>);
  2723. Type[] tArgs = type.GetGenericArguments ();
  2724. MethodInfo m = type.GetMethod ("M");
  2725. Type[] mArgs = m.GetGenericArguments ();
  2726. Assert.AreEqual(1, tArgs[0].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
  2727. Assert.AreEqual(1, tArgs[1].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
  2728. Assert.AreEqual(1, mArgs[0].GetCustomAttributes (typeof (DocAttribute), true).Length, "#1");
  2729. }
  2730. [Test] //bug #471255
  2731. public void GetTypeCalledUsingReflection ()
  2732. {
  2733. Type expectedType = Type.GetType ("NoNamespaceClass");
  2734. Assert.IsNotNull (expectedType, "#1");
  2735. MethodInfo m = typeof (Type).GetMethod ("GetType", BindingFlags.Public | BindingFlags.Static, null, new Type [] { typeof (string) }, null);
  2736. object r = m.Invoke (null, BindingFlags.Default, null, new object [] { "NoNamespaceClass" }, CultureInfo.InvariantCulture);
  2737. Assert.AreSame (expectedType, r, "#2");
  2738. }
  2739. [Test]
  2740. public void EqualsUserType () {
  2741. UserType2 t1 = new UserType2(null);
  2742. UserType2 t2 = new UserType2(t1);
  2743. Assert.IsTrue (t1.Equals(t2));
  2744. }
  2745. [Test]
  2746. public void GetHashCodeUserType () {
  2747. UserType2 t1 = new UserType2(null);
  2748. UserType2 t2 = new UserType2(t1);
  2749. Assert.AreEqual (42, t2.GetHashCode());
  2750. }
  2751. [Test]
  2752. public void IsGenericTypeDefinitionUserType () {
  2753. Assert.IsFalse (new UserType(null).IsGenericTypeDefinition);
  2754. }
  2755. [Test]
  2756. public void IsGenericTypeUserType () {
  2757. Assert.IsFalse (new UserType(null).IsGenericType);
  2758. }
  2759. [Test]
  2760. [ExpectedException (typeof (NotSupportedException))]
  2761. public void GetGenericTypeDefinitionUserType () {
  2762. new UserType(null).GetGenericTypeDefinition ();
  2763. }
  2764. [ExpectedException (typeof (NotSupportedException))]
  2765. public void GetGenericArgumentsUserType () {
  2766. new UserType(null).GetGenericArguments ();
  2767. }
  2768. [Test]
  2769. [ExpectedException (typeof (InvalidOperationException))]
  2770. public void GenericParameterPositionUserType () {
  2771. Assert.IsTrue (new UserType(null).GenericParameterPosition == 0);
  2772. }
  2773. [Test]
  2774. public void TypeGetMemberReturnTypeTest ()
  2775. {
  2776. object obj;
  2777. MemberTypes memtype;
  2778. Type testtype;
  2779. object [] flagsandtypes = new object [] {
  2780. MemberTypes.All, typeof (MemberInfo []),
  2781. MemberTypes.Constructor, typeof (ConstructorInfo []),
  2782. MemberTypes.Custom, typeof (MemberInfo []),
  2783. MemberTypes.Event, typeof (EventInfo []),
  2784. MemberTypes.Field, typeof (FieldInfo []),
  2785. MemberTypes.Method, typeof (MethodInfo []),
  2786. MemberTypes.NestedType, typeof (Type []),
  2787. MemberTypes.Property, typeof (PropertyInfo []),
  2788. MemberTypes.TypeInfo, typeof (Type [])};
  2789. for (int i=0; i < flagsandtypes.Length; i+=2) {
  2790. memtype = (MemberTypes)flagsandtypes [i];
  2791. testtype = (Type)flagsandtypes [i+1];
  2792. obj = GetType ().GetMember ("DummyMember", memtype,
  2793. BindingFlags.Public | BindingFlags.Instance);
  2794. Assert.AreEqual (testtype.GetHashCode (), obj.GetType ().GetHashCode (),
  2795. "Expected " + testtype.FullName);
  2796. }
  2797. }
  2798. [Test]
  2799. public void TypeNameStartsWithSpace ()
  2800. {
  2801. Type t1 = Type.GetType ("System.Type, mscorlib");
  2802. Type t2 = Type.GetType (" System.Type, mscorlib");
  2803. Assert.AreEqual (t1, t2);
  2804. }
  2805. #if !MONOTOUCH
  2806. [Test]
  2807. public void Bug506757 ()
  2808. {
  2809. AssemblyName assemblyName = new AssemblyName ();
  2810. assemblyName.Name = "customMod";
  2811. assemblyName.Version = new Version (1, 2, 3, 4);
  2812. AssemblyBuilder assembly
  2813. = Thread.GetDomain().DefineDynamicAssembly(
  2814. assemblyName, AssemblyBuilderAccess.RunAndSave);
  2815. ModuleBuilder module = assembly.DefineDynamicModule("res.exe", "res.exe");
  2816. TypeBuilder type0 = module.DefineType ("Base", TypeAttributes.Public, typeof (object));
  2817. TypeBuilder type1 = module.DefineType ("Middle", TypeAttributes.Public, type0);
  2818. TypeBuilder type2 = module.DefineType ("End", TypeAttributes.Public, type1);
  2819. MethodAttributes attrs0 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
  2820. MethodAttributes.NewSlot | MethodAttributes.FamORAssem;
  2821. MethodAttributes attrs1 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
  2822. MethodAttributes.FamORAssem;
  2823. MethodAttributes attrs2 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
  2824. MethodAttributes.Public;
  2825. MethodBuilder m0 = type0.DefineMethod ("Tst", attrs0, typeof (void), null);
  2826. m0.GetILGenerator ().Emit (OpCodes.Ret);
  2827. MethodBuilder m1 = type1.DefineMethod ("Tst", attrs1, typeof (void), null);
  2828. m1.GetILGenerator ().Emit (OpCodes.Ret);
  2829. MethodBuilder m2 = type2.DefineMethod ("Tst", attrs2, typeof (void), null);
  2830. m2.GetILGenerator ().Emit (OpCodes.Ret);
  2831. type0.CreateType ();
  2832. type1.CreateType ();
  2833. Type t2 = type2.CreateType ();
  2834. foreach (var m in t2.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic))
  2835. Assert.IsTrue (m.DeclaringType == typeof (object), String.Format ("{0}::{1}", m.DeclaringType, m.Name));
  2836. }
  2837. #endif
  2838. [Test]
  2839. public void MakeArrayTypeOfOneDimension ()
  2840. {
  2841. Type vector = typeof (int).MakeArrayType ();
  2842. Type szarray = typeof (int).MakeArrayType (1);
  2843. Assert.AreNotEqual (vector, szarray, "#1");
  2844. Assert.AreEqual ("Int32[]", vector.Name, "#2");
  2845. Assert.AreEqual ("Int32[*]", szarray.Name, "#3");
  2846. }
  2847. public class DeclaringMethodFoo {
  2848. public void Test<T> (T t) {}
  2849. public void Test2<T> (ref T t) {}
  2850. }
  2851. public class DeclaringMethodBar<T> {
  2852. public void Test2 (ref T t) {}
  2853. }
  2854. [Test]
  2855. public void DeclaringMethodOnlyWorksWithGenericArgs ()
  2856. {
  2857. MethodInfo testMethod = typeof (DeclaringMethodFoo).GetMethod ("Test");
  2858. MethodBase otherMethod = testMethod.GetParameters ()[0].ParameterType.DeclaringMethod;
  2859. Assert.AreEqual (testMethod, otherMethod,"#1");
  2860. Assert.IsNull (typeof (DeclaringMethodBar<>).GetGenericArguments ()[0].DeclaringMethod, "#2");
  2861. try {
  2862. var x = typeof (int).DeclaringMethod;
  2863. Assert.Fail ("#3");
  2864. } catch (InvalidOperationException) {}
  2865. try {
  2866. var x = typeof (DeclaringMethodFoo).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
  2867. Assert.Fail ("#4");
  2868. } catch (InvalidOperationException) {}
  2869. try {
  2870. var x = typeof (DeclaringMethodBar<>).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
  2871. Assert.Fail ("#5");
  2872. } catch (InvalidOperationException) {}
  2873. }
  2874. [Test]
  2875. public void GetArrayRankThrowsForNonArrayType ()
  2876. {
  2877. Assert.AreEqual (1, typeof (int[]).GetArrayRank (), "#1");
  2878. Assert.AreEqual (2, typeof (int[,]).GetArrayRank (), "#2");
  2879. try {
  2880. typeof (int).GetArrayRank ();
  2881. Assert.Fail ("#3");
  2882. } catch (ArgumentException) {}
  2883. }
  2884. [Test] //Bug #564379
  2885. public void GetMethodsReturnPublicMethodsInInterfaces ()
  2886. {
  2887. Type t = typeof (NonClosingStream);
  2888. MethodInfo[] methods = t.GetMethods (BindingFlags.Public | BindingFlags.Instance);
  2889. Assert.AreEqual (5, methods.Length, "#1");
  2890. int id = 2;
  2891. foreach (var m in methods) {
  2892. if (m.Name.Equals ("ToString"))
  2893. Assert.IsTrue (m.DeclaringType == typeof (NonClosingStream), "#" + id);
  2894. else if (m.Name.Equals ("Dispose") && m.GetParameters ().Length == 0)
  2895. Assert.IsTrue (m.DeclaringType == typeof (Stream), "#" + id);
  2896. else if (m.Name.Equals ("Equals") || m.Name.Equals ("GetHashCode") || m.Name.Equals ("GetType"))
  2897. Assert.IsTrue (m.DeclaringType == typeof (object), "#" + id);
  2898. else
  2899. Assert.Fail ("invalid method " + m);
  2900. ++id;
  2901. }
  2902. }
  2903. [Test] // Bug #574696
  2904. public void GetMember_DoesntReturnPrivatePropOfParent ()
  2905. {
  2906. BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
  2907. Assert.AreEqual (1, typeof (Bar).GetMember ("PrivInst", flags).Length);
  2908. Assert.AreEqual (0, typeof (Bar).GetMember ("PrivInstBase", flags).Length);
  2909. Assert.AreEqual (1, typeof (Foo).GetMember ("PrivInstBase", flags).Length);
  2910. }
  2911. [Test] // Bug #484246
  2912. public void GetInterfaceCompareAgainstGTDNames ()
  2913. {
  2914. var t = typeof (Dictionary<string,string>);
  2915. var iface = typeof (IDictionary<string,string>);
  2916. Assert.AreSame (iface, t.GetInterface ("System.Collections.Generic.IDictionary`2"), "#1");
  2917. 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]]";
  2918. Assert.IsNull (t.GetInterface (name), "#2");
  2919. }
  2920. [Test]
  2921. public void RuntimeCorrectlyNormalizeGenericTypes ()
  2922. {
  2923. Type lst = typeof (MList<>);
  2924. Type arg = lst.GetGenericArguments ()[0];
  2925. Type sup = lst.BaseType;
  2926. Type sa0 = sup.GetGenericArguments ()[0];
  2927. Type sa1 = sup.GetGenericArguments ()[1];
  2928. Assert.IsTrue (sa1 == lst, "#1");
  2929. Assert.IsTrue (sa0 == arg, "#2");
  2930. Type inst = typeof (Cons<,>).MakeGenericType (arg, lst.MakeGenericType (arg));
  2931. Assert.IsTrue (inst == sup, "#3");
  2932. }
  2933. class Cons<T,U>
  2934. {
  2935. }
  2936. class MList<A> : Cons<A, MList<A>>
  2937. {
  2938. }
  2939. [Test] // Bug #331126
  2940. public void IsAssignableFromWorksCorrectlyWithByRefs ()
  2941. {
  2942. Type int_byref = typeof (int).MakeByRefType ();
  2943. Type obj_byref = typeof (object).MakeByRefType ();
  2944. Type long_byref = typeof (long).MakeByRefType ();
  2945. Type enum1_byref = typeof (AttributeTargets).MakeByRefType ();
  2946. Type enum2_byref = typeof (PlatformID).MakeByRefType ();
  2947. Type uint_byref = typeof (uint).MakeByRefType ();
  2948. Type string_byref = typeof (object).MakeByRefType ();
  2949. Type struct0_byref = typeof (Size4).MakeByRefType ();
  2950. Type struct1_byref = typeof (Size4b).MakeByRefType ();
  2951. Type mvar0_byref = typeof (TypeTest).GetMethod ("Bug331126").GetGenericArguments ()[0].MakeByRefType ();
  2952. Type mvar1_byref = typeof (TypeTest).GetMethod ("Bug331126").GetGenericArguments ()[1].MakeByRefType ();
  2953. Assert.IsFalse (typeof (int).IsAssignableFrom (int_byref), "#1");
  2954. Assert.IsFalse (int_byref.IsAssignableFrom (typeof (int)), "#2");
  2955. Assert.IsFalse (obj_byref.IsAssignableFrom (long_byref), "#3");
  2956. Assert.IsFalse (long_byref.IsAssignableFrom (obj_byref), "#4");
  2957. Assert.IsTrue (enum1_byref.IsAssignableFrom (enum2_byref), "#5");
  2958. Assert.IsTrue (enum2_byref.IsAssignableFrom (enum1_byref), "#6");
  2959. Assert.IsTrue (int_byref.IsAssignableFrom (enum2_byref), "#7");
  2960. Assert.IsTrue (enum2_byref.IsAssignableFrom (int_byref), "#8");
  2961. Assert.IsTrue (enum2_byref.IsAssignableFrom (uint_byref), "#9");
  2962. Assert.IsTrue (uint_byref.IsAssignableFrom (enum2_byref), "#10");
  2963. Assert.IsTrue (int_byref.IsAssignableFrom (uint_byref), "#11");
  2964. Assert.IsTrue (uint_byref.IsAssignableFrom (int_byref), "#12");
  2965. Assert.IsTrue (typeof (object).IsAssignableFrom (typeof (long)), "#13");
  2966. Assert.IsTrue (obj_byref.IsAssignableFrom (string_byref), "#14");
  2967. Assert.IsTrue (string_byref.IsAssignableFrom (obj_byref), "#15");
  2968. Assert.IsFalse (uint_byref.IsAssignableFrom (struct0_byref), "#16");
  2969. Assert.IsFalse (struct0_byref.IsAssignableFrom (int_byref), "#17");
  2970. Assert.IsFalse (struct0_byref.IsAssignableFrom (struct1_byref), "#18");
  2971. Assert.IsFalse (obj_byref.IsAssignableFrom (mvar0_byref), "#19");
  2972. Assert.IsFalse (mvar0_byref.IsAssignableFrom (mvar1_byref), "#20");
  2973. Assert.IsTrue (mvar0_byref.IsAssignableFrom (mvar0_byref), "#21");
  2974. Assert.IsFalse (mvar0_byref.IsAssignableFrom (obj_byref), "#22");
  2975. }
  2976. public void Bug331126<T,K> () {}
  2977. public struct Size4 {
  2978. public int field;
  2979. }
  2980. public struct Size4b {
  2981. public int field;
  2982. }
  2983. [Test] // Bug #612780
  2984. public void CannotMakeDerivedTypesFromTypedByRef ()
  2985. {
  2986. try {
  2987. typeof (global::System.TypedReference).MakeArrayType ();
  2988. Assert.Fail ("#1");
  2989. } catch (TypeLoadException) { }
  2990. try {
  2991. typeof (global::System.TypedReference).MakeByRefType ();
  2992. Assert.Fail ("#2");
  2993. } catch (TypeLoadException) { }
  2994. try {
  2995. typeof (global::System.TypedReference).MakePointerType ();
  2996. Assert.Fail ("#3");
  2997. } catch (TypeLoadException) { }
  2998. }
  2999. [Test] //Bug643890
  3000. public void DeclaringTypeOfGenericNestedTypeInstanceIsOpen ()
  3001. {
  3002. var type = typeof (Foo<int>.Nested<string>);
  3003. Assert.AreSame (typeof (Foo<>), type.DeclaringType, "#1");
  3004. }
  3005. #if NET_4_0
  3006. interface IGetInterfaceMap<in T>
  3007. {
  3008. string Bar (T t);
  3009. }
  3010. class GetInterfaceMap : IGetInterfaceMap<object>
  3011. {
  3012. public string Bar (object t)
  3013. {
  3014. return t.GetType ().FullName;
  3015. }
  3016. }
  3017. [Test]
  3018. public void GetInterfaceMapWorksWithVariantIfaces ()
  3019. {
  3020. InterfaceMapping res = typeof (GetInterfaceMap).GetInterfaceMap (typeof (IGetInterfaceMap <object>));
  3021. Assert.AreEqual (typeof (IGetInterfaceMap <object>), res.InterfaceType);
  3022. Assert.AreEqual (typeof (object), res.InterfaceMethods [0].GetParameters () [0].ParameterType);
  3023. res = typeof (GetInterfaceMap).GetInterfaceMap (typeof (IGetInterfaceMap <string>));
  3024. Assert.AreEqual (typeof (IGetInterfaceMap <string>), res.InterfaceType);
  3025. Assert.AreEqual (typeof (string), res.InterfaceMethods [0].GetParameters () [0].ParameterType);
  3026. }
  3027. public class MyType : TypeDelegator {
  3028. public int eq, ust;
  3029. public override bool Equals (Type t) {
  3030. ++eq;
  3031. return base.Equals (t);
  3032. }
  3033. public override Type UnderlyingSystemType {
  3034. get {
  3035. ++ust;
  3036. return typeof (int);
  3037. }
  3038. }
  3039. }
  3040. [Test]
  3041. public void NewV4EqualsBehavior ()
  3042. {
  3043. var ta = new MyType ();
  3044. var tb = new MyType ();
  3045. object a = ta, b = tb;
  3046. a.Equals (a);
  3047. Assert.AreEqual (1, ta.eq, "#1");
  3048. Assert.AreEqual (0, ta.ust, "#2");
  3049. a.Equals (b);
  3050. Assert.AreEqual (2, ta.eq, "#3");
  3051. Assert.AreEqual (1, ta.ust, "#4");
  3052. Assert.AreEqual (0, tb.eq, "#5");
  3053. Assert.AreEqual (1, tb.ust, "#6");
  3054. }
  3055. public enum MyRealEnum : short {
  3056. A,B,C
  3057. }
  3058. public enum MyRealEnum2 : byte {
  3059. A,B,C
  3060. }
  3061. public enum MyRealEnum3 : short {
  3062. A,B,C
  3063. }
  3064. public class MyEnum : TypeDelegator {
  3065. public bool is_enum { get; set; }
  3066. public int fields { get; set; }
  3067. public override bool IsSubclassOf (Type c) {
  3068. return c == typeof (Enum) && is_enum;
  3069. }
  3070. public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
  3071. if (fields == 0)
  3072. return null;
  3073. FieldInfo[] res = new FieldInfo [fields];
  3074. for (int i = 0; i < fields; ++i) {
  3075. if ((bindingAttr & BindingFlags.Instance) != 0)
  3076. res [i] = typeof (MyRealEnum).GetField ("value__");
  3077. else
  3078. res [i] = typeof (MyRealEnum).GetField ("A");
  3079. }
  3080. return res;
  3081. }
  3082. }
  3083. [Test]
  3084. public void GetEnumUnderlyingType () {
  3085. try {
  3086. new MyEnum () { is_enum = false }.GetEnumUnderlyingType ();
  3087. Assert.Fail ("#1");
  3088. } catch (ArgumentException) {}
  3089. try {
  3090. new MyEnum () { is_enum = true, fields = 0 }.GetEnumUnderlyingType ();
  3091. Assert.Fail ("#2");
  3092. } catch (ArgumentException) {}
  3093. try {
  3094. new MyEnum () { is_enum = true, fields = 2 }.GetEnumUnderlyingType ();
  3095. Assert.Fail ("#3");
  3096. } catch (ArgumentException) {}
  3097. Assert.AreSame (typeof (short), new MyEnum () { is_enum = true, fields = 1 }.GetEnumUnderlyingType ());
  3098. }
  3099. [Test]
  3100. public void GetEnumNames () {
  3101. try {
  3102. new MyEnum () { is_enum = false }.GetEnumNames ();
  3103. Assert.Fail ("#1");
  3104. } catch (ArgumentException) {}
  3105. var res = new MyEnum () { is_enum = true, fields = 1 }.GetEnumNames ();
  3106. Assert.AreEqual (1, res.Length, "#2");
  3107. Assert.AreEqual ("A", res [0], "#3");
  3108. res = typeof (MyRealEnum).GetEnumNames ();
  3109. Assert.AreEqual (3, res.Length, "#4");
  3110. Assert.AreEqual ("A", res [0], "#5");
  3111. Assert.AreEqual ("B", res [1], "#6");
  3112. Assert.AreEqual ("C", res [2], "#7");
  3113. }
  3114. public enum OutOfOrderEnum : sbyte
  3115. {
  3116. D = -1, C = 2, B = 1, A = 0
  3117. }
  3118. [Test]
  3119. public void GetEnumNamesSortsByUnsignedValue ()
  3120. {
  3121. string[] names = typeof (OutOfOrderEnum).GetEnumNames ();
  3122. Assert.AreEqual (4, names.Length);
  3123. Assert.AreEqual ("A", names [0]);
  3124. Assert.AreEqual ("B", names [1]);
  3125. Assert.AreEqual ("C", names [2]);
  3126. Assert.AreEqual ("D", names [3]);
  3127. }
  3128. [Test]
  3129. public void GetEnumValues () {
  3130. try {
  3131. new MyEnum () { is_enum = false }.GetEnumValues ();
  3132. Assert.Fail ("#1");
  3133. } catch (ArgumentException) {}
  3134. try {
  3135. new MyEnum () { is_enum = true }.GetEnumValues ();
  3136. Assert.Fail ("#2");
  3137. } catch (NotImplementedException) {}
  3138. var array = typeof (MyRealEnum).GetEnumValues ();
  3139. Assert.AreEqual (typeof (MyRealEnum[]), array.GetType (), "#3");
  3140. MyRealEnum[] res = (MyRealEnum[])array;
  3141. Assert.AreEqual (3, res.Length, "#4");
  3142. Assert.AreEqual (MyRealEnum.A, res [0], "#5");
  3143. Assert.AreEqual (MyRealEnum.B, res [1], "#6");
  3144. Assert.AreEqual (MyRealEnum.C, res [2], "#7");
  3145. }
  3146. [Test]
  3147. public void GetEnumValue () {
  3148. try {
  3149. typeof (MyRealEnum).GetEnumName (null);
  3150. Assert.Fail ("#1");
  3151. } catch (ArgumentException) { }
  3152. try {
  3153. new MyEnum () { is_enum = false }.GetEnumName (99);
  3154. Assert.Fail ("#2");
  3155. } catch (ArgumentException) { }
  3156. Assert.IsNull (new MyEnum () { fields = 1, is_enum = true }.GetEnumName (77), "#3");
  3157. Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (0), "#4");
  3158. Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (MyRealEnum.A), "#5");
  3159. Assert.AreEqual ("A", new MyEnum () { fields = 1, is_enum = true }.GetEnumName (MyRealEnum2.A), "#6");
  3160. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName (MyRealEnum.A), "#7");
  3161. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((short)0), "#8");
  3162. Assert.AreEqual ("C", typeof (MyRealEnum).GetEnumName (2), "#9");
  3163. Assert.IsNull (typeof (MyRealEnum).GetEnumName (9), "#10");
  3164. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((byte)0), "#11");
  3165. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((sbyte)0), "#12");
  3166. try {
  3167. typeof (MyRealEnum).GetEnumName (false);
  3168. Assert.Fail ("#13");
  3169. } catch (ArgumentException) { }
  3170. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((short)0), "#14");
  3171. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((ushort)0), "#15");
  3172. try {
  3173. typeof (MyRealEnum).GetEnumName ('c');
  3174. Assert.Fail ("#16");
  3175. } catch (ArgumentException) { }
  3176. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((int)0), "#17");
  3177. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((uint)0), "#18");
  3178. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((long)0), "#19");
  3179. Assert.AreEqual ("A", typeof (MyRealEnum).GetEnumName ((ulong)0), "#20");
  3180. try {
  3181. typeof (MyRealEnum).GetEnumName ((float)0);
  3182. Assert.Fail ("#21");
  3183. } catch (ArgumentException) { }
  3184. try {
  3185. typeof (MyRealEnum).GetEnumName ((double)0);
  3186. Assert.Fail ("#22");
  3187. } catch (ArgumentException) { }
  3188. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((byte)0), "#23");
  3189. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((sbyte)0), "#24");
  3190. try {
  3191. typeof (MyRealEnum2).GetEnumName (false);
  3192. Assert.Fail ("#22", "#25");
  3193. } catch (ArgumentException) { }
  3194. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((short)0), "#26");
  3195. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((ushort)0), "#27");
  3196. try {
  3197. typeof (MyRealEnum2).GetEnumName ('c');
  3198. Assert.Fail ("#28");
  3199. } catch (ArgumentException) { }
  3200. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((int)0), "#29");
  3201. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((uint)0), "#30");
  3202. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((long)0), "#31");
  3203. Assert.AreEqual ("A", typeof (MyRealEnum2).GetEnumName ((ulong)0), "#32");
  3204. try {
  3205. typeof (MyRealEnum2).GetEnumName ((float)0);
  3206. Assert.Fail ("#33");
  3207. } catch (ArgumentException) { }
  3208. try {
  3209. typeof (MyRealEnum2).GetEnumName ((double)0);
  3210. Assert.Fail ("#34");
  3211. } catch (ArgumentException) { }
  3212. Assert.IsNull (typeof (MyRealEnum2).GetEnumName (12345), "#35");
  3213. }
  3214. [Test]
  3215. public void IsEnumDefined () {
  3216. try {
  3217. typeof (MyRealEnum).IsEnumDefined (null);
  3218. Assert.Fail ("#1");
  3219. } catch (ArgumentException) { }
  3220. try {
  3221. new MyEnum () { is_enum = false }.IsEnumDefined (99);
  3222. Assert.Fail ("#2");
  3223. } catch (ArgumentException) { }
  3224. try {
  3225. typeof (MyRealEnum).IsEnumDefined (0);
  3226. Assert.Fail ("#3");
  3227. } catch (ArgumentException) { }
  3228. try {
  3229. typeof (MyRealEnum).IsEnumDefined ((ushort)0);
  3230. Assert.Fail ("#4");
  3231. } catch (ArgumentException) { }
  3232. try {
  3233. typeof (MyRealEnum).IsEnumDefined (MyRealEnum3.A);
  3234. Assert.Fail ("#5");
  3235. } catch (ArgumentException) { }
  3236. try {
  3237. typeof (MyRealEnum).IsEnumDefined (true);
  3238. Assert.Fail ("#6");
  3239. } catch (InvalidOperationException) { }
  3240. try {
  3241. typeof (MyRealEnum).IsEnumDefined (MyRealEnum2.A);
  3242. Assert.Fail ("#7");
  3243. } catch (ArgumentException) { }
  3244. try {
  3245. typeof (MyRealEnum).IsEnumDefined (typeof (MyRealEnum));
  3246. Assert.Fail ("#8");
  3247. } catch (InvalidOperationException) { }
  3248. Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined ((short)0), "#9");
  3249. Assert.IsFalse (typeof (MyRealEnum).IsEnumDefined ((short)88), "#10");
  3250. Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined (MyRealEnum.A), "#11");
  3251. Assert.IsFalse (typeof (MyRealEnum).IsEnumDefined ("d"), "#12");
  3252. Assert.IsTrue (typeof (MyRealEnum).IsEnumDefined ("A"), "#13");
  3253. Assert.IsFalse (new MyEnum () { is_enum = true, fields = 1 }.IsEnumDefined ((short)99), "#14");
  3254. }
  3255. public class Outer {
  3256. public class Inner {}
  3257. }
  3258. public class Outer<T> {
  3259. public class Inner {}
  3260. }
  3261. [Test]
  3262. public void GetTypeWithDelegates () {
  3263. var tname = typeof (MyRealEnum).AssemblyQualifiedName;
  3264. var res = Type.GetType (tname, name => {
  3265. return Assembly.Load (name);
  3266. },(asm,name,ignore) => {
  3267. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3268. }, false, false);
  3269. Assert.AreEqual (typeof (MyRealEnum), res, "#1");
  3270. tname = typeof (Dictionary<int, string>).AssemblyQualifiedName;
  3271. res = Type.GetType (tname, name => {
  3272. return Assembly.Load (name);
  3273. },(asm,name,ignore) => {
  3274. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3275. }, false, false);
  3276. Assert.AreEqual (typeof (Dictionary<int, string>), res, "#2");
  3277. tname = typeof (Foo<int>).AssemblyQualifiedName;
  3278. res = Type.GetType (tname, name => {
  3279. return Assembly.Load (name);
  3280. },(asm,name,ignore) => {
  3281. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3282. }, false, false);
  3283. Assert.AreEqual (typeof (Foo<int>), res, "#3");
  3284. tname = typeof (Outer.Inner).AssemblyQualifiedName;
  3285. res = Type.GetType (tname, name => {
  3286. return Assembly.Load (name);
  3287. },(asm,name,ignore) => {
  3288. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3289. }, false, false);
  3290. Assert.AreEqual (typeof (Outer.Inner), res, "#4");
  3291. tname = typeof (Outer<double>.Inner).AssemblyQualifiedName;
  3292. res = Type.GetType (tname, name => {
  3293. return Assembly.Load (name);
  3294. },(asm,name,ignore) => {
  3295. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3296. }, false, false);
  3297. Assert.AreEqual (typeof (Outer<double>.Inner), res, "#5");
  3298. tname = "System.Collections.Generic.List`1[System.Int32]";
  3299. res = Type.GetType (tname, name => {
  3300. return Assembly.Load (name);
  3301. },(asm,name,ignore) => {
  3302. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3303. }, false, false);
  3304. Assert.AreEqual (typeof (List<int>), res, "#6");
  3305. tname = typeof (Foo<>).FullName + "[,][]";
  3306. res = Type.GetType (tname, name => {
  3307. Console.WriteLine ("resolve-asm name {0}", name);
  3308. return Assembly.Load (name);
  3309. },(asm,name,ignore) => {
  3310. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3311. }, false, false);
  3312. Assert.AreEqual (typeof (Foo<>).MakeArrayType (2).MakeArrayType (), res, "#7");
  3313. tname = string.Format("{0}[{1}][]*&", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName);
  3314. res = Type.GetType (tname, name => {
  3315. return Assembly.Load (name);
  3316. },(asm,name,ignore) => {
  3317. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3318. }, false, false);
  3319. Assert.AreEqual (typeof (Foo<MyRealEnum>[]).MakePointerType ().MakeByRefType (), res, "#8");
  3320. tname = typeof (MyRealEnum).FullName + "[][]";
  3321. res = Type.GetType (tname, name => {
  3322. return Assembly.Load (name);
  3323. },(asm,name,ignore) => {
  3324. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3325. }, false, false);
  3326. Assert.AreEqual (typeof (MyRealEnum[][]), res, "#9");
  3327. tname = typeof (MyRealEnum).FullName + "[*]";
  3328. res = Type.GetType (tname, name => {
  3329. return Assembly.Load (name);
  3330. },(asm,name,ignore) => {
  3331. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3332. }, false, false);
  3333. Assert.AreEqual (typeof (MyRealEnum).MakeArrayType (1), res, "#10");
  3334. tname = typeof (MyRealEnum).FullName + "&";
  3335. res = Type.GetType (tname, name => {
  3336. return Assembly.Load (name);
  3337. },(asm,name,ignore) => {
  3338. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3339. }, false, false);
  3340. Assert.AreEqual (typeof (MyRealEnum).MakeByRefType (), res, "#11");
  3341. tname = typeof (MyRealEnum).FullName + "*";
  3342. res = Type.GetType (tname, name => {
  3343. return Assembly.Load (name);
  3344. },(asm,name,ignore) => {
  3345. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3346. }, false, false);
  3347. Assert.AreEqual (typeof (MyRealEnum).MakePointerType (), res, "#12");
  3348. // assembly resolve without type resolve
  3349. res = Type.GetType ("System.String,mscorlib", delegate (AssemblyName aname) { return typeof (int).Assembly; }, null);
  3350. Assert.AreEqual (typeof (string), res);
  3351. }
  3352. public class CustomGetType : TypeDelegator {
  3353. string name;
  3354. public CustomGetType (string name) { this.name = name; }
  3355. public override Type MakeGenericType (Type[] args) {
  3356. return new CustomGetType ("GINST");
  3357. }
  3358. public override Type GetNestedType(String name, BindingFlags bidingAttr) {
  3359. return new CustomGetType ("NESTED");
  3360. }
  3361. public override string ToString () { return "UT_" + name; }
  3362. public override string Name {
  3363. get { return "UT_" + name; }
  3364. }
  3365. }
  3366. [Test]
  3367. public void GetTypeWithDelegatesAndUserTypes ()
  3368. {
  3369. var tname = "Magic[System.Int32]";
  3370. var res = Type.GetType (tname, name => {
  3371. return Assembly.Load (name);
  3372. },(asm,name,ignore) => {
  3373. if (name == "Magic") return new CustomGetType ("MAGIC");
  3374. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3375. }, false, false);
  3376. Assert.AreEqual ("UT_GINST", res.Name, "#1");
  3377. tname = "Magic+MyRealEnum";
  3378. res = Type.GetType (tname, name => {
  3379. return Assembly.Load (name);
  3380. },(asm,name,ignore) => {
  3381. if (name == "Magic") return new CustomGetType ("MAGIC");
  3382. return asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3383. }, false, false);
  3384. Assert.AreEqual ("UT_NESTED", res.Name, "#2");
  3385. }
  3386. void MustTLE (string tname) {
  3387. try {
  3388. var res = Type.GetType (tname, name => {
  3389. return Assembly.Load (name);
  3390. },(asm,name,ignore) => {
  3391. return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3392. }, true, false);
  3393. Assert.Fail (tname);
  3394. } catch (TypeLoadException) {}
  3395. }
  3396. void MustANE (string tname) {
  3397. try {
  3398. var res = Type.GetType (tname, name => {
  3399. return Assembly.Load (name);
  3400. },(asm,name,ignore) => {
  3401. return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3402. }, true, false);
  3403. Assert.Fail (tname);
  3404. } catch (ArgumentNullException) {}
  3405. }
  3406. void MustAE (string tname) {
  3407. try {
  3408. var res = Type.GetType (tname, name => {
  3409. return Assembly.Load (name);
  3410. },(asm,name,ignore) => {
  3411. return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3412. }, true, false);
  3413. Assert.Fail (tname);
  3414. } catch (ArgumentException) {}
  3415. }
  3416. void MustFNFE (string tname) {
  3417. try {
  3418. var res = Type.GetType (tname, name => {
  3419. return Assembly.Load (name);
  3420. },(asm,name,ignore) => {
  3421. return (object)asm == null ? Type.GetType (name, false, ignore) : asm.GetType (name, false, ignore);
  3422. }, true, false);
  3423. Assert.Fail (tname);
  3424. } catch (FileNotFoundException) {}
  3425. }
  3426. [Test]
  3427. public void NewGetTypeErrors () {
  3428. MustANE (null);
  3429. MustAE (string.Format ("{0}[{1}&]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3430. MustAE (string.Format ("{0}[{1}*]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3431. MustAE (string.Format ("{0}&&", typeof (MyRealEnum).FullName));
  3432. MustAE (string.Format ("{0}&*", typeof (MyRealEnum).FullName));
  3433. MustAE (string.Format ("{0}&[{1}]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3434. MustAE (string.Format ("{0}[[{1},", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3435. MustAE (string.Format ("{0}[[{1}]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3436. MustAE (string.Format ("{0}[[{1}],", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3437. MustAE (string.Format ("{0}[[{1}]_", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3438. MustAE (string.Format ("{0}[{1}", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3439. MustAE (string.Format ("{0}[{1},", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3440. MustAE (string.Format ("{0}[{1},,", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3441. MustAE (string.Format ("{0}[{1} (", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3442. MustAE (string.Format ("{0}[", typeof (Foo<>).FullName));
  3443. MustAE (string.Format ("{0}[**]", typeof (MyRealEnum).FullName));
  3444. MustAE (string.Format ("{0}[*,*]", typeof (MyRealEnum).FullName));
  3445. MustAE (string.Format ("{0}[*,]", typeof (MyRealEnum).FullName));
  3446. MustAE (string.Format ("{0}[,*]", typeof (MyRealEnum).FullName));
  3447. MustAE (string.Format ("{0}[,-]", typeof (MyRealEnum).FullName));
  3448. MustAE (string.Format ("{0}[,{0}]", typeof (MyRealEnum).FullName));
  3449. MustAE (string.Format ("{0}[{1}]]", typeof (Foo<>).FullName, typeof (MyRealEnum).FullName));
  3450. MustAE (string.Format ("{0}[,]]", typeof (MyRealEnum).FullName));
  3451. string aqn = typeof (MyRealEnum).Assembly.FullName;
  3452. MustFNFE (string.Format ("{0}, ZZZ{1}", typeof (MyRealEnum).FullName, aqn));
  3453. MustTLE (string.Format ("{0}ZZZZ", typeof (MyRealEnum).FullName));
  3454. MustTLE (string.Format ("{0}ZZZZ,{1}", typeof (MyRealEnum).FullName, aqn));
  3455. }
  3456. delegate void MyAction<in T>(T ag);
  3457. [Test] //bug #668506
  3458. public void IsAssignableFromWithVariantDelegate () {
  3459. Assert.IsFalse (typeof(MyAction<string>).IsAssignableFrom(typeof(MyAction<>)), "#1");
  3460. }
  3461. [Test] //bug #124
  3462. public void IsAssignableFromWithNullable () {
  3463. Console.WriteLine(typeof(IEnumerable<int?>).IsAssignableFrom(typeof(IEnumerable<int>)));
  3464. }
  3465. #endif
  3466. public abstract class Stream : IDisposable
  3467. {
  3468. public void Dispose ()
  3469. {
  3470. Console.WriteLine ("stream::dispose");
  3471. }
  3472. protected virtual void Dispose (bool disposing)
  3473. {
  3474. }
  3475. }
  3476. public class NonClosingStream
  3477. : Stream, IDisposable
  3478. {
  3479. void IDisposable.Dispose()
  3480. {
  3481. Console.WriteLine ("ncs::dispose");
  3482. }
  3483. public override string ToString () { return ""; }
  3484. }
  3485. static bool ContainsProperty (PropertyInfo [] props, string name)
  3486. {
  3487. foreach (PropertyInfo p in props)
  3488. if (p.Name == name)
  3489. return true;
  3490. return false;
  3491. }
  3492. public class NemerleAttribute : Attribute
  3493. {
  3494. }
  3495. public class VolatileModifier : NemerleAttribute
  3496. {
  3497. }
  3498. [VolatileModifier]
  3499. [FooAttribute]
  3500. class A
  3501. {
  3502. }
  3503. [AttributeUsage (AttributeTargets.Class, Inherited=false)]
  3504. public class FooAttribute : Attribute
  3505. {
  3506. }
  3507. public class BarAttribute : FooAttribute
  3508. {
  3509. }
  3510. [BarAttribute]
  3511. class BA : A
  3512. {
  3513. }
  3514. class BBA : BA
  3515. {
  3516. }
  3517. class CA : A
  3518. {
  3519. }
  3520. [AttributeUsage (AttributeTargets.Class, Inherited=true)]
  3521. public class InheritAttribute : Attribute
  3522. {
  3523. }
  3524. [AttributeUsage (AttributeTargets.Class, Inherited=false)]
  3525. public class NotInheritAttribute : InheritAttribute
  3526. {
  3527. }
  3528. [NotInheritAttribute]
  3529. public class bug82431A1
  3530. {
  3531. }
  3532. public class bug82431A2 : bug82431A1
  3533. {
  3534. }
  3535. [NotInheritAttribute]
  3536. [InheritAttribute]
  3537. public class bug82431A3 : bug82431A1
  3538. {
  3539. }
  3540. [InheritAttribute]
  3541. public class bug82431B1
  3542. {
  3543. }
  3544. public class bug82431B2 : bug82431B1
  3545. {
  3546. }
  3547. [NotInheritAttribute]
  3548. public class bug82431B3 : bug82431B2
  3549. {
  3550. }
  3551. public class bug82431B4 : bug82431B3
  3552. {
  3553. }
  3554. struct FooStruct
  3555. {
  3556. }
  3557. public class Bug77367
  3558. {
  3559. public void Run (bool b)
  3560. {
  3561. }
  3562. }
  3563. public class Blue
  3564. {
  3565. private string PrivInstBlue
  3566. {
  3567. get { return null; }
  3568. }
  3569. protected string ProtInstBlue
  3570. {
  3571. get { return null; }
  3572. }
  3573. protected internal string ProIntInstBlue
  3574. {
  3575. get { return null; }
  3576. }
  3577. public long PubInstBlue
  3578. {
  3579. get
  3580. {
  3581. if (PrivInstBlue == null)
  3582. return 0;
  3583. return long.MaxValue;
  3584. }
  3585. }
  3586. internal int IntInstBlue
  3587. {
  3588. get { return 0; }
  3589. }
  3590. private static string PrivStatBlue
  3591. {
  3592. get { return null; }
  3593. }
  3594. protected static string ProtStatBlue
  3595. {
  3596. get { return null; }
  3597. }
  3598. protected static internal string ProIntStatBlue
  3599. {
  3600. get { return null; }
  3601. }
  3602. public static long PubStatBlue
  3603. {
  3604. get
  3605. {
  3606. if (PrivStatBlue == null)
  3607. return 0;
  3608. return long.MaxValue;
  3609. }
  3610. }
  3611. internal static int IntStatBlue
  3612. {
  3613. get { return 0; }
  3614. }
  3615. }
  3616. public class Foo : Blue
  3617. {
  3618. private string PrivInstBase
  3619. {
  3620. get { return null; }
  3621. }
  3622. protected string ProtInstBase
  3623. {
  3624. get { return null; }
  3625. }
  3626. protected internal string ProIntInstBase
  3627. {
  3628. get { return null; }
  3629. }
  3630. public long PubInstBase
  3631. {
  3632. get
  3633. {
  3634. if (PrivInstBase == null)
  3635. return 0;
  3636. return long.MaxValue;
  3637. }
  3638. }
  3639. internal int IntInstBase
  3640. {
  3641. get { return 0; }
  3642. }
  3643. private static string PrivStatBase
  3644. {
  3645. get { return null; }
  3646. }
  3647. protected static string ProtStatBase
  3648. {
  3649. get { return null; }
  3650. }
  3651. protected static internal string ProIntStatBase
  3652. {
  3653. get { return null; }
  3654. }
  3655. public static long PubStatBase
  3656. {
  3657. get
  3658. {
  3659. if (PrivStatBase == null)
  3660. return 0;
  3661. return long.MaxValue;
  3662. }
  3663. }
  3664. internal static int IntStatBase
  3665. {
  3666. get { return 0; }
  3667. }
  3668. }
  3669. public class Bar : Foo
  3670. {
  3671. private string PrivInst
  3672. {
  3673. get { return null; }
  3674. }
  3675. protected string ProtInst
  3676. {
  3677. get { return null; }
  3678. }
  3679. protected internal string ProIntInst
  3680. {
  3681. get { return null; }
  3682. }
  3683. public long PubInst
  3684. {
  3685. get
  3686. {
  3687. if (PrivInst == null)
  3688. return 0;
  3689. return long.MaxValue;
  3690. }
  3691. }
  3692. internal int IntInst
  3693. {
  3694. get { return 0; }
  3695. }
  3696. private static string PrivStat
  3697. {
  3698. get { return null; }
  3699. }
  3700. protected static string ProtStat
  3701. {
  3702. get { return null; }
  3703. }
  3704. protected static internal string ProIntStat
  3705. {
  3706. get { return null; }
  3707. }
  3708. public static long PubStat
  3709. {
  3710. get
  3711. {
  3712. if (PrivStat == null)
  3713. return 0;
  3714. return long.MaxValue;
  3715. }
  3716. }
  3717. internal static int IntStat
  3718. {
  3719. get { return 0; }
  3720. }
  3721. }
  3722. class CtorsA
  3723. {
  3724. static CtorsA ()
  3725. {
  3726. }
  3727. }
  3728. class CtorsB
  3729. {
  3730. public CtorsB ()
  3731. {
  3732. }
  3733. }
  3734. class CtorsC
  3735. {
  3736. static CtorsC ()
  3737. {
  3738. }
  3739. public CtorsC (int x)
  3740. {
  3741. }
  3742. }
  3743. }
  3744. class UserType : Type
  3745. {
  3746. protected Type type;
  3747. public UserType(Type type) {
  3748. this.type = type;
  3749. }
  3750. public override Type UnderlyingSystemType { get { return this.type; } }
  3751. public override Assembly Assembly { get { return this.type == null ? null : this.type.Assembly; } }
  3752. public override string AssemblyQualifiedName { get { return null; } }
  3753. public override Type BaseType { get { return null; } }
  3754. public override Module Module { get { return this.type.Module; } }
  3755. public override string Namespace { get { return null; } }
  3756. public override bool IsGenericParameter { get { return true; } }
  3757. public override RuntimeTypeHandle TypeHandle { get { throw new NotSupportedException(); } }
  3758. public override bool ContainsGenericParameters { get { return true; } }
  3759. public override string FullName { get { return this.type.Name; } }
  3760. public override Guid GUID { get { throw new NotSupportedException(); } }
  3761. protected override bool IsArrayImpl() {
  3762. return false;
  3763. }
  3764. protected override bool IsByRefImpl()
  3765. {
  3766. return false;
  3767. }
  3768. protected override bool IsCOMObjectImpl()
  3769. {
  3770. return false;
  3771. }
  3772. protected override bool IsPointerImpl()
  3773. {
  3774. return false;
  3775. }
  3776. protected override bool IsPrimitiveImpl()
  3777. {
  3778. return false;
  3779. }
  3780. protected override TypeAttributes GetAttributeFlagsImpl()
  3781. {
  3782. return 0;
  3783. }
  3784. protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder,
  3785. CallingConventions callConvention, Type[] types,
  3786. ParameterModifier[] modifiers)
  3787. {
  3788. return null;
  3789. }
  3790. public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
  3791. {
  3792. return null;
  3793. }
  3794. public override Type GetElementType()
  3795. {
  3796. return null;
  3797. }
  3798. public override EventInfo GetEvent(string name, BindingFlags bindingAttr)
  3799. {
  3800. return null;
  3801. }
  3802. public override FieldInfo GetField(string name, BindingFlags bindingAttr)
  3803. {
  3804. return null;
  3805. }
  3806. public override Type GetInterface(string name, bool ignoreCase)
  3807. {
  3808. return null;
  3809. }
  3810. public override Type[] GetInterfaces()
  3811. {
  3812. return null;
  3813. }
  3814. public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
  3815. {
  3816. return null;
  3817. }
  3818. public override object[] GetCustomAttributes(Type attributeType, bool inherit)
  3819. {
  3820. return null;
  3821. }
  3822. public override object[] GetCustomAttributes(bool inherit)
  3823. {
  3824. return null;
  3825. }
  3826. public override bool IsDefined(Type attributeType, bool inherit)
  3827. {
  3828. return false;
  3829. }
  3830. public override string Name { get { return this.type.Name; } }
  3831. public override EventInfo[] GetEvents(BindingFlags bindingAttr)
  3832. {
  3833. throw new NotImplementedException();
  3834. }
  3835. public override FieldInfo[] GetFields(BindingFlags bindingAttr)
  3836. {
  3837. throw new NotImplementedException();
  3838. }
  3839. protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder,
  3840. CallingConventions callConvention, Type[] types,
  3841. ParameterModifier[] modifiers)
  3842. {
  3843. return null;
  3844. }
  3845. public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
  3846. {
  3847. return null;
  3848. }
  3849. public override Type GetNestedType(string name, BindingFlags bindingAttr)
  3850. {
  3851. return null;
  3852. }
  3853. public override Type[] GetNestedTypes(BindingFlags bindingAttr)
  3854. {
  3855. return null;
  3856. }
  3857. public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
  3858. {
  3859. return null;
  3860. }
  3861. protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder,
  3862. Type returnType, Type[] types, ParameterModifier[] modifiers)
  3863. {
  3864. return null;
  3865. }
  3866. protected override bool HasElementTypeImpl()
  3867. {
  3868. return false;
  3869. }
  3870. public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target,
  3871. object[] args, ParameterModifier[] modifiers, CultureInfo culture,
  3872. string[] namedParameters)
  3873. {
  3874. throw new NotSupportedException();
  3875. }
  3876. }
  3877. class UserType2 : UserType {
  3878. public UserType2 (Type type) : base (type) {
  3879. }
  3880. public override Type UnderlyingSystemType { get { return this.type ?? this; } }
  3881. public override int GetHashCode()
  3882. {
  3883. if (type == null)
  3884. return 42;
  3885. return type.GetHashCode();
  3886. }
  3887. }
  3888. }