17 lines
558 B
C#
17 lines
558 B
C#
using System.Text.Json;
|
|
|
|
namespace MycroForge.Core.Extensions;
|
|
|
|
public static class ObjectStreamExtensions
|
|
{
|
|
public static async Task<string> SerializeAsync(this object @object, JsonSerializerOptions? options = null)
|
|
{
|
|
using var stream = new MemoryStream();
|
|
using var reader = new StreamReader(stream);
|
|
options ??= DefaultJsonSerializerOptions.Default;
|
|
|
|
await JsonSerializer.SerializeAsync(stream, @object, options);
|
|
stream.Position = 0;
|
|
return await reader.ReadToEndAsync();
|
|
}
|
|
} |