8

インターフェイスに属性を適用して、そのインターフェイスを実装するクラスのすべてのメソッドに属性が適用されるようにしたいと思います。

私はそれが次のようになると思いました:

[Serializable]
[AttributeUsage(AttributeTargets.All, Inherited = true)]
public sealed class TestAttribute : OnMethodBoundaryAspect
{
    ...
}

しかし、以下のようなインターフェイスに適用すると、インターフェイスを実装するクラスでメソッドが呼び出されたときに、属性のOnEntry/OnExitコードにアクセスすることはありません。

[Test]
public interface ISystemService
{
    List<AssemblyInfo> GetAssemblyInfo();
}

以下のように、実装クラス自体に属性を適用すると、正常に機能します。

[Test]
public class SystemService : ISystemService
{
    ...
}

私は何が欠けている/間違っているのですか?

4

2 に答える 2

8

使用する必要があります:

[MulticastAttributeUsage(..., Inheritance=MulticastInheritance.Multicast)]
public sealed class TestAttribute : OnMethodBoundaryAspect 

または:

[Test(AttributeInheritance=MulticastInheritance.Multicast] 
public interface ISystemService 
于 2010-03-04T15:44:41.333 に答える
1

私は何が欠けている/間違っているのですか?

インターフェイスには実装がないため、「OnEntry/OnExitコード」を実行できません。

クラスから受け継ぐべきだと思います。


さらに、属性をマルチキャストできますが、 MulticastAttributeから継承する必要があります。

于 2010-03-04T04:21:59.233 に答える