SResult 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SResult --version 1.3.0
                    
NuGet\Install-Package SResult -Version 1.3.0
                    
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="SResult" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SResult" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="SResult" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SResult --version 1.3.0
                    
#r "nuget: SResult, 1.3.0"
                    
#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.
#addin nuget:?package=SResult&version=1.3.0
                    
Install SResult as a Cake Addin
#tool nuget:?package=SResult&version=1.3.0
                    
Install SResult as a Cake Tool

SResult

This is an "as simple as it could" result pattern library published to reuse in any clean software development.

Simplicity

It just a single class file and which is tested and reliable. And thats all I was needed on most cases. But instead of copying that again and again for every project, now I can simply refer to this package and all good.

Structure

Result<TResult, TReason>

Just a simple immutable object.
You define what is result when success and how you want to deliver reason when bad.
It has to have a Result when success.
It has to have a Reason when bad.
It impossible to be both or neither.
A Result cannot be null when success.
A Reason cannot be null when bad.

Because of these checks it is very reliable and need not to write check and guard rails and null checks all over code.

It guarantees a result when success. And guarantees a reason when bad.

public void Sample1()
{
    DummyHttpGet("http://somedomain.com")
    .OnSuccess(() => { /* Do something on success */ })
    .OnFail(() => { /* Do something on failure */ });
}

public void Sample2()
{
    DummyHttpGet("http://somedomain.com")
    .OnSuccess((result) => { /* Do something on success with result */ })
    .OnFail((reason) => { /* Do something on failure with failure */ });
}

private static Result<int, string> DummyHttpGet(string url)
{
    if (string.IsNullOrEmpty(url)) return "Url cannot be blank";
    return 200;
}

Manually making result

var result = Result.Success<int, int>(200);

Or

var result = Result.Fail<int, int>(-1);

Note: Manual way is the only way when result and reason have same types.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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.3.3 205 3/5/2025
1.3.2 82 3/1/2025
1.3.1 99 2/27/2025
1.3.0 100 2/27/2025
1.2.2 101 2/27/2025
1.2.1 105 2/27/2025
1.2.0 96 2/27/2025
1.0.2 92 12/13/2024
1.0.1 97 12/11/2024
1.0.0 99 12/6/2024