Is there a way to force the compiler to restrict the usage of a custom attribute to be used only on specific property types like int, short, string (all the primitive types)?
similar to the AttributeUsageAttribute‘s ValidOn-AttributeTargets enumeration.
Is there a way to force the compiler to restrict the usage of a
Share
No, you can’t, basically. You can limit it to
structvsclassvsinterface, that is about it. Plus: you can’t add attributes to types outside your code anyway (except for viaTypeDescriptor, which isn’t the same).