MethodInfoTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // System.Reflection.MethodInfo Test Cases
  3. //
  4. // Authors:
  5. // Zoltan Varga ([email protected])
  6. //
  7. // (c) 2003 Ximian, Inc. (http://www.ximian.com)
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Threading;
  32. using System.Reflection;
  33. using System.Runtime.InteropServices;
  34. using System.Runtime.CompilerServices;
  35. #if NET_2_0
  36. using System.Collections.Generic;
  37. #endif
  38. namespace MonoTests.System.Reflection
  39. {
  40. [TestFixture]
  41. public class MethodInfoTest
  42. {
  43. #if !TARGET_JVM
  44. [DllImport ("libfoo", EntryPoint="foo", CharSet=CharSet.Unicode, ExactSpelling=false, PreserveSig=true, SetLastError=true, BestFitMapping=true, ThrowOnUnmappableChar=true)]
  45. public static extern void dllImportMethod ();
  46. #endif
  47. [MethodImplAttribute(MethodImplOptions.PreserveSig)]
  48. public void preserveSigMethod ()
  49. {
  50. }
  51. [MethodImplAttribute(MethodImplOptions.Synchronized)]
  52. public void synchronizedMethod ()
  53. {
  54. }
  55. [Test]
  56. public void IsDefined_AttributeType_Null ()
  57. {
  58. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo");
  59. try {
  60. mi.IsDefined ((Type) null, false);
  61. Assert.Fail ("#1");
  62. } catch (ArgumentNullException ex) {
  63. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  64. Assert.IsNull (ex.InnerException, "#3");
  65. Assert.IsNotNull (ex.Message, "#4");
  66. Assert.IsNotNull (ex.ParamName, "#5");
  67. Assert.AreEqual ("attributeType", ex.ParamName, "#6");
  68. }
  69. }
  70. #if NET_2_0
  71. [Test]
  72. public void PseudoCustomAttributes ()
  73. {
  74. Type t = typeof (MethodInfoTest);
  75. DllImportAttribute attr = (DllImportAttribute)((t.GetMethod ("dllImportMethod").GetCustomAttributes (typeof (DllImportAttribute), true)) [0]);
  76. Assert.AreEqual (CallingConvention.Winapi, attr.CallingConvention, "#1");
  77. Assert.AreEqual ("foo", attr.EntryPoint, "#2");
  78. Assert.AreEqual ("libfoo", attr.Value, "#3");
  79. Assert.AreEqual (CharSet.Unicode, attr.CharSet, "#4");
  80. Assert.AreEqual (false, attr.ExactSpelling, "#5");
  81. Assert.AreEqual (true, attr.PreserveSig, "#6");
  82. Assert.AreEqual (true, attr.SetLastError, "#7");
  83. Assert.AreEqual (true, attr.BestFitMapping, "#8");
  84. Assert.AreEqual (true, attr.ThrowOnUnmappableChar, "#9");
  85. PreserveSigAttribute attr2 = (PreserveSigAttribute)((t.GetMethod ("preserveSigMethod").GetCustomAttributes (true)) [0]);
  86. // This doesn't work under MS.NET
  87. /*
  88. MethodImplAttribute attr3 = (MethodImplAttribute)((t.GetMethod ("synchronizedMethod").GetCustomAttributes (true)) [0]);
  89. */
  90. }
  91. [return: MarshalAs (UnmanagedType.Interface)]
  92. public void ReturnTypeMarshalAs ()
  93. {
  94. }
  95. [Test]
  96. [Category ("TargetJvmNotWorking")]
  97. public void ReturnTypePseudoCustomAttributes ()
  98. {
  99. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ReturnTypeMarshalAs");
  100. Assert.IsTrue (mi.ReturnTypeCustomAttributes.GetCustomAttributes (typeof (MarshalAsAttribute), true).Length == 1);
  101. }
  102. #endif
  103. public static int foo (int i, int j)
  104. {
  105. return i + j;
  106. }
  107. [Test]
  108. public void StaticInvokeWithObject ()
  109. {
  110. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo");
  111. mi.Invoke (new Object (), new object [] { 1, 2 });
  112. }
  113. [Test]
  114. public void ByRefInvoke ()
  115. {
  116. MethodInfo met = typeof(MethodInfoTest).GetMethod ("ByRefTest");
  117. object[] parms = new object[] {1};
  118. met.Invoke (null, parms);
  119. Assert.AreEqual (2, parms[0]);
  120. }
  121. public static void ByRefTest (ref int a1)
  122. {
  123. if (a1 == 1)
  124. a1 = 2;
  125. }
  126. static int byref_arg;
  127. public static void ByrefVtype (ref int i) {
  128. byref_arg = i;
  129. i = 5;
  130. }
  131. [Test]
  132. #if ONLY_1_1
  133. [Category ("NotDotNet")] // #A2 fails on MS.NET 1.x
  134. #endif
  135. public void ByrefVtypeInvoke ()
  136. {
  137. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ByrefVtype");
  138. object o = 1;
  139. object[] args = new object [] { o };
  140. mi.Invoke (null, args);
  141. Assert.AreEqual (1, byref_arg, "#A1");
  142. Assert.AreEqual (1, o, "#A2");
  143. Assert.AreEqual (5, args[0], "#A3");
  144. args [0] = null;
  145. mi.Invoke (null, args);
  146. Assert.AreEqual (0, byref_arg, "#B1");
  147. Assert.AreEqual (5, args[0], "#B2");
  148. }
  149. public void HeyHey (out string out1, ref string ref1)
  150. {
  151. out1 = null;
  152. }
  153. [Test] // bug #81538
  154. public void InvokeThreadAbort ()
  155. {
  156. MethodInfo method = typeof (MethodInfoTest).GetMethod ("AbortIt");
  157. try {
  158. method.Invoke (null, new object [0]);
  159. Assert.Fail ("#1");
  160. }
  161. #if NET_2_0
  162. catch (ThreadAbortException ex) {
  163. Thread.ResetAbort ();
  164. Assert.IsNull (ex.InnerException, "#2");
  165. }
  166. #else
  167. catch (TargetInvocationException ex) {
  168. Thread.ResetAbort ();
  169. Assert.IsNotNull (ex.InnerException, "#2");
  170. Assert.AreEqual (typeof (ThreadAbortException), ex.InnerException.GetType (), "#3");
  171. }
  172. #endif
  173. }
  174. public static void AbortIt ()
  175. {
  176. Thread.CurrentThread.Abort ();
  177. }
  178. [Test] // bug #76541
  179. public void ToStringByRef ()
  180. {
  181. Assert.AreEqual ("Void HeyHey(System.String ByRef, System.String ByRef)",
  182. this.GetType ().GetMethod ("HeyHey").ToString ());
  183. }
  184. #if NET_2_0
  185. [Test]
  186. public void ToStringGenericMethod ()
  187. {
  188. Assert.AreEqual ("System.Collections.ObjectModel.ReadOnlyCollection`1[T] AsReadOnly[T](T[])",
  189. typeof (Array).GetMethod ("AsReadOnly").ToString ());
  190. }
  191. #endif
  192. class GBD_A { public virtual void f () {} }
  193. class GBD_B : GBD_A { public override void f () {} }
  194. class GBD_C : GBD_B { public override void f () {} }
  195. class GBD_D : GBD_C { public new virtual void f () {} }
  196. class GBD_E : GBD_D { public override void f () {} }
  197. [Test]
  198. public void GetBaseDefinition ()
  199. {
  200. Assert.AreEqual (typeof (GBD_A), typeof (GBD_C).GetMethod ("f").GetBaseDefinition ().DeclaringType);
  201. Assert.AreEqual (typeof (GBD_D), typeof (GBD_D).GetMethod ("f").GetBaseDefinition ().DeclaringType);
  202. Assert.AreEqual (typeof (GBD_D), typeof (GBD_E).GetMethod ("f").GetBaseDefinition ().DeclaringType);
  203. }
  204. #if NET_2_0
  205. #if !TARGET_JVM // MethodBody is not supported for TARGET_JVM
  206. [Test]
  207. public void GetMethodBody_Abstract ()
  208. {
  209. MethodBody mb = typeof (ICloneable).GetMethod ("Clone").GetMethodBody ();
  210. Assert.IsNull (mb);
  211. }
  212. [Test]
  213. public void GetMethodBody_Runtime ()
  214. {
  215. MethodBody mb = typeof (AsyncCallback).GetMethod ("Invoke").GetMethodBody ();
  216. Assert.IsNull (mb);
  217. }
  218. [Test]
  219. public void GetMethodBody_Pinvoke ()
  220. {
  221. MethodBody mb = typeof (MethodInfoTest).GetMethod ("dllImportMethod").GetMethodBody ();
  222. Assert.IsNull (mb);
  223. }
  224. [Test]
  225. public void GetMethodBody_Icall ()
  226. {
  227. foreach (MethodInfo mi in typeof (object).GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance))
  228. if ((mi.GetMethodImplementationFlags () & MethodImplAttributes.InternalCall) != 0) {
  229. MethodBody mb = mi.GetMethodBody ();
  230. Assert.IsNull (mb);
  231. }
  232. }
  233. public static void locals_method ()
  234. {
  235. byte[] b = new byte [10];
  236. unsafe {
  237. /* This generates a pinned local */
  238. fixed (byte *p = &b [0]) {
  239. }
  240. }
  241. }
  242. [Test]
  243. public void GetMethodBody ()
  244. {
  245. MethodBody mb = typeof (MethodInfoTest).GetMethod ("locals_method").GetMethodBody ();
  246. Assert.IsTrue (mb.InitLocals, "#1");
  247. Assert.IsTrue (mb.LocalSignatureMetadataToken > 0, "#2");
  248. IList<LocalVariableInfo> locals = mb.LocalVariables;
  249. // This might break with different compilers etc.
  250. Assert.AreEqual (2, locals.Count, "#3");
  251. Assert.IsTrue ((locals [0].LocalType == typeof (byte[])) || (locals [1].LocalType == typeof (byte[])), "#4");
  252. if (locals [0].LocalType == typeof (byte[]))
  253. Assert.AreEqual (false, locals [0].IsPinned, "#5");
  254. else
  255. Assert.AreEqual (false, locals [1].IsPinned, "#6");
  256. }
  257. #endif // TARGET_JVM
  258. public int return_parameter_test ()
  259. {
  260. return 0;
  261. }
  262. [Test]
  263. public void GetMethodFromHandle_Generic ()
  264. {
  265. MethodHandleTest<int> test = new MethodHandleTest<int> ();
  266. RuntimeMethodHandle mh = test.GetType ().GetProperty ("MyList")
  267. .GetGetMethod ().MethodHandle;
  268. MethodBase mb = MethodInfo.GetMethodFromHandle (mh,
  269. typeof (MethodHandleTest<int>).TypeHandle);
  270. Assert.IsNotNull (mb, "#1");
  271. List<int> list = (List<int>) mb.Invoke (test, null);
  272. Assert.IsNotNull (list, "#2");
  273. Assert.AreEqual (1, list.Count, "#3");
  274. }
  275. [Test]
  276. public void ReturnParameter ()
  277. {
  278. ParameterInfo pi = typeof (MethodInfoTest).GetMethod ("return_parameter_test").ReturnParameter;
  279. Assert.AreEqual (typeof (int), pi.ParameterType, "#1");
  280. Assert.AreEqual (-1, pi.Position, "#2");
  281. // MS always return false here
  282. //Assert.IsTrue (pi.IsRetval, "#3");
  283. }
  284. #if !TARGET_JVM // ReflectionOnly is not supported yet on TARGET_JVM
  285. [Test]
  286. public void InvokeOnRefOnlyAssembly ()
  287. {
  288. Assembly a = Assembly.ReflectionOnlyLoad (typeof (MethodInfoTest).Assembly.FullName);
  289. Type t = a.GetType (typeof (RefOnlyMethodClass).FullName);
  290. MethodInfo m = t.GetMethod ("RefOnlyMethod", BindingFlags.Static | BindingFlags.NonPublic);
  291. try {
  292. m.Invoke (null, new object [0]);
  293. Assert.Fail ("#1");
  294. } catch (InvalidOperationException ex) {
  295. // The requested operation is invalid in the
  296. // ReflectionOnly context
  297. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  298. Assert.IsNull (ex.InnerException, "#3");
  299. Assert.IsNotNull (ex.Message, "#4");
  300. }
  301. }
  302. #endif // TARGET_JVM
  303. [Test]
  304. public void InvokeGenericVtype ()
  305. {
  306. KeyValuePair<string, uint> kvp = new KeyValuePair<string, uint> ("a", 21);
  307. Type type = kvp.GetType ();
  308. Type [] arguments = type.GetGenericArguments ();
  309. MethodInfo method = typeof (MethodInfoTest).GetMethod ("Go");
  310. MethodInfo generic_method = method.MakeGenericMethod (arguments);
  311. kvp = (KeyValuePair<string, uint>)generic_method.Invoke (null, new object [] { kvp });
  312. Assert.AreEqual ("a", kvp.Key, "#1");
  313. Assert.AreEqual (21, kvp.Value, "#2");
  314. }
  315. public static KeyValuePair<T1, T2> Go <T1, T2> (KeyValuePair <T1, T2> kvp)
  316. {
  317. return kvp;
  318. }
  319. [Test] // bug #81997
  320. public void InvokeGenericInst ()
  321. {
  322. List<string> str = null;
  323. object [] methodArgs = new object [] { str };
  324. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("GenericRefMethod");
  325. mi.Invoke (null, methodArgs);
  326. Assert.IsNotNull (methodArgs [0], "#A1");
  327. Assert.IsNull (str, "#A2");
  328. Assert.IsTrue (methodArgs [0] is List<string>, "#A3");
  329. List<string> refStr = methodArgs [0] as List<string>;
  330. Assert.IsNotNull (refStr, "#B1");
  331. Assert.AreEqual (1, refStr.Count, "#B2");
  332. Assert.AreEqual ("test", refStr [0], "#B3");
  333. }
  334. public static void GenericRefMethod (ref List<string> strArg)
  335. {
  336. strArg = new List<string> ();
  337. strArg.Add ("test");
  338. }
  339. public void MakeGenericMethodArgsMismatchFoo<T> ()
  340. {
  341. }
  342. [Test]
  343. public void MakeGenericMethodArgsMismatch ()
  344. {
  345. MethodInfo gmi = this.GetType ().GetMethod (
  346. "MakeGenericMethodArgsMismatchFoo");
  347. try {
  348. gmi.MakeGenericMethod ();
  349. Assert.Fail ("#1");
  350. } catch (ArgumentException ex) {
  351. // The type or method has 1 generic parameter(s),
  352. // but 0 generic argument(s) were provided. A
  353. // generic argument must be provided for each
  354. // generic parameter
  355. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  356. Assert.IsNull (ex.InnerException, "#3");
  357. Assert.IsNotNull (ex.Message, "#4");
  358. Assert.IsNull (ex.ParamName, "#5");
  359. }
  360. }
  361. public void SimpleGenericMethod<TFoo, TBar> () {}
  362. [Test]
  363. public void MakeGenericMethodWithNullArray ()
  364. {
  365. MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
  366. try {
  367. gmi.MakeGenericMethod ((Type []) null);
  368. Assert.Fail ("#1");
  369. } catch (ArgumentNullException ex) {
  370. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  371. Assert.IsNull (ex.InnerException, "#3");
  372. Assert.IsNotNull (ex.Message, "#4");
  373. Assert.AreEqual ("methodInstantiation", ex.ParamName, "#5");
  374. }
  375. }
  376. [Test]
  377. public void MakeGenericMethodWithNullValueInTypesArray ()
  378. {
  379. MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
  380. try {
  381. gmi.MakeGenericMethod (new Type [] { typeof (int), null });
  382. Assert.Fail ("#1");
  383. } catch (ArgumentNullException ex) {
  384. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  385. Assert.IsNull (ex.InnerException, "#3");
  386. Assert.IsNotNull (ex.Message, "#4");
  387. Assert.IsNull (ex.ParamName, "#5");
  388. }
  389. }
  390. public static int? pass_nullable (int? i)
  391. {
  392. return i;
  393. }
  394. [Test]
  395. public void NullableTests ()
  396. {
  397. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("pass_nullable");
  398. Assert.AreEqual (102, mi.Invoke (null, new object [] { 102 }), "#1");
  399. Assert.AreEqual (null, mi.Invoke (null, new object [] { null }), "#2");
  400. // Test conversion of vtype to a nullable type for the this argument
  401. PropertyInfo pi = typeof (Nullable <int>).GetProperty ("HasValue");
  402. Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
  403. PropertyInfo pi2 = typeof (Nullable <int>).GetProperty ("Value");
  404. Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
  405. }
  406. public static void foo_generic<T> ()
  407. {
  408. }
  409. [Test]
  410. public void IsGenericMethod ()
  411. {
  412. MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo_generic");
  413. Assert.AreEqual (true, mi.IsGenericMethod, "#1");
  414. MethodInfo mi2 = mi.MakeGenericMethod (new Type[] { typeof (int) });
  415. Assert.AreEqual (true, mi2.IsGenericMethod, "#2");
  416. MethodInfo mi3 = typeof (GenericHelper<int>).GetMethod ("Test");
  417. Assert.AreEqual (false, mi3.IsGenericMethod, "#3");
  418. }
  419. class A<T>
  420. {
  421. public static void Foo<T2> (T2 i)
  422. {
  423. }
  424. public static void Bar ()
  425. {
  426. }
  427. public class B
  428. {
  429. public static void Baz ()
  430. {
  431. }
  432. }
  433. }
  434. [Test]
  435. public void ContainsGenericParameters ()
  436. {
  437. // Non-generic method in open generic type
  438. Assert.IsTrue (typeof (A<int>).GetGenericTypeDefinition ().GetMethod ("Bar").ContainsGenericParameters);
  439. // open generic method in closed generic type
  440. Assert.IsTrue (typeof (A<int>).GetMethod ("Foo").ContainsGenericParameters);
  441. // non-generic method in closed generic type
  442. Assert.IsFalse (typeof (A<int>).GetMethod ("Bar").ContainsGenericParameters);
  443. // closed generic method in closed generic type
  444. Assert.IsFalse (typeof (A<int>).GetMethod ("Foo").MakeGenericMethod (new Type [] { typeof (int) }).ContainsGenericParameters);
  445. // non-generic method in non-generic nested type of closed generic type
  446. Assert.IsFalse (typeof (A<int>.B).GetMethod ("Baz").ContainsGenericParameters);
  447. // non-generic method in non-generic nested type of open generic type
  448. Assert.IsTrue (typeof (A<int>.B).GetGenericTypeDefinition ().GetMethod ("Baz").ContainsGenericParameters);
  449. }
  450. [Test]
  451. public void IsGenericMethodDefinition ()
  452. {
  453. MethodInfo m1 = typeof (A<>).GetMethod ("Foo");
  454. Assert.IsTrue (m1.IsGenericMethod, "#A1");
  455. Assert.IsTrue (m1.IsGenericMethodDefinition, "#A2");
  456. MethodInfo m2 = typeof (A<int>).GetMethod ("Foo");
  457. Assert.IsTrue (m2.IsGenericMethod, "#B1");
  458. Assert.IsTrue (m2.IsGenericMethodDefinition, "#B2");
  459. MethodInfo m3 = m2.MakeGenericMethod (typeof (int));
  460. Assert.IsTrue (m3.IsGenericMethod, "#C1");
  461. Assert.IsFalse (m3.IsGenericMethodDefinition, "#C2");
  462. }
  463. [Test]
  464. public void GetGenericMethodDefinition ()
  465. {
  466. MethodInfo mi1 = typeof (MyList<>).GetMethod ("ConvertAll");
  467. MethodInfo mi2 = typeof (MyList<int>).GetMethod ("ConvertAll");
  468. Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[T,TOutput]",
  469. mi1.GetParameters () [0].ParameterType.ToString (), "#A1");
  470. Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[System.Int32,TOutput]",
  471. mi2.GetParameters () [0].ParameterType.ToString (), "#A2");
  472. Assert.IsTrue (mi1.IsGenericMethod, "#A3");
  473. Assert.IsTrue (mi1.IsGenericMethodDefinition, "#A4");
  474. Assert.IsTrue (mi2.IsGenericMethod, "#A5");
  475. Assert.IsTrue (mi2.IsGenericMethodDefinition, "#A6");
  476. MethodInfo mi3 = mi2.GetGenericMethodDefinition ();
  477. Assert.IsTrue (mi3.IsGenericMethod, "#B1");
  478. Assert.IsTrue (mi3.IsGenericMethodDefinition, "#B2");
  479. Assert.AreSame (mi2, mi3, "#B3");
  480. }
  481. public class MyList<T>
  482. {
  483. public TOutput ConvertAll<TOutput> (Foo<T,TOutput> arg)
  484. {
  485. return default (TOutput);
  486. }
  487. public T ConvertAll2 (MyList<T> arg)
  488. {
  489. return default (T);
  490. }
  491. }
  492. public class Foo<T,TOutput>
  493. {
  494. }
  495. class GenericHelper<T>
  496. {
  497. public void Test (T t)
  498. {
  499. }
  500. }
  501. #endif
  502. }
  503. #if NET_2_0
  504. // Helper class
  505. class RefOnlyMethodClass
  506. {
  507. // Helper static method
  508. static void RefOnlyMethod ()
  509. {
  510. }
  511. }
  512. public class MethodHandleTest<T>
  513. {
  514. private List<T> _myList = new List<T> ();
  515. public MethodHandleTest ()
  516. {
  517. _myList.Add (default (T));
  518. }
  519. public List<T> MyList {
  520. get { return _myList; }
  521. set { _myList = value; }
  522. }
  523. }
  524. #endif
  525. }