/// <summary> /// Serializes a message using a given formatter. /// </summary> /// <param name="message">The message to serialize.</param> /// <param name="formatter">The formatter to use.</param> /// <remarks> /// This method should be used to serialize messages rather than /// calling message.SerializeAsync() directly. This correctly /// begins and finishes the message document and flushes the formatter. /// </remarks> public static async Task SerializeAsync(Message message, IFormatter formatter) { await formatter.BeginAsync("Message").ConfigureAwait(false); await message.SerializeAsync(formatter).ConfigureAwait(false); await formatter.FinishAsync().ConfigureAwait(false); await formatter.FlushAsync().ConfigureAwait(false); }