https://github.com/zeelyn/method.result
https://github.com/zeelyn/method.result
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zeelyn/method.result
- Owner: ZeeLyn
- License: mit
- Created: 2024-02-02T08:34:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-02T08:45:59.000Z (over 1 year ago)
- Last Synced: 2025-01-18T17:57:00.080Z (5 months ago)
- Language: C#
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 | [](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);
}
```