/// <summary> /// Throws a System.ArgumentException with the specified message. The parameter name for the /// exception will be the value of ensureArg.ArgumentName. /// </summary> /// <typeparam name="T">The type parameter of the IEnsureArg instance.</typeparam> /// <param name="ensureArg">The IEnsureArg instance to throw an exception for.</param> /// <param name="exceptionMessage"> /// The message to use in the exception. If no exception message is supplied then /// ensureArg.ExceptionMessage will be used. /// </param> public static void ThrowArgumentException <T>(this IEnsureArg <T> ensureArg, string exceptionMessage) { throw new ArgumentException(ensureArg.FormatArgumentExceptionMessage(exceptionMessage), ensureArg.ArgumentName); }
/// <summary> /// Creates an exception message appropriate for an ArgumentNullException given the /// context of the ensureArg instance. /// </summary> /// <typeparam name="T">The type parameter of the IEnsureArg instance.</typeparam> /// <param name="ensureArg">The IEnsureArg instance to format an exception message for.</param> /// <param name="exceptionMessage">An exception message to use which may provide place holders. /// The available place holders are: {argName} = ensureArg.ArgumentName, {arg} = ensureArg.Value. /// If this parameter is null the ensureArg.Exception message will be used.</param> /// <returns>A formatted exception message or null if no exception message was found.</returns> public static string FormatArgumentNullExceptionMessage <T>(this IEnsureArg <T> ensureArg, string exceptionMessage) { ensureArg.ValidateEnsureArgIsNotNull(); return(ensureArg.FormatArgumentExceptionMessage(exceptionMessage)); }