开发者

modify the assembly on runtime?

开发者 https://www.devze.com 2023-01-03 09:03 出处:网络
how can i modify me开发者_运维技巧mory loaded methods in given assembly so that clr when instantiates new objects for some class it makes new objects with modified code in it?You can use Mono Cecil to

how can i modify me开发者_运维技巧mory loaded methods in given assembly so that clr when instantiates new objects for some class it makes new objects with modified code in it?


You can use Mono Cecil to modify the assembly before you load it.

You can save the modified assembly to a byte array, then call Assembly.Load to load the byte array.


I don't think you can do that. But you can generate new classes in a new, in-memory assembly using Reflection.Emit.

That is a lot of work though. You can get help from a framework such as Castle DynamicProxy, which allows you to generate proxies for your classes at runtime. This way you can run any code before or after the original methods run, or change the methods totally by not calling into the original method.

0

精彩评论

暂无评论...
验证码 换一张
取 消