From 2eef9d318e526718c7af251ad702a1547a1d239d Mon Sep 17 00:00:00 2001 From: kumpera Date: Sat, 1 Aug 2009 02:17:11 +0000 Subject: [PATCH] 2009-07-31 Rodrigo Kumpera TypeTest.cs: Add test for Type::DeclaringMethod. In special for throwing when the type is not a generic param and for DeclaringMethod returning a method bound to the right type. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@139226 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- class/corlib/Test/System/ChangeLog | 7 +++++++ class/corlib/Test/System/TypeTest.cs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/class/corlib/Test/System/ChangeLog b/class/corlib/Test/System/ChangeLog index 3961a3d63e..d1ab3c9568 100644 --- a/class/corlib/Test/System/ChangeLog +++ b/class/corlib/Test/System/ChangeLog @@ -1,3 +1,10 @@ +2009-07-31 Rodrigo Kumpera + + TypeTest.cs: Add test for Type::DeclaringMethod. + In special for throwing when the type is not a + generic param and for DeclaringMethod returning + a method bound to the right type. + 2009-07-28 Rodrigo Kumpera TypeTest.cs: Fix the test. diff --git a/class/corlib/Test/System/TypeTest.cs b/class/corlib/Test/System/TypeTest.cs index a4fa4debbf..71ca34d798 100644 --- a/class/corlib/Test/System/TypeTest.cs +++ b/class/corlib/Test/System/TypeTest.cs @@ -3240,6 +3240,41 @@ PublicKeyToken=b77a5c561934e089")); Assert.AreEqual ("Int32[*]", szarray.Name, "#3"); } + public class DeclaringMethodFoo { + public void Test (T t) {} + public void Test2 (ref T t) {} + } + + public class DeclaringMethodBar { + public void Test2 (ref T t) {} + } + + [Test] + public void DeclaringMethodOnlyWorksWithGenericArgs () + { + MethodInfo testMethod = typeof (DeclaringMethodFoo).GetMethod ("Test"); + MethodBase otherMethod = testMethod.GetParameters ()[0].ParameterType.DeclaringMethod; + + Assert.AreEqual (testMethod, otherMethod,"#1"); + + Assert.IsNull (typeof (DeclaringMethodBar<>).GetGenericArguments ()[0].DeclaringMethod, "#2"); + + try { + var x = typeof (int).DeclaringMethod; + Assert.Fail ("#3"); + } catch (InvalidOperationException) {} + + try { + var x = typeof (DeclaringMethodFoo).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod; + Assert.Fail ("#4"); + } catch (InvalidOperationException) {} + + try { + var x = typeof (DeclaringMethodBar<>).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod; + Assert.Fail ("#5"); + } catch (InvalidOperationException) {} + + } #endif static bool ContainsProperty (PropertyInfo [] props, string name) -- 2.11.4.GIT