using System.Globalization;
using Newtonsoft.Json.Serialization;
public class MyTypeContractResolver<T> : DefaultContractResolver
protected override JsonProperty CreateProperty(MemberInfo member,
var property = base.CreateProperty(member, memberSerialization);
property.Ignored = false;
property.ShouldSerialize = propInstance => property.DeclaringType != typeof (T) && property.PropertyName != nameof(ExceptionBase.Features);
public enum ExceptionBaseFeatures
public class ExceptionBase {
public virtual int A_ { get => throw new InvalidOperationException(); set => throw new InvalidOperationException(); }
public virtual int B_ { get => throw new InvalidOperationException(); set => throw new InvalidOperationException(); }
public virtual int C_ { get => throw new InvalidOperationException(); set => throw new InvalidOperationException(); }
public virtual ExceptionBaseFeatures Features { get; }
public class A : ExceptionBase
public override int A_ { get; set; }
public override int B_ { get; set; }
public override ExceptionBaseFeatures Features => ExceptionBaseFeatures.HasA | ExceptionBaseFeatures.HasB;
public class B : ExceptionBase
public override int B_ { get; set; }
public override int C_ { get; set; }
public override ExceptionBaseFeatures Features => ExceptionBaseFeatures.HasB | ExceptionBaseFeatures.HasC;
public static void Main()
Console.WriteLine(JsonConvert.SerializeObject(a, new JsonSerializerSettings {ContractResolver = new MyTypeContractResolver<ExceptionBase>()}));
Console.WriteLine(JsonConvert.SerializeObject(b, new JsonSerializerSettings {ContractResolver = new MyTypeContractResolver<ExceptionBase>()}));
Console.WriteLine(((ExceptionBase)a).C_);