summary refs log tree commit diff
path: root/LibGit/Extensions/JsonElementExtensions.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-05 03:25:53 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-05 03:25:53 +0200
commit51d820e22a4517dbb06d38a4f07f7c48522ef811 (patch)
tree4a7749cf77223dff2414fd4b73cb17df43d7449e /LibGit/Extensions/JsonElementExtensions.cs
downloadGitTools-master.tar.xz
Initial commit HEAD master
Diffstat (limited to 'LibGit/Extensions/JsonElementExtensions.cs')
-rw-r--r--LibGit/Extensions/JsonElementExtensions.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/LibGit/Extensions/JsonElementExtensions.cs b/LibGit/Extensions/JsonElementExtensions.cs
new file mode 100644

index 0000000..dd97013 --- /dev/null +++ b/LibGit/Extensions/JsonElementExtensions.cs
@@ -0,0 +1,22 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace LibGit.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