Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/Wolfgang.TryPattern/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class Result
/// </summary>
/// <param name="succeeded">A value indicating whether the operation succeeded. Set to <see langword="true"/>
/// if the operation was successful; otherwise, <see langword="false"/>.</param>
/// <param name="errorMessage">Error errorMessage associated with the result.</param>
/// <param name="errorMessage">Error message associated with the result.</param>
/// <remarks>
/// If the operation was successful, errorMessage must be an empty string. If the operation failed
/// errorMessage must not be null or empty
/// If the operation was successful, <paramref name="errorMessage"/> must be an empty string. If the operation failed,
/// <paramref name="errorMessage"/> must not be null, empty, or whitespace.
/// </remarks>
protected Result
(
Expand All @@ -32,10 +32,10 @@ protected Result
switch (succeeded)
{
case true when errorMessage != string.Empty:
throw new ArgumentException("A successful result cannot have an error errorMessage.", nameof(errorMessage));
throw new ArgumentException("A successful result cannot have an error message.", nameof(errorMessage));

case false when string.IsNullOrWhiteSpace(errorMessage):
throw new ArgumentException("A failed result must have an error errorMessage.", nameof(errorMessage));
throw new ArgumentException("A failed result must have an error message.", nameof(errorMessage));

default:
Succeeded = succeeded;
Expand All @@ -59,7 +59,7 @@ public static Result Failure(string errorMessage) =>


/// <summary>
/// Creates a successful <see cref="Result"/>>.
/// Creates a successful <see cref="Result"/>.
/// </summary>
public static Result Success() => new(true, string.Empty);

Expand Down Expand Up @@ -124,7 +124,7 @@ public static Result Flatten(params Result[] results)
/// Returns true if any of the specified <see cref="Result"/>s indicate a failure.
/// Otherwise, false.
/// </summary>
/// <param name="results">The array of <see cref="Result"/>> to review</param>
/// <param name="results">The array of <see cref="Result"/> to review.</param>
/// <returns>
/// <see langword="true"/> if any of the specified <see cref="Result"/>s failed, otherwise <see langword="false"/>.
/// </returns>
Expand All @@ -137,7 +137,7 @@ public static bool AnyFailed(params Result[]? results) =>
/// <summary>
/// Returns true if all the specified <see cref="Result"/>s indicate success.
/// </summary>
/// <param name="results">The array of <see cref="Result"/>> to review</param>
/// <param name="results">The array of <see cref="Result"/> to review.</param>
/// <returns>
/// <see langword="true"/> if all the specified <see cref="Result"/>s succeeded, otherwise <see langword="false"/>.
/// </returns>
Expand All @@ -151,7 +151,7 @@ public static bool AllSucceeded(params Result[]? results) =>
/// <summary>
/// The result of executing an <seealso cref="Func{T}"/>. Contains properties indicating whether the operation
/// <see cref="Result.Succeeded"/> or <see cref="Result.Failed"/>. If the operation failed the
/// <see cref="Result.ErrorMessage"/> property will contain message as to why. If the operation succeeded the
/// <see cref="Result.ErrorMessage"/> property will contain a message as to why. If the operation succeeded the
/// <see cref="Result{T}.Value"/> property will contain the return value from the function.
/// </summary>
public class Result<T> : Result
Expand All @@ -171,11 +171,13 @@ public class Result<T> : Result
/// </summary>
/// <param name="succeeded">A value indicating whether the operation succeeded. Set to <see langword="true"/>
/// if the operation was successful; otherwise, <see langword="false"/>.</param>
/// <param name="errorMessage">Error errorMessage associated with the result.</param>
/// <param name="value">The return value of the function if it succeeded, otherwise the default value for {T}</param>
/// <param name="errorMessage">Error message associated with the result.</param>
/// <param name="value">The return value of the function if it succeeded, otherwise the default value for <typeparamref name="T"/>.</param>
/// <remarks>
/// If the operation was successful, errorMessage must be an empty string and value should be the return value from the function.
/// If the operation failed errorMessage must not be null or empty and the value should be default{T}
/// If the operation was successful, <paramref name="errorMessage"/> must be an empty string and
/// <paramref name="value"/> should be the return value from the function.
/// If the operation failed, <paramref name="errorMessage"/> must not be null, empty, or whitespace and
/// <paramref name="value"/> should be <c>default(T)</c>.
Comment thread
Chris-Wolfgang marked this conversation as resolved.
/// </remarks>
#if NET5_0_OR_GREATER
private Result(bool succeeded, string? errorMessage, T? value) : base(succeeded, errorMessage) => _value = value;
Expand Down
12 changes: 4 additions & 8 deletions src/Wolfgang.TryPattern/Try.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class Try
/// </summary>
/// <param name="action">The action to execute.</param>
/// <returns>
/// A <see cref="Result"/> that indicates if the action was successful
/// A <see cref="Result"/> that indicates if the action was successful.
/// </returns>
public static Result Run(Action action)
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public static Result Run(Action action)
/// <param name="action">The action to execute.</param>
/// <param name="token">The CancellationToken to monitor.</param>
/// <returns>
/// A <see cref="Task"/> of <see cref="Result"/> representing the asynchronous operation
/// A <see cref="Task"/> of <see cref="Result"/> representing the asynchronous operation.
/// </returns>
public static async Task<Result> RunAsync(Action action, CancellationToken token = default)
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public static async Task<Result> RunAsync(Action action, CancellationToken token
/// <param name="function">The function to execute.</param>
/// <returns>
/// A <see cref="Result{T}"/> indicating if the function was successful or not and the result of
/// the function if it was.
/// the function if it was.
/// </returns>
#if NET5_0_OR_GREATER
public static Result<T?> Run<T>(Func<T> function)
Expand Down Expand Up @@ -116,6 +116,7 @@ public static Result<T> Run<T>(Func<T>? function)
#endif



/// <summary>
/// Executes the specified function, catching any exception that may occur.
/// </summary>
Expand Down Expand Up @@ -170,9 +171,4 @@ public static async Task<Result<T>> RunAsync<T>(Func<Task<T>> function, Cancella
}
}
#endif




}

2 changes: 1 addition & 1 deletion tests/Wolfgang.TryPattern.Tests/RunAsyncFuncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#endif
namespace Wolfgang.TryPattern.Tests;

public class RunAsyncFuncTests // TODO Rename class and file
public class RunAsyncFuncTests
{
[Fact]
public async Task RunAsync_Func_when_passed_null_throws_ArgumentNullException()
Expand Down
2 changes: 1 addition & 1 deletion tests/Wolfgang.TryPattern.Tests/RunFuncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#endif
namespace Wolfgang.TryPattern.Tests;

public class RunFuncTests // TODO Rename class and file
public class RunFuncTests
{
[Fact]
public void Run_Func_WithNullFunction_ThrowsArgumentNullException()
Expand Down