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;
}