From 35a01a0415a9d6c61a56b7a5e3feb2c21bce5996 Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Sun, 12 Jun 2022 06:37:50 +0200 Subject: [PATCH] Add multiple new things + Select Random + IsNullOrEmpty + IsNullOrWhiteSpace --- UniversalExtensions.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 ///