Files

24 lines
789 B
C#

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 {
/// <summary>
/// Type类型的JSON转换器
/// </summary>
public class TypeConverter : JsonConverter<Type> {
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);
}
}
}