public XmlConfigurationOptionCollectionTypeDescriptor(XmlConfigurationCategoryCollection categories) : this() { foreach(XmlConfigurationCategory category in categories) { try { this.LoadOptions(category.Options); } catch(Exception ex) { Debug.WriteLine(ex); } } }
/// <summary> /// Initializes a new instance of the XmlConfigurationCategory class /// </summary> public XmlConfigurationCategory(XmlConfigurationCategory category) : base((XmlConfigurationElement)category) { _options = category.Options; _categories = category.Categories; _parent = category.Parent; }
/// <summary> /// Clones this category collection /// </summary> /// <returns></returns> public object Clone() { XmlConfigurationCategoryCollection clone = new XmlConfigurationCategoryCollection(); clone.ResetBeforeEdit(); clone.ResetChanged(); clone.ResetAfterEdit(); clone.ResetEditCancelled(); clone.Parent = _parent; foreach(XmlConfigurationCategory category in base.InnerList) { XmlConfigurationCategory clonedCategory = (XmlConfigurationCategory)category.Clone(); clonedCategory.Parent = clone; clone.Add(clonedCategory); } return clone; }
/// <summary> /// Writes a collection of categories to the XmlDocument /// </summary> /// <param name="doc"></param> /// <param name="parent"></param> /// <param name="categories"></param> /// <param name="alwaysPersist"></param> private void WriteCategories(XmlDocument doc, XmlElement parent, XmlConfigurationCategoryCollection categories, bool alwaysPersist) { try { /// write each category in this category collection foreach(XmlConfigurationCategory category in categories) this.WriteCategory(doc, parent, category, alwaysPersist); } catch(Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Reads an XmlConfigurationCategoryCollection using the specified XPathNavigator /// </summary> /// <param name="navigator"></param> /// <returns></returns> private XmlConfigurationCategoryCollection ReadCategories(XPathNavigator navigator, XmlConfigurationCategoryCollection categories) { if (navigator.HasChildren) { if (navigator.MoveToFirstChild()) { // is this element a category node? if (string.Compare(navigator.Name, @"Category", true) == 0) { // so read it XmlConfigurationCategory category = new XmlConfigurationCategory(); category.BeginInit(); category.Parent = categories; this.ReadCategory(navigator, category); // and add it to the current collection of categories categories.Add(category); category.EndInit(); } } } while (navigator.MoveToNext()) { // is this element a category node? if (string.Compare(navigator.Name, @"Category", true) == 0) { // so read it XmlConfigurationCategory category = new XmlConfigurationCategory(); category.BeginInit(); category.Parent = categories; this.ReadCategory(navigator, category); // and add it to the current collection of categories categories.Add(category); category.EndInit(); } } return categories; }
/// <summary> /// Recursively adds nodes for the specified categories /// </summary> /// <param name="tree"></param> /// <param name="nodes"></param> /// <param name="categories"></param> private void AddNodesForCategories(TreeView tree, TreeNodeCollection nodes, XmlConfigurationCategoryCollection categories) { if (this.InvokeRequired) { this.Invoke(new AddNodesForCategoriesInvoker(this.AddNodesForCategories), new object[] {tree, nodes, categories}); return; } tree.BeginUpdate(); try { foreach(XmlConfigurationCategory category in categories) { if (!category.Hidden) { // try and find an existing node that we can merge with CategoryTreeNode n = this.FindNodeForCategory(nodes, category); if (n == null) n = this.AddNodeForCategory(tree, nodes, category); if (n != null) { if (!n.IsBoundToCategory(category)) n.BindToCategory(category); this.AddNodesForCategories(tree, n.Nodes, category.Categories); } } } } catch(Exception ex) { Debug.WriteLine(ex); } finally { tree.EndUpdate(); } }