public static IValidateValue <T> NotToHaveValue <T>(this IValidateValue <T> param, string reason = null, params object[] reasonArgs) { if (!object.Equals(param.Value, default(T))) { param.HandleValueMismatch("not be specified", null, reason, reasonArgs); } return(param); }
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); }
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); }
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); }
public static IValidateValue <T> ToBeNull <T>(this IValidateValue <T> param, string reason = null, params object[] reasonArgs) where T : class { if (!object.ReferenceEquals(param.Value, null)) { param.HandleValueMismatch("not be specified", null, reason, reasonArgs); } return(param); }
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); }
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); }
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); }
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); }