diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-06-01 19:02:28 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-06-01 19:03:05 +0200 |
commit | a129b321998614b20e4ebb8a7c1632553ebee981 (patch) | |
tree | f4e16f7b1bbeffc21e81f8749e4980994242ff19 /LibMatrix.LegacyEvents.EventTypes | |
parent | Event serialisation fix (diff) | |
download | LibMatrix-a129b321998614b20e4ebb8a7c1632553ebee981.tar.xz |
Split event abstractions
Diffstat (limited to '')
-rw-r--r-- | LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEvent.cs (renamed from LibMatrix/LegacyMatrixEvent.cs) | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/LibMatrix/LegacyMatrixEvent.cs b/LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEvent.cs index a1ac5db..3cb9ecb 100644 --- a/LibMatrix/LegacyMatrixEvent.cs +++ b/LibMatrix.LegacyEvents.EventTypes/LegacyMatrixEvent.cs @@ -1,6 +1,7 @@ #if !DISABLE_LEGACY_EVENTS using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Reflection; using System.Text.Json; using System.Text.Json.Nodes; @@ -9,7 +10,6 @@ using ArcaneLibs; using ArcaneLibs.Attributes; using ArcaneLibs.Extensions; using LibMatrix.LegacyEvents.EventTypes; -using LibMatrix.Extensions; namespace LibMatrix; @@ -224,4 +224,28 @@ public class StateEventContentPolymorphicTypeInfoResolver : DefaultJsonTypeInfoR */ #endregion -#endif \ No newline at end of file +#endif + +public class JsonFloatStringConverter : JsonConverter<float> { + public override float Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => float.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} + +public class JsonDoubleStringConverter : JsonConverter<double> { + public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => double.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} + +public class JsonDecimalStringConverter : JsonConverter<decimal> { + public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => decimal.Parse(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options) + => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); +} \ No newline at end of file |