using System; using System.Collections.Generic; namespace ServerManagerTool.Updater { public static class IEnumerableExtensions { public static bool IsEmpty(this IEnumerable source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } using (IEnumerator enumerator = source.GetEnumerator()) { if (enumerator.MoveNext()) { return false; } } return true; } public static bool HasOne(this IEnumerable source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var count = 0; using (IEnumerator enumerator = source.GetEnumerator()) { while (enumerator.MoveNext()) { if (++count > 1) return false; } } return count == 1; } } }