Tethys.Results
1.0.0
dotnet add package Tethys.Results --version 1.0.0
NuGet\Install-Package Tethys.Results -Version 1.0.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="Tethys.Results" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tethys.Results" Version="1.0.0" />
<PackageReference Include="Tethys.Results" />
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 Tethys.Results --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tethys.Results, 1.0.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=Tethys.Results&version=1.0.0
#tool nuget:?package=Tethys.Results&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tethys.Results
A lightweight, thread-safe Result pattern implementation for .NET that provides a clean way to handle operation results with success/failure states, error messages, and optional data.
Features
- Simple and intuitive API for handling operation results
- Generic and non-generic result types
- Thread-safe and immutable implementation
- Comprehensive error handling with exception support
- Fluent extension methods for chaining operations
- Implicit conversion operators for seamless integration
- Aggregate error handling for combining multiple results
- Full XML documentation
Installation
Install the package via NuGet:
dotnet add package Tethys.Results
Or via the NuGet Package Manager:
Install-Package Tethys.Results
Usage
Basic Usage
using Tethys.Results;
// Create a successful result
var successResult = Result.Ok("Operation completed successfully");
// Create a failed result
var failResult = Result.Fail("Something went wrong");
// Create a failed result with an exception
var exceptionResult = Result.FromException(new Exception("An error occurred"));
// Check if the operation was successful
if (successResult.Success)
{
Console.WriteLine(successResult.Message);
}
Working with Data
// Create a successful result with data
var dataResult = Result<int>.Ok(42);
// Create a successful result with data and a custom message
var customDataResult = Result<string>.Ok("Hello, world!", "String retrieved successfully");
// Access the data
if (dataResult.Success)
{
Console.WriteLine($"The answer is: {dataResult.Data}");
}
// Get value or default
int value = dataResult.GetValueOrDefault();
// Try get value
if (dataResult.TryGetValue(out int result))
{
Console.WriteLine($"Got value: {result}");
}
// Get value or throw
try
{
int mustHaveValue = dataResult.GetValueOrThrow();
Console.WriteLine($"Value: {mustHaveValue}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
// Implicit conversion (will throw if result is not successful)
int answer = dataResult;
Combining Results
// Combine multiple results
var results = new List<Result>
{
Result.Ok("First operation succeeded"),
Result.Fail("Second operation failed"),
Result.FromException(new Exception("Third operation threw an exception"))
};
var combinedResult = Result.Combine(results);
// Combine multiple results with data
var dataResults = new List<Result<int>>
{
Result<int>.Ok(1),
Result<int>.Ok(2),
Result<int>.Fail("Failed to get third value")
};
var combinedDataResult = Result<int>.Combine(dataResults);
if (combinedDataResult.Success)
{
foreach (var item in combinedDataResult.Data)
{
Console.WriteLine(item);
}
}
Continuous Integration
This project uses GitHub Actions for continuous integration and deployment:
- Build and Test: Automatically builds and tests the project on every push to the main branch and pull requests. Uses the latest GitHub Actions (v4) for checkout, .NET setup, and artifact upload.
- Publish NuGet Package: Automatically publishes the package to NuGet.org when a new release is created on GitHub. Also uses the latest GitHub Actions (v4).
To use these workflows:
- Fork or clone this repository
- For publishing to NuGet.org, add your NuGet API key as a GitHub secret named
NUGET_API_KEY
- Create a new release on GitHub to trigger the publish workflow
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.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.0.0 | 237 | 4/2/2025 |