Resultify 1.0.9

dotnet add package Resultify --version 1.0.9
                    
NuGet\Install-Package Resultify -Version 1.0.9
                    
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="Resultify" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Resultify" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="Resultify" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Resultify --version 1.0.9
                    
#r "nuget: Resultify, 1.0.9"
                    
#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.
#:package Resultify@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Resultify&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=Resultify&version=1.0.9
                    
Install as a Cake Tool

Resultify

Resultify is a C# library designed to handle and map responses with various categories and HTTP status codes. It provides a structured way to manage responses in your application, making it easier to handle success, error, and informational messages.

Features

  • Response Handling: Manage responses with different categories such as Success, Information, Redirection, ClientError, ServerError, and GenericError.
  • Response Mapping: Map responses to different types or values using custom mapping functions.

Installation

To install Resultify, you can use the NuGet package manager:

dotnet add package Resultify

Usage

Response Handling You can create a ResultifyHandler to handle different types of responses:

var handler = new ResultifyHandler<string>("Test Value", ResponseCategory.Success, "Success message", HttpStatusCode.OK);
Console.WriteLine(handler.Message); // Output: Success message

Response Mapping

Map responses to different types or values using the MapResponse method:

var handler = new ResultifyHandler<string>("Test Value", ResponseCategory.Success, "Success message", HttpStatusCode.OK);
var result = handler.MapResponse(value => value.Length);
Console.WriteLine(result.Value); // Output: Test Value

Error Handling

Handle different categories of responses:

// Sample method that returns a ResultifyHandler
public async Task<ResultifyHandler<int?>> Producer()
{
    // Some work is done here
    int? result = await AnotherComputedValue();
    
    // Produce a response based on the result
    if (result is null)
    {
        return Resultify.NotFound<int?>(HttpStatusCode.NotFound, "Value not found");
    }
    return Resultify.Success(result, HttpStatusCode.OK, "Optional message");
    
}

// MapResponse method can be used to map the response to a different type
public async Task<ResultifyHandler<ObjectDTO>> Producer2()
{
    // Some work is done here
    ResultifyHandler<DbObject?> result = await AnotherComputedValue();
    
    return result.MapResponse(r => r.AsDTO());
}

// Sample method that consumes the ResultifyHandler
public async Task<int> Consumer()
{
    var result = await Producer();
    
    // Handle the response based on the category
    if (result.Category == ResponseCategory.Success)
    {
        Console.WriteLine(result.Value);
    }
    else
    {
        Console.WriteLine(result.Message);
    }
    
    // Check multiple values 
    var objectDto = await Producer2();
    
    if(Resultify.AnyFail(result, objectDto))
    {
        Console.WriteLine("At least one response is an error");
    }
    
    return Resultify.Success(result, HttpStatusCode.Ok);
}

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

    • No dependencies.
  • net7.0

    • No dependencies.
  • 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
1.0.9 185 9/22/2024
1.0.7 164 9/22/2024
1.0.6 153 9/22/2024
1.0.5 178 9/15/2024
1.0.0 177 9/15/2024