Exemple #1
1
 protected void AdjustToNewMinValue()
 {
     if (MaxValue.CompareTo(MinValue) < 0)
     {
         MaxValue = MinValue;
     }
 }
Exemple #2
0
        /// <summary>
        /// Perrform type-specific validation
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        protected override DateTime?OnValidate(object value)
        {
            DateTime?t = Convert(value);

            if (MinValue.CompareTo(t) > 0 || MaxValue.CompareTo(t) < 0)
            {
                throw new PropertyValidationException("minmax");
            }
            return(t);
        }
Exemple #3
0
 /// <summary>
 /// Checks if the value equals MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value equals MaxValue; otherwise, false.</returns>
 public override bool EqualsMaxValue(T value)
 {
     if (MaxValue == null && value == null)
     {
         return(true);
     }
     if (MaxValue == null || value == null)
     {
         return(false);
     }
     return(0 == MaxValue.CompareTo(value));
 }
Exemple #4
0
 /// <summary>
 /// Checks if the value is greater than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is greater than or equal MaxValue; otherwise, false.</returns>
 public override bool IsGreaterThanMaxValue(T value)
 {
     if (value == null)
     {
         return(true);
     }
     if (MaxValue == null)
     {
         return(false);
     }
     return(0 > MaxValue.CompareTo(value));
 }
Exemple #5
0
 /// <summary>
 /// Checks if the value is less than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is less than or equal MaxValue; otherwise, false.</returns>
 public override bool IsLessThanMaxValue(T value)
 {
     if (value == null)
     {
         return(false);
     }
     if (MaxValue == null)
     {
         return(true);
     }
     return(0 < (ValueComparer?.Compare(MaxValue, value) ?? MaxValue.CompareTo(value)));
 }
        /// <summary>
        ///     Check upper bounds
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <returns></returns>
        protected virtual bool CheckUpper(T value)
        {
            var isValid = MaxValueAllowerd
                ? MaxValue.CompareTo(value) >= 0
                : MaxValue.CompareTo(value) > 0;

            if (!isValid)
            {
                ErrorMessage = MaxErrorMessage ?? MinErrorMessage;
            }

            return(isValid);
        }
        /// <summary>
        /// Checks whether the value belongs to the [<see cref="MinValue"/>, <see cref="MaxValue"/>] interval
        /// (when <see cref="UseMinValue"/> and <see cref="UseMaxValue"/> are set).
        /// </summary>
        /// <param name="value">value to certify</param>
        /// <exception cref="CommandLineArgumentOutOfRangeException">Thrown when <paramref name="value"/> lies outside the interval. </exception>
        protected override void Certify(TValue value)
        {
            if (UseMinValue && MinValue.CompareTo(value) == 1)
            {
                throw new CommandLineArgumentOutOfRangeException(
                          string.Format(Messages.EXC_ARG_BOUNDED_LESSER_THAN_MIN, value, _minValue), Name);
            }

            if (UseMaxValue && MaxValue.CompareTo(value) == -1)
            {
                throw new CommandLineArgumentOutOfRangeException(
                          string.Format(Messages.EXC_ARG_BOUNDED_GREATER_THAN_MAX, value, _maxValue), Name);
            }
        }
        public T Correct(T value)
        {
            if (value == null)
            {
                return(value);
            }

            if (MinValue.CompareTo(value) > 0)
            {
                return(MinValue);
            }

            if (MaxValue.CompareTo(value) < 0)
            {
                return(MaxValue);
            }

            return(value);
        }
Exemple #9
0
        public bool Contains(T value)
        {
            ParameterChecker.NotNull(value, "value");

            if (MinValue.CompareTo(value) > 0)
            {
                return(false);
            }
            if (!IncludeMinValue && MinValue.CompareTo(value) == 0)
            {
                return(false);
            }

            if (MaxValue.CompareTo(value) < 0)
            {
                return(false);
            }
            if (!IncludeMaxValue && MaxValue.CompareTo(value) == 0)
            {
                return(false);
            }

            return(true);
        }
Exemple #10
0
 /// <summary>
 /// Checks if the value equals MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value equals MaxValue; otherwise, false.</returns>
 public override bool EqualsMaxValue(T value)
 {
     return(0 == MaxValue.CompareTo(value));
 }
Exemple #11
0
 /// <summary>
 /// Checks if the value is greater than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is greater than or equal MaxValue; otherwise, false.</returns>
 public override bool IsGreaterThanMaxValue(T value)
 {
     return(0 > MaxValue.CompareTo(value));
 }
Exemple #12
0
 /// <summary>
 /// Checks if the value is less than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is less than or equal MaxValue; otherwise, false.</returns>
 public override bool IsLessThanMaxValue(T value)
 {
     return(0 < MaxValue.CompareTo(value));
 }
Exemple #13
0
 /// <summary>
 /// Checks if the value equals MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value equals MaxValue; otherwise, false.</returns>
 public override bool EqualsMaxValue(T value)
 {
     return(0 == (ValueComparer?.Compare(MaxValue, value) ?? MaxValue.CompareTo(value)));
 }
Exemple #14
0
 /// <summary>
 /// Checks if the value is greater than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is greater than or equal MaxValue; otherwise, false.</returns>
 public override bool IsGreaterThanMaxValue(T value)
 {
     return(0 > (ValueComparer?.Compare(MaxValue, value) ?? MaxValue.CompareTo(value)));
 }
Exemple #15
0
 /// <summary>
 /// Checks if the value is less than MaxValue.
 /// </summary>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is less than or equal MaxValue; otherwise, false.</returns>
 public override bool IsLessThanMaxValue(T value)
 {
     return(0 < (ValueComparer?.Compare(MaxValue, value) ?? MaxValue.CompareTo(value)));
 }