12345678910111213141516171819202122232425 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MS.WebCore.Core
- {
- public class CustomContractResolver : DefaultContractResolver
- {
- private readonly HashSet<string> _propertiesToSerialize;
- public CustomContractResolver(IEnumerable<string> propertiesToSerialize)
- {
- _propertiesToSerialize = new HashSet<string>(propertiesToSerialize);
- }
- protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
- {
- IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
- return properties.Where(p => _propertiesToSerialize.Contains(p.PropertyName)).ToList();
- }
- }
- }
|