public void ApplyFilter(TestItem testItem, ApplyFilterPredicate predicate) { // Remove all test items not found in the list. // Not using foreach so that we can remove items from the list as we walk it for (int i = 0; i < testItem.Children.Count; i++) { TestItem child = testItem.Children[i]; // If the child passes the filter we're done // automatically include all its children as well if (!predicate(child)) { //If this is a leave test item then remove if (child.Children.Count <= 0) { testItem.Children.Remove(child); i--; } //Otherwise, check its children else { ApplyFilter(child, predicate); //If no test item children are left, (and since the test item wasn't on the list), //then the test item shouldn't be removed as well if (child.Children.Count <= 0) { testItem.Children.Remove(child); i--; } } } } }
public void ApplyFilter(TestItem testItem, ApplyFilterPredicate predicate) { // Remove all test items not found in the list. // Not using foreach so that we can remove items from the list as we walk it for (int i = 0; i < testItem.Children.Count; i++) { TestItem child = testItem.Children[i]; // If the child passes the filter we're done // automatically include all its children as well if (!predicate(child)) { //If this is a leave test item then remove if (child.Children.Count <= 0) { testItem.Children.Remove(child); i--; } //Otherwise, check its children else { ApplyFilter(child, predicate); //If no test item children are left, (and since the test item wasn't on the list), //then the test item shouldn't be removed as well if (child.Children.Count <= 0) { testItem.Children.Remove(child); i--; } } } } }