public static ValidateTarget <TValue?> IsGreaterThan <TValue>([ValidatedNotNull] this ValidateTarget <TValue?> target, TValue valueToCompare, Func <string> getErrorMessage = null, IComparer <TValue> customComparer = null) where TValue : struct, IComparable <TValue> { if (target.Value.HasValue) { IComparer <TValue> comparer = customComparer ?? Comparer <TValue> .Default; if (comparer.Compare(target.Value.Value, valueToCompare) <= 0) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeGreaterThan(target, valueToCompare)); } } return(target); }
public static ValidateTarget <double?> IsGreaterThan([ValidatedNotNull] this ValidateTarget <double?> target, double valueToCompare, double allowedError, Func <string> getErrorMessage = null) { if (target.Value.HasValue) { var diff = Math.Abs(target.Value.Value - valueToCompare); if (diff <= allowedError || target.Value <= valueToCompare) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeGreaterThan(target, valueToCompare)); } } return(target); }
public static ValidateTarget <TValue> IsGreaterThan <TValue>([ValidatedNotNull] this ValidateTarget <TValue> target, object valueToCompare, Func <string> getErrorMessage = null, System.Collections.IComparer customComparer = null) where TValue : IComparable { System.Collections.IComparer comparer = customComparer ?? Comparer <TValue> .Default; if (comparer.Compare(target.Value, valueToCompare) <= 0) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeGreaterThan(target, valueToCompare)); } return(target); }
public static ValidateTarget <float?> IsPositive([ValidatedNotNull] this ValidateTarget <float?> target, float allowedError, Func <string> getErrorMessage = null) { bool isValidationFailed = true; float valueToCompare = 0; if (target.Value.HasValue) { var diff = Math.Abs(target.Value.Value - valueToCompare); if (diff <= allowedError || target.Value.Value <= valueToCompare) { isValidationFailed = false; } } if (isValidationFailed) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeGreaterThan(target, valueToCompare)); } return(target); }