FieldInfoTest.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. //
  2. // FieldInfoTest - NUnit Test Cases for the FieldInfo class
  3. //
  4. // Authors:
  5. // Zoltan Varga ([email protected])
  6. // Gert Driesen ([email protected])
  7. //
  8. // (c) 2003 Ximian, Inc. (http://www.ximian.com)
  9. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Threading;
  32. using System.Reflection;
  33. #if !TARGET_JVM
  34. using System.Reflection.Emit;
  35. #endif // TARGET_JVM
  36. using System.Runtime.InteropServices;
  37. using NUnit.Framework;
  38. namespace MonoTests.System.Reflection
  39. {
  40. [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
  41. public class Class1
  42. {
  43. [FieldOffset (32)]
  44. public int i;
  45. }
  46. [StructLayout(LayoutKind.Sequential)]
  47. public class Class2
  48. {
  49. [MarshalAsAttribute(UnmanagedType.Bool)]
  50. public int f0;
  51. [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]
  52. public string[] f1;
  53. [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
  54. public string f2;
  55. [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof (Marshal1), MarshalCookie="5")]
  56. public int f3;
  57. [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
  58. public object f4;
  59. [Obsolete]
  60. public int f5;
  61. }
  62. public class Class3 : Class2
  63. {
  64. }
  65. [TestFixture]
  66. public class FieldInfoTest
  67. {
  68. [NonSerialized]
  69. public int i;
  70. [Test]
  71. public void IsDefined_AttributeType_Null ()
  72. {
  73. Type type = typeof (FieldInfoTest);
  74. FieldInfo field = type.GetField ("i");
  75. try {
  76. field.IsDefined ((Type) null, false);
  77. Assert.Fail ("#1");
  78. } catch (ArgumentNullException ex) {
  79. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  80. Assert.IsNull (ex.InnerException, "#3");
  81. Assert.IsNotNull (ex.Message, "#4");
  82. Assert.IsNotNull (ex.ParamName, "#5");
  83. Assert.AreEqual ("attributeType", ex.ParamName, "#6");
  84. }
  85. }
  86. [Test]
  87. public void GetCustomAttributes ()
  88. {
  89. object [] attrs;
  90. FieldInfo fi;
  91. fi = typeof (Class2).GetField ("f5");
  92. attrs = fi.GetCustomAttributes (false);
  93. Assert.AreEqual (1, attrs.Length, "#B1");
  94. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B2");
  95. attrs = fi.GetCustomAttributes (true);
  96. Assert.AreEqual (1, attrs.Length, "#B3");
  97. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B4");
  98. attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), false);
  99. Assert.AreEqual (0, attrs.Length, "#B5");
  100. attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), true);
  101. Assert.AreEqual (0, attrs.Length, "#B6");
  102. attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), false);
  103. Assert.AreEqual (1, attrs.Length, "#B7");
  104. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B8");
  105. attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), true);
  106. Assert.AreEqual (1, attrs.Length, "#B9");
  107. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B10");
  108. fi = typeof (Class3).GetField ("f5");
  109. attrs = fi.GetCustomAttributes (false);
  110. Assert.AreEqual (1, attrs.Length, "#D1");
  111. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D2");
  112. attrs = fi.GetCustomAttributes (true);
  113. Assert.AreEqual (1, attrs.Length, "#D3");
  114. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D4");
  115. attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), false);
  116. Assert.AreEqual (0, attrs.Length, "#D5");
  117. attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), true);
  118. Assert.AreEqual (0, attrs.Length, "#D6");
  119. attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), false);
  120. Assert.AreEqual (1, attrs.Length, "#D7");
  121. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D8");
  122. attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), true);
  123. Assert.AreEqual (1, attrs.Length, "#D9");
  124. Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D10");
  125. }
  126. [Test] // GetFieldFromHandle (RuntimeFieldHandle)
  127. public void GetFieldFromHandle1_Handle_Zero ()
  128. {
  129. RuntimeFieldHandle fh = new RuntimeFieldHandle ();
  130. try {
  131. FieldInfo.GetFieldFromHandle (fh);
  132. Assert.Fail ("#1");
  133. } catch (ArgumentException ex) {
  134. // Handle is not initialized
  135. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  136. Assert.IsNull (ex.InnerException, "#3");
  137. Assert.IsNotNull (ex.Message, "#4");
  138. Assert.IsNull (ex.ParamName, "#5");
  139. }
  140. }
  141. #if NET_2_0
  142. [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
  143. public void GetFieldFromHandle2_DeclaringType_Zero ()
  144. {
  145. RuntimeTypeHandle th = new RuntimeTypeHandle ();
  146. FieldInfo fi1 = typeof (Class2).GetField ("f5");
  147. RuntimeFieldHandle fh = fi1.FieldHandle;
  148. FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
  149. Assert.IsNotNull (fi2, "#1");
  150. Assert.AreSame (fi1.DeclaringType, fi2.DeclaringType, "#2");
  151. Assert.AreEqual (fi1.FieldType, fi2.FieldType, "#3");
  152. Assert.AreEqual (fi1.Name, fi2.Name, "#4");
  153. }
  154. [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
  155. public void GetFieldFromHandle2_Handle_Generic ()
  156. {
  157. FieldInfoTest<string> instance = new FieldInfoTest<string> ();
  158. Type t = instance.GetType ();
  159. FieldInfo fi1 = t.GetField ("TestField");
  160. RuntimeFieldHandle fh = fi1.FieldHandle;
  161. RuntimeTypeHandle th = t.TypeHandle;
  162. FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
  163. Assert.IsNotNull (fi2, "#1");
  164. Assert.AreSame (t, fi2.DeclaringType, "#2");
  165. Assert.AreEqual (typeof (string), fi2.FieldType, "#3");
  166. Assert.AreEqual ("TestField", fi2.Name, "#4");
  167. }
  168. [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
  169. [Category ("NotWorking")]
  170. [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=343449
  171. public void GetFieldFromHandle2_Handle_GenericDefinition ()
  172. {
  173. Type t1 = typeof (FieldInfoTest<>);
  174. FieldInfo fi1 = t1.GetField ("TestField");
  175. RuntimeFieldHandle fh = fi1.FieldHandle;
  176. FieldInfoTest<string> instance = new FieldInfoTest<string> ();
  177. Type t2 = instance.GetType ();
  178. RuntimeTypeHandle th = t2.TypeHandle;
  179. FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
  180. Assert.IsNotNull (fi2, "#1");
  181. Assert.AreSame (t2, fi2.DeclaringType, "#2");
  182. Assert.AreEqual (typeof (string), fi2.FieldType, "#3");
  183. Assert.AreEqual ("TestField", fi2.Name, "#4");
  184. }
  185. [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
  186. public void GetFieldFromHandle2_Handle_Zero ()
  187. {
  188. object instance = new Class2 ();
  189. RuntimeTypeHandle th = Type.GetTypeHandle (instance);
  190. RuntimeFieldHandle fh = new RuntimeFieldHandle ();
  191. try {
  192. FieldInfo.GetFieldFromHandle (fh, th);
  193. Assert.Fail ("#1");
  194. } catch (ArgumentException ex) {
  195. // Handle is not initialized
  196. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  197. Assert.IsNull (ex.InnerException, "#3");
  198. Assert.IsNotNull (ex.Message, "#4");
  199. Assert.IsNull (ex.ParamName, "#5");
  200. }
  201. }
  202. [Test]
  203. [ExpectedException (typeof (ArgumentException))]
  204. public void GetFieldFromHandle2_Incompatible ()
  205. {
  206. RuntimeFieldHandle fh = typeof (FieldInfoTest<int>).GetField ("TestField").FieldHandle;
  207. FieldInfoTest<string> instance = new FieldInfoTest<string> ();
  208. Type t2 = instance.GetType ();
  209. RuntimeTypeHandle th = t2.TypeHandle;
  210. FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
  211. }
  212. #endif
  213. [Test]
  214. public void PseudoCustomAttributes ()
  215. {
  216. object [] attrs;
  217. Type t = typeof (FieldInfoTest);
  218. #if NET_2_0
  219. Assert.AreEqual (1, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
  220. #else
  221. Assert.AreEqual (0, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
  222. #endif
  223. attrs = typeof (Class1).GetField ("i").GetCustomAttributes (true);
  224. #if NET_2_0
  225. Assert.AreEqual (1, attrs.Length, "#B1");
  226. FieldOffsetAttribute field_attr = (FieldOffsetAttribute) attrs [0];
  227. Assert.AreEqual (32, field_attr.Value, "#B2");
  228. #else
  229. Assert.AreEqual (0, attrs.Length, "#B1");
  230. #endif
  231. MarshalAsAttribute attr;
  232. attrs = typeof (Class2).GetField ("f0").GetCustomAttributes (true);
  233. #if NET_2_0
  234. Assert.AreEqual (1, attrs.Length, "#C1");
  235. attr = (MarshalAsAttribute) attrs [0];
  236. Assert.AreEqual (UnmanagedType.Bool, attr.Value, "#C2");
  237. #else
  238. Assert.AreEqual (0, attrs.Length, "#C1");
  239. #endif
  240. attrs = typeof (Class2).GetField ("f1").GetCustomAttributes (true);
  241. #if NET_2_0
  242. Assert.AreEqual (1, attrs.Length, "#D1");
  243. attr = (MarshalAsAttribute) attrs [0];
  244. Assert.AreEqual (UnmanagedType.LPArray, attr.Value, "#D2");
  245. Assert.AreEqual (UnmanagedType.LPStr, attr.ArraySubType, "#D3");
  246. #else
  247. Assert.AreEqual (0, attrs.Length, "#D1");
  248. #endif
  249. attrs = typeof (Class2).GetField ("f2").GetCustomAttributes (true);
  250. #if NET_2_0
  251. Assert.AreEqual (1, attrs.Length, "#E1");
  252. attr = (MarshalAsAttribute) attrs [0];
  253. Assert.AreEqual (UnmanagedType.ByValTStr, attr.Value, "#E2");
  254. Assert.AreEqual (100, attr.SizeConst, "#E3");
  255. #else
  256. Assert.AreEqual (0, attrs.Length, "#E1");
  257. #endif
  258. attrs = typeof (Class2).GetField ("f3").GetCustomAttributes (true);
  259. #if NET_2_0
  260. Assert.AreEqual (1, attrs.Length, "#F1");
  261. attr = (MarshalAsAttribute) attrs [0];
  262. Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#F2");
  263. Assert.AreEqual ("5", attr.MarshalCookie, "#F3");
  264. Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#F4");
  265. #else
  266. Assert.AreEqual (0, attrs.Length, "#F1");
  267. #endif
  268. attrs = typeof (Class3).GetField ("f3").GetCustomAttributes (false);
  269. #if NET_2_0
  270. Assert.AreEqual (1, attrs.Length, "#G1");
  271. attr = (MarshalAsAttribute) attrs [0];
  272. Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#G2");
  273. Assert.AreEqual ("5", attr.MarshalCookie, "#G3");
  274. Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#G4");
  275. #else
  276. Assert.AreEqual (0, attrs.Length, "#G1");
  277. #endif
  278. attrs = typeof (Class3).GetField ("f3").GetCustomAttributes (true);
  279. #if NET_2_0
  280. Assert.AreEqual (1, attrs.Length, "#H1");
  281. attr = (MarshalAsAttribute) attrs [0];
  282. Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#H2");
  283. Assert.AreEqual ("5", attr.MarshalCookie, "#H3");
  284. Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#H4");
  285. #else
  286. Assert.AreEqual (0, attrs.Length, "#H1");
  287. #endif
  288. // bug #82465
  289. attrs = typeof (Class2).GetField ("f3").GetCustomAttributes (true);
  290. #if NET_2_0
  291. Assert.AreEqual (1, attrs.Length, "#I1");
  292. attr = (MarshalAsAttribute) attrs [0];
  293. Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#I2");
  294. Assert.AreEqual ("5", attr.MarshalCookie, "#I3");
  295. Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#I4");
  296. #else
  297. Assert.AreEqual (0, attrs.Length, "#I1");
  298. #endif
  299. }
  300. class Foo {
  301. public static int static_field;
  302. public int field;
  303. }
  304. [ExpectedException (typeof (ArgumentException))]
  305. public void GetValueWrongObject ()
  306. {
  307. Foo f = new Foo ();
  308. typeof (Foo).GetField ("field").GetValue (typeof (int));
  309. }
  310. public void GetValueWrongObjectStatic ()
  311. {
  312. Foo f = new Foo ();
  313. // This is allowed in MS.NET
  314. typeof (Foo).GetField ("static_field").GetValue (typeof (int));
  315. }
  316. #if NET_2_0
  317. #if !TARGET_JVM // ReflectionOnlyLoad not supported for TARGET_JVM
  318. [Test]
  319. [ExpectedException (typeof (InvalidOperationException))]
  320. public void GetValueOnRefOnlyAssembly ()
  321. {
  322. Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
  323. Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
  324. FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
  325. f.GetValue (null);
  326. }
  327. [Test]
  328. [ExpectedException (typeof (InvalidOperationException))]
  329. public void SetValueOnRefOnlyAssembly ()
  330. {
  331. Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
  332. Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
  333. FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
  334. f.SetValue (null, 8);
  335. }
  336. #endif // TARGET_JVM
  337. const int literal = 42;
  338. [Test]
  339. [ExpectedException (typeof (FieldAccessException))]
  340. public void SetValueOnLiteralField ()
  341. {
  342. FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
  343. f.SetValue (null, 0);
  344. }
  345. public int? nullable_field;
  346. public static int? static_nullable_field;
  347. [Test]
  348. public void NullableTests ()
  349. {
  350. FieldInfoTest t = new FieldInfoTest ();
  351. FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field");
  352. fi.SetValue (t, 101);
  353. Assert.AreEqual (101, fi.GetValue (t));
  354. fi.SetValue (t, null);
  355. Assert.AreEqual (null, fi.GetValue (t));
  356. FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field");
  357. fi2.SetValue (t, 101);
  358. Assert.AreEqual (101, fi2.GetValue (t));
  359. fi2.SetValue (t, null);
  360. Assert.AreEqual (null, fi2.GetValue (t));
  361. }
  362. #if !TARGET_JVM // TypeBuilder not supported for TARGET_JVM
  363. [Test]
  364. public void NonPublicTests ()
  365. {
  366. Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
  367. Type t = assembly.GetType (typeof (NonPublicFieldClass).FullName);
  368. // try to get non-public field
  369. FieldInfo fi = t.GetField ("protectedField");
  370. Assert.IsNull (fi);
  371. // get it for real
  372. fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
  373. Assert.IsNotNull (fi);
  374. // get via typebuilder
  375. FieldInfo f = TypeBuilder.GetField (t, fi);
  376. Assert.IsNotNull (f);
  377. }
  378. #endif // TARGET_JVM
  379. [Test]
  380. public void GetRawDefaultValue ()
  381. {
  382. Assert.AreEqual (5, typeof (FieldInfoTest).GetField ("int_field").GetRawConstantValue ());
  383. Assert.AreEqual (Int64.MaxValue, typeof (FieldInfoTest).GetField ("long_field").GetRawConstantValue ());
  384. Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ());
  385. Assert.AreEqual (typeof (int), typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ().GetType ());
  386. Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ());
  387. Assert.AreEqual (typeof (long), typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ().GetType ());
  388. Assert.AreEqual ("Hello", typeof (FieldInfoTest).GetField ("string_field").GetRawConstantValue ());
  389. Assert.AreEqual (null, typeof (FieldInfoTest).GetField ("object_field").GetRawConstantValue ());
  390. }
  391. [Test]
  392. [ExpectedException (typeof (InvalidOperationException))]
  393. public void GetRawDefaultValueNoDefault ()
  394. {
  395. typeof (FieldInfoTest).GetField ("non_const_field").GetRawConstantValue ();
  396. }
  397. #if NET_2_0
  398. [Test]
  399. [ExpectedException (typeof (InvalidOperationException))]
  400. public void GetValueOpenGeneric ()
  401. {
  402. typeof(Foo<>).GetField ("field").GetValue (null);
  403. }
  404. [Test]
  405. [ExpectedException (typeof (InvalidOperationException))]
  406. public void SetValueOpenGeneric ()
  407. {
  408. typeof(Foo<>).GetField ("field").SetValue (null, 0);
  409. }
  410. [Test]
  411. public void GetValueOnConstantOfOpenGeneric ()
  412. {
  413. Assert.AreEqual (10, typeof(Foo<>).GetField ("constant").GetValue (null), "#1");
  414. }
  415. public class Foo<T>
  416. {
  417. public static int field;
  418. public const int constant = 10;
  419. }
  420. #endif
  421. public enum IntEnum {
  422. First = 1,
  423. Second = 2,
  424. Third = 3
  425. }
  426. public enum LongEnum : long {
  427. First = 1,
  428. Second = 2,
  429. Third = 3
  430. }
  431. public const int int_field = 5;
  432. public const long long_field = Int64.MaxValue;
  433. public const IntEnum int_enum_field = IntEnum.Second;
  434. public const LongEnum long_enum_field = LongEnum.Second;
  435. public const string string_field = "Hello";
  436. public const FieldInfoTest object_field = null;
  437. public int non_const_field;
  438. #endif
  439. }
  440. #if NET_2_0
  441. // Helper classes
  442. class RefOnlyFieldClass
  443. {
  444. // Helper property
  445. static int RefOnlyField;
  446. }
  447. class NonPublicFieldClass
  448. {
  449. protected int protectedField;
  450. }
  451. public class FieldInfoTest<T>
  452. {
  453. public T TestField;
  454. }
  455. #endif
  456. }