mirror of
https://github.com/Tribufu/ServerManagers
synced 2026-08-07 19:56:22 +00:00
47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|