mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Changed the discord bot to be case insensitive.
Added IsEmpty and HasOne IEnumerable Extensions.
This commit is contained in:
parent
734332f10c
commit
dd431e93b2
20 changed files with 383 additions and 107 deletions
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ServerManagerTool.Updater
|
||||
{
|
||||
public static class IEnumerableExtensions
|
||||
{
|
||||
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
|
||||
{
|
||||
if (enumerator.MoveNext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HasOne<TSource>(this IEnumerable<TSource> source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
|
||||
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (++count > 1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return count == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue