mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using CryptoExchange.Net.Interfaces;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using System.Text.Json.Serialization.Metadata;
|
|
|
|
namespace CryptoExchange.Net.Converters.SystemTextJson
|
|
{
|
|
/// <inheritdoc />
|
|
public class SystemTextJsonMessageSerializer : IMessageSerializer
|
|
{
|
|
private readonly JsonSerializerContext _options;
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
public SystemTextJsonMessageSerializer(JsonSerializerContext options)
|
|
{
|
|
_options = options;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
#if NET5_0_OR_GREATER
|
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
|
#endif
|
|
public string Serialize<T>(T message) => JsonSerializer.Serialize(message, SerializerOptions.WithConverters(_options));
|
|
}
|
|
}
|