Scenario:
I have a base class “MyBase”.
I have a custom attribute “MyAttrib”
With that I do this:
[MyAttrib(1234)]
class MyClass : MyBase()
{
MyClass()
{
}
}
Question:
Can I in any way force classes inherting from MyBase to have the attribute MyAttrib?
No, there is no way to have the compiler require an attribute in C#. You do have some other options available to you. You could write a unit test that reflects on all types in the assembly and checks for the attribute. But unfortunately there is no way to have the compiler force the usage of an attribute.