Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restricting the property type of a custom attribute

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?

like image 727
Guy Avatar asked Apr 25 '10 13:04

Guy


1 Answers

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.

like image 53
Richard Avatar answered Oct 07 '22 01:10

Richard