[reflection] Test MethodInfo.ReflectedType property
authorAleksey Kliger <aleksey@xamarin.com>
Mon, 11 Jan 2016 17:10:23 +0000 (12:10 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Mon, 11 Jan 2016 17:18:43 +0000 (12:18 -0500)
Test cases for [#12205](https://bugzilla.xamarin.com/show_bug.cgi?id=12205)

mcs/class/corlib/Test/System.Reflection/MethodInfoTest.cs

index 71119b1673a7308b2bc7bf692771aad259bfdca3..17ddddd3e04e36b9c91c3224db6597ba370e5681 100644 (file)
@@ -308,6 +308,9 @@ namespace MonoTests.System.Reflection
                        public override void f2 () { }
                }
 
+               class DerivedFromGenericBase : GenericBase<int, int> {
+               }
+
                [Test]
                public void GetBaseDefinition_OpenConstructedBaseType () // 36305
                {
@@ -824,6 +827,33 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual ("System.Nullable`1[System.Int32] Bug12856()", m.ToString (), "#1");
                }
 
+               [Test]
+               public void GetReflectedType () // #12205
+               {
+                       // public method declared in base type, queried from a derived type
+                       MethodInfo mi = typeof (TestInheritedMethodB).GetMethod ("TestMethod2");
+                       Assert.AreEqual (mi.ReflectedType, typeof (TestInheritedMethodB), "#1");
+
+                       // public method declared in a generic class,
+                       // queried from a non-generic class derived
+                       // from an instantiation of the generic class.
+                       mi = typeof (DerivedFromGenericBase).GetMethod ("f2");
+                       Assert.AreEqual (mi.ReflectedType, typeof (DerivedFromGenericBase), "#2");
+
+                       // public method declared in a generic class,
+                       // queried from the generic type defintion of
+                       // a generic derived class.
+                       mi = typeof (GenericMid<,>).GetMethod ("f2");
+                       Assert.AreEqual (mi.ReflectedType, typeof (GenericMid<,>), "#3");
+
+                       // public method declared in a generic class,
+                       // queried from an instantiation of a generic
+                       // derived class.
+                       mi = typeof (GenericMid<int,int>).GetMethod ("f2");
+                       Assert.AreEqual (mi.ReflectedType, typeof (GenericMid<int,int>), "#4");
+
+               }
+
 #if !MONOTOUCH
                class GenericClass<T>
                {