public static IValidationDef <T?> IsValidEnum <T>(this IValidationDef <T?> validationDef)
            where T : struct
        {
            if (typeof(T).IsEnum == false)
            {
                return(validationDef.Is(
                           predicate: _ => false,
                           message: $"Argument not valid, $name$ is expected to be of an enum type. {typeof(T).Name} is not an enum"));
            }

            return(validationDef.Is(
                       predicate: arg => arg == null || typeof(T).IsEnumDefined(arg.Value),
                       message: "Argument not valid, $name$ is $actualValue$ but expected to be one of $validValues$.",
                       validValues: typeof(T).GetEnumNames()));
        }
 private static IValidationDef <T> IsBetweenImpl <T>(this IValidationDef <T> validationDef, T value, T and)
     where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
 => validationDef.Is(
     predicate : arg =>
     (Comparer <T> .Default.Compare(arg, value) >= 0 && Comparer <T> .Default.Compare(arg, and) <= 0) ||
     (Comparer <T> .Default.Compare(arg, value) <= 0 && Comparer <T> .Default.Compare(arg, and) >= 0),
     message : $"Argument not valid, $name$ is $actualValue$ but expected to be between {value} and {and}.",
     validValues : value);
 public static IValidationDef <IEnumerable <T> > ContainsAny <T>(this IValidationDef <IEnumerable <T> > validationDef, Func <T, bool> matching, string message = null)
 => validationDef.Is(
     predicate: arg => matching != null && arg != null && arg.Any(matching),
     message: message ?? "Argument not valid, none of the items in $name$ is meeting the given condition");
 public static IValidationDef <IEnumerable <T> > IsNotEmpty <T>(this IValidationDef <IEnumerable <T> > validationDef)
 => validationDef.Is(
     predicate: arg => arg != null && arg.Any(),
     message: "Argument not valid, $name$ is empty or null but expected to contain atleast one item.");
 public static IValidationDef <string> Contains(this IValidationDef <string> validationDef, string value)
 => validationDef.Is(
     predicate: arg => arg != null && value != null && arg.Contains(value),
     message: "Argument not valid, $name$ is $actualValue$ but accepted value should contain $validValues$.",
     validValues: value);
 public static IValidationDef <T?> IsEqualTo <T>(this IValidationDef <T?> validationDef, T value) where T : struct
 => validationDef.Is(
     predicate : arg => arg.HasValue && EqualityComparer <T> .Default.Equals(arg.Value, value),
     message : "Argument not valid, $name$ is $actualValue$ but expected to be equal to $validValues$.",
     validValues : value);
 private static IValidationDef <T?> IsLessThanNullableImpl <T>(this IValidationDef <T?> validationDef, T value)
     where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
 => validationDef.Is(
     predicate : arg => arg.HasValue && Comparer <T> .Default.Compare(arg.Value, value) < 0,
     message : "Argument not valid, $name$ is $actualValue$ but expected to be less than $validValues$.",
     validValues : value);
 public static IValidationDef <T> IsIn <T>(this IValidationDef <T> validationDef, params T[] values)
 => validationDef.Is(
     predicate: arg => arg.In(values),
     message: "Argument not valid, $name$ is $actualValue$ but accepted values are $validValues$.",
     validValues: values);
 private static IValidationDef <T> IsGreaterThanImpl <T>(this IValidationDef <T> validationDef, T value)
     where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
 => validationDef.Is(
     predicate : arg => Comparer <T> .Default.Compare(arg, value) > 0,
     message : "Argument not valid, $name$ is $actualValue$ but expected to be greater than $validValues$.",
     validValues : value);