using Newtonsoft.Json.Serialization; using Newtonsoft.Json; using System.Reflection; namespace Back.Features { public class IgnorePropertiesResolver : DefaultContractResolver { private readonly HashSet ignoreProps; public IgnorePropertiesResolver(IEnumerable propNamesToIgnore) { this.ignoreProps = new HashSet(propNamesToIgnore); } protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); if (this.ignoreProps.Contains(property.PropertyName)) { property.ShouldSerialize = _ => false; } return property; } } }