这个话题相当模糊,因为我不确定我想要做的事情的正确术语是什么。
我下载了一个dll (我没有源代码),使用反射工具,我在dll实现中发现了一个bug。这个bug很容易修复。那么假设bug在这里:
class A
{
void f() { // BUG!!! }
}有任何方法来实现我自己的A,它可以修复错误并在运行时注入它来替换其他A实例吗?
发布于 2014-02-25 12:41:20
如果您使用的是.NET 4.0。或者更高的地方,看看:MethodRental.SwapMethodBody Method
其他方式:CLR Injection: Runtime Method Replacer
发布于 2014-02-25 12:48:22
最简单的方法是从该类继承并编写自己的实现。
class ParentClass
{
public void SomeMethod() {
//bug here
}
}
class Child:ParentClass
{
new public void SomeMethod() {
// I fixed it
}
}在这之后,用你的课。
Child child = new Child();
child.SomeMethod();https://stackoverflow.com/questions/22014473
复制相似问题