public bool MoveNext()
                {
                    switch (state)
                    {
                    case EnumeratorState.Enumerating:
                        if (++sourceIndex >= end)
                        {
                            state = EnumeratorState.Complete;
                            return(false);
                        }

                        var enumerable = selector.Invoke(source[sourceIndex]);
                        subEnumerator = enumerable.GetEnumerator();

                        state = EnumeratorState.EnumeratingSub;
                        goto case EnumeratorState.EnumeratingSub;

                    case EnumeratorState.EnumeratingSub:
                        if (!subEnumerator.MoveNext())
                        {
                            state = EnumeratorState.Enumerating;
                            goto case EnumeratorState.Enumerating;
                        }
                        return(true);

                    default:
                        return(false);
                    }
                }
Exemplo n.º 2
0
 internal DisposableEnumerator(DoublyLinkedList <T> list)
 {
     this.list = list;
     version   = list.version;
     current   = null;
     state     = list.IsEmpty ? EnumeratorState.Empty : EnumeratorState.First;
 }
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        ///
        /// <returns>
        /// true if the enumerator was successfully advanced to the next
        /// element; false if the enumerator has passed the end of the collection.
        /// </returns>
        ///
        /// <exception cref="T:System.InvalidOperationException">
        /// The collection was modified after the enumerator was created.
        /// </exception>
        /// <filterpriority>2</filterpriority>
        public bool MoveNext()
        {
            bool hasNext = GoNext();

            State = hasNext ? EnumeratorState.InProgress : EnumeratorState.AfterFinish;
            return(hasNext);
        }
Exemplo n.º 4
0
            public bool MoveNext()
            {
                var index = _currentState.Index + 1;

                if (_onValues)
                {
                    if (index >= _currentState.Branch.Values.Length)
                    {
                        index     = 0;
                        _onValues = false;
                    }
                    else
                    {
                        _currentState.Index = index;
                        return(true);
                    }
                }
                _currentState.Index = index;

                if (index >= _currentState.Branch.Branches.Length)
                {
                    if (_currentSlot == 0)
                    {
                        return(false);
                    }
                    _currentSlot--;
                    _currentState = CurrentStackState(ref this);
                    return(MoveNext());
                }

                var     branch    = _currentState.Branch.Branches[index];
                ref var nextState = ref CurrentStackState(ref this);
 internal Enumerator(SpanSelectManyEnumerable <TSource, TSubEnumerable, TSubEnumerator, TResult, TSelector> enumerable)
 {
     source        = enumerable.source;
     selector      = enumerable.selector;
     state         = EnumeratorState.Enumerating;
     sourceIndex   = -1;
     end           = sourceIndex + enumerable.source.Length;
     subEnumerator = default;
 }
Exemplo n.º 6
0
 public static void CheckCurrentState(EnumeratorState state)
 {
     if (state == EnumeratorState.Before)
     {
         throw new EnumeratorInvalidStateException("Enumerator in initial satte. Use MoveNext() for moving to 1st element.");
     }
     if (state == EnumeratorState.After)
     {
         throw new EnumeratorInvalidStateException("End of enumerator. Use Reset().");
     }
 }
Exemplo n.º 7
0
 internal Enumerator(Branch start)
 {
     _start        = start;
     _slot0        = default;
     _slot1        = default;
     _slot2        = default;
     _slot3        = default;
     _slot4        = default;
     _slot5        = default;
     _slot6        = default;
     _currentState = new EnumeratorState(start, -1);
     _onValues     = true;
     _currentSlot  = 0;
 }
        public bool MoveNext()
        {
            if (_enumeratorState == EnumeratorState.Ended)
            {
                throw Error.EnumerationFinished();
            }

            bool result = DoMoveNext();

            if (result)
            {
                _enumeratorState = EnumeratorState.Started;
            }
            else
            {
                _enumeratorState = EnumeratorState.Ended;
            }
            return(result);
        }
        public bool MoveNext()
        {
            if (_enumeratorState == EnumeratorState.Ended)
            {
                throw new InvalidOperationException("Enumeration already finished.");
            }

            bool result = DoMoveNext();

            if (result)
            {
                _enumeratorState = EnumeratorState.Started;
            }
            else
            {
                _enumeratorState = EnumeratorState.Ended;
            }
            return(result);
        }
 public void Reset()
 {
     DoReset();
     _enumeratorState = EnumeratorState.NotStarted;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Sets the enumerator to its initial position, which is before
 /// the first element in the collection. This implementation
 /// always throw <see cref="NotSupportedException"/>.
 /// </summary>
 /// <remarks>
 /// This method is intentionally sealed. Derived class should override
 /// <see cref="DoReset"/> protected method instead.
 /// </remarks>
 /// <exception cref="NotSupportedException">
 /// Always thrown.
 /// </exception>
 /// <exception cref="T:System.InvalidOperationException">
 /// The collection was modified after the enumerator was created.
 /// </exception>
 /// <filterpriority>2</filterpriority>
 public void Reset()
 {
     DoReset();
     _state = EnumeratorState.BeforeStart;
 }