2

假设我有程序集 A。它用 Mono.Cecil 进行了一些修改。现在假设我有程序集 B。它有一个名为SomeClass. 程序集 A 还有一个名为 的类SomeClass。现在我想用SomeClass程序集 B 中的替换程序集 A。我尝试了一些事情,但我知道对于我的一次尝试,它实际上重新映射了一个方法调用,如下所示:

Console.WriteLine("Test.");

...进入这个:

int.WriteLine("Test.");

这不可能。用 Mono.Cecil 替换类的正确方法是什么?

4

1 回答 1

1

You're probably doing something that Cecil doesn't understand. It's impossible to tell you what without seeing any code.

Swapping a type by another is not trivial, you'd have to recreate in the target module the object model you want to inject, and replace every reference of it with the new one. Basically, you'd have to walk over every reference in the target module and make sure it's properly processed.

于 2010-04-11T21:11:38.750 回答