private void InitPages() { foreach (Expandable exa in Core.loadedModules) { Expandable.IConfig config = exa.config; if (config == null) { continue; } string module = exa.dllFileName; string text = module == Core.CORE_ID ? "General" : exa.getTitle(); Dictionary <string, string> strRes = exa.strRes; TabPage page = new TabPage { Text = text, AutoScroll = true, Location = new Point(4, 22), Padding = new Padding(3), Size = new Size(290, 294), TabIndex = tabControl1.TabCount, UseVisualStyleBackColor = true, Name = module }; Type type = config.GetType(); FieldInfo[] fields = type.GetFields(); List <Control> controls = new List <Control>(); int index = 0; foreach (FieldInfo fi in fields) { dynamic value = Convert.ChangeType(fi.GetValue(config), fi.FieldType); Control control = createControl(ref index, page, fi, exa, value); if (control == null) { continue; } controls.Add(control); } page.Tag = new object[] { exa, controls.ToArray(), config }; tabControl1.Controls.Add(page); } }
private static List <Expandable.Property> convertConfig(Expandable.IConfig config) { if (config == null) { return(null); } List <Expandable.Property> fieldList = new List <Expandable.Property>(); Type type = config.GetType(); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo fi in fields) { object value = fi.GetValue(config); //Console.WriteLine(fi.Name + ", as " + fi.FieldType); Expandable.Property property = new Expandable.Property(fi.Name, value); fieldList.Add(property); } return(fieldList); }
public static bool loadConfig(string module, Expandable.IConfig config, Hotkey[] hks) { string file = module == CORE_ID ? CORE_CONFIG_PATH : CONFIG_PATH + module + ".ini"; if (!File.Exists(file)) { return(false); } Config tmp = new Config(); using (Stream str = File.OpenRead(file)) { try { XmlSerializer xs = new XmlSerializer(typeof(Config)); tmp = (Config)xs.Deserialize(str); } catch (Exception e) { MessageBox.Show(e.Message); } } if (tmp.Properties.Count == 0 && tmp.Hotkeys.Count == 0) { return(false); } if (tmp.Hotkeys.Count > 0) { for (int i = 0; i < hks.Length; i++) { HotkeyInfo hki = tmp.Hotkeys.FirstOrDefault(_ => _.id == hks[i].id); if (hki.id != null) { hks[i].keys = hki.keys; } } } if (tmp.Properties.Count > 0) { Type confType = config.GetType(); FieldInfo[] fields = confType.GetFields(); foreach (FieldInfo fi in fields) { object value = tmp.Properties.FirstOrDefault(_ => _.name == fi.Name).value; if (value == null) { continue; } if (value.GetType().AssemblyQualifiedName == fi.FieldType.AssemblyQualifiedName) { fi.SetValue(config, value); } } } return(true); }