我正在尝试在装配级别上将 fody 与MethodDecorator一起使用。
我尝试使用示例代码提供的属性而不做任何更改:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor |
AttributeTargets.Assembly | AttributeTargets.Module)]
public class InterceptorAttribute : Attribute, IMethodDecorator {
// The code of the implemented methods doesn't matter.
}
如果我使用 all 装饰一个方法[Interceptor]
,则按预期工作。
但是我尝试拦截程序集中的每个方法。示例代码将此属性定位到AttributeTargets.Assembly
. 这向我表明这可能有效。
为了完成这项工作,我添加[assembly: InterceptorAttribute]
了AssemblyInfo.cs
我的项目。
代码仍然编译没有任何错误,但不会调用拦截器。
如果我使用[module: Interceptor]
.
我该怎么做才能让它工作?
有没有其他方法可以拦截程序集/模块中的每个方法?
更新
我发现MethodBoundaryAspect按预期工作。