public IDtoValidatorResult Validate(object dto) { var dtoValidator = _dtoValidatorFactory.TryCreate(dto.GetType()); if (dtoValidator == null) { return(new DtoValidatorResult <object>()); } var dependentDtosValidatorResult = new DtoValidatorResult <object>(); foreach (var propertyInfo in dto.GetType().GetProperties()) { if (!(propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(String) || propertyInfo.PropertyType == typeof(Decimal) || propertyInfo.PropertyType == typeof(Decimal?) || propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?))) { var val = propertyInfo.GetValue(dto); var propertyName = propertyInfo.Name; if (val != null) { if (val.GetType().GetInterface("IEnumerable") != null) { VisitEnumerable(propertyName, val, dependentDtosValidatorResult); } else { VisitSingle(propertyName, val, dependentDtosValidatorResult); } } } } var dtoValidatorResult = dtoValidator.Validate(dto); dtoValidatorResult.AddArgumentErrors(dependentDtosValidatorResult.ArgumentErrors); return(dtoValidatorResult); }
private DtoValidatorResult <TDto> ValidateFluent(TDto dto) { var fluentValidatorResult = _fluentDtoValidator.Validate(dto); var result = new DtoValidatorResult <TDto>(); var argumentErrors = new List <ResponseArgumentError>(); foreach (var validationFailure in fluentValidatorResult.Errors) { string argumentName = validationFailure.PropertyName; var argumentError = FluentValidationResources.GetArgumentError(validationFailure.ErrorMessage, argumentName); argumentErrors.Add(new ResponseArgumentError(argumentName, argumentError)); } result.ArgumentErrors = argumentErrors; return(result); }
protected virtual void ValidateInternal(TDto dto, DtoValidatorResult <TDto> dtoValidatorResult) { }