protected Category GetCategory(string categoryname, string subcategoryname) { foreach (Category category in categories) { if (category.Text == categoryname) { if (subcategoryname == null) { return(category); } else { return(GetSubcategory(category, subcategoryname)); } } } Category newcategory = new Category(categoryname, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(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.Text == name) { return(subcategory); } } Category newsubcategory = new Category(name, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(parentCategory.Name, name)); parentCategory.Categories.Add(newsubcategory); return(newsubcategory); }