我正在从Newtonsoft转换一些逻辑,并发现以下实现之一
public class CustomDataContractResolver : DefaultContractResolver
{
public Dictionary<string, string> FieldNameChanges { get; set; }
public List<FieldValueReplica> FieldValueReplica { get; set; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
if (property.DeclaringType != typeof(logEvent)) return property;
if (FieldNameChanges.Count > 0 && FieldNameChanges.TryGetValue(property.PropertyName, out var newValue))
property.PropertyName = newValue;
return property;
}
}
任何人都已将DefaultContractResolver转换为System.Text.Json