public static AutomationElement FirstOrDefault(this AutomationQueryable source, Expression <Func <AutomationTypeHolder, bool> > predicate) { if (source == null) { throw new ArgumentNullException("source"); } if (predicate == null) { throw new ArgumentNullException("predicate"); } var result = source.First(predicate); if (result != null) { return(result); } else { return(null); } }
//public static IEnumerable<AutomationElement> Where(this AutomationQueryable source, Expression<Func<AutomationTypeHolder, bool>> predicate) //{ // if (source == null) // { // throw new ArgumentNullException("source"); // } // if (predicate == null) // { // throw new ArgumentNullException("predicate"); // } // var result = (AutomationElementCollection)source.Provider.Execute(predicate); // foreach (AutomationElement el in result) // { // yield return el; // } //} public static AutomationElement First(this AutomationQueryable source, Expression <Func <AutomationTypeHolder, bool> > predicate) { if (source == null) { throw new ArgumentNullException("source"); } if (predicate == null) { throw new ArgumentNullException("predicate"); } var result = (AutomationElement)source.Provider.Execute(predicate); return(result); //var result = (IEnumerable)source.Provider.Execute(predicate); //AutomationElement el = null; //var enumerator = result.GetEnumerator(); //if (enumerator.MoveNext()) //{ // el = (AutomationElement)enumerator.Current; //} //return el; }