namespace Unity.Tutorials.Core.Editor { /// /// Extension methods for System.String. /// public static class StringExtensions { /// /// Indicates whether this string is null or an empty string (""). /// /// The string this function acts on /// True if null or empty public static bool IsNullOrEmpty(this string self) => string.IsNullOrEmpty(self); /// /// Indicates whether this string is not null or an empty string (""). /// /// The string this function acts on /// True if not null or empty public static bool IsNotNullOrEmpty(this string self) => !self.IsNullOrEmpty(); /// /// Indicates whether this string is null, empty, or consists only of white-space characters. /// /// The string this function acts on /// True if null or whitespace only public static bool IsNullOrWhiteSpace(this string self) => string.IsNullOrWhiteSpace(self); /// /// Indicates whether this string is not null, empty, or consists only of white-space characters. /// /// The string this function acts on /// True if not empty or only whitespace public static bool IsNotNullOrWhiteSpace(this string self) => !self.IsNullOrWhiteSpace(); /// /// Returns null if this string is not null, empty, or consists only of white-space characters. /// /// The string this function acts on /// null if the string is only whitespace, the unmodified string otherwise public static string AsNullIfWhiteSpace(this string self) => string.IsNullOrWhiteSpace(self) ? null : self; /// /// Returns null if this string is null or an empty string (""). /// /// The string this function acts on /// null if the string is empty, the unmodified string otherwise public static string AsNullIfEmpty(this string self) => self.IsNullOrEmpty() ? null : self; /// /// Returns an empty string ("") if this string is null. /// /// The string this function acts on /// An empty string if the string is null public static string AsEmptyIfNull(this string self) => self ?? string.Empty; } /// /// Static helper functions for System.String. /// Useful for example in LINQ queries. /// public static class StringExt { /// /// Indicates whether a specified string is not null or an empty string (""). /// /// The string this function acts on /// True if the string is not null or empty public static bool IsNotNullOrEmpty(string str) => !str.IsNullOrEmpty(); /// /// Indicates whether a specified string is not null, empty, or consists only of white-space characters. /// /// The string this function acts on /// True if the string is not null or not only whitespace public static bool IsNotNullOrWhiteSpace(string str) => !string.IsNullOrWhiteSpace(str); } }