Reputation: 364249
According to PostSharp documentation, aspect inheritance should be among others supported on:
Parameter or Return Value of an abstract, virtual or interface method
But in my case it doesn't seem to support inheritance when those supported elements are combined. I have this minimal code to reproduce the issue:
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();
}
}
Building this code ends with:
PostSharp.Patterns.Contracts.RequiredAttribute" cannot be applied to method "PostSharpInheritance.AbstractTest.DoSomething(PostSharpInheritance.IData)@data" because it is abstract.
If I move the Required
attribute from interface to to abstract method the compilation will succeed. If I place the Required
attribute in both interface and abstract method I will get the same error.
How am I supposed to place attributes (contracts) on interface without loosing option for using abstract classes in class hierarchy implementing that interface?
Upvotes: 3
Views: 164
Reputation: 5101
The example code from the question should work as described in the documentation. The problem is caused by a bug in PostSharp code, which has been reported to PostSharp team. The fix will be implemented in one of the upcoming builds of version 3.1.
Update: This bug has been fixed in the PostSharp build 3.1.33.
Upvotes: 1