MongoDB.Bson.IO.MultiChunkBuffer.GetSlice C# (CSharp) Метод

GetSlice() публичный Метод

Gets a slice of this buffer.
MultiChunkBuffer GetSlice can only be called for read only buffers. /// position /// or /// length ///
public GetSlice ( int position, int length ) : IByteBuffer
position int The position of the start of the slice.
length int The length of the slice.
Результат IByteBuffer
        public IByteBuffer GetSlice(int position, int length)
        {
            ThrowIfDisposed();
            EnsureIsReadOnly();
            if (position < 0 || position >= _length)
            {
                throw new ArgumentOutOfRangeException("position");
            }
            if (length <= 0 || length > _length - position)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            var firstChunk = (_sliceOffset + position) / _chunkSize;
            var lastChunk = (_sliceOffset + position + length - 1) / _chunkSize;
            var sliceOffset = (_sliceOffset + position) - (firstChunk * _chunkSize);

            if (firstChunk == lastChunk)
            {
                return new SingleChunkBuffer(_chunks[firstChunk], sliceOffset, length, true);
            }
            else
            {
                var chunks = _chunks.Skip(firstChunk).Take(lastChunk - firstChunk + 1);
                return new MultiChunkBuffer(chunks, sliceOffset, length, true);
            }
        }