private static async Task <BinaryData> FromSerializableAsync <T>( T data, ObjectSerializer serializer, bool async) { Argument.AssertNotNull(serializer, nameof(serializer)); using var memoryStream = new MemoryStream(); if (async) { await serializer.SerializeAsync(memoryStream, data, typeof(T)).ConfigureAwait(false); } else { serializer.Serialize(memoryStream, data, typeof(T)); } return(new BinaryData(memoryStream.ToArray())); }
private static async Task <BinaryData> SerializeInternalAsync <T>( T data, ObjectSerializer serializer, bool async, CancellationToken cancellationToken) { Argument.AssertNotNull(serializer, nameof(serializer)); using var memoryStream = new MemoryStream(); if (async) { await serializer.SerializeAsync(memoryStream, data, typeof(T), cancellationToken).ConfigureAwait(false); } else { serializer.Serialize(memoryStream, data, typeof(T), cancellationToken); } return(new BinaryData((ReadOnlyMemory <byte>)memoryStream.ToArray())); }