/// <summary> /// Retrieves the member attributes. /// </summary> protected override void RetrieveMemberAttributes() { List <FieldInfo> fieldInfos = new List <FieldInfo>(MemberType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)); foreach (FieldInfo fieldInfo in fieldInfos) { List <Attribute> customAttributes = new List <Attribute>(Attribute.GetCustomAttributes(fieldInfo, typeof(ValidationAttribute), true)); foreach (Attribute attribute in customAttributes) { ValidationAttribute att = (ValidationAttribute)attribute; att.Target = fieldInfo.GetValue(BuilderSource.Action); ValidationAttributes.Add(att); } } }
/// <summary> /// Retrieves the member attributes. /// </summary> protected override void RetrieveMemberAttributes() { List <PropertyInfo> propertyInfos = new List <PropertyInfo>(MemberType.GetProperties(BindingFlags.Public | BindingFlags.Instance)); foreach (PropertyInfo info in propertyInfos) { List <Attribute> propertyAttributes = new List <Attribute>(Attribute.GetCustomAttributes(info, typeof(ValidationAttribute), true)); foreach (Attribute attribute in propertyAttributes) { if (attribute is ValidationAttribute) { ValidationAttribute att = (ValidationAttribute)attribute; att.Target = info.GetValue(BuilderSource.Action, null); ValidationAttributes.Add(att); } } } }
public EmailAttribute() { ValidationAttributes.Add(new EmailAddressAttribute()); ValidationAttributes.Add(new StringLengthAttribute(5)); }
public NameAttribute() { ValidationAttributes.Add(new MinLengthAttribute(5)); ValidationAttributes.Add(new RequiredAttribute()); ValidationAttributes.Add(new RegularExpressionAttribute(@"^[A-Z]+[a-zA-Z""'\s-]*$")); }