2011-10-23 13 views

risposta

12

io suppone che si abbia qualcosa di simile:

[StringLength(20, MinimumLength = 5, ErrorMessage = "First name must be between 5 and 20 characters")] 
public string FirstName {get;set;} 

Per ottenere l'attributo e una proprietà da esso:

StringLengthAttribute strLenAttr = 
    typeof(Person).GetProperty("FirstName").GetCustomAttributes(
    typeof(StringLengthAttribute), false).Cast<StringLengthAttribute>().Single(); 


int maxLen = strLenAttribute.MaximumLength; 
Problemi correlati