Esempio n. 1
0
        public static IValidateValue <T> ToHaveValue <T>(this IValidateValue <T> param, string reason = null, params object[] reasonArgs)
        {
            if (object.Equals(param.Value, default(T)))
            {
                param.HandleMissingValue("be specified", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 2
0
        public static IValidateValue <T> NotToBeEqualTo <T>(this IValidateValue <T> param, object other, string reason = null, params object[] reasonArgs)
        {
            if (object.Equals(param.Value, other))
            {
                param.HandleValueMismatch($"be equal to '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 3
0
        public static IValidateValue <T> ToBeMoreOrEqualThan <T>(this IValidateValue <T> param, T other, IComparer <T> comparer, string reason = null, params object[] reasonArgs)
        {
            if (comparer.Compare(param.Value, other) < 0)
            {
                param.HandleValueMismatch($"be more or equal than '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 4
0
        public static IValidateValue <T> NotToBeSameAs <T>(this IValidateValue <T> param, object other, string reason = null, params object[] reasonArgs)
            where T : class
        {
            if (object.ReferenceEquals(param.Value, other))
            {
                param.HandleValueMismatch($"be different than '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 5
0
        public static IValidateValue <T> NotToBeNull <T>(this IValidateValue <T> param, string reason = null, params object[] reasonArgs)
            where T : class
        {
            if (object.ReferenceEquals(param.Value, null))
            {
                param.HandleMissingValue("be specified", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 6
0
        public static IValidateValue <T> ToBeLessOrEqualThan <T>(this IValidateValue <T> param, T other, string reason = null, params object[] reasonArgs)
            where T : IComparable <T>
        {
            if (param.Value.CompareTo(other) > 0)
            {
                param.HandleValueMismatch($"be less or equal to '{MessageFormatter.FormatValue(other)}'", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 7
0
        public static IValidateValue <T> ToBeNegative <T>(this IValidateValue <T> param, string reason = null, params object[] reasonArgs)
            where T : IComparable <T>
        {
            if (param.Value.CompareTo(default(T)) >= 0)
            {
                param.HandleValueMismatch("to be negative", null, reason, reasonArgs);
            }

            return(param);
        }
Esempio n. 8
0
        public static IValidateValue <Type> ToBeAssignableTo(this IValidateValue <Type> param, Type type, string reason = null, params object[] reasonArgs)
        {
            if (!type.IsAssignableFrom(param.Value))
            {
                param.HandleValueMismatch(
                    $"be assignable to \"{type.FullName}\"",
                    null,
                    reason,
                    reasonArgs);
            }

            return(param);
        }
Esempio n. 9
0
        public static IValidateValue <TValue> ToBeInstanceOf <TValue>(this IValidateValue <TValue> param, Type targetType, string reason = null, params object[] reasonArgs)
        {
            if (!targetType.IsInstanceOfType(param.Value))
            {
                param.HandleValueMismatch(
                    $"be instance of \"{targetType.FullName}\"",
                    param.Value != null ? $"instance of \"{param.Value.GetType().FullName}\"" : null,
                    reason,
                    reasonArgs);
            }

            return(param);
        }
Esempio n. 10
0
 public static IValidateValue <TValue> ToBeInstanceOf <TValue, TType>(this IValidateValue <TValue> param, string reason = null, params object[] reasonArgs)
 {
     return(param.ToBeInstanceOf(typeof(TType), reason, reasonArgs));
 }
Esempio n. 11
0
 public static IValidateValue <Type> ToBeAssignableTo <T>(this IValidateValue <Type> param, string reason = null, params object[] reasonArgs)
 {
     return(param.ToBeAssignableTo(typeof(T), reason, reasonArgs));
 }
Esempio n. 12
0
 public static IValidateValue <T> NotToBeEqualTo <T>(this IValidateValue <T> param, T other, string reason = null, params object[] reasonArgs)
 {
     return(param.NotToBeEqualTo(other, EqualityComparer <T> .Default, reason, reasonArgs));
 }