It sounds like you want to create an Attribute
which can only be applied to certain types in much the way that AttributeUsage
can only be applied to types deriving from Attribute
. Introducing this type of custom restriction is simply not possible. The particular error you're seeing is not because of a custom restriction, it's one that's simply hard wired into the compiler itself.