diff --git a/csharp/Lib/StatusApi/DeviceStatus.cs b/csharp/Lib/StatusApi/DeviceStatus.cs index ef92280ab..380007d85 100644 --- a/csharp/Lib/StatusApi/DeviceStatus.cs +++ b/csharp/Lib/StatusApi/DeviceStatus.cs @@ -1,26 +1,14 @@ -using System.Text.Json; using InnovEnergy.Lib.Utils; -using static InnovEnergy.Lib.Units.Units; namespace InnovEnergy.Lib.StatusApi; public abstract record DeviceStatus { - private static readonly JsonSerializerOptions JsonSerializerOptions; - - static DeviceStatus() - { - JsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true }; - JsonConverters.ForEach(JsonSerializerOptions.Converters.Add); // how stupid is that?!! - } - public String DeviceType => GetType() - .Generate(t => t.BaseType!) + .Unfold(t => t.BaseType) .First(t => t.IsAbstract) .Name .Replace("Status", ""); - - public String ToJson() => JsonSerializer.Serialize(this, GetType(), JsonSerializerOptions); } diff --git a/csharp/Lib/Units/Angle.generated.cs b/csharp/Lib/Units/Angle.generated.cs index 0c1abd7e5..837f0b2a2 100644 --- a/csharp/Lib/Units/Angle.generated.cs +++ b/csharp/Lib/Units/Angle.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Angle; +[JsonConverter(typeof(AngleConverter))] public readonly partial struct Angle { public Decimal Value { get; } diff --git a/csharp/Lib/Units/ApparentPower.generated.cs b/csharp/Lib/Units/ApparentPower.generated.cs index ae632e889..a72053726 100644 --- a/csharp/Lib/Units/ApparentPower.generated.cs +++ b/csharp/Lib/Units/ApparentPower.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = ApparentPower; +[JsonConverter(typeof(ApparentPowerConverter))] public readonly partial struct ApparentPower { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Current.generated.cs b/csharp/Lib/Units/Current.generated.cs index 1bb733666..c06cb3ff0 100644 --- a/csharp/Lib/Units/Current.generated.cs +++ b/csharp/Lib/Units/Current.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Current; +[JsonConverter(typeof(CurrentConverter))] public readonly partial struct Current { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Frequency.generated.cs b/csharp/Lib/Units/Frequency.generated.cs index b1e8c6e65..576e7b1a4 100644 --- a/csharp/Lib/Units/Frequency.generated.cs +++ b/csharp/Lib/Units/Frequency.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Frequency; +[JsonConverter(typeof(FrequencyConverter))] public readonly partial struct Frequency { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Generator/Template.txt b/csharp/Lib/Units/Generator/Template.txt index 857ecad58..38e30aa04 100644 --- a/csharp/Lib/Units/Generator/Template.txt +++ b/csharp/Lib/Units/Generator/Template.txt @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Template; +[JsonConverter(typeof(TemplateConverter))] public readonly partial struct Template { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Number.generated.cs b/csharp/Lib/Units/Number.generated.cs index 4e533f664..4c6eb5693 100644 --- a/csharp/Lib/Units/Number.generated.cs +++ b/csharp/Lib/Units/Number.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Number; +[JsonConverter(typeof(NumberConverter))] public readonly partial struct Number { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Power.generated.cs b/csharp/Lib/Units/Power.generated.cs index 923275e3b..1e68ec3a8 100644 --- a/csharp/Lib/Units/Power.generated.cs +++ b/csharp/Lib/Units/Power.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Power; +[JsonConverter(typeof(PowerConverter))] public readonly partial struct Power { public Decimal Value { get; } diff --git a/csharp/Lib/Units/ReactivePower.generated.cs b/csharp/Lib/Units/ReactivePower.generated.cs index 252438ae1..f6b694b7a 100644 --- a/csharp/Lib/Units/ReactivePower.generated.cs +++ b/csharp/Lib/Units/ReactivePower.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = ReactivePower; +[JsonConverter(typeof(ReactivePowerConverter))] public readonly partial struct ReactivePower { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Resistance.generated.cs b/csharp/Lib/Units/Resistance.generated.cs index d81ace678..6918e60dd 100644 --- a/csharp/Lib/Units/Resistance.generated.cs +++ b/csharp/Lib/Units/Resistance.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Resistance; +[JsonConverter(typeof(ResistanceConverter))] public readonly partial struct Resistance { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Temperature.generated.cs b/csharp/Lib/Units/Temperature.generated.cs index e0ff31eaa..c182f6737 100644 --- a/csharp/Lib/Units/Temperature.generated.cs +++ b/csharp/Lib/Units/Temperature.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Temperature; +[JsonConverter(typeof(TemperatureConverter))] public readonly partial struct Temperature { public Decimal Value { get; } diff --git a/csharp/Lib/Units/Voltage.cs b/csharp/Lib/Units/Voltage.cs index 2c65129e4..9d9df166c 100644 --- a/csharp/Lib/Units/Voltage.cs +++ b/csharp/Lib/Units/Voltage.cs @@ -16,4 +16,5 @@ public readonly partial struct Voltage // P=UI public static Power operator *(Voltage voltage, Current current) => new Power(current.Value * voltage.Value); -} \ No newline at end of file +} + diff --git a/csharp/Lib/Units/Voltage.generated.cs b/csharp/Lib/Units/Voltage.generated.cs index 44c32da19..4f5c57f91 100644 --- a/csharp/Lib/Units/Voltage.generated.cs +++ b/csharp/Lib/Units/Voltage.generated.cs @@ -10,6 +10,7 @@ namespace InnovEnergy.Lib.Units; using T = Voltage; +[JsonConverter(typeof(VoltageConverter))] public readonly partial struct Voltage { public Decimal Value { get; } diff --git a/csharp/Lib/Utils/EnumerableUtils.cs b/csharp/Lib/Utils/EnumerableUtils.cs index dd0243ef8..af9cc1998 100644 --- a/csharp/Lib/Utils/EnumerableUtils.cs +++ b/csharp/Lib/Utils/EnumerableUtils.cs @@ -243,7 +243,7 @@ public static class EnumerableUtils return ts.ElementAtOrDefault(index) ?? defaultValue; } - public static IEnumerable Generate(this T seed, Func next) + public static IEnumerable Unfold(this T seed, Func next) { var value = seed; while (value is not null)