| using Newtonsoft.Json; |
| using Newtonsoft.Json.Serialization; |
| using System.Reflection; |
| |
| namespace BaSys40.Utils.JsonHandling |
| { |
| public class PrivatePropertyContractResolver : DefaultContractResolver |
| { |
| protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) |
| { |
| var prop = base.CreateProperty(member, memberSerialization); |
| |
| if (!prop.Writable) |
| { |
| var property = member as PropertyInfo; |
| if (property != null) |
| { |
| var hasPrivateSetter = property.GetSetMethod(true) != null; |
| prop.Writable = hasPrivateSetter; |
| } |
| } |
| |
| return prop; |
| } |
| |
| } |
| } |