DynamicMethod 是否可以调用(例如通过 ILGenerator.EmitCall 或类似方法)“正常”方法,例如 Private Sub BlahBlah(ByVal obj as Object)?
提前致谢
DynamicMethod 是否可以调用(例如通过 ILGenerator.EmitCall 或类似方法)“正常”方法,例如 Private Sub BlahBlah(ByVal obj as Object)?
提前致谢
在评估堆栈上加载值以提供给方法
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();
}