summary refs log tree commit diff
path: root/LibGit/Extensions/JsonElementExtensions.cs
blob: dd97013b1fda1174b5acc5943fcbe2ad08a2e8cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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());
    }
}