generated from ricardo/MVCLogin
35 lines
966 B
C#
35 lines
966 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);
|
|
public static Result Failure<T>(Error error) => new(false, Error.None);
|
|
}
|
|
}
|