Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace HttpPatchSample.Models
{
/// <summary>
/// Class that plugs in to Newtonsoft deserialization pipeline for classes descending from <see cref="PatchDtoBase"/>.
/// For all properties, that are present in JSON it calls <see cref="PatchDtoBase.SetHasProperty"/>.`
/// </summary>
public class PatchRequestContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var prop = base.CreateProperty(member, memberSerialization);
prop.SetIsSpecified += (o, o1) =>
{
if (o is PatchDtoBase patchDtoBase)
{
patchDtoBase.SetHasProperty(prop.PropertyName);
}
};
return prop;
}
}
}