/// <summary>
        /// Indicates whether the instance is less or equal to the reference value.
        /// </summary>
        /// <param name="value">The instance to test.</param>
        /// <param name="referenceValue">The reference value to test.</param>
        /// <returns><strong>true</strong> if the instance is less or equal to the reference
        /// value; otherwise, <strong>false</strong>.</returns>
        /// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is
        /// <strong>null</strong>.</exception>
        public static bool IsLessOrEqual(this IComparable value, IComparable referenceValue)
        {
            Precondition.IsNotNull(value, nameof(value));
            Precondition.IsNotNull(referenceValue, nameof(referenceValue));

            return(value.IsLess(referenceValue) || value.IsEqual(referenceValue));
        }
Example #2
0
 /// <summary>
 /// Checks whether the value is equal to the reference value.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <param name="referenceValue">The reference value to test.</param>
 /// <param name="paramName">The name of the parameter that caused the exception.</param>
 /// <param name="message">A message that describes the error.</param>
 /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of
 /// range.</exception>
 public static void IsEqual(IComparable value, IComparable referenceValue, string paramName, string message)
 {
     if (!value.IsEqual(referenceValue))
     {
         throw new ArgumentOutOfRangeException(paramName, referenceValue, message);
     }
 }
Example #3
0
 /// <summary>
 /// Checks whether the value is equal to the reference value.
 /// </summary>
 /// <param name="value">The value to test.</param>
 /// <param name="referenceValue">The reference value to test.</param>
 /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of
 /// range.</exception>
 public static void IsEqual(IComparable value, IComparable referenceValue)
 {
     if (!value.IsEqual(referenceValue))
     {
         throw new ArgumentOutOfRangeException();
     }
 }
        void IsEqual(IComparable x, Object y, Boolean expected)
        {
            Boolean result = default;

            Test.IfNot.Action.ThrowsException(() => result = x.IsEqual(y), out Exception ex);
            Test.If.Value.IsEqual(result, expected);
        }
Example #5
0
 /// <summary>
 /// 如果等于比较值则返回默认值否则返回原值
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="t"></param>
 /// <param name="compareValue">比较值</param>
 /// <param name="becomeValue">默认值</param>
 /// <returns></returns>
 public static T IfEqualBecome <T>(this IComparable <T> t, T compareValue, T becomeValue)
 {
     if (t.IsEqual(compareValue))
     {
         return(becomeValue);
     }
     else
     {
         return((T)t);
     }
 }
 public void IsEqual_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter)
 {
     AssertThrowsException<ArgumentNullException>(() => value.IsEqual(referenceValue), expectedParameter);
 }
 public void IsEqual_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter)
 {
     AssertThrowsException <ArgumentNullException>(() => value.IsEqual(referenceValue), expectedParameter);
 }