about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-25 03:07:05 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-25 03:07:05 +0200
commitf866946fbbe962c712049327ade9dcbd43900295 (patch)
tree3400fcce20f68a6ef3eb130f4ef57733e346d0e9 /MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs
parentWorking sync (diff)
downloadMatrixUtils-f866946fbbe962c712049327ade9dcbd43900295.tar.xz
Working state, refactored Rory&::LibMatrix
Diffstat (limited to '')
-rw-r--r--MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs17
1 files changed, 16 insertions, 1 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs b/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs

index b007136..78f4456 100644 --- a/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs +++ b/MatrixRoomUtils.Core/Extensions/JsonElementExtensions.cs
@@ -1,12 +1,13 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Text.Json; +using System.Text.Json.Nodes; using System.Text.Json.Serialization; namespace MatrixRoomUtils.Core.Extensions; public static class JsonElementExtensions { - public static void FindExtraJsonFields([DisallowNull] this JsonElement? res, Type t) { + public static void FindExtraJsonElementFields([DisallowNull] this JsonElement? res, Type t) { var props = t.GetProperties(); var unknownPropertyFound = false; foreach (var field in res.Value.EnumerateObject()) { @@ -17,4 +18,18 @@ public static class JsonElementExtensions { if (unknownPropertyFound) Console.WriteLine(res.Value.ToJson()); } + public static void FindExtraJsonObjectFields([DisallowNull] this JsonObject? res, Type t) { + var props = t.GetProperties(); + var unknownPropertyFound = false; + foreach (var field in res) { + if (props.Any(x => x.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name == field.Key)) continue; + Console.WriteLine($"[!!] Unknown property {field.Key} in {t.Name}!"); + unknownPropertyFound = true; + // foreach (var propertyInfo in props) { + // Console.WriteLine($"[!!] Known property {propertyInfo.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name} in {t.Name}!"); + // } + } + + if (unknownPropertyFound) Console.WriteLine(res.ToJson()); + } } \ No newline at end of file