Does anyone knows if it is possible to define/declare on your own custom attribute a restriction to the field type it may apply on? There are a flags that do restrict the usage of the attribute:
[AttributeUsage(
AttributeTargets.Property,
AllowMultiple = false)]
Im looking for something like:
UseOnlyOnType = typeof(string)
Any ideas?
This is not possible directly.
But since you have to write code to make use of the attribute (on their own they are just unused metadata), that code could work by only checking for your attribute when the field's type is string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With