about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Extensions
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 17:19:17 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 17:19:17 +0200
commitf143c8cd3adc23a8f4473fc7cea7d1c58322233b (patch)
tree0aca8c6b5c694e46d3b713b965e35f7d9e89c322 /MatrixRoomUtils.Core/Extensions
parentPrevent deploy without commit (diff)
downloadMatrixUtils-f143c8cd3adc23a8f4473fc7cea7d1c58322233b.tar.xz
idk
Diffstat (limited to 'MatrixRoomUtils.Core/Extensions')
-rw-r--r--MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs b/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs
new file mode 100644
index 0000000..725c832
--- /dev/null
+++ b/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs
@@ -0,0 +1,22 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MatrixRoomUtils.Core.Extensions;
+
+public static class JsonElementExtensions
+{
+    public static void FindExtraJsonFields([DisallowNull] this JsonElement? res, Type t)
+    {
+        var props = t.GetProperties();
+        var unknownPropertyFound = false;
+        foreach (var field in res.Value.EnumerateObject())
+        {
+            if (props.Any(x => x.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name == field.Name)) continue;
+            Console.WriteLine($"[!!] Unknown property {field.Name} in {t.Name}!");
+            unknownPropertyFound = true;
+        }
+        if(unknownPropertyFound) Console.WriteLine(res.Value.ToJson());
+    }
+}
\ No newline at end of file