.net 如何调用';正常';方法通过ILGenerator.Emit*?

.net 如何调用';正常';方法通过ILGenerator.Emit*?,.net,vb.net,visual-studio-2010,dynamicmethod,ilgenerator,.net,Vb.net,Visual Studio 2010,Dynamicmethod,Ilgenerator,DynamicMethod是否可以调用(例如,通过ILGenerator.EmitCall或类似的方法)一个“普通”方法,例如Private Sub BlahBlah(ByVal obj as Object) 提前感谢为该方法加载评估堆栈上的值 delegate void foo(); public static void show(string foo) { MessageBox.Show(foo); } public void test() { DynamicMethod

DynamicMethod是否可以调用(例如,通过ILGenerator.EmitCall或类似的方法)一个“普通”方法,例如Private Sub BlahBlah(ByVal obj as Object)


提前感谢

为该方法加载评估堆栈上的值

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();
}
MethodInfo methodInfo = typeof(ClassName).GetMethod(MethodName, new Type[1] { typeof(-method argument types-) });

IL.Emit(OpCodes.Call, methodInfo );