Removed Linq Usage
This commit is contained in:
parent
2ef5f0bc9a
commit
3f2599171e
2 changed files with 36 additions and 8 deletions
|
|
@ -3,7 +3,6 @@ global using System.Net;
|
||||||
global using System.Security.Cryptography;
|
global using System.Security.Cryptography;
|
||||||
global using System;
|
global using System;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
global using System.Linq;
|
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Threading.Tasks;
|
global using System.Threading.Tasks;
|
||||||
global using System.Drawing;
|
global using System.Drawing;
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,32 @@
|
||||||
|
|
||||||
public static class UniversalExtensions
|
public static class UniversalExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extensions for string.IsNullOrWhiteSpace
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns>Whether the string is null, empty or only contains whitespaces</returns>
|
||||||
public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str);
|
public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extensions for string.IsNullOrEmpty
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns>Whether the string is null or empty</returns>
|
||||||
public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str);
|
public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select a random item from a list
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns>The randomly selected item</returns>
|
||||||
|
/// <exception cref="ArgumentNullException">The list is null</exception>
|
||||||
|
/// <exception cref="ArgumentException">The list is empty</exception>
|
||||||
public static T SelectRandom<T>(this IEnumerable<T> obj)
|
public static T SelectRandom<T>(this IEnumerable<T> obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
|
|
@ -23,10 +45,17 @@ public static class UniversalExtensions
|
||||||
return obj.ElementAt(rng) ?? throw new ArgumentNullException();
|
return obj.ElementAt(rng) ?? throw new ArgumentNullException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNotNullAndNotEmpty<T>(this IEnumerable<T> obj)
|
|
||||||
{
|
|
||||||
return obj is not null && obj.Any();
|
/// <summary>
|
||||||
}
|
/// Check whether a list contains elements and is not null
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns>Whether the list contains elements and is not null</returns>
|
||||||
|
public static bool IsNotNullAndNotEmpty<T>(this IEnumerable<T> obj) => obj is not null && obj.Any();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the current CPU Usage on all plattforms
|
/// Get the current CPU Usage on all plattforms
|
||||||
|
|
@ -326,12 +355,12 @@ public static class UniversalExtensions
|
||||||
/// Gets a list of all registered tasks
|
/// Gets a list of all registered tasks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of all registered tasks</returns>
|
/// <returns>A list of all registered tasks</returns>
|
||||||
public static List<KeyValuePair<string, taskInfo>>? GetScheduleTasks()
|
public static IReadOnlyDictionary<string, taskInfo>? GetScheduleTasks()
|
||||||
{
|
{
|
||||||
if (registeredScheduledTasks is null)
|
if (registeredScheduledTasks is null)
|
||||||
registeredScheduledTasks = new();
|
registeredScheduledTasks = new();
|
||||||
|
|
||||||
return registeredScheduledTasks.ToList();
|
return registeredScheduledTasks as IReadOnlyDictionary<string, taskInfo>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue