public static void TestStaticField() { TestClass.StaticIntField = -1; FieldInfo field = typeof(TestClass).GetField("StaticIntField");; StaticDynamicMethodProxyHandler handler = fac.GetStaticFieldSetDelegate(field); handler(new object[] { 5 }); Check.Assert(TestClass.StaticIntField == 5); handler = fac.GetStaticFieldGetDelegate(field); Check.Assert(((int)handler(null)) == 5); }
public static void TestStaticProperty() { TestClass.StaticIntField = -1; PropertyInfo property = typeof(TestClass).GetProperty("StaticIntProperty");; StaticDynamicMethodProxyHandler handler = fac.GetStaticMethodDelegate(property.GetSetMethod()); handler(new object[] { 5 }); Check.Assert(TestClass.StaticIntProperty == 5); handler = fac.GetStaticMethodDelegate(property.GetGetMethod()); Check.Assert(((int)handler(null)) == 5); }
public static void TestStaticMethod() { StaticDynamicMethodProxyHandler handler = fac.GetStaticMethodDelegate(typeof(TestClass).GetMethod("StaticReturnVoidMethod")); handler(null); object[] inputParams = new object[] { "str", 1, 3, "instr" }; handler = fac.GetStaticMethodDelegate(typeof(TestClass).GetMethod("StaticReturnIntMethod")); object ret = handler(inputParams); Check.Assert(((int)inputParams[2]) == 2); Check.Assert(((string)inputParams[3]) == "refstr"); Check.Assert(((int)ret) == 4); }