From a357bec1831611758a19bf23ff0fa5a5fe99ca52 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 28 May 2023 11:30:53 +0200 Subject: Add changes --- MatrixRoomUtils.Core/StateEvent.cs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'MatrixRoomUtils.Core/StateEvent.cs') diff --git a/MatrixRoomUtils.Core/StateEvent.cs b/MatrixRoomUtils.Core/StateEvent.cs index 2201587..f98d963 100644 --- a/MatrixRoomUtils.Core/StateEvent.cs +++ b/MatrixRoomUtils.Core/StateEvent.cs @@ -6,15 +6,12 @@ namespace MatrixRoomUtils.Core; public class StateEvent { - [JsonPropertyName("content")] - public dynamic Content { get; set; } = new{}; - [JsonPropertyName("state_key")] - public string? StateKey { get; set; } - [JsonPropertyName("type")] - public string Type { get; set; } - [JsonPropertyName("replaces_state")] - public string? ReplacesState { get; set; } - + [JsonPropertyName("content")] public dynamic Content { get; set; } = new { }; + + [JsonPropertyName("state_key")] public string StateKey { get; set; } = ""; + [JsonPropertyName("type")] public string Type { get; set; } + [JsonPropertyName("replaces_state")] public string? ReplacesState { get; set; } + //extra properties [JsonIgnore] public JsonNode ContentAsJsonNode @@ -22,17 +19,24 @@ public class StateEvent get => JsonSerializer.SerializeToNode(Content); set => Content = value; } + + public StateEvent As() where T : class + { + return (StateEvent)this; + } } public class StateEvent : StateEvent where T : class { - public new T content { get; set; } - - - [JsonIgnore] - public new JsonNode ContentAsJsonNode + public StateEvent() { - get => JsonSerializer.SerializeToNode(Content); - set => Content = value.Deserialize(); + //import base content if not an empty object + if (base.Content.GetType() == typeof(T)) + { + Console.WriteLine($"StateEvent<{typeof(T)}> created with base content of type {base.Content.GetType()}. Importing base content."); + Content = base.Content; + } } + [JsonPropertyName("content")] + public T Content { get; set; } } \ No newline at end of file -- cgit 1.5.1