Intelsoft.Platform.Common.Result
1.0.0-beta-1
dotnet add package Intelsoft.Platform.Common.Result --version 1.0.0-beta-1
NuGet\Install-Package Intelsoft.Platform.Common.Result -Version 1.0.0-beta-1
<PackageReference Include="Intelsoft.Platform.Common.Result" Version="1.0.0-beta-1" />
paket add Intelsoft.Platform.Common.Result --version 1.0.0-beta-1
#r "nuget: Intelsoft.Platform.Common.Result, 1.0.0-beta-1"
// Install Intelsoft.Platform.Common.Result as a Cake Addin #addin nuget:?package=Intelsoft.Platform.Common.Result&version=1.0.0-beta-1&prerelease // Install Intelsoft.Platform.Common.Result as a Cake Tool #tool nuget:?package=Intelsoft.Platform.Common.Result&version=1.0.0-beta-1&prerelease
Result Library
Overview
The Result
and Result<T>
classes are designed to represent the outcome of operations within an application. They encapsulate the success or failure of an operation, with Result<T>
optionally containing a return value if the operation is successful, or errors if it fails.
This library also includes the ResultExtensions
class which provides utility methods for working with Result
and Result<T>
objects, allowing for clean and expressive handling of operation results without the need to manually check flags and error lists.
Installation
Using NuGet Package Manager
If the library is packaged as a NuGet package, you can install it using the NuGet Package Manager with the following command:
Install-Package Intelsoft.Platform.Common.Intelsoft
Manual Installation
If you are including the library manually:
- Clone the repository or download the latest release.
- Include the project or compiled DLL in your solution.
- Add a reference to the project or the DLL in your application.
Usage
Quick Start
Here is a simple example of how to use the Result
and Result<T>
classes:
using Intelsoft.Platform.Common.Result;
// Example of a successful result without data
Result successResult = Result.Ok();
// Example of a successful result with data
Result<int> successResultWithValue = Result.Ok(42);
// Example of a failure result
Result failureResult = Result.Fail(new Error("ERR001", "Invalid operation", ErrorType.Validation));
// Using ResultExtensions to handle results
string message = successResultWithValue.Match(
onSuccess: value => $"Operation succeeded with value: {value}",
onError: errors => $"Operation failed with error: {errors.First().Description}"
);
Handling Asynchronous Results
You can handle asynchronous results using the async extensions:
Task<Result<int>> resultTask = GetResultAsync();
int processedValue = await resultTask.Match(
onSuccess: value => ProcessValue(value),
onError: errors => HandleErrors(errors)
);
Running Tests
Ensure you have a testing framework like xUnit installed and configure your test environment:
- Navigate to the test directory.
- Run the tests using a test runner compatible with your setup (e.g., Visual Studio, Rider, or command line).
dotnet test
Contributing
Contributions are welcome! Please fork the repository and submit pull requests with any enhancements, bug fixes, or improvements you have made.
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 (1)
Showing the top 1 NuGet packages that depend on Intelsoft.Platform.Common.Result:
Package | Downloads |
---|---|
Intelsoft.Platform.Domain.Core
Core domain library containing essential building blocks for domain-driven design such as AggregateRoot, Entity, ValueObject, DomainEvent, Repository, and Specification. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta-1 | 66 | 4/12/2024 |