From 3f2599171e418343d344319741885b83504f3613 Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Sun, 14 Aug 2022 08:27:27 +0200 Subject: [PATCH] Removed Linq Usage --- Global.cs | 1 - UniversalExtensions.cs | 43 +++++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Global.cs b/Global.cs index dc6c67e..49783af 100644 --- a/Global.cs +++ b/Global.cs @@ -3,7 +3,6 @@ global using System.Net; global using System.Security.Cryptography; global using System; global using System.Collections.Generic; -global using System.Linq; global using System.Text; global using System.Threading.Tasks; global using System.Drawing; diff --git a/UniversalExtensions.cs b/UniversalExtensions.cs index deff631..506174e 100644 --- a/UniversalExtensions.cs +++ b/UniversalExtensions.cs @@ -2,10 +2,32 @@ public static class UniversalExtensions { + /// + /// Extensions for string.IsNullOrWhiteSpace + /// + /// + /// Whether the string is null, empty or only contains whitespaces public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str); + + + /// + /// Extensions for string.IsNullOrEmpty + /// + /// + /// Whether the string is null or empty public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str); + + + /// + /// Select a random item from a list + /// + /// + /// + /// The randomly selected item + /// The list is null + /// The list is empty public static T SelectRandom(this IEnumerable obj) { if (obj == null) @@ -22,11 +44,18 @@ public static class UniversalExtensions int rng = new Random().Next(0, obj.Count()); return obj.ElementAt(rng) ?? throw new ArgumentNullException(); } - - public static bool IsNotNullAndNotEmpty(this IEnumerable obj) - { - return obj is not null && obj.Any(); - } + + + + /// + /// Check whether a list contains elements and is not null + /// + /// + /// + /// Whether the list contains elements and is not null + public static bool IsNotNullAndNotEmpty(this IEnumerable obj) => obj is not null && obj.Any(); + + /// /// Get the current CPU Usage on all plattforms @@ -326,12 +355,12 @@ public static class UniversalExtensions /// Gets a list of all registered tasks /// /// A list of all registered tasks - public static List>? GetScheduleTasks() + public static IReadOnlyDictionary? GetScheduleTasks() { if (registeredScheduledTasks is null) registeredScheduledTasks = new(); - return registeredScheduledTasks.ToList(); + return registeredScheduledTasks as IReadOnlyDictionary; }