public double First { get; set; }
public double Second { get; set; }
public Dictionary<double, Total> Dictionary { get; set; }
public class TotalConverter : JsonConverter
private readonly Func<Total, bool> _strategy;
public TotalConverter(Func<Total, bool> strategy)
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
var result = _strategy((Total)value);
JToken.FromObject(new { First = result, Second = !result }).WriteTo(writer);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
throw new NotImplementedException();
public override bool CanConvert(Type objectType)
return typeof(Total) == objectType;
public static void Main(string[] args)
Dictionary = new Dictionary<double, Total>
[1] = new Total { First = 0.3, Second = 0.7 },
[2] = new Total { First = 0.4, Second = 0.6 },
[3] = new Total { First = 0.9, Second = 0.1 }
var result = JsonConvert.SerializeObject(mc, new TotalConverter(total => total.First > total.Second));