You cannot do this in .NET. At best, you can allow one instance of the same attribute for a class, as in this example:
using System; [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] class BaseAttribute : Attribute { } [Base] [Base]
But this behavior cannot be extended to derived classes, i.e. if you do this, it compiles:
using System; [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] class BaseAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] class Derived1Attribute : BaseAttribute { } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] class Derived2Attribute : BaseAttribute { } [Derived1] [Derived2]
The best I can think of is that you can write something to check for types with both attributes and use validation as a step after assembly.
source share