I have defined an:
IValidator<SomeClass> _myValidator
I can do:
_myValidator.ValidateAndThrow(someObject);
instead I would like to:
var errors = _myValidator.Validate(entity);
add some errors manually and then re-throw the errors. Is this possible?
If you want to store the errors in a variable, you'll have to return the error, or a list of errors, instead of throwing them.
IList<Exception> ValidateAndThrow(object someObject){
IList<Exception> errors = new List<Exception>();
try{
SomethingGoesWrong();
} catch (Exception e){
errors.Add(e);
}
return errors;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With