Ejemplo n.º 1
0
        /// <summary>
        /// Deferred execution of iterator
        /// </summary>
        private void EnsureReady()
        {
            // only execute when requested
            if (this.isReady || this.isCompleted)
            {
                return;
            }
            this.isReady = true;

            // store the current item or null if complete
            int next = this.index + 1;

            SequenceBuffer <T> sBuffer = this.Buffer as SequenceBuffer <T>;

            if (sBuffer != null)
            {
                // avoid using SequenceBuffer<T>.Count as will need to enumerate entire sequence
                if (sBuffer.TryAdvance(next))
                {
                    this.current = this.Buffer[next];
                }
                else
                {
                    this.isCompleted = true;
                    this.current     = default(T);
                }
            }
            else
            {
                if (next < this.Buffer.Count)
                {
                    this.current = this.Buffer[next];
                }
                else
                {
                    this.isCompleted = true;
                    this.current     = default(T);
                }
            }
        }