DynamicMethod是否可以调用(例如,通过ILGenerator.EmitCall或类似的)“正常”方法,例如私有子对象(ByVal obj as Object)?
提前感谢
发布于 2011-06-16 05:54:44
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();
}发布于 2011-07-23 14:47:47
将赋值给该方法的计算堆栈上的加载值
MethodInfo methodInfo = typeof(ClassName).GetMethod(MethodName, new Type[1] { typeof(-method argument types-) });
IL.Emit(OpCodes.Call, methodInfo );https://stackoverflow.com/questions/5906867
复制相似问题