HCK.Result
8.0.0
See the version list below for details.
dotnet add package HCK.Result --version 8.0.0
NuGet\Install-Package HCK.Result -Version 8.0.0
<PackageReference Include="HCK.Result" Version="8.0.0" />
paket add HCK.Result --version 8.0.0
#r "nuget: HCK.Result, 8.0.0"
// Install HCK.Result as a Cake Addin #addin nuget:?package=HCK.Result&version=8.0.0 // Install HCK.Result as a Cake Tool #tool nuget:?package=HCK.Result&version=8.0.0
HCK.Result
HCK.Result
is a .NET
library that simplifies the process of returning and handling operation results from methods, including success or failure information, error messages, and HTTP status codes. It's particularly useful in web applications and APIs but can be utilized in any .NET
project to make result handling more structured and consistent.
Features
- Generic
Result<T>
type for operation results with an optional data payload. - Support for error messages as a list of strings.
- Includes HTTP status codes for integration with web projects.
- Simplifies method return types by encapsulating success, data, and error information.
- Supports implicit conversion from data or error information to
Result<T>
objects, making it easy to return from methods.
Getting Started
Installation
To use HCK.Result
in your project, install it via NuGet package manager or the dotnet
CLI:
Install-Package HCK.Result
Or through the .NET CLI:
dotnet add package HCK.Result
Usage
- Here's how to use
HCK.Result
in your.NET
applications:
Returning Success
public Result<string> GetGreeting(string name)
{
return $"Hello, {name}!";
}
- Returning Failure
public Result<string> GetGreeting(string name)
{
if (string.IsNullOrEmpty(name))
{
return (HttpStatusCode.BadRequest, "Name cannot be empty");
}
return $"Hello, {name}!";
}
- Handling Results
var result = GetGreeting("John");
if (result.IsSuccessful)
{
Console.WriteLine(result.Data);
}
else
{
Console.WriteLine($"Error ({result.StatusCode}): {string.Join(", ", result.ErrorMessages)}");
}
Contributing
We welcome contributions! Please submit any bug reports, suggestions, or pull requests to the project's issue tracker or repository.
License
HCK.Result
is licensed under the MIT License. See the LICENSE file in the source repositor for full details.
This Markdown formatted text can be directly used as a `README.md` file in your repository. Just make sure to update the placeholder `(LICENSE)` with a link to your actual license file, if applicable.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.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.