MVCPostall/BaseDomain/Results/Result.cs
2025-03-04 19:06:01 -03:00

34 lines
886 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaseDomain.Results
{
public class Result
{
protected Result(bool isSuccess, Error error)
{
if (isSuccess && error.ErrorType != ErrorTypeEnum.None)
{
throw new InvalidOperationException();
}
if (!isSuccess && error == Error.None)
{
throw new InvalidOperationException();
}
this.IsSuccess = isSuccess;
this.Error = error;
}
public bool IsSuccess { get; }
public bool IsFalilure => !IsSuccess;
public Error Error { get; }
public static Result Success() => new(true, Error.None);
public static Result Failure(Error error) => new(false, Error.None);
}
}