2011-10-23 10 views

Odpowiedz

12

Zakładam, że masz coś takiego:

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

aby uzyskać atrybut i właściwość z niego:

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


int maxLen = strLenAttribute.MaximumLength;