kri*_*isg 8 c# attributes interface postsharp
我希望能够将属性应用于接口,以便实现该接口的任何类中的每个方法都将应用该属性.
我以为它看起来像这样:
[Serializable]
[AttributeUsage(AttributeTargets.All, Inherited = true)]
public sealed class TestAttribute : OnMethodBoundaryAspect
{
...
}
Run Code Online (Sandbox Code Playgroud)
然而,当我将它应用于如下界面时,在实现接口的类中调用方法时,永远不会访问属性中的OnEntry/OnExit代码:
[Test]
public interface ISystemService
{
List<AssemblyInfo> GetAssemblyInfo();
}
Run Code Online (Sandbox Code Playgroud)
如果我在实现类本身中应用该属性,如下所示,它可以正常工作:
[Test]
public class SystemService : ISystemService
{
...
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么/做错了什么?
你必须使用:
[MulticastAttributeUsage(..., Inheritance=MulticastInheritance.Multicast)]
public sealed class TestAttribute : OnMethodBoundaryAspect
Run Code Online (Sandbox Code Playgroud)
要么:
[Test(AttributeInheritance=MulticastInheritance.Multicast]
public interface ISystemService
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2044 次 |
| 最近记录: |