An open API service indexing awesome lists of open source software.

https://github.com/olivegamestudio/utility.result

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.
https://github.com/olivegamestudio/utility.result

best-practice best-practices csharp patterns result result-pattern standards utility utility-library

Last synced: 7 months ago
JSON representation

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.

Awesome Lists containing this project

README

          

[![Utility.Result](https://img.shields.io/nuget/v/Utility.Result)](https://www.nuget.org/packages/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.

```

```

## 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 ReturnIntegerResult()
{
ObjectResult result = OkObjectResult.Ok(100);
return result;
}
```

### Returns a successful result from a task.

```
public Task ReturnResultForTask()
{
return Task.FromResult(OkResult.Ok());
}
```

### Returns a failure from a function

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