using System; using System.Collections; using System.Collections.Generic; namespace Cobilas.Collections { /// Transforms an array into an enumerator. public class ArrayToIEnumerator : IEnumerator { #pragma warning disable CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente protected T[] list; protected long index; protected T current = default; #pragma warning restore CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente private bool disposedValue; /// Gets the element in the collection at the current position of the enumerator. public virtual T Current => current; object IEnumerator.Current => (object)current; /// Internal constructor. protected ArrayToIEnumerator() { list = Array.Empty(); index = -1; } #pragma warning disable CS1591 public ArrayToIEnumerator(T[] list) : this() => this.list = list; #pragma warning restore CS1591 /// Advances the enumerator to the next element of the collection. public virtual bool MoveNext() { if (++index >= ArrayManipulation.ArrayLongLength(list)) return false; else current = list[index]; return true; } /// Sets the enumerator to its initial position, which is before the first element in the collection. public virtual void Reset() => index = -1; /// Internal disposal of the object. protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { list = Array.Empty(); current = default; index = default; } disposedValue = true; } } /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } }