Skip to content

Commit

Permalink
Delete shared ThrowHelper used only a single test (dotnet#110313)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored and mikelle-rogers committed Dec 4, 2024
1 parent 4e6c3d7 commit e410459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 47 deletions.
40 changes: 0 additions & 40 deletions src/libraries/Common/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,6 @@ internal static void ThrowIfNull(
[DoesNotReturn]
#endif
private static void Throw(string? paramName) => throw new ArgumentNullException(paramName);

/// <summary>
/// Throws either an <see cref="System.ArgumentNullException"/> or an <see cref="System.ArgumentException"/>
/// if the specified string is <see langword="null"/> or whitespace respectively.
/// </summary>
/// <param name="argument">String to be checked for <see langword="null"/> or whitespace.</param>
/// <param name="paramName">The name of the parameter being checked.</param>
/// <returns>The original value of <paramref name="argument"/>.</returns>
[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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public TimeSpanAttribute(int minMs, int maxMs)
/// <param name="min">Minimum represented as time span string.</param>
public TimeSpanAttribute(string min)
{
_ = ThrowHelper.IfNullOrWhitespace(min);

_min = min;
_min = ThrowIfNullOrWhitespace(min);
_max = null;
}

Expand All @@ -98,11 +96,20 @@ public TimeSpanAttribute(string min)
/// <param name="max">Maximum represented as time span string.</param>
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;
}

/// <summary>
Expand Down

0 comments on commit e410459

Please sign in to comment.