SS.Result 8.0.0

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

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

ResultNuGetPackage

The ResultNuGetPackage provides a generic Result<T> class for managing operation results in .NET applications. It helps in representing both successful and failed outcomes with appropriate status codes and error messages.

Namespace

namespace ResultNuGetPackage.ClassLibrary
{
    public sealed class Result<T>
    {
        // Class implementation
    }
}

Overview

The Result<T> class encapsulates the result of an operation, including success status, data, error messages, and an HTTP status code. It is designed to simplify error handling and result management in your applications.

Properties

  • Data: Contains the result data if the operation was successful.
  • ErrorMessages: A list of error messages if the operation failed.
  • IsSuccessful: A boolean indicating whether the operation was successful.
  • StatusCode: An HTTP status code representing the result of the operation.

Constructors

  • Result(T data): Initializes a new instance representing a successful operation with the provided data. Defaults to a status code of 200 (OK).

  • Result(string message, int statusCode = 400): Initializes a new instance representing a failed operation with a single error message and an optional status code (defaults to 400).

  • Result(List<string> messages, int statusCode = 400): Initializes a new instance representing a failed operation with multiple error messages and an optional status code (defaults to 400).

Static Methods

  • static Result<T> Successful(T data): Creates a new Result<T> instance representing a successful operation with the given data.

  • static Result<T> Failure(string message): Creates a new Result<T> instance representing a failed operation with a single error message and a default status code of 500 (Internal Server Error).

  • static Result<T> Failure(List<string> messages, int statusCode = 500): Creates a new Result<T> instance representing a failed operation with multiple error messages and a customizable status code (defaults to 500).

Usage

Successful Result

var result = Result<int>.Successful(42);
Console.WriteLine(result.IsSuccessful);  // Output: True
Console.WriteLine(result.Data);           // Output: 42
Console.WriteLine(result.StatusCode);    // Output: 200

Failed Result with Single Error Message

var result = Result<int>.Failure("An error occurred");
Console.WriteLine(result.IsSuccessful);  // Output: False
Console.WriteLine(result.ErrorMessages[0]); // Output: An error occurred
Console.WriteLine(result.StatusCode);    // Output: 500

Failed Result with Multiple Error Messages

var errorMessages = new List<string> { "First error", "Second error" };
var result = Result<int>.Failure(errorMessages, 400);
Console.WriteLine(result.IsSuccessful);  // Output: False
Console.WriteLine(string.Join(", ", result.ErrorMessages)); // Output: First error, Second error
Console.WriteLine(result.StatusCode);    // Output: 400

Installation

To install the SS.Result, use the following NuGet command:

dotnet add package SS.Result

Or search for SS.Result on NuGet Package Manager in Visual Studio.

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.0 118 8/19/2024

Bu bir Result paketidir.