为什么不能仅温莎拦截虚拟或接口的方法呢? [英] Why can Windsor only intercept virtual or interfaced methods?

查看:218
本文介绍了为什么不能仅温莎拦截虚拟或接口的方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读文档,看看,如果你不使用的接口,那么温莎只能拦截虚拟方法?

I'm reading the documentation and see that if you don't use an interface then Windsor can only intercept virtual methods?

这是一个与温莎或限制简单的C#语言?我深入的答案寻找一个。

Is this a limitation with Windsor or simply the C# language? I'm looking for an in depth answer.

推荐答案

C#语言是完全不相干的在这里。现在的问题是如何拦截在工作运行时的水平。

The C# language is completely irrelevant here. The question is how the interception works at the runtime level.

一种方法是从类继承/实现该接口,并将它作为一个代理。这显然只能重写虚方法和接口方法。我怀疑温莎使用此技术。该技术的优点是,它不需要任何特殊。只是在运行时创建一个类。

One technique is inheriting from the class/implementing the interface and using that as a proxy. This can obviously only override virtual methods and interface methods. I suspect Windsor uses this technique. The advantage of this technique is that it doesn't need anything special. Just create a class at runtime.

另一种方法是使用分析API。这使您可以修改任何方法,包括非虚拟的的IL。这是更为侵入,通常只测试遗留代码时使用。

Another way is using the profiling API. This allows you to modify the IL of any method, including non virtual ones. This is much more intrusive, and typically only used when testing legacy code.

另一种方法是使用IL在构建时重写。这可以在你写的代码添加拦截点,但不是在框架代码。

Yet another way is using IL rewriting at build time. This can add interception points in code you wrote, but not in framework code.

这篇关于为什么不能仅温莎拦截虚拟或接口的方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆