/// <summary> /// Advances the underlying <see cref="IBufferWriter{Byte}" /> based on what has been written so far. /// </summary> /// <param name="isFinalBlock">Let's the writer know whether more data will be written. This is used to validate /// that the JSON written so far is structurally valid if no more data is to follow.</param> /// <exception cref="InvalidOperationException"> /// Thrown when incomplete JSON has been written and <paramref name="isFinalBlock"/> is true. /// (for example when an open object or array needs to be closed). /// </exception> public void Flush(bool isFinalBlock = true) { if (isFinalBlock && !_writerOptions.SkipValidation && (CurrentDepth != 0 || _tokenType == JsonTokenType.None)) { ThrowHelper.ThrowInvalidOperationException_DepthNonZeroOrEmptyJson(_currentDepth); } Flush(); }