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.
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="*" />
public Result ReturnOkResult()
{
return OkResult.Ok();
}
public ObjectResult<int> ReturnIntegerResult()
{
ObjectResult<int> result = OkObjectResult<int>.Ok(100);
return result;
}
public Task<Result> ReturnResultForTask()
{
return Task.FromResult<Result>(OkResult.Ok());
}
public Result ReturnFailure()
{
return ErrorResult.Fail("This function has failed because of...");
}