using System;
using System.Reflection;
-class Test {
+class Tests {
public struct SimpleStruct {
public bool a;
b = false;
}
}
-
- static void Test2 () {
- Console.WriteLine ("Test2 called");
- }
-
- public static SimpleStruct Test1 (SimpleStruct ss) {
- Console.WriteLine ("Test1 called " + ss.a + " " + ss.b);
- SimpleStruct res = new SimpleStruct ();
- res.a = !ss.a;
- res.b = !ss.b;
- return res;
- }
public static void Foo(ref int x, ref int y)
{
y = 30;
}
- static int Main () {
- Type t = typeof (Test);
-
- MethodInfo m2 = t.GetMethod ("Test2");
- if (m2 != null)
- return 1;
-
- MethodInfo m1 = t.GetMethod ("Test1");
- if (m1 == null)
- return 1;
-
- object [] args = new object [1];
- SimpleStruct ss = new SimpleStruct ();
- ss.a = true;
- ss.b = false;
- args [0] = ss;
-
- SimpleStruct res = (SimpleStruct)m1.Invoke (null, args);
-
- if (res.a == true)
- return 1;
- if (res.b == false)
- return 1;
+ public static int Main (string[] args) {
+ return TestDriver.RunTests (typeof (Tests), args);
+ }
+ public static int test_0_byref_null () {
// Test that the objects for byref valuetype arguments are
// automatically created
- MethodInfo m3 = typeof(Test).GetMethod("Foo");
+ MethodInfo m3 = typeof(Tests).GetMethod("Foo");
- args = new object[2];
+ var args = new object[2];
m3.Invoke(null, args);
if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30))
return 2;
+ return 0;
+ }
+
+ public static int test_0_ctor_vtype () {
// Test the return value from ConstructorInfo.Invoke when a precreated
// valuetype is used.
+
+ SimpleStruct ss = new SimpleStruct ();
+ ss.a = true;
+ ss.b = false;
+
ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) });
- SimpleStruct res2 = (SimpleStruct)ci.Invoke (ss, new object [] { false });
+ ci.Invoke (ss, new object [] { false });
+
+ return 0;
+ }
+
+ public static int test_0_array_get_set () {
+ // Test invoking of the array Get/Set methods
+ string[,] arr = new string [10, 10];
+
+ arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 1, 1, "FOO" });
+ string s = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 1, 1 });
+ if (s != "FOO")
+ return 3;
+
+ return 0;
+ }
+
+ public static int test_0_string_ctor_sharing () {
+ // Test the sharing of runtime invoke wrappers for string ctors
+ typeof (string).GetConstructor (new Type [] { typeof (char[]) }).Invoke (new object [] { new char [] { 'a', 'b', 'c' } });
+
+ typeof (Assembly).GetMethod ("GetType", new Type [] { typeof (string), }).Invoke (typeof (int).Assembly, new object [] { "A" });
return 0;
}