Category GetCategory(string categoryname, string subcategoryname) { foreach (Category category in categories) { if (category.Name == categoryname) { if (subcategoryname == null) { return(category); } else { return(GetSubcategory(category, subcategoryname)); } } } Category newcategory = new Category(categoryname, TemplateCategorySortOrderFile.GetFileCategorySortOrder(categoryname)); categories.Add(newcategory); if (subcategoryname != null) { return(GetSubcategory(newcategory, subcategoryname)); } return(newcategory); }
Category GetSubcategory(Category parentCategory, string name) { foreach (Category subcategory in parentCategory.Categories) { if (subcategory.Name == name) { return(subcategory); } } Category newsubcategory = new Category(name, TemplateCategorySortOrderFile.GetFileCategorySortOrder(parentCategory.Name, name)); parentCategory.Categories.Add(newsubcategory); return(newsubcategory); }
public void SetUpFixture() { string xml = "<Categories>\r\n" + " <Category Name='C#'>\r\n" + " <Category Name='Windows Applications' SortOrder='10'/>\r\n" + " </Category>\r\n" + " <Category Name='Misc' SortOrder='20'/>\r\n" + " <Category Name='Error' SortOrder='A'/>\r\n" + " <Category mis-typed-Name='Test' SortOrder='100'/>\r\n" + "</Categories>"; sortOrderFile = new TemplateCategorySortOrderFile(new XmlTextReader(new StringReader(xml))); csharpSortOrder = sortOrderFile.GetCategorySortOrder("C#"); windowsAppsSortOrder = sortOrderFile.GetCategorySortOrder("C#", "Windows Applications"); miscSortOrder = sortOrderFile.GetCategorySortOrder("Misc"); errorSortOrder = sortOrderFile.GetCategorySortOrder("Error"); misTypedNameSortOrder = sortOrderFile.GetCategorySortOrder(String.Empty); }