2011-10-23 12 views

Respuesta

12

supongo que tienes algo como esto:

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

Para obtener el atributo y una propiedad de ella:

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


int maxLen = strLenAttribute.MaximumLength; 
Cuestiones relacionadas