using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace IpcLibrary.Serialization {
///
/// Type类型的JSON转换器
///
public class TypeConverter : JsonConverter {
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
var typeName = reader.GetString();
return string.IsNullOrEmpty(typeName) ? null : Type.GetType(typeName);
}
public override void Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options) {
writer.WriteStringValue(value?.AssemblyQualifiedName);
}
}
}