using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace System; /// /// Throw helper extensions for . /// internal static class ArgumentExceptionExtensions { /// /// Throws an for a given parameter name. /// /// Dummy value to invoke the extension upon (always pass . /// The name of the parameter to report in the exception. /// Thrown with . [DoesNotReturn] public static void Throw(this ArgumentException? _, string? parameterName) { throw new ArgumentException(null, parameterName); } /// /// Throws an for a given parameter name and message. /// /// Dummy value to invoke the extension upon (always pass . /// The name of the parameter to report in the exception. /// The message to include in the exception. /// Thrown with . [DoesNotReturn] public static void Throw(this ArgumentException? _, string? parameterName, string? message) { throw new ArgumentException(message, parameterName); } /// /// Throws an for a given parameter name. /// /// The type to let the compiler assume it returns. /// Dummy value to invoke the extension upon (always pass . /// The name of the parameter to report in the exception. /// This method never returns any values. /// Thrown with . [DoesNotReturn] public static T Throw(this ArgumentException? _, string? parameterName) { throw new ArgumentException(null, parameterName); } /// /// Throws an if is . /// /// Dummy value to invoke the extension upon (always pass . /// The condition to decide whether to throw the exception. /// The name of the parameter with which corresponds. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ThrowIf(this ArgumentException? _, [DoesNotReturnIf(true)] bool condition, string? parameterName = null) { if (condition) { Throw(parameterName); } } /// /// Throws an for a given parameter name. /// /// The name of the parameter to report in the exception. /// Thrown with . [DoesNotReturn] private static void Throw(string? parameterName) { throw new ArgumentException(null, parameterName); } }