Skip to content

Commit

Permalink
result error comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Aug 25, 2024
1 parent dda0126 commit 0811677
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions src/Danom/Result/ResultErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public ResultErrors(string key, string error)
public ResultErrors(string error)
: this([new ResultError(error)]) { }

/// <summary>
/// Adds a new error to the collection.
/// </summary>
/// <param name="error"></param>
public void Add(ResultError error) =>
_errors.Add(error);

Expand All @@ -67,34 +71,75 @@ public override string ToString()
}

/// <summary>
/// Static methods for creating <see cref="IResult{T, TError}"/> instances with
/// <see cref="ResultErrors"/> as the error type.
/// The <see cref="Result{T, TError}"/> with <see cref="ResultErrors"/>
/// as the predefined error type.
///
/// Alias for <see cref="Result{T, ResultErrors}"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
public static class Result<T>
{
/// <summary>
/// Creates a new Result with the specified value.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static IResult<T, ResultErrors> Ok(T value) =>
Result<T, ResultErrors>.Ok(value);

/// <summary>
/// Creates Result with the specified value wrapped in a completed Task.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Task<IResult<T, ResultErrors>> OkAsync(T value) =>
Result<T, ResultErrors>.OkAsync(value);

/// <summary>
/// Creates Result with the value of the awaited Task.
/// </summary>
/// <param name="valueTask"></param>
/// <returns></returns>
public static Task<IResult<T, ResultErrors>> OkAsync(Task<T> valueTask) =>
Result<T, ResultErrors>.OkAsync(valueTask);

/// <summary>
/// Creates a new Result with the specified error.
/// </summary>
/// <param name="errors"></param>
/// <returns></returns>
public static IResult<T, ResultErrors> Error(ResultErrors errors) =>
Result<T, ResultErrors>.Error(errors);

/// <summary>
/// Creates Result with the specified error wrapped in a completed Task.
/// </summary>
/// <param name="errors"></param>
/// <returns></returns>
public static Task<IResult<T, ResultErrors>> ErrorAsync(ResultErrors errors) =>
Task.FromResult(Error(errors));

/// <summary>
/// Creates a new Result with the specified error.
/// </summary>
/// <param name="messages"></param>
/// <returns></returns>
public static IResult<T, ResultErrors> Error(IEnumerable<string> messages) =>
Error(new ResultErrors(messages));

/// <summary>
/// Creates Result with the specified error wrapped in a completed Task.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static IResult<T, ResultErrors> Error(string message) =>
Error([message]);


/// <summary>
/// Creates Result with the specified error wrapped in a completed Task.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static Task<IResult<T, ResultErrors>> ErrorAsync(string message) =>
Task.FromResult(Error(message));
}
Expand Down

0 comments on commit 0811677

Please sign in to comment.