Skip to content

DekCode/GenericResult

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A supper lightweight handy utility to return a result with a value on success or errors on failure. Better error handling.

Quickly why?

  • Results with errors allow you to handle errors in your application properly. Let's say a function that returns a boolean can be true, false, or errors.
  • Clean code. The method returns errors and a value at once.

Why use this package?

  • Supper lightweight
  • Free + opensource
  • Easy to use
  • Simple, look at the code below
  • Support earlier version of .NetFramework and .NetCore

Usages

using Decepticon.GenericResult;
...
void ResultDemo()
{
    var result = Divide(108.0, 9);
    if (result.IsFailed)
    {
        Console.WriteLine(result.Error);
    }

    Console.WriteLine(result.Value);
}

Result<double> Divide(double dividen, double divider)
{
    if (divider == 0.0)
    {
        Result.Fail("Cannot divide by zero");
    }

    var someNumber = dividen / divider;
    return Result.Succeed(someNumber);
}

About

Source code for GenericResult library in C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages