Skip to content

Shameful rename of [IsNullOr]WhiteSpace Guard APIs #3515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 commits merged into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 82 additions & 8 deletions Microsoft.Toolkit/Diagnostics/Guard.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public static void IsNotNullOrEmpty([NotNull] string? text, string name)
{
if (!string.IsNullOrEmpty(text))
{
#pragma warning disable CS8777 // Does not return when text is null
return;
#pragma warning restore CS8777
}

ThrowHelper.ThrowArgumentExceptionForIsNotNullOrEmpty(text, name);
#pragma warning disable CS8777 // Does not return when text is null (.NET Standard 2.0 string.IsNullOrEmpty lacks flow attribute)
}
#pragma warning restore CS8777

/// <summary>
/// Asserts that the input <see cref="string"/> instance must be <see langword="null"/> or whitespace.
Expand All @@ -58,14 +58,32 @@ public static void IsNotNullOrEmpty([NotNull] string? text, string name)
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is neither <see langword="null"/> nor whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNullOrWhiteSpace(string? text, string name)
{
if (string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsNullOrWhiteSpace(text, name);
}

/// <summary>
/// Asserts that the input <see cref="string"/> instance must be <see langword="null"/> or whitespace.
/// </summary>
/// <param name="text">The input <see cref="string"/> instance to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is neither <see langword="null"/> nor whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use " + nameof(IsNullOrWhiteSpace))]
public static void IsNullOrWhitespace(string? text, string name)
{
if (string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsNullOrWhitespace(text, name);
ThrowHelper.ThrowArgumentExceptionForIsNullOrWhiteSpace(text, name);
}

/// <summary>
Expand All @@ -75,17 +93,37 @@ public static void IsNullOrWhitespace(string? text, string name)
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNullOrWhitespace([NotNull] string? text, string name)
public static void IsNotNullOrWhiteSpace([NotNull] string? text, string name)
{
if (!string.IsNullOrWhiteSpace(text))
{
#pragma warning disable CS8777 // Does not return when text is null
return;
#pragma warning restore CS8777
}

ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhitespace(text, name);
#pragma warning disable CS8777 // Does not return when text is null
ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhiteSpace(text, name);
}

/// <summary>
/// Asserts that the input <see cref="string"/> instance must not be <see langword="null"/> or whitespace.
/// </summary>
/// <param name="text">The input <see cref="string"/> instance to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use " + nameof(IsNotNullOrWhiteSpace))]
public static void IsNotNullOrWhitespace([NotNull] string? text, string name)
{
if (!string.IsNullOrWhiteSpace(text))
{
#pragma warning disable CS8777 // Does not return when text is null
return;
#pragma warning restore CS8777
}

ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhiteSpace(text, name);
}

/// <summary>
/// Asserts that the input <see cref="string"/> instance must be empty.
Expand Down Expand Up @@ -128,14 +166,49 @@ public static void IsNotEmpty(string text, string name)
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is neither <see langword="null"/> nor whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsWhiteSpace(string text, string name)
{
if (string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsWhiteSpace(text, name);
}

/// <summary>
/// Asserts that the input <see cref="string"/> instance must be whitespace.
/// </summary>
/// <param name="text">The input <see cref="string"/> instance to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is neither <see langword="null"/> nor whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use " + nameof(IsWhiteSpace))]
public static void IsWhitespace(string text, string name)
{
if (string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsWhitespace(text, name);
ThrowHelper.ThrowArgumentExceptionForIsWhiteSpace(text, name);
}

/// <summary>
/// Asserts that the input <see cref="string"/> instance must not be <see langword="null"/> or whitespace.
/// </summary>
/// <param name="text">The input <see cref="string"/> instance to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotWhiteSpace(string text, string name)
{
if (!string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsNotWhiteSpace(text, name);
}

/// <summary>
Expand All @@ -145,14 +218,15 @@ public static void IsWhitespace(string text, string name)
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use " + nameof(IsNotWhiteSpace))]
public static void IsNotWhitespace(string text, string name)
{
if (!string.IsNullOrWhiteSpace(text))
{
return;
}

ThrowHelper.ThrowArgumentExceptionForIsNotWhitespace(text, name);
ThrowHelper.ThrowArgumentExceptionForIsNotWhiteSpace(text, name);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, str
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name)
internal static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}");
}
Expand All @@ -50,7 +50,7 @@ internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, s
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name)
internal static void ThrowArgumentExceptionForIsNotNullOrWhiteSpace(string? text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}");
}
Expand Down Expand Up @@ -80,7 +80,7 @@ internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string nam
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
internal static void ThrowArgumentExceptionForIsWhitespace(string text, string name)
internal static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}");
}
Expand All @@ -90,7 +90,7 @@ internal static void ThrowArgumentExceptionForIsWhitespace(string text, string n
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name)
internal static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}");
}
Expand Down