EffectiveResult 1.0.0-alpha

This is a prerelease version of EffectiveResult.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package EffectiveResult --version 1.0.0-alpha                
NuGet\Install-Package EffectiveResult -Version 1.0.0-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EffectiveResult" Version="1.0.0-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EffectiveResult --version 1.0.0-alpha                
#r "nuget: EffectiveResult, 1.0.0-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EffectiveResult as a Cake Addin
#addin nuget:?package=EffectiveResult&version=1.0.0-alpha&prerelease

// Install EffectiveResult as a Cake Tool
#tool nuget:?package=EffectiveResult&version=1.0.0-alpha&prerelease                

Effective Result

Simple examples

// Just result
Result successRes = Result.Ok();

bool isSuccess = successRes.IsSuccess;
bool isFailed = successRes.IsFailed;

// Error from message
Result failedRes1 = Result.Fail("Ooops!"); 
// Error from exception
Result failedRes2 = Result.Fail(new Exception("Bad situation!")); 

Result with value

Result<int> successValuedRes = Result.Ok(5);
// Error from message
Result<int> failedValueRes1 = Result.Fail<int>("Ooops!"); 
// Error from exception
Result<int> failedValueRes2 = Result.Fail<int>(new Exception("Bad situation!")); 

/// Result methods
Result<int> countResult = Result.Ok(1000);

// Throw, if failed
int myValue1 = countResult.Value; 
// Not throw, but can return default value of type
int myValue2 = countResult.ValueOrDefault; 
// Get value or return other value
int myValue3 = countResult.GetValueOrDefault(100); 
// Get value or construct and return other value
int myValue4 = countResult.GetValueOrDefault(() => 2); 

Work with errors

// Base type of errors
var coreError = new Error("Bad 1");
var exError = new ExceptionalError(new Exception("Sorry, but..."));

// Errors using
Result fail = Result.Fail(new ArgumentException("myVariable"));
// Get errors of result
IReadOnlyCollection<IError> errors = fail.Errors; 

bool hasSpecificError = fail.Errors.HasErrorsOfType<ExceptionalError>(x => x.Exception is ArgumentException);

// Get all exception of ExceptionalError, if contains
IEnumerable<Exception> exceptions = fail.GetExceptions(); 
// Get all typed exception of ExceptionalError, if contains
IEnumerable<ArgumentException> exceptionsTyped = fail.GetExceptions<ArgumentException>(); 
// Get all filtered exception of ExceptionalError, if contains
IEnumerable<Exception> exceptionsFiltered = fail.GetExceptions(x => x.Message == "Oops!"); 

// Get first exception of ExceptionalError, if contains
bool contains1 = fail.TryGetException(out Exception? exception); 
// Get first typed exception of ExceptionalError, if contains
bool contains2 = fail.TryGetException(out ArgumentException? argumentEx); 
// Get first filtered exception of ExceptionalError, if contains
bool contains3 = fail.TryGetException(out Exception? filtered, x => x.Message == "Oops!"); 

Useful static methods

// Conditional
Result cond1 = Result.OkIf(1 == 2, "Error message");
Result cond2 = Result.FailIf(2 == 1, new Exception("Oh..."));

/// Try and return
// Return failed result with error, variable will be false
Result wasSuccess = Result.Try(() => throw new Exception("No no no")); 
// Return success result with value
Result<int> valuedResult = Result.Try(() => 100); 
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-alpha-2 93 10/18/2024
1.0.0-alpha 63 8/31/2024

Initial pre-release version