Exemple #1
0
 /// <summary>
 /// Ensures a param is greater than or equal to <paramref name="value" />.
 /// </summary>
 /// <param name="param">Parameter to check.</param>
 /// <param name="value">Value that the parameter must be greater than or equal to.</param>
 /// <param name="paramName">Name of the parameter.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="param" /> must be greater than or equal to <paramref name="value" />.</exception>
 public static void GreaterThanOrEqual(byte param, byte value, string paramName = null)
 {
     if (param < value)
     {
         ExceptionThrower.ThrowGreaterThanOrEqualException(value.ToString(), paramName);
     }
 }
Exemple #2
0
 /// <summary>
 /// Ensures a param is greater than or equal to <paramref name="value" />.
 /// </summary>
 /// <param name="param">Parameter to check.</param>
 /// <param name="value">Value that the parameter must be greater than or equal to.</param>
 /// <param name="paramName">Name of the parameter.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="param" /> must be greater than or equal to <paramref name="value" />.</exception>
 public static void GreaterThanOrEqual(decimal param, decimal value, string paramName = null)
 {
     if (param < value)
     {
         ExceptionThrower.ThrowGreaterThanOrEqualException(value.ToString(CultureInfo.InvariantCulture), paramName);
     }
 }
Exemple #3
0
        /// <summary>
        /// Ensures a parameter is within a given range.
        /// </summary>
        /// <typeparam name="TParam">Type of parameter.</typeparam>
        /// <param name="param">Parameter to check.</param>
        /// <param name="from">Inclusive start of the range.</param>
        /// <param name="to">Inclusive end of the range.</param>
        /// <param name="paramName">Name of the parameter.</param>
        /// <exception cref="T:System.ArgumentException"><paramref name="from" /> must be less or equal to <paramref name="to" /></exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="param" /> was not within the range.</exception>
        public static void Between <TParam>(TParam param, TParam from, TParam to, string paramName = null)
        {
            var range = new Range <TParam>(from, to);

            if (!range.IsInRange(param))
            {
                ExceptionThrower.ThrowNotBetween(param, from, to, paramName);
            }
        }
Exemple #4
0
        /// <summary>
        /// Ensures a parameter is not contained in a sequence of values.
        /// </summary>
        /// <typeparam name="TParam">Type of parameter.</typeparam>
        /// <param name="param">Parameter to check.</param>
        /// <param name="values">Set of values to check against.</param>
        /// <param name="paramName">Name of the parameter.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="param" /> must not be in the sequence of provided values.</exception>
        public static void NotIn <TParam>(TParam param, IEnumerable <TParam> values, string paramName = null)
        {
            if (values == null)
            {
                return;
            }

            if (values.Contains(param))
            {
                ExceptionThrower.ThrowNotInException(param, paramName);
            }
        }