/// <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); } }
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); } }
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); } }
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); } }
/// <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); } }