27 lines
No EOL
615 B
C#
27 lines
No EOL
615 B
C#
using Ellie.Common.JsonConverters;
|
|
using System.Text.Json;
|
|
|
|
namespace Ellie.Common;
|
|
|
|
public class JsonSeria : ISeria
|
|
{
|
|
private readonly JsonSerializerOptions _serializerOptions = new()
|
|
{
|
|
Converters =
|
|
{
|
|
new Rgba32Converter(),
|
|
new CultureInfoConverter()
|
|
}
|
|
};
|
|
|
|
public byte[] Serialize<T>(T data)
|
|
=> JsonSerializer.SerializeToUtf8Bytes(data, _serializerOptions);
|
|
|
|
public T? Deserialize<T>(byte[]? data)
|
|
{
|
|
if (data is null)
|
|
return default;
|
|
|
|
return JsonSerializer.Deserialize<T>(data, _serializerOptions);
|
|
}
|
|
} |