From 81bf1a1cd1678efd2e73ebc347f51809cffaac46 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 29 May 2023 09:33:32 +0200 Subject: Bugfixes, improvements --- MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs | 3 ++- MatrixRoomUtils.Core/StateEvent.cs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'MatrixRoomUtils.Core') diff --git a/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs index aa1832d..5aa9645 100644 --- a/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs +++ b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs @@ -4,11 +4,12 @@ namespace MatrixRoomUtils.Core.Extensions; public static class ObjectExtensions { - public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false) + public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false, bool unsafeContent = false) { var jso = new JsonSerializerOptions(); if(indent) jso.WriteIndented = true; if(ignoreNull) jso.IgnoreNullValues = true; + if(unsafeContent) jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping; return JsonSerializer.Serialize(obj, jso); } } \ No newline at end of file diff --git a/MatrixRoomUtils.Core/StateEvent.cs b/MatrixRoomUtils.Core/StateEvent.cs index f98d963..6321fb6 100644 --- a/MatrixRoomUtils.Core/StateEvent.cs +++ b/MatrixRoomUtils.Core/StateEvent.cs @@ -24,6 +24,19 @@ public class StateEvent { return (StateEvent)this; } + + public string dtype + { + get + { + string res = GetType().Name switch + { + "StateEvent`1" => $"StateEvent<{Content.GetType().Name}>", + _ => GetType().Name + }; + return res; + } + } } public class StateEvent : StateEvent where T : class @@ -38,5 +51,5 @@ public class StateEvent : StateEvent where T : class } } [JsonPropertyName("content")] - public T Content { get; set; } + public new T Content { get; set; } } \ No newline at end of file -- cgit 1.5.1