using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Models { public class Compare { /// /// Vergleicht die JSON-Datei-Struktur mit dem Vorlagen-Model /// /// Gibt die fehlenden Eigenschaften aus public static IEnumerable Structure(string filepath) { foreach (var property in typeof(T).GetProperties()) { if (!Exists(filepath, property.GetPropertyAttribute().PropertyName)) { yield return property.GetPropertyAttribute(); } } } /// /// Vergleicht die JSON-Datei-Struktur mit dem Vorlagen-Model /// /// Gibt die fehlenden Eigenschaften aus public static IEnumerable StructurePrevalence(string filepath) { foreach (var property in new AppList().GetType().GetProperties()) { if (!Exists(filepath, property.GetPropertyAttribute().PropertyName)) { yield return property.GetPropertyAttribute(); } } } /// /// Vergleicht die JSON-Datei-Struktur mit dem Vorlagen-Model /// /// Gibt die fehlenden Eigenschaften aus public static IEnumerable StructureUserConfig(string filepath) { foreach (var property in new Config.User().GetType().GetProperties()) { if (!Exists(filepath, property.GetPropertyAttribute().PropertyName)) { yield return property.GetPropertyAttribute().PropertyName; } } } private static bool Exists(string path, string propertyname) { dynamic jsonobject = JsonConvert.DeserializeObject(string.Concat(JObject.Parse(File.ReadAllText(path))), new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Include, Formatting = Formatting.Indented }); return jsonobject.ContainsKey(propertyname); } } }