Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Utility.Result package and add result methods #4

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@ You can use the NUGET package named **Utility.Result** that is on nuget.org or a
### Returning a successful result from a function.

```
Result Method()
{
return Result.Ok();
}
public Result ReturnOkResult()
{
return OkResult.Ok();
}
```

### Returning a successful result and value from a function.

```
Result<int> Method()
{
return Result.Ok(100);
}
public ObjectResult<int> ReturnIntegerResult()
{
ObjectResult<int> result = OkObjectResult<int>.Ok(100);
return result;
}
```

### Returns a successful result from a task.

```
Task Method()
{
return Task.FromResult(Result.Ok());
}
public Task<Result> ReturnResultForTask()
{
return Task.FromResult<Result>(OkResult.Ok());
}
```

### Returns a failure from a function

```
Result Method()
{
return Result.Fail("This function has failed because of...");
}
public Result ReturnFailure()
{
return ErrorResult.Fail("This function has failed because of...");
}
```
21 changes: 21 additions & 0 deletions Utility.Result.Tests/ObjectResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,25 @@ public void Ok_Result_WithValue_Returns_Success()
result.Error.MustBeNullOrEmpty();
result.ErrorCode.MustBeZero();
}

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...");
}
}
17 changes: 11 additions & 6 deletions Utility.Result.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utility.Result", "Utility.R
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utility.Result.Tests", "Utility.Result.Tests\Utility.Result.Tests.csproj", "{2624FC37-2216-42F7-9640-D5751367986D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7E44851C-52C5-4453-A7FC-715B16AC294D}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D25D4C6-E7A0-4490-8BDE-9076CA666008}
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1A0DD539-9D41-4015-B493-48EFFAFDECE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -20,11 +26,10 @@ Global
{2624FC37-2216-42F7-9640-D5751367986D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2624FC37-2216-42F7-9640-D5751367986D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D25D4C6-E7A0-4490-8BDE-9076CA666008}
EndGlobalSection
EndGlobal
Loading