ResultSharp.Core
1.3.0
dotnet add package ResultSharp.Core --version 1.3.0
NuGet\Install-Package ResultSharp.Core -Version 1.3.0
<PackageReference Include="ResultSharp.Core" Version="1.3.0" />
<PackageVersion Include="ResultSharp.Core" Version="1.3.0" />
<PackageReference Include="ResultSharp.Core" />
paket add ResultSharp.Core --version 1.3.0
#r "nuget: ResultSharp.Core, 1.3.0"
#:package ResultSharp.Core@1.3.0
#addin nuget:?package=ResultSharp.Core&version=1.3.0
#tool nuget:?package=ResultSharp.Core&version=1.3.0
ResultSharp
ResultSharp is a Rust-like error and null handling package for C#. It provides Option and Result types to handle optional values and error handling in a more expressive and safer way.
Features
Option<T>type for handling optional values.Result<T>type for handling operations that can succeed or fail.- Extension methods for mapping and transforming
OptionandResulttypes. - Asynchronous support for mapping
OptionandResulttypes.
Installation
To install ResultSharp, add the following package reference to your project file:
<PackageReference Include="ResultSharp" Version="1.2.0" />
Alternatively, you can install it via the .NET CLI:
dotnet add package ResultSharp --version 1.3.0
Usage
Here is a simple example of how to use ResultSharp:
using ResultSharp;
public class Example
{
public static void Main()
{
var result = Result.Ok("Success");
var message = result switch
{
Ok<string> ok => $"Operation succeeded with value: {ok.Value}",
Err<string> err => $"Operation failed with error: {err.Exception.Message}",
_ => "Unknown result",
};
}
}
Mapping and Transforming
You can use the Map and MapAsync methods to transform Option and Result types.
Synchronous Mapping
using ResultSharp;
public class Example
{
public static void Main()
{
var option = Option.Some(5);
var mappedOption = option.Map(x => x * 2);
Console.WriteLine(mappedOption); // Output: Some(10)
var result = Result.Ok(5);
var mappedResult = result.Map(x => x * 2);
Console.WriteLine(mappedResult); // Output: Ok(10)
}
}
Asynchronous Mapping
using ResultSharp;
using System.Threading.Tasks;
public class Example
{
public static async Task Main()
{
var optionTask = Task.FromResult(Option.Some(5));
var mappedOption = await optionTask.MapAsync(async x => await Task.FromResult(x * 2));
Console.WriteLine(mappedOption); // Output: Some(10)
var resultTask = Task.FromResult(Result.Ok(5));
var mappedResult = await resultTask.MapAsync(async x => await Task.FromResult(x * 2));
Console.WriteLine(mappedResult); // Output: Ok(10)
}
}
Contributing
We welcome contributions to ResultSharp! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes.
- Submit a pull request with a detailed description of your changes.
Please make sure to follow the coding standards and write tests for your changes.
License
ResultSharp is licensed under the MIT License. See the LICENSE file for more information.
Contact
If you have any questions or feedback, feel free to open an issue on GitHub or contact us at geffc1454@gmail.com.
| 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.