/// <summary> /// Sets the category list of Category objects. /// </summary> protected void SetCategoryList() { // Iterate through the list of Business to get each Category foreach (var b in BusinessList) { // A Business will have n Categories (a given Category may have a unique list of Subcategories) foreach (var c in b.CategoryList) { Predicate <Category> catFinder = (Category catToFind) => { return(catToFind.Name == c.Name); }; Category oldCat = CategoryList.Find(catFinder); // Insert new Category or update the SubcategoryList of a Category already represented in CategoryList if (oldCat == null) { CategoryList.Add(c); } else { foreach (var sc in c.SubcategoryList) { oldCat.SubcategoryList.Add(sc); } CategoryList.Insert(CategoryList.FindIndex(catFinder), oldCat); } } } }