using NewHorizons.External.Modules; using NewHorizons.Utility; using System; using System.Collections.Generic; namespace NewHorizons.External.Configs { public class Config { public Config(Dictionary dict) { if (dict == null) return; foreach (var item in dict) { var property = GetType().GetProperty(item.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (property == null) property = GetType().GetProperty(item.Key.ToCamelCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (property == null) property = GetType().GetProperty(item.Key.ToTitleCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (property != null) { if (property.PropertyType.BaseType == typeof(Module)) { if (property.GetValue(this) == null) { var module = Activator.CreateInstance(property.PropertyType); property.SetValue(this, module); } ((Module)property.GetValue(this)).Build(item.Value as Dictionary); } else { property.SetValue(this, Convert.ChangeType(item.Value, property.PropertyType)); } } else Logger.LogError($"{item.Key} {item.Value} is not valid. Is your config formatted correctly?"); } } } }