public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { foreach (var info in Profile) { var validation = RegistrationHelper.GetFieldValidatorDefinition(info.Key); if (validation != null) { if (validation.Required.HasValue && validation.Required.Value && string.IsNullOrEmpty(info.Value)) { var requiredErrorMessage = this.GetErrorMessageFromResource(validation.RequiredViolationMessage); yield return(new ValidationResult($"{requiredErrorMessage}", new List <string> { "Profile[" + info.Key + "]" })); } else if (info.Value.Length > 1) { if (info.Value.Length < (int)validation.MinLength || ((int)validation.MaxLength != 0 && info.Value.Length > (int)validation.MaxLength)) { var lengthErrorMessage = this.GetErrorMessageFromResource(validation.MaxLengthViolationMessage); yield return(new ValidationResult($"{lengthErrorMessage}", new List <string> { "Profile[" + info.Key + "]" })); } } } } }