【问题标题】:PostSharp and aspect inheritance through hierarchy通过层次结构继承 PostSharp 和方面
【发布时间】:2014-02-28 17:34:08
【问题描述】:

根据 PostSharp 文档,方面继承应受以下支持:

抽象、虚拟或接口方法的参数或返回值

但在我的情况下,当这些支持的元素组合在一起时,它似乎不支持继承。我有这个最小的代码来重现这个问题:

public interface IData { }

public interface ITest
{
    void DoSomething([Required] IData data);
}

public abstract class AbstractTest : ITest
{
    public abstract void DoSomething(IData data);
}

public class Test : AbstractTest
{
    public override void DoSomething(IData data)
    {
        throw new NotImplementedException();
    }
}

构建此代码结束于:

PostSharp.Patterns.Contracts.RequiredAttribute" 不能应用于 方法 “PostSharpInheritance.AbstractTest.DoSomething(PostSharpInheritance.IData)@data” 因为它是抽象的。

如果我将Required 属性从接口移动到抽象方法,编译将成功。如果我将Required 属性放在接口和抽象方法中,我会得到同样的错误。

我应该如何在接口上放置属性(合同)而不丢失在实现该接口的类层次结构中使用抽象类的选项?

【问题讨论】:

    标签: c# inheritance interface aop postsharp


    【解决方案1】:

    问题中的示例代码应该按照文档中的说明工作。该问题是由 PostSharp 代码中的错误引起的,该错误已报告给 PostSharp 团队。该修复将在即将发布的 3.1 版本之一中实施。

    更新:此错误已在 PostSharp build 3.1.33 中修复。

    【讨论】:

      猜你喜欢
      • 2020-10-24
      • 2011-06-16
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多