我也可以把.NET方法调用在运行时的新方法?我也、新方法、方法、NET

由网友(魅)分享简介:假设我有以下.NET类:Suppose I have the following .NET classes:public class C{public void M(){....}}和public class D{public void N(){....}}这些2类位于不同的命名空间,在不同的组件。有没有...

假设我有以下.NET类:

Suppose I have the following .NET classes:

public class C
{
    public void M()
    {
        ....
    }
}

public class D
{
    public void N()
    {
        ....
    }
}

这些2类位于不同的命名空间,在不同的组件。有没有一种方法,以使所有呼叫 CM()来重定向自动 DN()?因此,调用方法的东​​西它调用 CM ,但在现实中, DN 是实际被调用,任何参数该 CM 将采取。这不要紧,如果这种情况发生在类的所有实例,或只为一个特定的对象。

These 2 classes reside in different namespaces, in different assemblies. Is there a way to cause all call to C.M() to 'redirect' automatically to D.N()? So, the calling method things its invoking C.M, but in reality, D.N is what actually gets called, with any parameters that C.M would have taken. It doesn't matter if this happens for all instantiations of the class, or just for one specific object.

MS研究具有走弯路库,可以做一些非常相似的正常的Win32 DLL导出。我正在寻找一种方式来用.NET方法做到这一点。

MS Research has the Detours Library that can do something very similar for normal Win32 DLL exports. I'm looking for a way to do this with a .NET method.

推荐答案

微软已经创建了一个管理等同于走弯路叫的痣。我不知道的唯一的事情就是发牌;它的目的是为测试(如Pex的的一部分)。

Microsoft has created a managed equivalent to Detours called Moles. The only thing I'm not sure of is the licensing; it is intended for testing (as part of Pex).

依赖注入需要修改源; PostSharp需要修改二进制;但痣可以在运行时动态完成。

Dependency injection requires modifying the source; PostSharp requires modifying the binary; but Moles can be done dynamically at runtime.

阅读全文

相关推荐

最新文章