ResultWrapper.Library 2.1.0

dotnet add package ResultWrapper.Library --version 2.1.0
                    
NuGet\Install-Package ResultWrapper.Library -Version 2.1.0
                    
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="ResultWrapper.Library" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ResultWrapper.Library" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ResultWrapper.Library" />
                    
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 ResultWrapper.Library --version 2.1.0
                    
#r "nuget: ResultWrapper.Library, 2.1.0"
                    
#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 ResultWrapper.Library@2.1.0
                    
#: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=ResultWrapper.Library&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ResultWrapper.Library&version=2.1.0
                    
Install as a Cake Tool

Publish package to Nuget

A Simple Result wrapper for ASP.NET API projects

You can wrap all ASP.NET API response data via this package.

Features

  • Simple
  • Easy to use
  • Support both strong and dynamic types
  • Support auto type casting

Installation

You can install via nuget. Link

dotnet add package ResultWrapper.Library

Usage

Status result

[HttpGet]
public Wrapper OnlyStatus()
{
    return Wrapper.FromStatus(HttpStatusCode.OK);
}

[HttpGet]
public Wrapper OnlyStatus()
{
    return HttpStatusCode.OK;
}

[HttpGet]
public Wrapper OnlyStatus()
{
    return 200;
}

Success result

[HttpGet]
public Wrapper Add(int a, int b)
{
    return Wrapper.FromSuccess(a + b);
}

[HttpGet]
public Wrapper TextResult(int a, int b)
{
    return "Well Done!";
}

[HttpGet]
public Wrapper ResultWithCustomCode(int a, int b)
{
    return (new
    {
        Sum = a + b
    }, 200);
}

Error result


[HttpGet]
public Wrapper Error()
{
    try
    {
        throw new InvalidOperationException();
    }
    catch (Exception e)
    {
        return Wrapper.FromError(e, HttpStatusCode.BadRequest);
    }
}

Model state error

[HttpGet]
public Wrapper Error([FromBody] SampleModel model)
{
    if (!ModelState.IsValid)
        return Wrapper.FromModelState(ModelState);

    return Wrapper.FromStatus(HttpStatusCode.OK);
}

And you can also use Strong Typed Wrapper(Wrapper<T>) with such methods.

[HttpGet]
public Wrapper<string> ResultWithCustomCode()
{
    return Wrapper<string>.FromSuccess("Well Done!", HttpStatusCode.OK);
}

or

[HttpGet]
public Wrapper<string> ResultWithCustomCode()
{
    return "Well Done!";
}

Thanks for your attention!

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 is compatible.  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.
  • net9.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
2.1.0 119 6/23/2026
1.2.0 173 11/25/2024
1.1.3 32,168 6/28/2024
1.0.3 462 6/21/2024
1.0.2 434 5/5/2024
1.0.1 204 5/4/2024
1.0.0 197 5/4/2024