diff --git a/src/libraries/Common/src/System/ThrowHelper.cs b/src/libraries/Common/src/System/ThrowHelper.cs index 098b8321492764..0e9117b9e7bf69 100644 --- a/src/libraries/Common/src/System/ThrowHelper.cs +++ b/src/libraries/Common/src/System/ThrowHelper.cs @@ -31,46 +31,6 @@ internal static void ThrowIfNull( [DoesNotReturn] #endif private static void Throw(string? paramName) => throw new ArgumentNullException(paramName); - - /// - /// Throws either an or an - /// if the specified string is or whitespace respectively. - /// - /// String to be checked for or whitespace. - /// The name of the parameter being checked. - /// The original value of . - [MethodImpl(MethodImplOptions.AggressiveInlining)] -#if NET - [return: NotNull] -#endif - public static string IfNullOrWhitespace( -#if NET - [NotNull] -#endif - string? argument, - [CallerArgumentExpression(nameof(argument))] string paramName = "") - { -#if !NET - if (argument == null) - { - throw new ArgumentNullException(paramName); - } -#endif - - if (string.IsNullOrWhiteSpace(argument)) - { - if (argument == null) - { - throw new ArgumentNullException(paramName); - } - else - { - throw new ArgumentException(paramName, "Argument is whitespace"); - } - } - - return argument; - } } } diff --git a/src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Extensions/TimeSpanAttribute.cs b/src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Extensions/TimeSpanAttribute.cs index e1e7639fc6af04..b2c3da04f71d4b 100644 --- a/src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Extensions/TimeSpanAttribute.cs +++ b/src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Extensions/TimeSpanAttribute.cs @@ -85,9 +85,7 @@ public TimeSpanAttribute(int minMs, int maxMs) /// Minimum represented as time span string. public TimeSpanAttribute(string min) { - _ = ThrowHelper.IfNullOrWhitespace(min); - - _min = min; + _min = ThrowIfNullOrWhitespace(min); _max = null; } @@ -98,11 +96,20 @@ public TimeSpanAttribute(string min) /// Maximum represented as time span string. public TimeSpanAttribute(string min, string max) { - _ = ThrowHelper.IfNullOrWhitespace(min); - _ = ThrowHelper.IfNullOrWhitespace(max); + _min = ThrowIfNullOrWhitespace(min); + _max = ThrowIfNullOrWhitespace(max); + } + + private static string ThrowIfNullOrWhitespace(string? value) + { + if (string.IsNullOrWhiteSpace(value)) + { + throw value is null ? + new ArgumentNullException(nameof(value)) : + new ArgumentException("Value cannot be empty or whitespace.", nameof(value)); + } - _min = min; - _max = max; + return value; } ///