📜  DefaultContractResolver .net 排除空值 JsonSerializerSettings ContractResolver DefaultContractResolver - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:54.934000             🧑  作者: Mango

代码示例1
public class DataContractResolver : DefaultContractResolver
{
    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
    {
        var property = base.CreateProperty(member, memberSerialization);
        property.NullValueHandling = NullValueHandling.Include;
        property.DefaultValueHandling = DefaultValueHandling.Include;
        property.ShouldSerialize = o => true;
        return property;
    }
}