public override bool Read(GH_IReader reader) { try { var constructorName = reader.GetString("SelectedConstructorName"); var typeName = reader.GetString("SelectedTypeName"); try { UseSchemaTag = reader.GetBoolean("UseSchemaTag"); UserSetSchemaTag = reader.GetBoolean("UserSetSchemaTag"); } catch { } SelectedConstructor = CSOUtils.FindConstructor(constructorName, typeName); if (SelectedConstructor == null) readFailed = true; } catch { readFailed = true; } try { Seed = reader.GetString("seed"); } catch { } return base.Read(reader); }
private void RecurseNamespace(string[] ns, Dictionary <string, object> tree, Type t) { var key = ns[0]; if (!tree.ContainsKey(ns[0])) { tree[key] = new Dictionary <string, object>(); } if (ns.Length > 1) { RecurseNamespace(ns.Skip(1).ToArray(), tree[key] as Dictionary <string, object>, t); } else { var constructors = CSOUtils.GetValidConstr(t) .ToDictionary(x => x.GetCustomAttribute <SchemaInfo>().Name, x => (object)x); if (constructors.Values.Count > 1) { ((Dictionary <string, object>)tree[key])[t.Name] = constructors; } else { //simplify structure if only 1 constructor ((Dictionary <string, object>)tree[key])[t.Name] = constructors.Values.First(); } } }
public override bool Read(GH_IReader reader) { try { var constructorName = reader.GetString("SelectedConstructorName"); var typeName = reader.GetString("SelectedTypeName"); SelectedConstructor = CSOUtils.FindConstructor(constructorName, typeName); if (SelectedConstructor == null) { readFailed = true; } } catch { readFailed = true; } try { Seed = reader.GetString("seed"); } catch { } return(base.Read(reader)); }
public override bool Write(GH_IWriter writer) { if (SelectedConstructor != null) { writer.SetString("SelectedConstructorName", CSOUtils.MethodFullName(SelectedConstructor)); writer.SetString("SelectedTypeName", SelectedConstructor.DeclaringType.FullName); } writer.SetString("seed", Seed); return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { if (SelectedConstructor != null) { var methodFullName = CSOUtils.MethodFullName(SelectedConstructor); var declaringTypeFullName = SelectedConstructor.DeclaringType.FullName; writer.SetString("SelectedConstructorName", methodFullName); writer.SetString("SelectedTypeName", declaringTypeFullName); writer.SetBoolean("UseSchemaTag", UseSchemaTag); writer.SetBoolean("UserSetSchemaTag", UserSetSchemaTag); } writer.SetString("seed", Seed); return base.Write(writer); }
private TreeGridItemCollection GenerateTree() { //create a tree of dictionaries to ensure uniqueness of namespaces and define structure var tree = new Dictionary <string, object>(); counts = new Dictionary <string, int>(); foreach (var type in typesFiltered) { RecurseNamespace(type.Namespace.Split('.'), tree, type); //treat the type name as part of the namespace, since now we are using constructors to populate //out tree items IncreaseCounts($"{type.Namespace}.{type.Name}", CSOUtils.GetValidConstr(type).Count()); } var item = new TreeGridItem(); var collection = new TreeGridItemCollection(); RecurseTree(tree, item); collection.AddRange(item.Children); return(collection); }
public CreateSchemaObjectDialog() { model = new CSOViewModel(); DataContext = model; Title = "Create an Object by Schema"; Padding = 5; Resizable = true; types = CSOUtils.ListAvailableTypes(); typesFiltered = types; search = new SearchBox { PlaceholderText = "Search for a schema class" }; search.Focus(); search.TextChanged += Search_TextChanged; //list = new ListBox //{ // Size = new Size(200, 200), // ItemTextBinding = Binding.Property<Type, string>(x => x.Name), // DataStore = typesFiltered, // SelectedIndex = 0 //}; //list.SelectedIndexBinding.BindDataContext((CSOViewModel m) => m.SelectedIndex, DualBindingMode.OneWayToSource); //list.SelectedValueBinding.BindDataContext((CSOViewModel m) => m.SelectedType, DualBindingMode.OneWayToSource); tree = new TreeGridView { Size = new Size(300, 200) }; tree.Columns.Add(new GridColumn { DataCell = new TextBoxCell(0) }); tree.DataStore = GenerateTree(); tree.BindDataContext(x => x.SelectedItem, (CSOViewModel m) => m.SelectedItem, DualBindingMode.OneWayToSource); description = new TextArea { ReadOnly = true, Size = new Size(400, 200) }; description.TextBinding.BindDataContext(Binding.Property((CSOViewModel m) => m.SelectedItem). Convert(x => GetDescription(x)), DualBindingMode.OneWay); Content = new TableLayout { Spacing = new Size(5, 5), Padding = new Padding(10), Rows = { new TableRow(search), new TableRow(tree, description), } }; // buttons DefaultButton = new Button { Text = "Create" }; DefaultButton.BindDataContext(x => x.Enabled, Binding.Property((CSOViewModel m) => m.SelectedItem) .Convert(x => x != null && x.Tag != null), DualBindingMode.OneWay); DefaultButton.Click += (sender, e) => { HasResult = true; Close(); }; PositiveButtons.Add(DefaultButton); AbortButton = new Button { Text = "C&ancel" }; AbortButton.Click += (sender, e) => Close(); NegativeButtons.Add(AbortButton); }