Guard icon indicating copy to clipboard operation
Guard copied to clipboard

Ability to specify custom exceptions on validation errors.

Open terminalxposure opened this issue 6 years ago • 0 comments

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());

terminalxposure avatar Jun 30 '18 07:06 terminalxposure