From 17a2cb5675aa214e2a80ca7f8ea4994439ce3fbf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 1 Oct 2020 17:11:25 +0200 Subject: [PATCH] Fixed incorrect uppercase for Guard APIs --- Microsoft.Toolkit/Diagnostics/Guard.String.cs | 82 ++++++++++++++++++- .../Internals/ThrowHelper.Guard.String.cs | 8 +- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Guard.String.cs index 15a4a5c6..2488ad7d 100644 --- a/Microsoft.Toolkit/Diagnostics/Guard.String.cs +++ b/Microsoft.Toolkit/Diagnostics/Guard.String.cs @@ -58,6 +58,24 @@ namespace Microsoft.Toolkit.Diagnostics /// The name of the input parameter being tested. /// Thrown if is neither nor whitespace. [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNullOrWhiteSpace(string? text, string name) + { + if (string.IsNullOrWhiteSpace(text)) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNullOrWhiteSpace(text, name); + } + + /// + /// Asserts that the input instance must be or whitespace. + /// + /// The input instance to test. + /// The name of the input parameter being tested. + /// Thrown if is neither nor whitespace. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Obsolete("Use " + nameof(IsNullOrWhiteSpace))] public static void IsNullOrWhitespace(string? text, string name) { if (string.IsNullOrWhiteSpace(text)) @@ -65,7 +83,7 @@ namespace Microsoft.Toolkit.Diagnostics return; } - ThrowHelper.ThrowArgumentExceptionForIsNullOrWhitespace(text, name); + ThrowHelper.ThrowArgumentExceptionForIsNullOrWhiteSpace(text, name); } /// @@ -75,6 +93,26 @@ namespace Microsoft.Toolkit.Diagnostics /// The name of the input parameter being tested. /// Thrown if is or whitespace. [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotNullOrWhiteSpace([NotNull] string? text, string name) + { + if (!string.IsNullOrWhiteSpace(text)) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhiteSpace(text, name); +#pragma warning disable CS8777 // Does not return when text is null + } +#pragma warning restore CS8777 + + /// + /// Asserts that the input instance must not be or whitespace. + /// + /// The input instance to test. + /// The name of the input parameter being tested. + /// Thrown if is or whitespace. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Obsolete("Use " + nameof(IsNotNullOrWhiteSpace))] public static void IsNotNullOrWhitespace([NotNull] string? text, string name) { if (!string.IsNullOrWhiteSpace(text)) @@ -82,7 +120,7 @@ namespace Microsoft.Toolkit.Diagnostics return; } - ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhitespace(text, name); + ThrowHelper.ThrowArgumentExceptionForIsNotNullOrWhiteSpace(text, name); #pragma warning disable CS8777 // Does not return when text is null } #pragma warning restore CS8777 @@ -128,6 +166,24 @@ namespace Microsoft.Toolkit.Diagnostics /// The name of the input parameter being tested. /// Thrown if is neither nor whitespace. [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsWhiteSpace(string text, string name) + { + if (string.IsNullOrWhiteSpace(text)) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsWhiteSpace(text, name); + } + + /// + /// Asserts that the input instance must be whitespace. + /// + /// The input instance to test. + /// The name of the input parameter being tested. + /// Thrown if is neither nor whitespace. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Obsolete("Use " + nameof(IsWhiteSpace))] public static void IsWhitespace(string text, string name) { if (string.IsNullOrWhiteSpace(text)) @@ -135,7 +191,7 @@ namespace Microsoft.Toolkit.Diagnostics return; } - ThrowHelper.ThrowArgumentExceptionForIsWhitespace(text, name); + ThrowHelper.ThrowArgumentExceptionForIsWhiteSpace(text, name); } /// @@ -145,6 +201,24 @@ namespace Microsoft.Toolkit.Diagnostics /// The name of the input parameter being tested. /// Thrown if is or whitespace. [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void IsNotWhiteSpace(string text, string name) + { + if (!string.IsNullOrWhiteSpace(text)) + { + return; + } + + ThrowHelper.ThrowArgumentExceptionForIsNotWhiteSpace(text, name); + } + + /// + /// Asserts that the input instance must not be or whitespace. + /// + /// The input instance to test. + /// The name of the input parameter being tested. + /// Thrown if is or whitespace. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Obsolete("Use " + nameof(IsNotWhiteSpace))] public static void IsNotWhitespace(string text, string name) { if (!string.IsNullOrWhiteSpace(text)) @@ -152,7 +226,7 @@ namespace Microsoft.Toolkit.Diagnostics return; } - ThrowHelper.ThrowArgumentExceptionForIsNotWhitespace(text, name); + ThrowHelper.ThrowArgumentExceptionForIsNotWhiteSpace(text, name); } /// diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs index bfcbed6f..2469466b 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs @@ -40,7 +40,7 @@ namespace Microsoft.Toolkit.Diagnostics /// [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()}"); } @@ -50,7 +50,7 @@ namespace Microsoft.Toolkit.Diagnostics /// [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")}"); } @@ -80,7 +80,7 @@ namespace Microsoft.Toolkit.Diagnostics /// [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()}"); } @@ -90,7 +90,7 @@ namespace Microsoft.Toolkit.Diagnostics /// [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()}"); }