/// <summary> /// Applies the validation attributes. /// </summary> /// <param name="attr">The attribute.</param> /// <param name="pi">The property info.</param> private static void ApplyValidationAttributes(this AttributeModel attr, PropertyInfo pi) { attr.Validations = new Dictionary <string, ValidationAttribute>(); Type modelType = typeof(AttributeModel); IEnumerable <Attribute> attrs = pi.GetCustomAttributes(); foreach (Attribute a in attrs) { if (a is ValidationAttribute) { ValidationAttribute va = (ValidationAttribute)a; va.ErrorMessage = va.FormatErrorMessage(attr.DisplayName); Type attributeType = a.GetType(); string valName = attributeType.Name.Replace("Attribute", string.Empty); attr.Validations[valName] = va; } } }