C# 流畅的验证手动添加验证错误并重新显示错误
我定义了一个:C# 流畅的验证手动添加验证错误并重新显示错误,c#,fluentvalidation,C#,Fluentvalidation,我定义了一个: IValidator<SomeClass> _myValidator 相反,我想: var errors = _myValidator.Validate(entity); 手动添加一些错误,然后重新抛出错误。这可能吗?如果要将错误存储在变量中,则必须返回错误或错误列表,而不是抛出错误 IList<Exception> ValidateAndThrow(object someObject){ IList<Exception> err
IValidator<SomeClass> _myValidator
相反,我想:
var errors = _myValidator.Validate(entity);
手动添加一些错误,然后重新抛出错误。这可能吗?如果要将错误存储在变量中,则必须返回错误或错误列表,而不是抛出错误
IList<Exception> ValidateAndThrow(object someObject){
IList<Exception> errors = new List<Exception>();
try{
SomethingGoesWrong();
} catch (Exception e){
errors.Add(e);
}
return errors;
}
IList ValidateAndThrow(对象someObject){
IList errors=新列表();
试一试{
有些事情变得很糟糕;
}捕获(例外e){
添加(e);
}
返回错误;
}
我自己才意识到这一点。我使用了类似的方法:ValidationFailure test=newvalidationfailure(“bla”,“bla”);错误。添加(测试);抛出新的ValidationException(错误);
IList<Exception> ValidateAndThrow(object someObject){
IList<Exception> errors = new List<Exception>();
try{
SomethingGoesWrong();
} catch (Exception e){
errors.Add(e);
}
return errors;
}