using System; using System.Collections; using System.Collections.Generic; namespace AMWD.Common.Cli { /// /// Walks through an and allows retrieving additional items. /// /// internal class EnumerableWalker : IEnumerable where T : class { private readonly IEnumerable array; private IEnumerator enumerator; /// /// Initialises a new instance of the class. /// /// The array to walk though. public EnumerableWalker(IEnumerable array) { this.array = array ?? throw new ArgumentNullException(nameof(array)); } IEnumerator IEnumerable.GetEnumerator() { enumerator = array.GetEnumerator(); return enumerator; } /// /// Gets the enumerator. /// /// The enumerator. public IEnumerator GetEnumerator() { enumerator = array.GetEnumerator(); return enumerator; } /// /// Gets the next item. /// /// The next item. public T GetNext() { if (enumerator.MoveNext()) { return enumerator.Current; } else { return default; } } } }