mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 02:45:41 +00:00
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:
parent
45804c2da6
commit
4f99763a0a
@ -477,28 +477,6 @@ public static class StringExtensions
|
||||
: 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>
|
||||
/// Normalizes a string which may be either <see langword="null" /> or empty to a specified alternative.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user