HCK.Result 8.0.4

dotnet add package HCK.Result --version 8.0.4                
NuGet\Install-Package HCK.Result -Version 8.0.4                
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="HCK.Result" Version="8.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HCK.Result --version 8.0.4                
#r "nuget: HCK.Result, 8.0.4"                
#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 HCK.Result as a Cake Addin
#addin nuget:?package=HCK.Result&version=8.0.4

// Install HCK.Result as a Cake Tool
#tool nuget:?package=HCK.Result&version=8.0.4                

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 (400, "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)}");
}
  • For error using Failure method:
  • One error message
Result<string> result = Result<string>.Failure("Is fail!");
  • Multiple error messages
Result<string> result = Result<string>.Failure(new List<string>() {"Is fail!","Is not unique!"});
  • One error message return 500 status code
Result<string> result = Result<string>.Failure("Is fail!"); //return 500 status code
  • Multiple error messages return 500 status code
Result<string> result = Result<string>.Failure(new List<string>() {"Is fail!","Is not unique!"}); //return 500 status code

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
8.0.4 101 4/8/2024
8.0.3 96 4/3/2024
8.0.2 90 4/3/2024
8.0.1 56 4/2/2024
8.0.0 73 4/1/2024