Redzen.IO.MemoryBlockStream.Seek C# (CSharp) Method

Seek() public method

Sets the position within the stream to the specified value.
public Seek ( long offset, SeekOrigin origin ) : long
offset long The new position within the stream. This is relative to the loc parameter, and can be positive or negative.
origin SeekOrigin A value of type SeekOrigin, which acts as the seek reference point.
return long
        public override long Seek(long offset, SeekOrigin origin)
        {
            if(!this._isOpen) throw new ObjectDisposedException("Stream is closed.");
            if(offset > (long)int.MaxValue) throw new ArgumentOutOfRangeException("offset", "Stream length must be non-negative and less than 2^31-1.");

            switch(origin)
            {
                case SeekOrigin.Begin:
                {
                    if(offset < 0) throw new IOException("An attempt was made to move the position before the beginning of the stream.");
                    _position = (int)offset;
                    break;
                }
                case SeekOrigin.Current:
                {
                    int newPos = unchecked(_position + (int)offset);
                    if(newPos < 0) throw new IOException("An attempt was made to move the position before the beginning of the stream.");
                    _position = newPos;
                    break;
                }
                case SeekOrigin.End:
                {
                    int newPos = unchecked(_length + (int)offset);
                    if(newPos < 0) throw new IOException("An attempt was made to move the position before the beginning of the stream.");
                    _position = newPos;
                    break;
                }
                default:
                {
                    throw new ArgumentException("Invalid seek origin.");
                }
            }
            return _position;
        }