How can I force a subclass to implement certain Attributes of its superclass? The reason is that I want to use Attributes for general information about the class, e.g. "DisplayName", "Description" or "Capabilities".
So I thought I might implement them in a superclass and force the subclasses to implement the attributes.
Is there something like an abstract
attribute like for methods?
[abstract DeclareMe]
public abstract class InheritMe {
public abstract void DeclareMe();
}
In addition to the answers from that other thread:
You could use FxCop and implement a custom rule that checks if your attributes are present.
As your class must be run sooner or later, you can add checking mechanism to your base class to verify the existance of certain attributes in your sub classes.
Here's some sample code for you.
The last word, don't be too wary of yourself. Once I was doing my design, I always thought I might call two methods in a wrong order or forget to do something, then I turned a simple design into a complicated one to prevent my possible mistakes. Later I threw away the guards, just throwing Exceptions and the code used to detect unexpected situations were surrounded by
#if DEBUG
.