diff --git a/UniversalExtensions.cs b/UniversalExtensions.cs index 9f3eff7..bd1f426 100644 --- a/UniversalExtensions.cs +++ b/UniversalExtensions.cs @@ -2,6 +2,27 @@ public static class UniversalExtensions { + public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str); + + public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str); + + public static T SelectRandom(this IEnumerable obj) + { + if (obj == null) + { + throw new ArgumentNullException(); + } + + if (!obj.Any()) + { + throw new ArgumentException("The sequence is empty."); + } + + + int rng = new Random().Next(0, obj.Count()); + return obj.ElementAt(rng) ?? throw new ArgumentNullException(); + } + /// /// Get the current CPU Usage on all plattforms ///