// Caller of Category.GetItems public Item[] GetItems() { foreach (var item in AvailableSorts) { item.button.ForegroundColor = Color.Gray; } if (SelectedSort == null || !AvailableSorts.Contains(SelectedSort)) { //ErrorLogger.Log("Default Sort Selected"); SelectedSort = DefaultSorts[0]; } SelectedSort.button.ForegroundColor = Color.White; List <Item> result = new List <Item>(); if (SelectedCategory == null) { foreach (Category category in Categories) { Item[] items = category.GetItems(); foreach (Item item in items) { result.Add(item); } } } else { result = SelectedCategory.GetItems().ToList(); } result = result.Where(item => item.Name.IndexOf(SearchBox.Text, StringComparison.OrdinalIgnoreCase) != -1).ToList(); result = result.Distinct().Where(item => PassFilters(item)).ToList(); result.Sort(new MyComparer(this)); return(result.ToArray()); }