Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to call a function with parameters from DynamicMethod?

$
0
0
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?
 

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>