ZeidLab.ToolBox
1.0.0-preview-250205134509
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
This is a prerelease version of ZeidLab.ToolBox.
dotnet add package ZeidLab.ToolBox --version 1.0.0-preview-250205134509
NuGet\Install-Package ZeidLab.ToolBox -Version 1.0.0-preview-250205134509
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="ZeidLab.ToolBox" Version="1.0.0-preview-250205134509" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZeidLab.ToolBox --version 1.0.0-preview-250205134509
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ZeidLab.ToolBox, 1.0.0-preview-250205134509"
#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 ZeidLab.ToolBox as a Cake Addin #addin nuget:?package=ZeidLab.ToolBox&version=1.0.0-preview-250205134509&prerelease // Install ZeidLab.ToolBox as a Cake Tool #tool nuget:?package=ZeidLab.ToolBox&version=1.0.0-preview-250205134509&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ToolBox Project
The ToolBox project is a utility library designed to simplify error handling and functional programming in C#. It provides types and methods for working with railway-oriented programming (ROP), making it easier to write robust, predictable, and maintainable code.
Key Features
- Result Type: Represents the outcome of an operation that can either succeed or fail.
- Error Type: Encapsulates error details, including a code, name, message, and optional exception.
- Unit Type: Represents a void-like value for operations that don't return meaningful results.
- Try and TryAsync Delegates: Simplify exception handling for synchronous and asynchronous operations.
## Installation
Add the ToolBox library to your project via NuGet:
```bash
dotnet add package ZeidLab.ToolBox
```
### Examples
1. Using Result<T> for Success and Failure
```csharp
Result<int> Divide(int a, int b)
{
if (b == 0)
return Result<int>.Failure(Error.New("Division by zero is not allowed."));
return Result<int>.Success(a / b);
}
var result = Divide(10, 0);
if (result.IsSuccess)
Console.WriteLine($"Result: {result.Value}");
else
Console.WriteLine($"Error: {result.Error.Message}");
```
2. Using Unit for Void-like Operations
```csharp
Result<Unit> LogMessage(string message)
{
Console.WriteLine(message);
return Result<Unit>.Success(Unit.Default);
}
var result = LogMessage("Hello, World!");
if (result.IsSuccess)
Console.WriteLine("Message logged successfully.");
else
Console.WriteLine($"Error: {result.Error.Message}");
```
3. Using Try and TryAsync for Error Handling
```csharp
Try<int> riskyOperation = () => throw new InvalidOperationException("Something went wrong.");
Result<int> result = riskyOperation.Try();
if (result.IsFailure)
Console.WriteLine($"Error: {result.Error.Message}");
TryAsync<int> asyncOperation = async () =>
{
await Task.Delay(100);
throw new InvalidOperationException("Async failure.");
};
var asyncResult = await asyncOperation.Try();
if (asyncResult.IsFailure)
Console.WriteLine($"Async Error: {asyncResult.Error.Message}");
```
4. Chaining Operations with Railway-Oriented Programming
```csharp
Result<int> operation1 = Result<int>.Success(10);
Result<int> operation2 = operation1.Bind(value => Result<int>.Success(value * 2));
if (operation2.IsSuccess)
Console.WriteLine($"Chained Result: {operation2.Value}");
```
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
## 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 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 is compatible. 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 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 is compatible. 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 is compatible. |
.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
- AsyncMethodNameFixer (>= 2.3.0)
-
.NETStandard 2.1
- AsyncMethodNameFixer (>= 2.3.0)
-
net6.0
- AsyncMethodNameFixer (>= 2.3.0)
-
net7.0
- AsyncMethodNameFixer (>= 2.3.0)
-
net8.0
- AsyncMethodNameFixer (>= 2.3.0)
-
net9.0
- AsyncMethodNameFixer (>= 2.3.0)
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-preview-250205134509 | 0 | 2/5/2025 |
1.0.0-preview-250117102955 | 32 | 1/17/2025 |
1.0.0-preview-250113112143 | 38 | 1/13/2025 |
1.0.0-preview-250113110427 | 35 | 1/13/2025 |
1.0.0-preview-250112104449 | 43 | 1/12/2025 |
1.0.0-preview-250110120258 | 35 | 1/10/2025 |
1.0.0-preview-250109195935 | 25 | 1/9/2025 |