/// <summary> /// Add a single category as a child of a category. If the category already exists, just return that one. /// </summary> /// <param name="parent">The parent category </param> /// <param name="childCategoryName">The name of the child category (can't be nested)</param> /// <returns>The newly created category</returns> public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName) { var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName; // support long nested categories like Math.Math.StaticMembers.Abs var parentItem = parent as BrowserInternalElement; while (parentItem != null) { var grandParent = parentItem.Parent; if (null == grandParent) { break; } newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName; parentItem = grandParent as BrowserInternalElement; } if (ContainsCategory(newCategoryName)) { return(GetCategoryByName(newCategoryName)); } var tempCat = new BrowserInternalElement(childCategoryName, parent); parent.AddChild(tempCat); return(tempCat); }
/// <summary> /// Add a single category as a child of a category. If the category already exists, just return that one. /// </summary> /// <param name="parent">The parent category </param> /// <param name="childCategoryName">The name of the child category (can't be nested)</param> /// <returns>The newly created category</returns> public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName) { var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName; if (ContainsCategory(newCategoryName)) { return(GetCategoryByName(newCategoryName)); } var tempCat = new BrowserInternalElement(childCategoryName, parent); parent.AddChild(tempCat); return(tempCat); }
/// <summary> /// Add a single category as a child of a category. If the category already exists, just return that one. /// </summary> /// <param name="parent">The parent category </param> /// <param name="childCategoryName">The name of the child category (can't be nested)</param> /// <returns>The newly created category</returns> public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName) { var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName; // support long nested categories like Math.Math.StaticMembers.Abs var parentItem = parent as BrowserInternalElement; while (parentItem != null) { var grandParent = parentItem.Parent; if (null == grandParent) break; newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName; parentItem = grandParent as BrowserInternalElement; } if (ContainsCategory(newCategoryName)) { return GetCategoryByName(newCategoryName); } var tempCat = new BrowserInternalElement(childCategoryName, parent); parent.AddChild(tempCat); return tempCat; }
/// <summary> /// Add a single category as a child of a category. If the category already exists, just return that one. /// </summary> /// <param name="parent">The parent category </param> /// <param name="childCategoryName">The name of the child category (can't be nested)</param> /// <returns>The newly created category</returns> public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName) { var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName; if (ContainsCategory(newCategoryName)) { return GetCategoryByName(newCategoryName); } var tempCat = new BrowserInternalElement(childCategoryName, parent); parent.AddChild(tempCat); return tempCat; }