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.
- Host: GitHub
- URL: https://github.com/olivegamestudio/utility.result
- Owner: olivegamestudio
- Created: 2024-07-22T07:54:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-29T12:57:03.000Z (10 months ago)
- Last Synced: 2025-01-25T22:54:50.605Z (8 months ago)
- Topics: best-practice, best-practices, csharp, patterns, result, result-pattern, standards, utility, utility-library
- Language: C#
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](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...");
}
```