2 // System.Reflection.MethodInfo Test Cases
5 // Zoltan Varga (vargaz@gmail.com)
7 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
32 using System.Threading;
33 using System.Reflection;
35 using System.Reflection.Emit;
37 using System.Runtime.InteropServices;
38 using System.Runtime.CompilerServices;
41 using System.Collections.Generic;
45 public struct MethodInfoTestStruct {
49 namespace MonoTests.System.Reflection
52 public class MethodInfoTest
55 [DllImport ("libfoo", EntryPoint="foo", CharSet=CharSet.Unicode, ExactSpelling=false, PreserveSig=true, SetLastError=true, BestFitMapping=true, ThrowOnUnmappableChar=true)]
56 public static extern void dllImportMethod ();
58 [MethodImplAttribute(MethodImplOptions.PreserveSig)]
59 public void preserveSigMethod ()
63 [MethodImplAttribute(MethodImplOptions.Synchronized)]
64 public void synchronizedMethod ()
69 public void IsDefined_AttributeType_Null ()
71 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo");
74 mi.IsDefined ((Type) null, false);
76 } catch (ArgumentNullException ex) {
77 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
78 Assert.IsNull (ex.InnerException, "#3");
79 Assert.IsNotNull (ex.Message, "#4");
80 Assert.IsNotNull (ex.ParamName, "#5");
81 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
86 public void TestInvokeByRefReturnMethod ()
89 MethodInfo m = typeof (int[]).GetMethod ("Address");
90 m.Invoke (new int[1], new object[] { 0 });
92 } catch (NotSupportedException e) {
93 Assert.AreEqual (typeof (NotSupportedException), e.GetType (), "#2");
94 Assert.IsNull (e.InnerException, "#3");
95 Assert.IsNotNull (e.Message, "#4");
101 public void PseudoCustomAttributes ()
103 Type t = typeof (MethodInfoTest);
105 DllImportAttribute attr = (DllImportAttribute)((t.GetMethod ("dllImportMethod").GetCustomAttributes (typeof (DllImportAttribute), true)) [0]);
107 Assert.AreEqual (CallingConvention.Winapi, attr.CallingConvention, "#1");
108 Assert.AreEqual ("foo", attr.EntryPoint, "#2");
109 Assert.AreEqual ("libfoo", attr.Value, "#3");
110 Assert.AreEqual (CharSet.Unicode, attr.CharSet, "#4");
111 Assert.AreEqual (false, attr.ExactSpelling, "#5");
112 Assert.AreEqual (true, attr.PreserveSig, "#6");
113 Assert.AreEqual (true, attr.SetLastError, "#7");
114 Assert.AreEqual (true, attr.BestFitMapping, "#8");
115 Assert.AreEqual (true, attr.ThrowOnUnmappableChar, "#9");
117 PreserveSigAttribute attr2 = (PreserveSigAttribute)((t.GetMethod ("preserveSigMethod").GetCustomAttributes (true)) [0]);
119 // This doesn't work under MS.NET
121 MethodImplAttribute attr3 = (MethodImplAttribute)((t.GetMethod ("synchronizedMethod").GetCustomAttributes (true)) [0]);
125 [return: MarshalAs (UnmanagedType.Interface)]
126 public void ReturnTypeMarshalAs ()
131 [Category ("TargetJvmNotWorking")]
132 public void ReturnTypePseudoCustomAttributes ()
134 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ReturnTypeMarshalAs");
136 Assert.IsTrue (mi.ReturnTypeCustomAttributes.GetCustomAttributes (typeof (MarshalAsAttribute), true).Length == 1);
140 public static int foo (int i, int j)
146 public void StaticInvokeWithObject ()
148 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo");
150 mi.Invoke (new Object (), new object [] { 1, 2 });
154 public void ByRefInvoke ()
156 MethodInfo met = typeof(MethodInfoTest).GetMethod ("ByRefTest");
157 object[] parms = new object[] {1};
158 met.Invoke (null, parms);
159 Assert.AreEqual (2, parms[0]);
162 public static void ByRefTest (ref int a1)
168 static int byref_arg;
170 public static void ByrefVtype (ref int i) {
177 [Category ("NotDotNet")] // #A2 fails on MS.NET 1.x
179 public void ByrefVtypeInvoke ()
181 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ByrefVtype");
184 object[] args = new object [] { o };
185 mi.Invoke (null, args);
186 Assert.AreEqual (1, byref_arg, "#A1");
187 Assert.AreEqual (1, o, "#A2");
188 Assert.AreEqual (5, args[0], "#A3");
191 mi.Invoke (null, args);
192 Assert.AreEqual (0, byref_arg, "#B1");
193 Assert.AreEqual (5, args[0], "#B2");
196 public void HeyHey (out string out1, ref DateTime ref1)
201 public void SignatureTest (__arglist)
205 public static unsafe int* PtrFunc (int* a)
211 public void InvokeThreadAbort ()
213 MethodInfo method = typeof (MethodInfoTest).GetMethod ("AbortIt");
215 method.Invoke (null, new object [0]);
219 catch (ThreadAbortException ex) {
220 Thread.ResetAbort ();
221 Assert.IsNull (ex.InnerException, "#2");
224 catch (TargetInvocationException ex) {
225 Thread.ResetAbort ();
226 Assert.IsNotNull (ex.InnerException, "#2");
227 Assert.AreEqual (typeof (ThreadAbortException), ex.InnerException.GetType (), "#3");
232 public static void AbortIt ()
234 Thread.CurrentThread.Abort ();
238 public void ToStringByRef ()
240 Assert.AreEqual ("Void HeyHey(System.String ByRef, System.DateTime ByRef)",
241 this.GetType ().GetMethod ("HeyHey").ToString ());
245 public void ToStringArgList ()
247 Assert.AreEqual ("Void SignatureTest(...)",
248 this.GetType ().GetMethod ("SignatureTest").ToString ());
252 public void ToStringWithPointerSignatures () //bug #409583
254 Assert.AreEqual ("Int32* PtrFunc(Int32*)", this.GetType ().GetMethod ("PtrFunc").ToString ());
257 public struct SimpleStruct
262 public static unsafe SimpleStruct* PtrFunc2 (SimpleStruct* a, A.B.C.MethodInfoTestStruct *b)
264 return (SimpleStruct*) 0;
268 public void ToStringWithPointerSignaturesToNonPrimitiveType ()
270 Assert.AreEqual ("SimpleStruct* PtrFunc2(SimpleStruct*, A.B.C.MethodInfoTestStruct*)",
271 this.GetType ().GetMethod ("PtrFunc2").ToString ());
274 public void ToStringGenericMethod ()
276 Assert.AreEqual ("System.Collections.ObjectModel.ReadOnlyCollection`1[T] AsReadOnly[T](T[])",
277 typeof (Array).GetMethod ("AsReadOnly").ToString ());
280 class GBD_A { public virtual void f () {} }
281 class GBD_B : GBD_A { public override void f () {} }
282 class GBD_C : GBD_B { public override void f () {} }
283 class GBD_D : GBD_C { public new virtual void f () {} }
284 class GBD_E : GBD_D { public override void f () {} }
287 public void GetBaseDefinition ()
289 Assert.AreEqual (typeof (GBD_A), typeof (GBD_C).GetMethod ("f").GetBaseDefinition ().DeclaringType);
290 Assert.AreEqual (typeof (GBD_D), typeof (GBD_D).GetMethod ("f").GetBaseDefinition ().DeclaringType);
291 Assert.AreEqual (typeof (GBD_D), typeof (GBD_E).GetMethod ("f").GetBaseDefinition ().DeclaringType);
294 class TestInheritedMethodA {
295 private void TestMethod ()
299 public void TestMethod2 ()
304 class TestInheritedMethodB : TestInheritedMethodA {
308 public void InheritanceTestGetMethodTest ()
310 MethodInfo inheritedMethod = typeof(TestInheritedMethodB).GetMethod("TestMethod", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
311 MethodInfo baseMethod = typeof(TestInheritedMethodB).GetMethod("TestMethod", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
312 Assert.AreSame (inheritedMethod, baseMethod);
314 MethodInfo inheritedMethod2 = typeof(TestInheritedMethodB).GetMethod("TestMethod2", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
315 MethodInfo baseMethod2 = typeof(TestInheritedMethodB).GetMethod("TestMethod2", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
316 Assert.AreSame (inheritedMethod, baseMethod);
320 #if !TARGET_JVM // MethodBody is not supported for TARGET_JVM
322 public void GetMethodBody_Abstract ()
324 MethodBody mb = typeof (ICloneable).GetMethod ("Clone").GetMethodBody ();
329 public void GetMethodBody_Runtime ()
331 MethodBody mb = typeof (AsyncCallback).GetMethod ("Invoke").GetMethodBody ();
336 public void GetMethodBody_Pinvoke ()
338 MethodBody mb = typeof (MethodInfoTest).GetMethod ("dllImportMethod").GetMethodBody ();
343 public void GetMethodBody_Icall ()
345 foreach (MethodInfo mi in typeof (object).GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance))
346 if ((mi.GetMethodImplementationFlags () & MethodImplAttributes.InternalCall) != 0) {
347 MethodBody mb = mi.GetMethodBody ();
352 public static void locals_method ()
354 byte[] b = new byte [10];
357 /* This generates a pinned local */
358 fixed (byte *p = &b [0]) {
364 public void GetMethodBody ()
366 MethodBody mb = typeof (MethodInfoTest).GetMethod ("locals_method").GetMethodBody ();
368 Assert.IsTrue (mb.InitLocals, "#1");
369 Assert.IsTrue (mb.LocalSignatureMetadataToken > 0, "#2");
371 IList<LocalVariableInfo> locals = mb.LocalVariables;
373 // This might break with different compilers etc.
374 Assert.AreEqual (2, locals.Count, "#3");
376 Assert.IsTrue ((locals [0].LocalType == typeof (byte[])) || (locals [1].LocalType == typeof (byte[])), "#4");
377 if (locals [0].LocalType == typeof (byte[]))
378 Assert.AreEqual (false, locals [0].IsPinned, "#5");
380 Assert.AreEqual (false, locals [1].IsPinned, "#6");
384 public int return_parameter_test ()
390 public void GetMethodFromHandle_Generic ()
392 MethodHandleTest<int> test = new MethodHandleTest<int> ();
393 RuntimeMethodHandle mh = test.GetType ().GetProperty ("MyList")
394 .GetGetMethod ().MethodHandle;
395 MethodBase mb = MethodInfo.GetMethodFromHandle (mh,
396 typeof (MethodHandleTest<int>).TypeHandle);
397 Assert.IsNotNull (mb, "#1");
398 List<int> list = (List<int>) mb.Invoke (test, null);
399 Assert.IsNotNull (list, "#2");
400 Assert.AreEqual (1, list.Count, "#3");
404 public void ReturnParameter ()
406 ParameterInfo pi = typeof (MethodInfoTest).GetMethod ("return_parameter_test").ReturnParameter;
407 Assert.AreEqual (typeof (int), pi.ParameterType, "#1");
408 Assert.AreEqual (-1, pi.Position, "#2");
409 // MS always return false here
410 //Assert.IsTrue (pi.IsRetval, "#3");
413 #if !TARGET_JVM // ReflectionOnly is not supported yet on TARGET_JVM
415 public void InvokeOnRefOnlyAssembly ()
417 Assembly a = Assembly.ReflectionOnlyLoad (typeof (MethodInfoTest).Assembly.FullName);
418 Type t = a.GetType (typeof (RefOnlyMethodClass).FullName);
419 MethodInfo m = t.GetMethod ("RefOnlyMethod", BindingFlags.Static | BindingFlags.NonPublic);
421 m.Invoke (null, new object [0]);
423 } catch (InvalidOperationException ex) {
424 // The requested operation is invalid in the
425 // ReflectionOnly context
426 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
427 Assert.IsNull (ex.InnerException, "#3");
428 Assert.IsNotNull (ex.Message, "#4");
434 [ExpectedException (typeof (TargetInvocationException))]
435 public void InvokeInvalidOpExceptionThrow () {
436 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ThrowMethod");
437 mi.Invoke(null, null);
440 public static void ThrowMethod () {
441 throw new InvalidOperationException ();
445 public void InvokeGenericVtype ()
447 KeyValuePair<string, uint> kvp = new KeyValuePair<string, uint> ("a", 21);
448 Type type = kvp.GetType ();
449 Type [] arguments = type.GetGenericArguments ();
450 MethodInfo method = typeof (MethodInfoTest).GetMethod ("Go");
451 MethodInfo generic_method = method.MakeGenericMethod (arguments);
452 kvp = (KeyValuePair<string, uint>)generic_method.Invoke (null, new object [] { kvp });
454 Assert.AreEqual ("a", kvp.Key, "#1");
455 Assert.AreEqual (21, kvp.Value, "#2");
458 public static KeyValuePair<T1, T2> Go <T1, T2> (KeyValuePair <T1, T2> kvp)
464 public void InvokeGenericInst ()
466 List<string> str = null;
468 object [] methodArgs = new object [] { str };
469 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("GenericRefMethod");
470 mi.Invoke (null, methodArgs);
471 Assert.IsNotNull (methodArgs [0], "#A1");
472 Assert.IsNull (str, "#A2");
473 Assert.IsTrue (methodArgs [0] is List<string>, "#A3");
475 List<string> refStr = methodArgs [0] as List<string>;
476 Assert.IsNotNull (refStr, "#B1");
477 Assert.AreEqual (1, refStr.Count, "#B2");
478 Assert.AreEqual ("test", refStr [0], "#B3");
481 public static void GenericRefMethod (ref List<string> strArg)
483 strArg = new List<string> ();
487 public void MakeGenericMethodArgsMismatchFoo<T> ()
492 public void MakeGenericMethodArgsMismatch ()
494 MethodInfo gmi = this.GetType ().GetMethod (
495 "MakeGenericMethodArgsMismatchFoo");
497 gmi.MakeGenericMethod ();
499 } catch (ArgumentException ex) {
500 // The type or method has 1 generic parameter(s),
501 // but 0 generic argument(s) were provided. A
502 // generic argument must be provided for each
504 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
505 Assert.IsNull (ex.InnerException, "#3");
506 Assert.IsNotNull (ex.Message, "#4");
507 Assert.IsNull (ex.ParamName, "#5");
511 public void SimpleGenericMethod<TFoo, TBar> () {}
514 public void MakeGenericMethodWithNullArray ()
516 MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
518 gmi.MakeGenericMethod ((Type []) null);
520 } catch (ArgumentNullException ex) {
521 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
522 Assert.IsNull (ex.InnerException, "#3");
523 Assert.IsNotNull (ex.Message, "#4");
524 Assert.AreEqual ("methodInstantiation", ex.ParamName, "#5");
529 public void MakeGenericMethodWithNullValueInTypesArray ()
531 MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
533 gmi.MakeGenericMethod (new Type [] { typeof (int), null });
535 } catch (ArgumentNullException ex) {
536 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
537 Assert.IsNull (ex.InnerException, "#3");
538 Assert.IsNotNull (ex.Message, "#4");
539 Assert.IsNull (ex.ParamName, "#5");
544 public void MakeGenericMethodWithNonGenericMethodDefinitionMethod ()
546 MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
547 MethodInfo inst = gmi.MakeGenericMethod (typeof (int), typeof (double));
549 inst.MakeGenericMethod (typeof (int), typeof (double));
551 } catch (InvalidOperationException ex) {
555 public TFoo SimpleGenericMethod2<TFoo, TBar> () { return default (TFoo); }
556 /*Test for the uggly broken behavior of SRE.*/
558 public void MakeGenericMethodWithSreTypeResultsInStupidMethodInfo ()
560 AssemblyName assemblyName = new AssemblyName ();
561 assemblyName.Name = "MonoTests.System.Reflection.Emit.MethodInfoTest";
562 AssemblyBuilder assembly = Thread.GetDomain ().DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.RunAndSave, ".");
563 ModuleBuilder module = assembly.DefineDynamicModule ("module1", "tst.dll");
564 TypeBuilder tb = module.DefineType ("Test", TypeAttributes.Public);
566 MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod2");
567 MethodInfo ins = gmi.MakeGenericMethod (typeof (int), tb);
569 Assert.AreSame (tb, ins.GetGenericArguments () [1], "#1");
570 /*broken ReturnType*/
571 Assert.AreSame (gmi.GetGenericArguments () [0], ins.ReturnType, "#2");
574 public static int? pass_nullable (int? i)
580 public void NullableTests ()
582 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("pass_nullable");
583 Assert.AreEqual (102, mi.Invoke (null, new object [] { 102 }), "#1");
584 Assert.AreEqual (null, mi.Invoke (null, new object [] { null }), "#2");
586 // Test conversion of vtype to a nullable type for the this argument
587 PropertyInfo pi = typeof (Nullable <int>).GetProperty ("HasValue");
588 Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
589 PropertyInfo pi2 = typeof (Nullable <int>).GetProperty ("Value");
590 Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
593 public static void foo_generic<T> ()
598 public void IsGenericMethod ()
600 MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo_generic");
601 Assert.AreEqual (true, mi.IsGenericMethod, "#1");
602 MethodInfo mi2 = mi.MakeGenericMethod (new Type[] { typeof (int) });
603 Assert.AreEqual (true, mi2.IsGenericMethod, "#2");
604 MethodInfo mi3 = typeof (GenericHelper<int>).GetMethod ("Test");
605 Assert.AreEqual (false, mi3.IsGenericMethod, "#3");
610 public static void Foo<T2> (T2 i)
614 public static void Bar ()
620 public static void Baz ()
627 public void ContainsGenericParameters ()
629 // Non-generic method in open generic type
630 Assert.IsTrue (typeof (A<int>).GetGenericTypeDefinition ().GetMethod ("Bar").ContainsGenericParameters);
631 // open generic method in closed generic type
632 Assert.IsTrue (typeof (A<int>).GetMethod ("Foo").ContainsGenericParameters);
633 // non-generic method in closed generic type
634 Assert.IsFalse (typeof (A<int>).GetMethod ("Bar").ContainsGenericParameters);
635 // closed generic method in closed generic type
636 Assert.IsFalse (typeof (A<int>).GetMethod ("Foo").MakeGenericMethod (new Type [] { typeof (int) }).ContainsGenericParameters);
637 // non-generic method in non-generic nested type of closed generic type
638 Assert.IsFalse (typeof (A<int>.B).GetMethod ("Baz").ContainsGenericParameters);
639 // non-generic method in non-generic nested type of open generic type
640 Assert.IsTrue (typeof (A<int>.B).GetGenericTypeDefinition ().GetMethod ("Baz").ContainsGenericParameters);
644 public void IsGenericMethodDefinition ()
646 MethodInfo m1 = typeof (A<>).GetMethod ("Foo");
647 Assert.IsTrue (m1.IsGenericMethod, "#A1");
648 Assert.IsTrue (m1.IsGenericMethodDefinition, "#A2");
650 MethodInfo m2 = typeof (A<int>).GetMethod ("Foo");
651 Assert.IsTrue (m2.IsGenericMethod, "#B1");
652 Assert.IsTrue (m2.IsGenericMethodDefinition, "#B2");
654 MethodInfo m3 = m2.MakeGenericMethod (typeof (int));
655 Assert.IsTrue (m3.IsGenericMethod, "#C1");
656 Assert.IsFalse (m3.IsGenericMethodDefinition, "#C2");
660 public void GetGenericMethodDefinition ()
662 MethodInfo mi1 = typeof (MyList<>).GetMethod ("ConvertAll");
663 MethodInfo mi2 = typeof (MyList<int>).GetMethod ("ConvertAll");
665 Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[T,TOutput]",
666 mi1.GetParameters () [0].ParameterType.ToString (), "#A1");
667 Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[System.Int32,TOutput]",
668 mi2.GetParameters () [0].ParameterType.ToString (), "#A2");
669 Assert.IsTrue (mi1.IsGenericMethod, "#A3");
670 Assert.IsTrue (mi1.IsGenericMethodDefinition, "#A4");
671 Assert.IsTrue (mi2.IsGenericMethod, "#A5");
672 Assert.IsTrue (mi2.IsGenericMethodDefinition, "#A6");
674 MethodInfo mi3 = mi2.GetGenericMethodDefinition ();
676 Assert.IsTrue (mi3.IsGenericMethod, "#B1");
677 Assert.IsTrue (mi3.IsGenericMethodDefinition, "#B2");
678 Assert.AreSame (mi2, mi3, "#B3");
680 MethodInfo mi4 = mi2.MakeGenericMethod (typeof (short));
681 Assert.IsTrue (mi4.IsGenericMethod, "#C1");
682 Assert.IsFalse (mi4.IsGenericMethodDefinition, "#C2");
683 Assert.AreSame (mi2, mi4.GetGenericMethodDefinition (), "#C3");
686 public void TestMethod123(int a, int b) {}
689 public void GetParametersDontReturnInternedArray ()
691 var method = typeof (MethodInfoTest).GetMethod ("TestMethod123");
692 var parms = method.GetParameters ();
693 Assert.AreNotSame (parms, method.GetParameters (), "#1");
696 Assert.IsNotNull (method.GetParameters () [0], "#2");
700 public void Bug354757 ()
702 MethodInfo gmd = (typeof (MyList <int>)).GetMethod ("ConvertAll");
703 MethodInfo oi = gmd.MakeGenericMethod (gmd.GetGenericArguments ());
704 Assert.AreSame (gmd, oi);
708 [ExpectedException (typeof (ArgumentException))]
710 [Category ("NotWorking")] // #10552
712 public void MakeGenericMethodRespectConstraints ()
714 var m = typeof (MethodInfoTest).GetMethod ("TestMethod");
715 m.MakeGenericMethod (typeof (Type));
718 public void TestMethod <T> () where T : Exception
722 public class MyList<T>
724 public TOutput ConvertAll<TOutput> (Foo<T,TOutput> arg)
726 return default (TOutput);
728 public T ConvertAll2 (MyList<T> arg)
734 public class Foo<T,TOutput>
738 class GenericHelper<T>
740 public void Test (T t)
746 interface IMethodInvoke<out T>
751 class MethodInvoke : IMethodInvoke<string>
753 public string Test ()
755 return "MethodInvoke";
760 public void GetInterfaceMapWorksWithVariantIfaces ()
762 var m0 = typeof (IMethodInvoke<object>).GetMethod ("Test");
763 var m1 = typeof (IMethodInvoke<string>).GetMethod ("Test");
764 var obj = new MethodInvoke ();
766 Assert.AreEqual ("MethodInvoke", m0.Invoke (obj, new Object [0]));
767 Assert.AreEqual ("MethodInvoke", m1.Invoke (obj, new Object [0]));
772 public int? Bug12856 ()
778 public void MethodToStringShouldPrintFullNameOfGenericStructs ()
780 var m = GetType ().GetMethod ("Bug12856");
781 Assert.AreEqual ("System.Nullable`1[System.Int32] Bug12856()", m.ToString (), "#1");
787 class RefOnlyMethodClass
789 // Helper static method
790 static void RefOnlyMethod ()
795 public class MethodHandleTest<T>
797 private List<T> _myList = new List<T> ();
799 public MethodHandleTest ()
801 _myList.Add (default (T));
804 public List<T> MyList {
805 get { return _myList; }
806 set { _myList = value; }