SResult 1.0.2
dotnet add package SResult --version 1.0.2
NuGet\Install-Package SResult -Version 1.0.2
<PackageReference Include="SResult" Version="1.0.2" />
paket add SResult --version 1.0.2
#r "nuget: SResult, 1.0.2"
// Install SResult as a Cake Addin #addin nuget:?package=SResult&version=1.0.2 // Install SResult as a Cake Tool #tool nuget:?package=SResult&version=1.0.2
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<TSuccessType, TFailureReason>
Just a simple immutable object.
You define what is result for success and how you want to deliver reason for failure.
It has to have a Result when success.
It has to have a Reason for failure.
It impossible to be both or neither.
A Result cannot be null when success.
A Reason cannot be null when failed.
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 for failure.
public void Sample1()
{
DummyHttpGet("http://somedomain.com")
.OnSuccess(() => { /* Do something on success */ })
.OnFailure(() => { /* Do something on failure */ });
}
public void Sample2()
{
DummyHttpGet("http://somedomain.com")
.OnSuccess((result) => { /* Do something on success with success result */ })
.OnFailure((reason) => { /* Do something on failure with failure reason */ });
}
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.CreateSuccessResult(200);
Or
var result = Result.CreateFailureReason(-1);
Or
var result = Result.CreateFailureReason<string, string>(-1);
Note: Manual way is the only way when result and reason have same types.
Product | Versions 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. |
-
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.