28 lines
732 B
C#
28 lines
732 B
C#
namespace CommonMessurementUnits.JsonConverters
|
|
{
|
|
using Newtonsoft.Json;
|
|
|
|
using System;
|
|
|
|
public class FlowConverter : JsonConverter<Flow>
|
|
{
|
|
public override Flow ReadJson(JsonReader reader, Type objectType, Flow existingValue, bool hasExistingValue, JsonSerializer serializer)
|
|
{
|
|
while (reader.ValueType != typeof(double))
|
|
{
|
|
reader.Read();
|
|
}
|
|
|
|
if (reader.Value is double value)
|
|
{
|
|
return value;
|
|
}
|
|
|
|
return existingValue;
|
|
}
|
|
|
|
public override void WriteJson(JsonWriter writer, Flow value, JsonSerializer serializer)
|
|
=> writer.WriteValue((double)value);
|
|
}
|
|
}
|