System.Text.Json中的DefaultContractResolver等效项

时间:2020-11-07 15:35:34

标签: json.net .net-core-3.1 system.text.json

我正在从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

0 个答案:

没有答案