diff --git a/src/Wolfgang.TryPattern/Result.cs b/src/Wolfgang.TryPattern/Result.cs
index 8443c09..f791e12 100644
--- a/src/Wolfgang.TryPattern/Result.cs
+++ b/src/Wolfgang.TryPattern/Result.cs
@@ -30,19 +30,26 @@ protected Result
string? errorMessage
)
{
- switch (succeeded)
+ if (succeeded && errorMessage != string.Empty)
{
- case true when errorMessage != string.Empty:
- 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 message.", nameof(errorMessage));
+ throw new ArgumentException
+ (
+ "A successful result cannot have an error message.",
+ nameof(errorMessage)
+ );
+ }
- default:
- Succeeded = succeeded;
- ErrorMessage = errorMessage;
- break;
+ if (!succeeded && string.IsNullOrWhiteSpace(errorMessage))
+ {
+ throw new ArgumentException
+ (
+ "A failed result must have an error message.",
+ nameof(errorMessage)
+ );
}
+
+ Succeeded = succeeded;
+ ErrorMessage = errorMessage;
}
@@ -51,7 +58,7 @@ protected Result
/// Creates a failed Result with the specified error Message.
///
/// The error message indicating the reason for failure.
- /// errorMessage is null or empty
+ /// errorMessage is null, empty, or whitespace
public static Result Failure(string errorMessage) =>
string.IsNullOrWhiteSpace(errorMessage)
? throw new ArgumentException("errorMessage cannot be empty", nameof(errorMessage))
@@ -302,7 +309,7 @@ public class Result : Result
/// Creates a failed Result with the specified error message.
///
/// The error message indicating the reason for failure.
- /// errorMessage is null or empty
+ /// errorMessage is null, empty, or whitespace
#if NET5_0_OR_GREATER
public static new Result Failure(string errorMessage) =>
string.IsNullOrWhiteSpace(errorMessage)