| | | 1 | | using System.Collections; |
| | | 2 | | using System.Diagnostics.CodeAnalysis; |
| | | 3 | | |
| | | 4 | | namespace Pozitron.QuerySpecification; |
| | | 5 | | |
| | | 6 | | internal abstract class Iterator<TSource> : IEnumerable<TSource>, IEnumerator<TSource> |
| | | 7 | | { |
| | 286 | 8 | | private readonly int _threadId = Environment.CurrentManagedThreadId; |
| | | 9 | | |
| | | 10 | | private protected int _state; |
| | | 11 | | private protected TSource _current = default!; |
| | | 12 | | |
| | | 13 | | public Iterator<TSource> GetEnumerator() |
| | | 14 | | { |
| | 274 | 15 | | var enumerator = _state == 0 && _threadId == Environment.CurrentManagedThreadId ? this : Clone(); |
| | 274 | 16 | | enumerator._state = 1; |
| | 274 | 17 | | return enumerator; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public abstract Iterator<TSource> Clone(); |
| | | 21 | | public abstract bool MoveNext(); |
| | | 22 | | |
| | 503 | 23 | | public TSource Current => _current; |
| | 2 | 24 | | object? IEnumerator.Current => Current; |
| | 273 | 25 | | IEnumerator<TSource> IEnumerable<TSource>.GetEnumerator() => GetEnumerator(); |
| | 1 | 26 | | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
| | | 27 | | |
| | | 28 | | [ExcludeFromCodeCoverage] |
| | | 29 | | void IEnumerator.Reset() => throw new NotSupportedException(); |
| | | 30 | | |
| | | 31 | | public virtual void Dispose() |
| | | 32 | | { |
| | 444 | 33 | | _current = default!; |
| | 444 | 34 | | _state = -1; |
| | 444 | 35 | | } |
| | | 36 | | } |