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) { _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; } } } }