/// <summary> /// Checks whether the value is greater or 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 IsGreaterOrEqual(IComparable value, IComparable referenceValue, string paramName, string message) { if (!value.IsGreaterOrEqual(referenceValue)) { throw new ArgumentOutOfRangeException(paramName, referenceValue, message); } }
/// <summary> /// Checks whether the value is greater or 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 IsGreaterOrEqual(IComparable value, IComparable referenceValue) { if (!value.IsGreaterOrEqual(referenceValue)) { throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Indicates whether the instance is between a minimum and maximum value. /// </summary> /// <param name="value">The instance to test.</param> /// <param name="min">The minimum value to test.</param> /// <param name="max">The maximum value to test.</param> /// <returns><strong>true</strong> if the instance is between the minimum and maximum /// value; otherwise, <strong>false</strong>.</returns> /// <exception cref="ArgumentNullException"><em>value</em>, <em>min</em> or <em>max</em> is /// <strong>null</strong>.</exception> public static bool IsBetween(this IComparable value, IComparable min, IComparable max) { Precondition.IsNotNull(value, nameof(value)); Precondition.IsNotNull(min, nameof(min)); Precondition.IsNotNull(max, nameof(max)); return(value.IsGreaterOrEqual(min) && value.IsLessOrEqual(max)); }
/// <summary> /// 如果大于等于比较值则返回默认值否则返回原值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="compareValue">比较值</param> /// <param name="becomeValue">默认值</param> /// <returns></returns> public static T IfGreaterOrEqualBecome <T>(this IComparable <T> t, T compareValue, T becomeValue) { if (t.IsGreaterOrEqual(compareValue)) { return(becomeValue); } else { return((T)t); } }
public void IsGreaterOrEqual_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter) { AssertThrowsException<ArgumentNullException>(() => value.IsGreaterOrEqual(referenceValue), expectedParameter); }
public void IsGreaterOrEqual_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter) { AssertThrowsException <ArgumentNullException>(() => value.IsGreaterOrEqual(referenceValue), expectedParameter); }