2011-05-06 2 views

Répondre

4
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(); 
} 
4

valeurs de charge sur la pile d'évaluation à donner à la méthode

MethodInfo methodInfo = typeof(ClassName).GetMethod(MethodName, new Type[1] { typeof(-method argument types-) }); 

IL.Emit(OpCodes.Call, methodInfo);