Guard
Guard copied to clipboard
Ability to specify custom exceptions on validation errors.
Something like this:
Implementation
public static IArg<T> WithExceptions<T>(this IArg<T> arg, Action<T,
IEnumerable<ErrorInfo>> handleErrorsAction) where T : IComparable
{
if (arg.Errors.Any())
{
handleErrorsAction(arg.Value, arg.Errors);
}
return arg;
}
Usage
var x = 1;
Validate.That(() => x).IsEqual(0).WithExceptions((value, errors) => throw new Exception());