Giter Site home page Giter Site logo

gayemce / gayemce.result Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 354 KB

It is designed for improving error handling and response consistency while developing applications. It is a .NET library intended to encapsulate processing outcomes with support for success, failure, and associated HTTP status code.

License: MIT License

C# 100.00%

gayemce.result's Introduction

Gayemce.Result NuGet Package

Overview

The Gayemce.Result package is designed to encapsulate the result of operations in .NET applications, offering a structured way to handle success and failure states with associated data or error messages. It is ideal for improving error handling and response consistency across various application layers.

Features

  • Generic Result Type: Facilitates strong typing of the operation outcome, accommodating any data type.
  • Error Handling: Enables capturing multiple error messages, suitable for scenarios requiring detailed feedback.
  • HTTP Status Code Integration: Aligns operation results with HTTP response standards, enhancing API development.
  • Implicit Conversions: Streamlines result creation from data or errors through implicit conversion operators.

Getting Started

Installation

To integrate Gayemce.Result into your project, install it via the NuGet package manager:

Install-Package Gayemce.Result

Or through the .NET CLI:

dotnet add package Gayemce.Result

Usage

  • For a successful operation, instantiate a Result object with the desired data:
var successResult = new Result<string>("Operation successful.");
  • Alternatively, leverage implicit conversion from data:
Result<string> result = "Operation successful.";
  • For failures, create a Result object with an HTTP status code and error messages:
var errorResult = new Result<string>(400, new List<string> { "Error 1", "Error 2" });
  • Or use implicit conversion from error details:
Result<string> result = (400, new List<string> { "Error 1", "Error 2" });
  • For single error messages:
Result<string> result = (400, "Single error message");
  • For success using Succeed method:
Result<string> result = Result<string>.Succeed("Is successful");
  • For error using Failure method:
  • One error message:
Result<string> result = Result<string>.Failure(500, "Is fail!");
  • One error message return 500 status code:
Result<string> result = Result<string>.Failure(500, "Is fail!"); //return 500 status code
  • Multiple error messages:
Result<string> result = Result<string>.Failure(500, new List<string>() {"Is fail!", "Is not unique!"});
  • Multiple error messages return 500 status code:
Result<string> result = Result<string>.Failure(500, new List<string>() {"Is fail!", "Is not unique!"}); //return 500 status code

Contributing

We welcome contributions! Feel free to open an issue or submit a pull request on our GitHub repository for any suggestions or improvements.

License

Gayemce.Result is licensed under the MIT License. See the LICENSE file in the source repository for full details.

gayemce.result's People

Contributors

gayemce avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.