public void SetLength(long value)
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(value));
if (FStream())
{
_stream.SetLength(value);
}
else
{
// If there is a buffer, even the value of SqlBytes is Null,
// still allow setting length to zero, which will make it not Null.
// If the buffer is null, raise exception
//
if (null == _rgbBuf)
throw new SqlTypeException(SR.SqlMisc_NoBufferMessage);
if (value > _rgbBuf.Length)
throw new ArgumentOutOfRangeException(nameof(value));
else if (IsNull)
// At this point we know that value is small enough
// Go back in buffer mode
_state = SqlBytesCharsState.Buffer;
_lCurLen = value;
}
AssertValid();
}