1 files changed, 20 insertions, 16 deletions
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<T> As<T>() where T : class
+ {
+ return (StateEvent<T>)this;
+ }
}
public class StateEvent<T> : 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<T>();
+ //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
|