public override long Seek(long offset, SeekOrigin loc)
{
if (!_isOpen)
throw new InvalidOperationException();
if (offset > _memStreamMaxLength)
throw new ArgumentOutOfRangeException("offset");
switch (loc)
{
case SeekOrigin.Begin:
{
var tempPosition = unchecked(_origin + (int)offset);
if (offset < 0 || tempPosition < _origin)
throw new IOException();
_position = tempPosition;
break;
}
case SeekOrigin.Current:
{
var tempPosition = unchecked(_position + (int)offset);
if (unchecked(_position + offset) < _origin || tempPosition < _origin)
throw new IOException();
_position = tempPosition;
break;
}
case SeekOrigin.End:
{
var tempPosition = unchecked(_length + (int)offset);
if (unchecked(_length + offset) < _origin || tempPosition < _origin)
throw new IOException();
_position = tempPosition;
break;
}
default:
throw new ArgumentException();
}
return _position;
}