private static void EnsureBufferLength(ref byte[] buffer, int minLength) { if (buffer == null || buffer.Length < minLength) { buffer = new byte[minLength]; } }