Remove string.WithAlternative

Yeah... so I already had this method which accepted a bool, forgot about that.

But now it's separated into more meaningfully-named methods. So...

https://www.youtube.com/watch?v=oJimiVFCjJ0
This commit is contained in:
Oliver Booth 2022-03-06 17:32:53 +00:00
parent 45804c2da6
commit 4f99763a0a
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
1 changed files with 0 additions and 22 deletions

View File

@ -477,28 +477,6 @@ public static class StringExtensions
: default; : default;
} }
/// <summary>
/// Returns the current string, or an alternative value if the current string is null or empty, or optionally if the
/// current string consists of only whitespace.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="alternative">The alternative value if <paramref name="value" /> does not meet the criteria.</param>
/// <param name="includeWhiteSpace">
/// Optional. If set to <see langword="true" />, <paramref name="alternative" /> will be returned also if
/// <paramref name="value" /> only consists of whitespace.
/// </param>
/// <returns>Returns <paramref name="value" /> or <paramref name="alternative" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="alternative" /> is <see langword="null" />.</exception>
public static string WithAlternative(this string? value, string alternative, bool includeWhiteSpace = false)
{
if (alternative is null)
{
throw new ArgumentNullException(nameof(alternative));
}
return (includeWhiteSpace ? value?.AsNullIfWhiteSpace() : value?.AsNullIfEmpty()) ?? alternative;
}
/// <summary> /// <summary>
/// Normalizes a string which may be either <see langword="null" /> or empty to a specified alternative. /// Normalizes a string which may be either <see langword="null" /> or empty to a specified alternative.
/// </summary> /// </summary>