using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using UnityEngine; using Valve.Newtonsoft.Json; using Valve.Newtonsoft.Json.Linq; namespace ConfigReader { public static class ConfigParser { private static string ConfigPath = "./Assets/CSVInput/Config.json"; public static bool ParseConfig() { try { string data = File.ReadAllText(ConfigPath); var source = JsonConvert.DeserializeObject(data); var destinationProperties = typeof(Config).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (JProperty prop in source) { var destinationProp = destinationProperties.SingleOrDefault(p => p.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)); var value = ((JValue)prop.Value).Value; destinationProp.SetValue(null, Convert.ChangeType(value, destinationProp.PropertyType)); } } catch { return false; } return true; } } }