Here is a code to help you understand.
publicstringHelloWorld(stringGreeting){returnGreeting;}
publicvoidMethodGenerator(){MethodInfoHelloWorldMethod=typeof(MyClass).GetMethod("HelloWorld");DynamicMethod DM =newDynamicMethod("HelloWorld",typeof(string),newType[]{typeof(MyClass)});ILGenerator IL = DM.GetILGenerator();
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Call,HelloWorldMethod);
IL.Emit(OpCodes.Ret);Func<MyClass,string>DMDelegate=(Func<MyClass,string>)DM.CreateDelegate(typeof(Func<MyClass,string>));stringResult=DMDelegate(MyObject);}
How to send parameter to HelloWord method?