This is repository for OperationResult
opensource library (on .NET 6).
OperationResult
and OperationResult<TType>
is a type that can be used in validation, performing various actions.
Allows you to return from the method:
- a sign of success of execution;
- data of any type;
- validation message.
dotnet add package Sterlyukin.OperationResult
using OperationResultLibrary;
var service = new Service();
var successServiceResult = service.GetSuccess();
Console.WriteLine(successServiceResult.IsSuccess); //true
Console.WriteLine(successServiceResult.Message); //success message
var failServiceResult = service.GetFail();
Console.WriteLine(failServiceResult.IsSuccess); //fail
Console.WriteLine(failServiceResult.Message); //fail message
var successServiceResultWithData = service.GetSuccessWithData();
Console.WriteLine(successServiceResultWithData.IsSuccess); //true
Console.WriteLine(successServiceResultWithData.Message); //success message with data
Console.WriteLine(successServiceResultWithData.Data); //4
var failServiceResultWithData = service.GetFailWithData();
Console.WriteLine(failServiceResultWithData.IsSuccess); //fail
Console.WriteLine(failServiceResultWithData.Message); //fail message with data
Console.WriteLine(failServiceResultWithData.Data); //3
public class Service
{
public OperationResult GetSuccess()
{
return OperationResult.Success("success message");
}
public OperationResult GetFail()
{
return OperationResult.Fail("fail message");
}
public OperationResult<int> GetSuccessWithData()
{
return OperationResult<int>.Success(4, "success message with data");
}
public OperationResult<int> GetFailWithData()
{
return OperationResult<int>.Fail(3, "fail message with data");
}
}
Repository is opened for your contribution.
Improve it by creating Issues
and Pull requests
.
Pay attention that pull requests can be created only from issues.
Algorithm:
- Create an issue - describe what do you want to impore/fix in the library;
- Create new branch from
main
by patternissues_{issue number}
; - Create pull request to
main
branch; - Make sure that all checks passed successfully;
- Assign
sterlyukin
as reviewer of your pull-request; - Link issue to your PR;
- Wait for comments or approve;
- If your PR has some comments to fix - fix them and push to the branch again;
- Leave comments that you fixed under all remarks;
- When PR will be successfully closed - I will publish it to
nuget
.
CI/CD automated by Github Actions.
Build
and test
are launched on push to the branch.
Publish
to nuget launches manually in releases.