add JsonConverters for Units
This commit is contained in:
parent
2328dd8d13
commit
55f70f056d
|
@ -0,0 +1,16 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using InnovEnergy.Units.Json;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
|
namespace InnovEnergy.Units;
|
||||||
|
|
||||||
|
public static partial class Units
|
||||||
|
{
|
||||||
|
public static IReadOnlyList<JsonConverter> JsonConverters = new JsonConverter[]
|
||||||
|
{
|
||||||
|
new CurrentConverter(),
|
||||||
|
new VoltageConverter(),
|
||||||
|
new PowerConverter(),
|
||||||
|
new ResistanceConverter()
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace InnovEnergy.Units.Json;
|
||||||
|
|
||||||
|
public class CurrentConverter : JsonConverter<Current>
|
||||||
|
{
|
||||||
|
public override Current Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return new Current(reader.GetDecimal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Current value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteNumberValue(value.Value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace InnovEnergy.Units.Json;
|
||||||
|
|
||||||
|
public class PowerConverter : JsonConverter<Power>
|
||||||
|
{
|
||||||
|
public override Power Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return new Power(reader.GetDecimal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Power value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteNumberValue(value.Value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace InnovEnergy.Units.Json;
|
||||||
|
|
||||||
|
public class ResistanceConverter : JsonConverter<Current>
|
||||||
|
{
|
||||||
|
public override Current Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return new Current(reader.GetDecimal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Current value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteNumberValue(value.Value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace InnovEnergy.Units.Json;
|
||||||
|
|
||||||
|
public class VoltageConverter : JsonConverter<Voltage>
|
||||||
|
{
|
||||||
|
public override Voltage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return new Voltage(reader.GetDecimal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Voltage value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteNumberValue(value.Value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue