想用TraceModel替换掉MyTraceModel,还不够成熟,默认的DefaultSpanBuilder里面有好些属性只读,导致反序列化后无法赋值。
大石头 authored at 2020-09-08 22:18:06
985.00 B
Stardust
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using NewLife.Log;

namespace Stardust.Server.Common
{
    internal class JsonConverterForBuilder : JsonConverter<ISpanBuilder>
    {
        public override ISpanBuilder Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => JsonSerializer.Deserialize<DefaultSpanBuilder>(ref reader, options);

        public override void Write(Utf8JsonWriter writer, ISpanBuilder value, JsonSerializerOptions options) => JsonSerializer.Serialize(writer, value, options);
    }

    internal class JsonConverterForSpan : JsonConverter<ISpan>
    {
        public override ISpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => JsonSerializer.Deserialize<DefaultSpan>(ref reader, options);

        public override void Write(Utf8JsonWriter writer, ISpan value, JsonSerializerOptions options) => JsonSerializer.Serialize(writer, value, options);
    }
}