2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00
pulsar/ObservatoryFramework/Files/Converters/NumberOrStringConverter.cs
Ben Parsons 68eff73dbd Add Startup Events to Database
Now emit startup events on conneciton
Some events still to add
2024-05-25 19:45:46 +10:00

21 lines
782 B
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters;
class NumberOrStringConverter : JsonConverter<NumberOrString>
{
public override NumberOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TokenType == JsonTokenType.String ? new NumberOrString(reader.GetString()) : new NumberOrString(reader.GetDouble());
}
public override void Write(Utf8JsonWriter writer, NumberOrString value, JsonSerializerOptions options)
{
if (value.IsString)
writer.WriteStringValue(value.StringValue!);
else
writer.WriteNumberValue(value.DoubleValue!.Value);
}
}