public object Run(ITreeConfigNode node, bool isShortVersion) { TypeBuilder tbSol = SettingsTypeBuilder.GetTypeBuilder(); // type builder for solutions ConstructorBuilder constructor = tbSol.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName); Config cfg = (Config)node.GetConfig(); var dic_sols = new Dictionary <string, object>(); foreach (var t in cfg.GroupAppSolutions.ListAppSolutions) { TypeBuilder tbPrj = SettingsTypeBuilder.GetTypeBuilder(); // type builder for projects var dic_prjs = new Dictionary <string, object>(); foreach (var tt in t.ListAppProjects) { Dictionary <string, object> dic_apgs = new Dictionary <string, object>(); var objAppGen = CreateSettingsForProject(node, tt, dic_apgs, isShortVersion); if (dic_apgs.Count > 0) { dic_prjs[tt.Name] = objAppGen; SettingsTypeBuilder.CreateProperty(tbPrj, tt.Name, objAppGen.GetType(), tt.NameUi, tt.Description); } } SettingsTypeBuilder.CreateToString(tbPrj, "Solution"); Type prjsType = tbPrj.CreateType(); SettingsTypeBuilder.CreateProperty(tbSol, t.Name, prjsType, t.NameUi, t.Description); object objPrj = Activator.CreateInstance(prjsType); foreach (var dt in dic_prjs) { prjsType.InvokeMember(dt.Key, BindingFlags.SetProperty, null, objPrj, new object[] { dt.Value }); } //if (dic_prjs.Count > 0) dic_sols[t.Name] = objPrj; } SettingsTypeBuilder.CreateToString(tbSol, "Solutions"); Type solsType = tbSol.CreateType(); object objSol = Activator.CreateInstance(solsType); foreach (var dt in dic_sols) { if (dic_sols.Count == 1) // remove solution level node in settings { return(dt.Value); } solsType.InvokeMember(dt.Key, BindingFlags.SetProperty, null, objSol, new object[] { dt.Value }); } if (dic_sols.Count == 0) { return(null); } return(objSol); }
public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem) { Contract.Requires(propertyItem != null); // this.Config.GroupPlugins.ListPlugins ITreeConfigNode instance = (ITreeConfigNode)propertyItem.Instance; IConfig cnfg = instance.GetConfig(); ComboBox cbx = new ComboBox(); cbx.DisplayMemberPath = "Name"; cbx.SelectedValuePath = "Guid"; var _binding_lst = new Binding("ListPlugins"); // bind to the Value property of the PropertyItem _binding_lst.Source = cnfg.GroupPlugins; _binding_lst.ValidatesOnExceptions = false; _binding_lst.ValidatesOnDataErrors = false; _binding_lst.Mode = BindingMode.OneWay; BindingOperations.SetBinding(cbx, ComboBox.ItemsSourceProperty, _binding_lst); // //var en = cnfg.GroupPlugins.ListPlugins.GetEnumerator(); //if (en.MoveNext()) //{ // var plg = en.Current; // if (!en.MoveNext()) // { // propertyItem.Value = plg.Guid; // } //} var _binding = new Binding("Value"); // bind to the Value property of the PropertyItem _binding.Source = propertyItem; _binding.ValidatesOnExceptions = true; _binding.ValidatesOnDataErrors = true; _binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay; BindingOperations.SetBinding(cbx, ComboBox.SelectedValueProperty, _binding); return(cbx); }