예제 #1
0
		public void DelegateWithValueTypeArguments ()
		{
			Struct695978 es = new Struct695978 ();
			es.value = 100;

			var ar1 = (Delegate695978_1)Delegate.CreateDelegate(typeof (Delegate695978_1), typeof (Struct695978).GetMethod("test"));
			Assert.IsNotNull (ar1);
			Assert.AreEqual (110, ar1 (ref es));

			var ar2 = (Delegate695978_2)Delegate.CreateDelegate(typeof (Delegate695978_2), null, typeof (Struct695978).GetMethod("test"));
			Assert.IsNotNull (ar2);
			Assert.AreEqual (110, ar2 ());

			ar1 = (Delegate695978_1) Delegate.CreateDelegate(typeof (Delegate695978_1), typeof (Struct695978).GetMethod("test2"));
			Assert.IsNotNull (ar1);
			Assert.AreEqual (120, ar1 (ref es));

			try {
				Delegate.CreateDelegate(typeof (Delegate695978_2), null, typeof (Struct695978).GetMethod("test2"));
				Assert.Fail ("#1");
			} catch (ArgumentException) {}


			ar2 = (Delegate695978_2) Delegate.CreateDelegate(typeof (Delegate695978_2), new Struct695978 (), typeof (Struct695978).GetMethod("test"));
			Assert.IsNotNull (ar2);
			Assert.AreEqual (120, ar2 ());

			try {
				Delegate.CreateDelegate(typeof (Delegate695978_2), new Struct695978 (), typeof (Struct695978).GetMethod("test2"));
				Assert.Fail ("#2");
			} catch (ArgumentException) {}

			try {
				Delegate.CreateDelegate(typeof (Delegate695978_3), typeof (Struct695978).GetMethod("test"));
				Assert.Fail ("#3");
			} catch (ArgumentException) {}
		}
예제 #2
0
			public static int test2 (ref Struct695978 foo) { return foo.value + 20; }