/// <summary> /// Returns the list items that match the specified criteria. /// </summary> /// <remarks> /// The select criteria can be any expression that would be valid for the <seealso cref="Filter"/> property. /// </remarks> /// <param name="criteria">The criteria.</param> /// <returns>The matching items. If no items match the critiera, an empty list is returned.</returns> public IList Select(string criteria) { if (criteria == null) throw new ArgumentNullException("criteria"); if (criteria == "") throw new ArgumentException("criteria"); FilterNode expressionTree = FilterNode.Parse(criteria); FilterEvaluator evaluator = new FilterEvaluator(expressionTree, this.itemProperties); ArrayList matches = new ArrayList(); foreach (object item in this) { if (evaluator.Matches(item)) matches.Add(item); } return matches; }
/// <summary> /// Finds the index of the first list item matching the specified criteria. /// </summary> /// <remarks> /// The find criteria can be any expression that would be valid for the <seealso cref="Filter"/> property. /// </remarks> /// <param name="criteria">The criteria.</param> /// <returns>The index of the list item found, or -1 if not found.</returns> public int Find(string criteria) { if (criteria == null) throw new ArgumentNullException("criteria"); if (criteria == "") throw new ArgumentException("criteria"); FilterNode expressionTree = FilterNode.Parse(criteria); FilterEvaluator evaluator = new FilterEvaluator(expressionTree, this.itemProperties); for (int i = 0; i < this.Count; i++) { if (evaluator.Matches(this[i])) return i; } return -1; }