소스 검색

In Test/System.Reflection:
2009-10-18 Sebastien Pouliot <[email protected]>

* MethodBaseTest.cs: Add new, working, test for non-generic
GetMethodFromHandle. Add test case to show generic overload
behave exactly the same when no second RuntimeMethodHandle is
provided. Remove [Category("NotWorking")] on existing test case.

In System.Reflection:
2009-10-18 Sebastien Pouliot <[email protected]>

* MethodBase.cs: Reduce code duplication and the number of direct
calls to icalls (affecting the number of SecuritySafeCritical in
Moonlight)


svn path=/trunk/mcs/; revision=144335

Sebastien Pouliot 16 년 전
부모
커밋
a976fb2ed7

+ 6 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,9 @@
+2009-10-18  Sebastien Pouliot  <[email protected]>
+
+	* MethodBase.cs: Reduce code duplication and the number of direct
+	calls to icalls (affecting the number of SecuritySafeCritical in
+	Moonlight)
+
 2009-10-17  Sebastien Pouliot  <[email protected]>
 
 	* MonoMethod.cs: Reduce code duplication and the number of direct

+ 14 - 12
mcs/class/corlib/System.Reflection/MethodBase.cs

@@ -46,17 +46,24 @@ namespace System.Reflection {
 		[MethodImplAttribute (MethodImplOptions.InternalCall)]
 		public extern static MethodBase GetCurrentMethod ();
 
-		internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle) {
-			if (handle.Value == IntPtr.Zero)
+		internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle)
+		{
+			return GetMethodFromIntPtr (handle.Value, IntPtr.Zero);
+		}
+
+		static MethodBase GetMethodFromIntPtr (IntPtr handle, IntPtr declaringType)
+		{
+			if (handle == IntPtr.Zero)
 				throw new ArgumentException ("The handle is invalid.");
-			MethodBase res = GetMethodFromHandleInternalType (handle.Value, IntPtr.Zero);
+			MethodBase res = GetMethodFromHandleInternalType (handle, declaringType);
 			if (res == null)
 				throw new ArgumentException ("The handle is invalid.");			
 			return res;
 		}
 
-		public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
-			MethodBase res = GetMethodFromHandleNoGenericCheck (handle);
+		public static MethodBase GetMethodFromHandle (RuntimeMethodHandle handle)
+		{
+			MethodBase res = GetMethodFromIntPtr (handle.Value, IntPtr.Zero);
 #if NET_2_0
 			Type t = res.DeclaringType;
 			if (t.IsGenericType || t.IsGenericTypeDefinition)
@@ -70,14 +77,9 @@ namespace System.Reflection {
 
 #if NET_2_0 || BOOTSTRAP_NET_2_0
 		[ComVisible (false)]
-		public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
+		public static MethodBase GetMethodFromHandle (RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
 		{
-			if (handle.Value == IntPtr.Zero)
-				throw new ArgumentException ("The handle is invalid.");
-			MethodBase res = GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
-			if (res == null)
-				throw new ArgumentException ("The handle is invalid.");
-			return res;
+			return GetMethodFromIntPtr (handle.Value, declaringType.Value);
 		}
 #endif
 

+ 7 - 0
mcs/class/corlib/Test/System.Reflection/ChangeLog

@@ -1,3 +1,10 @@
+2009-10-18  Sebastien Pouliot  <[email protected]>
+
+	* MethodBaseTest.cs: Add new, working, test for non-generic
+	GetMethodFromHandle. Add test case to show generic overload
+	behave exactly the same when no second RuntimeMethodHandle is
+	provided. Remove [Category("NotWorking")] on existing test case.
+
 2009-08-07 Rodrigo Kumpera  <[email protected]>
 
 	* MonoGenericClassTest.cs: Test for methods that must

+ 30 - 3
mcs/class/corlib/Test/System.Reflection/MethodBaseTest.cs

@@ -60,7 +60,6 @@ namespace MonoTests.System.Reflection
 	{
 #if NET_2_0
 		[Test] // GetMethodFromHandle (RuntimeMethodHandle)
-		[Category ("NotWorking")]
 		public void GetMethodFromHandle1_Handle_Generic ()
 		{
 			G<string> instance = new G<string> ();
@@ -99,7 +98,35 @@ namespace MonoTests.System.Reflection
 			}
 		}
 
+		[Test]
+		public void GetMethodFromHandle ()
+		{
+			Type t = typeof (object);
+			RuntimeMethodHandle rmh = t.GetConstructor (Type.EmptyTypes).MethodHandle;
+			MethodBase mb = MethodBase.GetMethodFromHandle (rmh);
+			Assert.IsNotNull (mb, "#1");
+			Assert.AreEqual (t, mb.DeclaringType, "#2");
+			Assert.AreEqual (".ctor", mb.Name, "#3");
+			ParameterInfo [] parameters = mb.GetParameters ();
+			Assert.IsNotNull (parameters, "#4");
+			Assert.AreEqual (0, parameters.Length, "#5");
+		}
+
 #if NET_2_0
+		[Test]
+		public void GetMethodFromHandle_NonGenericType_DeclaringTypeZero ()
+		{
+			Type t = typeof (object);
+			RuntimeMethodHandle rmh = t.GetConstructor (Type.EmptyTypes).MethodHandle;
+			MethodBase mb = MethodBase.GetMethodFromHandle (rmh, new RuntimeTypeHandle ());
+			Assert.IsNotNull (mb, "#1");
+			Assert.AreEqual (t, mb.DeclaringType, "#2");
+			Assert.AreEqual (".ctor", mb.Name, "#3");
+			ParameterInfo [] parameters = mb.GetParameters ();
+			Assert.IsNotNull (parameters, "#4");
+			Assert.AreEqual (0, parameters.Length, "#5");
+		}
+
 		[Test] // GetMethodFromHandle (RuntimeMethodHandle, RuntimeTypeHandle)
 		public void GetMethodFromHandle2_DeclaringType_Zero ()
 		{
@@ -190,7 +217,7 @@ namespace MonoTests.System.Reflection
 
 		[Test]
 		public void GetMethodFromHandle_Handle_Generic_Method_On_Generic_Class ()
-	    {
+		{
 			MethodInfo mi = typeof (Generic<>).GetMethod ("GenericFoo");
 			RuntimeMethodHandle handle = mi.MethodHandle;
 			MethodBase res;
@@ -239,7 +266,7 @@ namespace MonoTests.System.Reflection
 
 		[Test]
 		public void GetMethodFromHandle_Handle_Method_On_Generic_Class ()
-	    {
+		{
 			MethodInfo mi = typeof (Generic<>).GetMethod ("Foo");
 			RuntimeMethodHandle handle = mi.MethodHandle;
 			MethodBase res;