Exemple #1
0
 public static NativeValidator <T> NotEmptyCollection <T>(this NativeValidator <T> target) where T : System.Collections.ICollection
 {
     if (target.Value.Count == 0)
     {
         throw new ArgumentException(ResourceMessageFormatter.Create(() => Properties.Resources.ValidationErrors_NotEmptyCollection, target.Name).Format());
     }
     return(target);
 }
Exemple #2
0
 public static NativeValidator <T> NotNull <T>(this NativeValidator <T> target)
 {
     if (target.Value == null)
     {
         throw new ArgumentNullException(ResourceMessageFormatter.Create(() => Properties.Resources.ValidationErrors_NotNull, target.Name).Format());
     }
     return(target);
 }
Exemple #3
0
 /// <summary>
 /// Aplica a validação para verificar se o objeto é o tipo experado.
 /// </summary>
 /// <typeparam name="T">Tipo do argumento que será validado.</typeparam>
 /// <param name="target">Instancia do objeto que será validado.</param>
 /// <param name="desiredType">O <see cref="Type"/> para verifica se o tipo é compatível.</param>
 /// <exception cref="InvalidCastException">Caso o target não seja do tipo especificado pelo parametro <paramref name="desiredType"/>.</exception>
 public static NativeValidator <T> IsOfType <T>(this NativeValidator <T> target, Type desiredType)
 {
     if (target.Value.GetType() != desiredType)
     {
         throw new InvalidCastException(ResourceMessageFormatter.Create(() => Properties.Resources.ValidationErrors_IsOfType, target.Name, desiredType.FullName).Format());
     }
     return(target);
 }
Exemple #4
0
 public static NativeValidator <string> NotEmpty(this NativeValidator <string> target)
 {
     if (target.Value.Length == 0)
     {
         throw new ArgumentException(ResourceMessageFormatter.Create(() => Properties.Resources.ValidationErrors_NotEmpty, target.Name).Format());
     }
     return(target);
 }
Exemple #5
0
 public static NativeValidator <int> CheckForOutOfRange(this NativeValidator <int> target, int minimum)
 {
     if (target.Value < minimum)
     {
         throw new ArgumentOutOfRangeException(target.Name, target.Value, ResourceMessageFormatter.Create(() => Properties.Resources.ValidationErrors_OutOfRange, target.Name).Format());
     }
     return(target);
 }