Dynamically replace the contents of a C# method?

后端 未结 10 2313
面向向阳花
面向向阳花 2020-11-22 16:09

What I want to do is change how a C# method executes when it is called, so that I can write something like this:

[Distributed]
public DTask Solve         


        
10条回答
  •  遇见更好的自我
    2020-11-22 16:41

    You can replace a method at runtime by using the ICLRPRofiling Interface.

    1. Call AttachProfiler to attach to the process.
    2. Call SetILFunctionBody to replace the method code.

    See this blog for more details.

提交回复
热议问题