mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
source code checkin
This commit is contained in:
parent
5f8fb2c825
commit
7e57b72e35
675 changed files with 168433 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue