From 5f317130981dae1fb9048ffd457c54bbd4859352 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Fri, 4 Oct 2024 10:56:07 -0700 Subject: [PATCH] fix compatibility issues --- CodeTimer.cs | 2 +- StringUtilities.cs | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CodeTimer.cs b/CodeTimer.cs index 145cfe5..d4f6b08 100644 --- a/CodeTimer.cs +++ b/CodeTimer.cs @@ -19,7 +19,7 @@ public class CodeTimer : IDisposable private CodeTimer(string name) { - _name = string.IsNullOrWhiteSpace(name) + _name = name.IsNullOrWhiteSpace() ? throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name)) : name; diff --git a/StringUtilities.cs b/StringUtilities.cs index 6787e00..9f1ee7c 100644 --- a/StringUtilities.cs +++ b/StringUtilities.cs @@ -5,10 +5,21 @@ namespace System { - public static class StringUtilities - { - public static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s); - public static bool IsNullOrWhiteSpace(this string s) => string.IsNullOrWhiteSpace(s); - public static bool Contains(this string s, string value, StringComparison comparison) => s.IndexOf(value, comparison) >= 0; - } + public static class StringUtilities + { + public static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s); + public static bool IsNullOrWhiteSpace(this string value) + { + if (value == null) return true; + + for (int i = 0; i < value.Length; i++) + { + if (!Char.IsWhiteSpace(value[i])) return false; + } + + return true; + } + + public static bool Contains(this string s, string value, StringComparison comparison) => s.IndexOf(value, comparison) >= 0; + } }