public void LoadFromLines(string[] lines) { INILoader ini = new INILoader(); ini.LoadFromLines(lines); LoadFromINILoader(ini); }
private void LoadFromINILoader(INILoader ini) { PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); for (int iProperty = 0; iProperty < properties.Length; iProperty++) { PropertyInfo iterProperty = properties[iProperty]; CategoryAttribute categoryAttribute = iterProperty.GetCustomAttribute <CategoryAttribute>(); string key = categoryAttribute != null ? ini.CombineKey(categoryAttribute.Category, iterProperty.Name) : iterProperty.Name; if (!ini.HasKey(key)) { continue; } if (iterProperty.PropertyType == typeof(string)) { if (ini.TryGetValue(key, out string value)) { iterProperty.SetValue(this, value); } } else if (iterProperty.PropertyType == typeof(int)) { if (ini.TryGetIntValue(key, out int value)) { iterProperty.SetValue(this, value); } } else if (iterProperty.PropertyType == typeof(float)) { if (ini.TryGetFloatValue(key, out float value)) { iterProperty.SetValue(this, value); } } else if (iterProperty.PropertyType == typeof(bool)) { if (ini.TryGetBoolValue(key, out bool value)) { iterProperty.SetValue(this, value); } } else if (iterProperty.PropertyType.IsEnum) { if (ini.TryGetEnumValue(key, iterProperty.PropertyType, out object value)) { iterProperty.SetValue(this, value); } } } }
public void LoadFromFile(string path) { if (!File.Exists(path)) { return; } INILoader ini = new INILoader(); ini.LoadFromFile(path); LoadFromINILoader(ini); }