Skip to content

Simple class(es) for returning a result value and success/failure state

License

Notifications You must be signed in to change notification settings

putridparrot/PutridParrot.Results

Repository files navigation

PutridParrot.Results

Build PutridParrot.Results NuGet version (PutridParrot.Results) GitHub license GitHub Releases GitHub Issues

Note: This is a total re-write of the Results code-base to simplify everything.

There are several ways to return a result and/or error code from a method/function. For example, we might return an integer value, if the value is negative it represents an error. We might return an integer error code (such as some of the Windows API functions do) and the actual return value is returned via out parameters or similar. Or we return something like a tuple with a value to indicate the error or success along with a returned value.

The IResult is an interface for implementing a better tuple version of this, in that we will return a Success or Failure object and we can using type pattern matching to determine whether the return is a success or failure and then access a return value accordingly.

IResult<string> DoSomething()
{
    // do some stuff

    // if failed, return a failure with a failure message
    // return Result.Failure("Failed");


    // if succeeded, with result value (a string in this case)
    return Result.Success("Completed");
}

About

Simple class(es) for returning a result value and success/failure state

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages