ZeidLab.ToolBox 1.0.0-preview-250117102955

This is a prerelease version of ZeidLab.ToolBox.
dotnet add package ZeidLab.ToolBox --version 1.0.0-preview-250117102955                
NuGet\Install-Package ZeidLab.ToolBox -Version 1.0.0-preview-250117102955                
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-250117102955" />                
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-250117102955                
#r "nuget: ZeidLab.ToolBox, 1.0.0-preview-250117102955"                
#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-250117102955&prerelease

// Install ZeidLab.ToolBox as a Cake Tool
#tool nuget:?package=ZeidLab.ToolBox&version=1.0.0-preview-250117102955&prerelease                

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 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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.