CutelynResults 0.1.0-alpha
See the version list below for details.
dotnet add package CutelynResults --version 0.1.0-alpha
NuGet\Install-Package CutelynResults -Version 0.1.0-alpha
<PackageReference Include="CutelynResults" Version="0.1.0-alpha" />
paket add CutelynResults --version 0.1.0-alpha
#r "nuget: CutelynResults, 0.1.0-alpha"
// Install CutelynResults as a Cake Addin
#addin nuget:?package=CutelynResults&version=0.1.0-alpha&prerelease
// Install CutelynResults as a Cake Tool
#tool nuget:?package=CutelynResults&version=0.1.0-alpha&prerelease
last updated: 19/10/2022
CutelynResults creates away to manage exceptions in C# while enforcing exception handling. Heavily inspired by Rust's results, a result can either be Success
or Error
. An Error
here contains an Exception. Success<T>
also can contain a value.
The benefits of using IResults is it requires you to check if the result is successful or not before being able to get the success value. Prompting handling of the error cases.
Basic Usage
Returning IResult
Returning a result from a function is as simple as calling IResult.Success(VALUE)
where your function wants to successfully return a value, and IResult.Exception(EXCEPTION)
where an error arises.
public IResult<HttpContent> IoCall(){
...
//success case
if(Response.IsSuccessStatusCode)
{
return IResult.Success(Response.Content)
}
//error case
return IResult.Error(new IoException())
...
}
Handling IResult
Using c# pattern matching you can check wether a result is ISuccess
or IError
, and then get the .Value
or .Exception
from these casted variables.
public void UserRequestsIoCall(){
IResult<HttpContent> requestResult = IoCall();
//on error
if(requestResult is IError requestError){
var exception = requestError.Exception;
Console.WriteLine(exception.Message)
return;
}
//on success
var requestSuccess = (Success<HttpContent>) requestResult;
var requestContent = requestSuccess.Value;
...
}
Documentation Incomplete...
Product | Versions 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. |
-
net6.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 |
---|---|---|
0.2.0-alpha.1 | 90 | 6/20/2023 |
0.1.0 | 298 | 1/15/2023 |
0.1.0-alpha.2 | 131 | 10/21/2022 |
0.1.0-alpha | 147 | 10/19/2022 |