Add multiple new things
+ Select Random + IsNullOrEmpty + IsNullOrWhiteSpace
This commit is contained in:
parent
565e11882b
commit
35a01a0415
1 changed files with 21 additions and 0 deletions
|
|
@ -2,6 +2,27 @@
|
||||||
|
|
||||||
public static class UniversalExtensions
|
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>
|
/// <summary>
|
||||||
/// Get the current CPU Usage on all plattforms
|
/// Get the current CPU Usage on all plattforms
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue