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

https://github.com/zeelyn/method.result


https://github.com/zeelyn/method.result

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Method.Return.Results

It returns an object indicating success or failure of an operation instead of throwing/using exceptions.

# Packages & Status

| Packages | NuGet |Note|
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |---|
| Method.Return.Results | [![NuGet package](https://buildstats.info/nuget/Method.Return.Results )](https://www.nuget.org/packages/Method.Return.Results )

```csharp
public Result Create1(string name, string address)
{
if (string.IsNullOrWhiteSpace(name))
{
return Result.Fail("Name is required!");
}

if (string.IsNullOrWhiteSpace(address))
{
return Result.Fail("Address is required!");
}

//.....
return Result.Ok(123);
}

public Result Create2(string name, string address)
{
var result = Result.Fail(
string.IsNullOrWhiteSpace(name) ? "Name is required!" : string.Empty,
string.IsNullOrWhiteSpace(address) ? "Address is required!" : string.Empty
);
if (result.Failed)
return result;
//.....
return Result.Ok(123);
}

public Result Create3(string name, string address)
{
var result = Result.Merge(
Result.FailIf(string.IsNullOrWhiteSpace(name), "Name is required!"),
Result.FailIf(string.IsNullOrWhiteSpace(address), "Address is required!")
);
if (result.Failed)
return result;
//.....
return Result.Ok(123);
}
```