Example #1
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="sequence"></param>
        public Subsequence(IList <T> sequence, int start, int length)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException("sequence");
            }
            if (start < 0 || start >= sequence.Count)
            {
                throw new ArgumentOutOfRangeException("start");
            }
            if (length < 0 || length > start + sequence.Count)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            Subsequence <T> subsequence = sequence as Subsequence <T>;

            if (subsequence != null)
            {
                // optimize by using original internal list
                this.Items = subsequence.Items;
                this.Start = subsequence.Start + start;
                this.Size  = length;
                return;
            }

            this.Items = sequence;
            this.Start = start;
            this.Size  = length;
        }
Example #2
0
        /// <summary>
        /// Ends chunking at the current index and returns the buffered chunk
        /// </summary>
        /// <returns></returns>
        public override IEnumerable <T> EndChunk()
        {
            if (this.start < 0)
            {
                throw new InvalidOperationException("Not currently chunking.");
            }

            // build chunk value
            IEnumerable <T> value = new Subsequence <T>(this.Buffer, this.start, (1 + this.index - this.start));

            // reset chunk start
            this.start = -1;

            return(value);
        }