1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 22:55:42 +00:00

Add string.AsNullIfEmpty and string.AsNullIfWhiteSpace methods

This commit is contained in:
Oliver Booth 2020-10-20 14:58:32 +01:00
parent 00acaff779
commit 6a1f05832e

View File

@ -12,6 +12,27 @@
/// </summary> /// </summary>
public static class StringExtensions public static class StringExtensions
{ {
/// <summary>
/// Returns the current string, or <see langword="null" /> if the current string is null or empty.
/// </summary>
/// <param name="value">The value to sanitize.</param>
/// <returns><see langword="null" /> or <paramref name="value" />.</returns>
public static string? AsNullIfEmpty(this string value)
{
return string.IsNullOrEmpty(value) ? null : value;
}
/// <summary>
/// Returns the current string, or <see langword="null" /> if the current string is null, empty, or consists of only
/// whitespace.
/// </summary>
/// <param name="value">The value to sanitize.</param>
/// <returns><see langword="null" /> or <paramref name="value" />.</returns>
public static string? AsNullIfWhiteSpace(this string value)
{
return string.IsNullOrWhiteSpace(value) ? null : value;
}
/// <summary> /// <summary>
/// Decodes a base-64 encoded string. /// Decodes a base-64 encoded string.
/// </summary> /// </summary>