public IEnumerable <ValidationError> Validate(object instance) { var validators = _propertyValidatorFactory.GetValidators(instance.GetType()); foreach (var propertyValidator in validators) { var results = propertyValidator.Validate(instance); foreach (var result in results) { yield return(result); } } foreach (var validationError in _validatableObjectAdapter.Validate(instance)) { yield return(validationError); } }
/// <summary> /// Initializes a new instance of the <see cref="DataAnnotationsValidator"/> class. /// </summary> /// <param name="typeForValidation">The type for validation.</param> /// <param name="factory">The <see cref="IPropertyValidatorFactory"/> instance that should be used by the validator.</param> /// <param name="validatableObjectAdapter">The <see cref="validatableObjectAdapter"/> instance that should be used by the validator.</param> public DataAnnotationsValidator(Type typeForValidation, IPropertyValidatorFactory factory, IValidatableObjectAdapter validatableObjectAdapter) { this.ModelType = typeForValidation; this.validatableObjectAdapter = validatableObjectAdapter; this.validators = factory.GetValidators(typeForValidation); }