Add multiple new things

+ Select Random
+ IsNullOrEmpty
+ IsNullOrWhiteSpace
This commit is contained in:
Mira 2022-06-12 06:37:50 +02:00
parent 565e11882b
commit 35a01a0415
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36

View file

@ -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<T>(this IEnumerable<T> 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();
}
/// <summary>
/// Get the current CPU Usage on all plattforms
/// </summary>