Skip to content

Instantly share code, notes, and snippets.

@pedrovasconcellos
Last active November 30, 2018 19:53
Show Gist options
  • Save pedrovasconcellos/f6ba41bfda39c70d49e1ff32cea124ec to your computer and use it in GitHub Desktop.
Save pedrovasconcellos/f6ba41bfda39c70d49e1ff32cea124ec to your computer and use it in GitHub Desktop.
DictionaryError Equals FluentValidation.AspNetCore
/// <summary>
/// DictionaryError
/// </summary>
/// <remarks>
/// Classe responsável por gerar o dicionário de erro da regra de negócio igual ao dicionário de erro do FluentValidation.AspNetCore.
/// </remarks>
internal static class ErrorDictionary
{
internal static Dictionary<string, string[]> GenerateError(string parameter, string message, Dictionary<string, string[]> dictionaryErrors = null)
{
if (string.IsNullOrEmpty(message)) throw new ArgumentException("A mensagem de erro não pode ser vazia.");
if (dictionaryErrors == null) dictionaryErrors = new Dictionary<string, string[]>();
dictionaryErrors.Add(parameter, new string[] { message });
return dictionaryErrors;
}
internal static Dictionary<string, string[]> GenerateError(string parameter, string[] messages, Dictionary<string, string[]> dictionaryErrors = null)
{
if (string.IsNullOrEmpty(messages[0])) throw new ArgumentException("A mensagem de erro não pode ser vazia.");
if (dictionaryErrors == null) dictionaryErrors = new Dictionary<string, string[]>();
dictionaryErrors.Add(parameter, messages);
return dictionaryErrors;
}
internal static Dictionary<string, string[]> GenerateError(Dictionary<string, string[]> dictionaryErrors)
{
if (dictionaryErrors == null || dictionaryErrors.Count == 0) throw new ArgumentException("A mensagem de erro não pode ser vazia.");
return dictionaryErrors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment