generated from ricardo/MVCLogin
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BaseDomain.Results
|
|
{
|
|
public enum ErrorTypeEnum
|
|
{
|
|
None = 0, //Erro vazio (para result)
|
|
Failure = 1, //Quando for uma falha que eu queira retornar no lugar de uma Exception
|
|
Validation = 2, //Quando for um problema de validação
|
|
Others = 3 //Inesperado ou sem categoria
|
|
}
|
|
|
|
public class Error
|
|
{
|
|
public Error(ErrorTypeEnum error, string message, string description="")
|
|
{
|
|
ErrorType = error;
|
|
Message = message;
|
|
}
|
|
|
|
public static Error None => new Error(ErrorTypeEnum.None, string.Empty, string.Empty);
|
|
|
|
public ErrorTypeEnum ErrorType { get; }
|
|
public string Message { get; }
|
|
public string Description { get; }
|
|
|
|
public static implicit operator string(Error error) => error.Message;
|
|
|
|
//Permitir atribuir um error diretamente ao resultado.
|
|
public static implicit operator Result(Error error) => Result.Failure(error);
|
|
}
|
|
}
|