-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJsonPrivateResolver.cs
More file actions
24 lines (23 loc) · 799 Bytes
/
JsonPrivateResolver.cs
File metadata and controls
24 lines (23 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#if NEWTONSOFT
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using JsonProperty = Newtonsoft.Json.Serialization.JsonProperty;
namespace AndreasReitberger.Shared.Core.Utilities
{
public class JsonPrivateResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty prop = base.CreateProperty(member, memberSerialization);
if (!prop.Writable)
{
PropertyInfo? property = member as PropertyInfo;
bool hasPrivateSetter = property?.GetSetMethod(true) != null;
prop.Writable = hasPrivateSetter;
}
return prop;
}
}
}
#endif