internal static void ValidateWriteParameters(byte[] buffer, int offset, int count)
{
if (buffer == null)
{
throw ADP.ArgumentNull(nameof(buffer));
}
if (offset < 0)
{
throw ADP.ArgumentOutOfRange(nameof(offset));
}
if (count < 0)
{
throw ADP.ArgumentOutOfRange(nameof(count));
}
try
{
if (checked(offset + count) > buffer.Length)
{
throw ExceptionBuilder.InvalidOffsetLength();
}
}
catch (OverflowException)
{
// If we've overflowed when adding offset and count, then they never would have fit into buffer anyway
throw ExceptionBuilder.InvalidOffsetLength();
}
}
}