private void GetValidationErrors(List <EntityErrorInfo> output, ValidationReason?validationReason = null) { if (entitiesToValidate == null) { return; } var currentEntityErrors = new List <ValidationResult>(); var entitiesToProcess = entitiesToValidate; entitiesToValidate = null; foreach (var entity in entitiesToProcess.Keys) { if (entity.CanBeValidated) { GetValidationErrors(entity, currentEntityErrors, validationReason); if (currentEntityErrors.Count > 0) { var errorInfo = new EntityErrorInfo(entity, currentEntityErrors.AsReadOnly()); RegisterForValidation(entity, errorInfo); output.Add(errorInfo); currentEntityErrors = new List <ValidationResult>(); } } } }
private void RegisterForValidation(Entity target, EntityErrorInfo previousStatus) { if (!target.TypeInfo.HasValidators) { return; } if (entitiesToValidate == null) { entitiesToValidate = new Dictionary <Entity, EntityErrorInfo>(); } entitiesToValidate[target] = previousStatus; }
public override IList <ValidationResult> ValidateAndGetErrors(Entity target) { var result = new List <ValidationResult>(); GetValidationErrors(target, result); if (result.Count == 0) { return(EmptyValidationResultCollection); } var lockedResult = result.AsReadOnly(); var errorInfo = new EntityErrorInfo(target, lockedResult); RegisterForValidation(target, errorInfo); return(lockedResult); }