source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,29 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Linq;
using System.Reflection;
namespace ServerManagerTool.Common.Lib
{
public class UserScopedSettingContractResolver : DefaultContractResolver
{
public static readonly UserScopedSettingContractResolver Instance = new UserScopedSettingContractResolver();
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
var customAttributes = member.CustomAttributes?.ToArray() ?? new CustomAttributeData[0];
if (customAttributes.Any(a => a.AttributeType == typeof(System.Configuration.UserScopedSettingAttribute)))
{
property.ShouldSerialize = instance => { return property.PropertyType.IsValueType || property.PropertyType == typeof(string); };
}
else
{
property.ShouldSerialize = instance => { return false; };
}
return property;
}
}
}