/// <summary> /// Serializes given hypermedia to stream asynchronously. /// </summary> /// <param name="outputStream"> /// The output stream in which hypermedia would be serialized. /// </param> /// <param name="instance"> /// The instance of hypermedia that would be serialized. /// </param> /// <param name="formatting"> /// <see cref="Formatting">Formatting</see> options for serialization. /// </param> /// <returns> /// Task or void. /// </returns> public static async Task SerializeAsync(Stream outputStream, Hypermedia instance, Formatting formatting) { await Task.Run(async() => { var serializator = SerializationVersionTools.GetSerializationVersion(instance.Version); var buffer = Encoding.UTF8.GetBytes(serializator.SerializeToString(instance, formatting, 0)); await outputStream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false); }).ConfigureAwait(false); }
/// <summary> /// Serializes given hypermedia to stream synchronously. /// </summary> /// <param name="outputStream"> /// The output stream in which hypermedia would be serialized. /// </param> /// <param name="instance"> /// The instance of hypermedia that would be serialized. /// </param> /// <param name="formatting"> /// <see cref="Formatting">Formatting</see> options for serialization. /// </param> /// <returns> /// void. /// </returns> public static void Serialize(Stream outputStream, Hypermedia instance, Formatting formatting) { SerializeAsync(outputStream, instance, formatting).ConfigureAwait(false).GetAwaiter().GetResult(); }
/// <summary> /// Serializes given hypermedia to stream asynchronously. /// </summary> /// <param name="outputStream"> /// The output stream in which hypermedia would be serialized. /// </param> /// <param name="instance"> /// The in public static async Task SerializeAsync(Stream outputStream, Hypermedia instance) { await SerializeAsync(outputStream, instance, Formatting.None).ConfigureAwait(false); }