Example #1
0
 /// <summary>
 /// Success: Calls <paramref name="onSuccess"/> and returns a <see cref="ResultOrError{TError}.Success"/>.
 /// <para></para>
 /// Error: Calls <paramref name="onError"/> and returns a <see cref="ResultOrError{TError}.Error(TError)"/> with the <typeparamref name="TError"/> from <paramref name="onError"/>.
 /// </summary>
 /// <typeparam name="TError">The type of the Error.</typeparam>
 /// <param name="onSuccess">Is called if This is a <see cref="Success"/>.</param>
 /// <param name="onError">Is called and returned as <see cref="ResultOrError{TError}.Error(TError)"/> if This is a <see cref="Error"/>.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public ResultOrError <TError> Either <TError>(Action onSuccess, Func <TError> onError)
 {
     Args.ExceptionIfNull(onSuccess, nameof(onSuccess), onError, nameof(onError));
     if (_isSuccess)
     {
         onSuccess();
         return(ResultOrError <TError> .Success());
     }
     return(onError());
 }
 /// <summary>
 /// Creates a instance of <see cref="ResultOrError{TError}"/>.
 /// </summary>
 /// <typeparam name="TError"></typeparam>
 /// <param name="success"></param>
 /// <param name="errorFunc"></param>
 /// <returns></returns>
 public static ResultOrError <TError> Create <TError>(bool success, Func <TError> errorFunc)
 {
     Args.ExceptionIfNull(errorFunc, nameof(errorFunc));
     return(success ? ResultOrError <TError> .Success() : ResultOrError <TError> .Error(errorFunc()));
 }
Example #3
0
 /// <summary>
 /// Success: Returns a <see cref="ResultOrError{TError}.Success"/>.
 /// <para></para>
 /// Error: Calls <paramref name="onError"/> and returns a <see cref="ResultOrError{TError}.Error(TError)"/> with the <typeparamref name="TError"/> from <paramref name="onError"/>.
 /// </summary>
 /// <typeparam name="TError">The type of the Error.</typeparam>
 /// <param name="onError">Is called and returned as <see cref="ResultOrError{TError}.Error(TError)"/> if This is a <see cref="Error"/>.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public ResultOrError <TError> OnError <TError>(Func <TError> onError)
 {
     Args.ExceptionIfNull(onError, nameof(onError));
     return(_isSuccess ? ResultOrError <TError> .Success() : onError());
 }