Преглед на файлове

2008-03-06 Zoltan Varga <[email protected]>

	* DynamicMethodTest.cs: Add a test for anon-hosted dynamic methods.

svn path=/trunk/mcs/; revision=97525
Zoltan Varga преди 18 години
родител
ревизия
4af25aa9e4
променени са 2 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 2 0
      mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
  2. 20 0
      mcs/class/corlib/Test/System.Reflection.Emit/DynamicMethodTest.cs

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

@@ -1,5 +1,7 @@
 2008-03-06  Zoltan Varga  <[email protected]>
 
+	* DynamicMethodTest.cs: Add a test for anon-hosted dynamic methods.
+
 	* ModuleBuilderTest.cs: Add a test for #367668.
 
 2008-03-06  Jb Evain  <[email protected]>

+ 20 - 0
mcs/class/corlib/Test/System.Reflection.Emit/DynamicMethodTest.cs

@@ -312,6 +312,26 @@ namespace MonoTests.System.Reflection.Emit
 			string ret = (string) method.Invoke (null, new object [] {});
 			Assert.AreEqual ("foo", ret, "#1");
 		}
+
+		[Test]
+		public void AnonHosted ()
+		{
+			DynamicMethod hello = new DynamicMethod ("Hello",
+													 typeof (int),
+													 new Type[] { typeof (string) });
+			ILGenerator helloIL = hello.GetILGenerator ();
+			helloIL.Emit (OpCodes.Ldc_I4_2);
+			helloIL.Emit (OpCodes.Ret);
+
+			HelloInvoker hi =
+				(HelloInvoker) hello.CreateDelegate (typeof (HelloInvoker));
+			int ret = hi ("Hello, World!");
+			Assert.AreEqual (2, ret);
+
+			object[] invokeArgs = { "Hello, World!" };
+			object objRet = hello.Invoke (null, invokeArgs);
+			Assert.AreEqual (2, objRet);
+		}			
 	}
 }