DynamicMethod是否可以通过ILGenerator。EmitCall—或类似—例如)一个"正常"的方法,例如Private Sub BlahBlah(ByVal obj as Object)?
Thanks in advance
将赋值堆栈上的值赋给方法
MethodInfo methodInfo = typeof(ClassName).GetMethod(MethodName, new Type[1] { typeof(-method argument types-) });
IL.Emit(OpCodes.Call, methodInfo );
delegate void foo();
public static void show(string foo)
{
MessageBox.Show(foo);
}
public void test()
{
DynamicMethod dm = new DynamicMethod("foo", null, null);
ILGenerator gen = dm.GetILGenerator();
gen.Emit(OpCodes.Ldstr, "hello world");
gen.EmitCall(OpCodes.Call, this.GetType().GetMethod("show"),null);
gen.Emit(OpCodes.Ret);
var b = dm.CreateDelegate(typeof(foo)) as foo;
b();
}