public override void Flush()
{
if (Disposed) { throw new ObjectDisposedException("BsonBinaryWriter"); }
if (State == BsonWriterState.Closed)
{
throw new InvalidOperationException("Flush called on closed BsonWriter.");
}
if (State != BsonWriterState.Done)
{
throw new InvalidOperationException("Flush called before BsonBinaryWriter was finished writing to buffer.");
}
if (_stream != null)
{
_buffer.WriteTo(_stream);
_stream.Flush();
_buffer.Clear(); // only clear the buffer if we have written it to a stream
}
}