// private methods private void BackpatchSize() { int size = _buffer.Position - _context.StartPosition; if (size > _binaryWriterSettings.MaxDocumentSize) { var message = string.Format("Size {0} is larger than MaxDocumentSize {1}.", size, _binaryWriterSettings.MaxDocumentSize); throw new FileFormatException(message); } _buffer.Backpatch(_context.StartPosition, size); }