From 6a1f05832e9e7912d47dc24c559d3206c454fee8 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 20 Oct 2020 14:58:32 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20string.AsNullIfEmpty=20and=20?= =?UTF-8?q?string.AsNullIfWhiteSpace=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D/src/StringExtensions.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index a462ad4..50a80a8 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -12,6 +12,27 @@ /// public static class StringExtensions { + /// + /// Returns the current string, or if the current string is null or empty. + /// + /// The value to sanitize. + /// or . + public static string? AsNullIfEmpty(this string value) + { + return string.IsNullOrEmpty(value) ? null : value; + } + + /// + /// Returns the current string, or if the current string is null, empty, or consists of only + /// whitespace. + /// + /// The value to sanitize. + /// or . + public static string? AsNullIfWhiteSpace(this string value) + { + return string.IsNullOrWhiteSpace(value) ? null : value; + } + /// /// Decodes a base-64 encoded string. ///