Skip to content

A utility library featuring a Result type, designed to handle success or failure outcomes from functions, optionally returning a value. This approach helps avoid the overhead and inconvenience of throwing exceptions, making your code more efficient and readable.

Notifications You must be signed in to change notification settings

olivegamestudio/Utility.Result

Repository files navigation

Utility.Result

Result (Utility Library)

A utility library with Result type. This type provides a means of returning success or failure and an optional value. Great for avoiding throwing exceptions which are expensive.

Installation

You can use the NUGET package named Utility.Result that is on nuget.org or adding this line to an ItemGroup in your csproj file.

<PackageReference Include="Utility.Result" Version="*" />

Usage Examples

Returning a successful result from a function.

    public Result ReturnOkResult()
    {
        return OkResult.Ok();
    }

Returning a successful result and value from a function.

    public ObjectResult<int> ReturnIntegerResult()
    {
        ObjectResult<int> result = OkObjectResult<int>.Ok(100);
        return result;
    }

Returns a successful result from a task.

    public Task<Result> ReturnResultForTask()
    {
        return Task.FromResult<Result>(OkResult.Ok());
    }

Returns a failure from a function

    public Result ReturnFailure()
    {
        return ErrorResult.Fail("This function has failed because of...");
    }

About

A utility library featuring a Result type, designed to handle success or failure outcomes from functions, optionally returning a value. This approach helps avoid the overhead and inconvenience of throwing exceptions, making your code more efficient and readable.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages