Ejemplo n.º 1
0
        /// <summary>
        /// Checks an individual parameter and throws an <see cref="ArgumentException"/> if it is not correct.
        /// This is meant to be used in public facing methods.
        /// </summary>
        /// <param name="test">The boolean state of the parameter test.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="errorTextHandler">Delegate for getting the error text.</param>
        /// <remarks>It is more efficient to pass the error text through a delegate if the text is extracted
        /// from a resource file. The text will only be loaded if it is actually needed.</remarks>
        /// <exception cref="ArgumentException"></exception>
        public static void Require(bool test, string parameterName, ParamErrorTextHandler errorTextHandler)
        {
            Params.Ignore(test, parameterName, errorTextHandler);

            if (test == false)
            {
                string message = string.Empty;
                if (errorTextHandler != null)
                {
                    message = errorTextHandler();
                }

                Debug.Assert(test, parameterName, message);
                throw new ArgumentException(message, parameterName);
            }
        }
Ejemplo n.º 2
0
 public static void RequireValidIndex(bool test, string parameterName, ParamErrorTextHandler errorTextHandler)
 {
     if (!test)
     {
         string paramName = string.Empty;
         if (errorTextHandler != null)
         {
             paramName = errorTextHandler();
         }
         throw new ArgumentOutOfRangeException(paramName, parameterName);
     }
 }
Ejemplo n.º 3
0
 public static void RequireNotNull(object parameter, string parameterName, ParamErrorTextHandler errorTextHandler)
 {
     if (parameter == null)
     {
         string paramName = string.Empty;
         if (errorTextHandler != null)
         {
             paramName = errorTextHandler();
         }
         throw new ArgumentNullException(paramName, parameterName);
     }
 }
Ejemplo n.º 4
0
 public static void Require(bool test, string parameterName, ParamErrorTextHandler errorTextHandler)
 {
     if (!test)
     {
         string message = string.Empty;
         if (errorTextHandler != null)
         {
             message = errorTextHandler();
         }
         throw new ArgumentException(message, parameterName);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Requires that the given parameter must not be null.
        /// </summary>
        /// <param name="parameter">The parameter to check for null.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="errorTextHandler">Delegate for getting the error text.</param>
        /// <remarks>It is more efficient to pass the error text through a delegate if the text is extracted
        /// from a resource file. The text will only be loaded if it is actually needed.</remarks>
        public static void RequireNotNull(object parameter, string parameterName, ParamErrorTextHandler errorTextHandler)
        {
            Param.Ignore(parameter, parameterName, errorTextHandler);
            if (parameter == null)
            {
                string message = string.Empty;
                if (errorTextHandler != null)
                {
                    message = errorTextHandler();
                }

                Debug.Assert(false, parameterName, message);
                throw new ArgumentNullException(message, parameterName);
            }
        }