From e1974948ef44af0ca000eb61ba014c9828c093ea Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:25:21 -0500 Subject: [PATCH 1/5] fix: add checks for conditional compilation --- src/StevanFreeborn.Results/Result.cs | 132 ++++++---- .../ResultAsyncExtensions.cs | 240 ++++++++++++------ 2 files changed, 248 insertions(+), 124 deletions(-) diff --git a/src/StevanFreeborn.Results/Result.cs b/src/StevanFreeborn.Results/Result.cs index d64262f..b1ee909 100644 --- a/src/StevanFreeborn.Results/Result.cs +++ b/src/StevanFreeborn.Results/Result.cs @@ -53,15 +53,23 @@ namespace StevanFreeborn.Results /// Thrown when func or errorHandler is null. public static Result Try(Func func, Func errorHandler) where TError : IError { - if (func is null) - { - throw new ArgumentNullException(nameof(func)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(func); + #else + if (func is null) + { + throw new ArgumentNullException(nameof(func)); + } + #endif - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(errorHandler); + #else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } + #endif try { @@ -142,10 +150,14 @@ namespace StevanFreeborn.Results /// Thrown when mapper is null. public Result Map(Func mapper) { - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(mapper); + #else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } + #endif return IsSuccess ? Result.Ok(mapper(Value)) : Result.Fail(Error); } @@ -158,10 +170,14 @@ namespace StevanFreeborn.Results /// Thrown when mapper is null. public Result MapError(Func mapper) where TNewError : IError { - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(mapper); + #else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } + #endif return IsFailure ? Result.Fail(mapper(Error)) : Result.Ok(Value); } @@ -175,10 +191,14 @@ namespace StevanFreeborn.Results /// Thrown when binder is null. public Result Bind(Func> binder) { - if (binder is null) - { - throw new ArgumentNullException(nameof(binder)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(binder); + #else + if (binder is null) + { + throw new ArgumentNullException(nameof(binder)); + } + #endif return IsSuccess ? binder(Value) : Result.Fail(Error); } @@ -193,15 +213,23 @@ namespace StevanFreeborn.Results /// Thrown when onSuccess or onFailure is null. public TResult Match(Func onSuccess, Func onFailure) { - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onFailure); + #else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } + #endif return IsSuccess ? onSuccess(Value) : onFailure(Error); } @@ -214,15 +242,23 @@ namespace StevanFreeborn.Results /// Thrown when onSuccess or onFailure is null. public void Match(Action onSuccess, Action onFailure) { - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onFailure); + #else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } + #endif if (IsSuccess) { @@ -242,10 +278,14 @@ namespace StevanFreeborn.Results /// Thrown when action is null. public Result Map(Action action) { - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(action); + #else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + #endif if (IsSuccess) { @@ -262,10 +302,14 @@ namespace StevanFreeborn.Results /// Thrown when action is null. public Result Map(Action action) { - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(action); + #else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + #endif if (IsSuccess) { diff --git a/src/StevanFreeborn.Results/ResultAsyncExtensions.cs b/src/StevanFreeborn.Results/ResultAsyncExtensions.cs index ee5ed71..a081816 100644 --- a/src/StevanFreeborn.Results/ResultAsyncExtensions.cs +++ b/src/StevanFreeborn.Results/ResultAsyncExtensions.cs @@ -19,15 +19,23 @@ namespace StevanFreeborn.Results public static async Task> MapAsync(this Result result, Func> mapper) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(mapper); + #else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } + #endif return result.IsSuccess ? await mapper(result.Value).ConfigureAwait(false) : result.Error; } @@ -46,15 +54,23 @@ namespace StevanFreeborn.Results where TError : IError where TNewError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(mapper); + #else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } + #endif return result.IsFailure ? await mapper(result.Error).ConfigureAwait(false) : Result.Ok(result.Value); } @@ -70,15 +86,23 @@ namespace StevanFreeborn.Results public static async Task> MapAsync(this Result result, Func onSuccess) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif if (result.IsSuccess) { @@ -99,15 +123,23 @@ namespace StevanFreeborn.Results public static async Task> BindAsync(this Result result, Func>> onSuccess) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) : result; } @@ -125,20 +157,32 @@ namespace StevanFreeborn.Results public static async Task MatchAsync(this Result result, Func> onSuccess, Func> onFailure) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onFailure); + #else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } + #endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) @@ -164,15 +208,23 @@ namespace StevanFreeborn.Results /// Thrown when action or errorHandler is null. public static async Task> TryAsync(Func action, Func errorHandler) { - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(action); + #else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + #endif - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(errorHandler); + #else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } + #endif try { @@ -198,15 +250,23 @@ namespace StevanFreeborn.Results public static async Task> BindAsync(this Result result, Func>> binder) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (binder is null) - { - throw new ArgumentNullException(nameof(binder)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(binder); + #else + if (binder is null) + { + throw new ArgumentNullException(nameof(binder)); + } + #endif return result.IsSuccess ? await binder(result.Value).ConfigureAwait(false) : Result.Fail(result.Error); } @@ -225,20 +285,32 @@ namespace StevanFreeborn.Results public static async Task MatchAsync(this Result result, Func> onSuccess, Func> onFailure) where TError : IError { - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(result); + #else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } + #endif - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onSuccess); + #else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } + #endif - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(onFailure); + #else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } + #endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) @@ -266,15 +338,23 @@ namespace StevanFreeborn.Results /// Thrown when func or errorHandler is null. public static async Task> TryAsync(Func> func, Func errorHandler) { - if (func is null) - { - throw new ArgumentNullException(nameof(func)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(func); + #else + if (func is null) + { + throw new ArgumentNullException(nameof(func)); + } + #endif - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } + #if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(errorHandler); + #else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } + #endif try { From eda47f616b627ef48758aa1c3b33f08f7f6ff109 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:25:35 -0500 Subject: [PATCH 2/5] chore: remove analyzer setting --- src/.editorconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/.editorconfig b/src/.editorconfig index a834286..3ae1c72 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -1,5 +1,4 @@ [*.cs] dotnet_diagnostic.CA1031.severity = none -dotnet_diagnostic.CA1510.severity = none dotnet_diagnostic.CA2225.severity = none \ No newline at end of file From 0630a673076a8f9d52f046732bb940173ed31f57 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:26:29 -0500 Subject: [PATCH 3/5] chore: enable CI builds --- src/StevanFreeborn.Results/StevanFreeborn.Results.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/StevanFreeborn.Results/StevanFreeborn.Results.csproj b/src/StevanFreeborn.Results/StevanFreeborn.Results.csproj index 1284e54..38d36a9 100644 --- a/src/StevanFreeborn.Results/StevanFreeborn.Results.csproj +++ b/src/StevanFreeborn.Results/StevanFreeborn.Results.csproj @@ -21,6 +21,9 @@ README.md LICENSE.md + + true + From b177276b3d55997f22719a5f57208cf1f41d2b0b Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:29:41 -0500 Subject: [PATCH 4/5] chore: run dotnet format --- src/StevanFreeborn.Results/Result.cs | 154 +++++----- .../ResultAsyncExtensions.cs | 280 +++++++++--------- .../ErrorTests.cs | 2 +- .../ResultAsyncExtensionsTests.cs | 2 +- .../ResultTTests.cs | 2 +- .../ResultTests.cs | 4 +- 6 files changed, 222 insertions(+), 222 deletions(-) diff --git a/src/StevanFreeborn.Results/Result.cs b/src/StevanFreeborn.Results/Result.cs index b1ee909..65529ea 100644 --- a/src/StevanFreeborn.Results/Result.cs +++ b/src/StevanFreeborn.Results/Result.cs @@ -53,23 +53,23 @@ namespace StevanFreeborn.Results /// Thrown when func or errorHandler is null. public static Result Try(Func func, Func errorHandler) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(func); - #else - if (func is null) - { - throw new ArgumentNullException(nameof(func)); - } - #endif +#else + if (func is null) + { + throw new ArgumentNullException(nameof(func)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(errorHandler); - #else - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } - #endif +#else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } +#endif try { @@ -150,14 +150,14 @@ namespace StevanFreeborn.Results /// Thrown when mapper is null. public Result Map(Func mapper) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(mapper); - #else - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } - #endif +#else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } +#endif return IsSuccess ? Result.Ok(mapper(Value)) : Result.Fail(Error); } @@ -170,14 +170,14 @@ namespace StevanFreeborn.Results /// Thrown when mapper is null. public Result MapError(Func mapper) where TNewError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(mapper); - #else - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } - #endif +#else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } +#endif return IsFailure ? Result.Fail(mapper(Error)) : Result.Ok(Value); } @@ -191,14 +191,14 @@ namespace StevanFreeborn.Results /// Thrown when binder is null. public Result Bind(Func> binder) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(binder); - #else - if (binder is null) - { - throw new ArgumentNullException(nameof(binder)); - } - #endif +#else + if (binder is null) + { + throw new ArgumentNullException(nameof(binder)); + } +#endif return IsSuccess ? binder(Value) : Result.Fail(Error); } @@ -213,23 +213,23 @@ namespace StevanFreeborn.Results /// Thrown when onSuccess or onFailure is null. public TResult Match(Func onSuccess, Func onFailure) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onFailure); - #else - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } - #endif +#else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } +#endif return IsSuccess ? onSuccess(Value) : onFailure(Error); } @@ -242,23 +242,23 @@ namespace StevanFreeborn.Results /// Thrown when onSuccess or onFailure is null. public void Match(Action onSuccess, Action onFailure) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onFailure); - #else - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } - #endif +#else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } +#endif if (IsSuccess) { @@ -278,14 +278,14 @@ namespace StevanFreeborn.Results /// Thrown when action is null. public Result Map(Action action) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(action); - #else - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } - #endif +#else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } +#endif if (IsSuccess) { @@ -302,14 +302,14 @@ namespace StevanFreeborn.Results /// Thrown when action is null. public Result Map(Action action) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(action); - #else - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } - #endif +#else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } +#endif if (IsSuccess) { diff --git a/src/StevanFreeborn.Results/ResultAsyncExtensions.cs b/src/StevanFreeborn.Results/ResultAsyncExtensions.cs index a081816..eeff219 100644 --- a/src/StevanFreeborn.Results/ResultAsyncExtensions.cs +++ b/src/StevanFreeborn.Results/ResultAsyncExtensions.cs @@ -19,23 +19,23 @@ namespace StevanFreeborn.Results public static async Task> MapAsync(this Result result, Func> mapper) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(mapper); - #else - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } - #endif +#else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } +#endif return result.IsSuccess ? await mapper(result.Value).ConfigureAwait(false) : result.Error; } @@ -54,23 +54,23 @@ namespace StevanFreeborn.Results where TError : IError where TNewError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(mapper); - #else - if (mapper is null) - { - throw new ArgumentNullException(nameof(mapper)); - } - #endif +#else + if (mapper is null) + { + throw new ArgumentNullException(nameof(mapper)); + } +#endif return result.IsFailure ? await mapper(result.Error).ConfigureAwait(false) : Result.Ok(result.Value); } @@ -86,23 +86,23 @@ namespace StevanFreeborn.Results public static async Task> MapAsync(this Result result, Func onSuccess) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif if (result.IsSuccess) { @@ -123,23 +123,23 @@ namespace StevanFreeborn.Results public static async Task> BindAsync(this Result result, Func>> onSuccess) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) : result; } @@ -157,32 +157,32 @@ namespace StevanFreeborn.Results public static async Task MatchAsync(this Result result, Func> onSuccess, Func> onFailure) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onFailure); - #else - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } - #endif +#else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } +#endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) @@ -208,23 +208,23 @@ namespace StevanFreeborn.Results /// Thrown when action or errorHandler is null. public static async Task> TryAsync(Func action, Func errorHandler) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(action); - #else - if (action is null) - { - throw new ArgumentNullException(nameof(action)); - } - #endif +#else + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(errorHandler); - #else - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } - #endif +#else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } +#endif try { @@ -250,23 +250,23 @@ namespace StevanFreeborn.Results public static async Task> BindAsync(this Result result, Func>> binder) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(binder); - #else - if (binder is null) - { - throw new ArgumentNullException(nameof(binder)); - } - #endif +#else + if (binder is null) + { + throw new ArgumentNullException(nameof(binder)); + } +#endif return result.IsSuccess ? await binder(result.Value).ConfigureAwait(false) : Result.Fail(result.Error); } @@ -285,32 +285,32 @@ namespace StevanFreeborn.Results public static async Task MatchAsync(this Result result, Func> onSuccess, Func> onFailure) where TError : IError { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(result); - #else - if (result is null) - { - throw new ArgumentNullException(nameof(result)); - } - #endif +#else + if (result is null) + { + throw new ArgumentNullException(nameof(result)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onSuccess); - #else - if (onSuccess is null) - { - throw new ArgumentNullException(nameof(onSuccess)); - } - #endif +#else + if (onSuccess is null) + { + throw new ArgumentNullException(nameof(onSuccess)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(onFailure); - #else - if (onFailure is null) - { - throw new ArgumentNullException(nameof(onFailure)); - } - #endif +#else + if (onFailure is null) + { + throw new ArgumentNullException(nameof(onFailure)); + } +#endif return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) @@ -338,23 +338,23 @@ namespace StevanFreeborn.Results /// Thrown when func or errorHandler is null. public static async Task> TryAsync(Func> func, Func errorHandler) { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(func); - #else - if (func is null) - { - throw new ArgumentNullException(nameof(func)); - } - #endif +#else + if (func is null) + { + throw new ArgumentNullException(nameof(func)); + } +#endif - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(errorHandler); - #else - if (errorHandler is null) - { - throw new ArgumentNullException(nameof(errorHandler)); - } - #endif +#else + if (errorHandler is null) + { + throw new ArgumentNullException(nameof(errorHandler)); + } +#endif try { diff --git a/tests/StevanFreeborn.Results.Tests/ErrorTests.cs b/tests/StevanFreeborn.Results.Tests/ErrorTests.cs index 132d790..1242fca 100644 --- a/tests/StevanFreeborn.Results.Tests/ErrorTests.cs +++ b/tests/StevanFreeborn.Results.Tests/ErrorTests.cs @@ -61,4 +61,4 @@ public class ErrorTests await Assert.That(error).IsAssignableTo(); } -} +} \ No newline at end of file diff --git a/tests/StevanFreeborn.Results.Tests/ResultAsyncExtensionsTests.cs b/tests/StevanFreeborn.Results.Tests/ResultAsyncExtensionsTests.cs index 91621b9..cdf5762 100644 --- a/tests/StevanFreeborn.Results.Tests/ResultAsyncExtensionsTests.cs +++ b/tests/StevanFreeborn.Results.Tests/ResultAsyncExtensionsTests.cs @@ -196,4 +196,4 @@ public class ResultAsyncExtensionsTests await Assert.That(result.IsFailure).IsTrue(); await Assert.That(result.Error.Code).IsEqualTo("custom"); } -} +} \ No newline at end of file diff --git a/tests/StevanFreeborn.Results.Tests/ResultTTests.cs b/tests/StevanFreeborn.Results.Tests/ResultTTests.cs index b3b5ec9..0415972 100644 --- a/tests/StevanFreeborn.Results.Tests/ResultTTests.cs +++ b/tests/StevanFreeborn.Results.Tests/ResultTTests.cs @@ -200,4 +200,4 @@ public class ResultTTests await Assert.That(result.IsFailure).IsTrue(); await Assert.That(result.Error.Code).IsEqualTo("custom"); } -} +} \ No newline at end of file diff --git a/tests/StevanFreeborn.Results.Tests/ResultTests.cs b/tests/StevanFreeborn.Results.Tests/ResultTests.cs index 93a2396..ef7e42c 100644 --- a/tests/StevanFreeborn.Results.Tests/ResultTests.cs +++ b/tests/StevanFreeborn.Results.Tests/ResultTests.cs @@ -16,7 +16,7 @@ public class ResultTests { var error = new Error("code", "message"); var result = Result.Fail(error); - + await Assert.That(result.IsSuccess).IsFalse(); await Assert.That(result.IsFailure).IsTrue(); await Assert.That(result.Error).IsEqualTo(error); @@ -163,4 +163,4 @@ public class ResultTests await Assert.That(result.IsFailure).IsTrue(); await Assert.That(result.Error.Code).IsEqualTo("custom"); } -} +} \ No newline at end of file From 5e5758f55d696d785dd7887d2338f06e4b4d97d8 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:40:16 -0500 Subject: [PATCH 5/5] docs: update README.md [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39ce4b3..73000f3 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![NuGet](https://img.shields.io/nuget/v/StevanFreeborn.Results.svg)](https://www.nuget.org/packages/StevanFreeborn.Results) [![NuGet](https://img.shields.io/nuget/dt/StevanFreeborn.Results.svg)](https://www.nuget.org/packages/StevanFreeborn.Results) -[![Build](https://github.com/StevanFreeborn/stevanfreeborn.results/actions/workflows/ci.yaml/badge.svg)](https://github.com/StevanFreeborn/stevanfreeborn.results/actions/workflows/ci.yaml) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Build](https://gitea.freeborn.cloud/Stevan/stevanfreeborn.results/actions/workflows/ci.yml/badge.svg)](https://github.com/StevanFreeborn/stevanfreeborn.results/actions/workflows/ci.yaml) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE.md) A minimalistic, AOT-compatible Result type library with support for custom error types, for railway-oriented programming and functional error handling in .NET.