/// <summary> /// 用遍历的方式查找链表,返回符合要求的第一个节点 /// </summary> /// <param name="func"></param> /// <returns></returns> public CircleListNode <T> FindFirst(FindFunc <T> func) { CircleListEnumerator iter = new CircleListEnumerator(this); while (iter.MoveNext()) { if (func(iter.curNode.value)) { return(iter.curNode); } } return(null); }
IQueryElement Find <T>(IEnumerable <T> arr, FindFunc find) where T : class, IQueryElement { foreach (T item in arr) { IQueryElement e = Find(item, find); if (e != null) { return(e); } } return(null); }
/// <summary> /// 用遍历的方式查找链表,返回所以符合要求的节点 /// </summary> /// <param name="func"></param> /// <returns></returns> public CircleListNode <T>[] FindAll(FindFunc <T> func) { List <CircleListNode <T> > result = new List <CircleListNode <T> >(); CircleListEnumerator iter = new CircleListEnumerator(this); while (iter.MoveNext()) { if (func(iter.curNode.value)) { result.Add(iter.curNode); } } return(result.ToArray()); }
public IQueryElement Find(IQueryElement element, FindFunc find) { if (element == null || find(element)) { return(element); } switch (element.ElementType) { case QueryElementType.SqlFunction: return(Find(((SqlFunction)element).Parameters, find)); case QueryElementType.SqlExpression: return(Find(((SqlExpression)element).Parameters, find)); case QueryElementType.Join: return(Find(((Join)element).JoinOns, find)); case QueryElementType.Column: return(Find(((SqlQuery.Column)element).Expression, find)); case QueryElementType.SearchCondition: return(Find(((SqlQuery.SearchCondition)element).Conditions, find)); case QueryElementType.Condition: return(Find(((SqlQuery.Condition)element).Predicate, find)); case QueryElementType.ExprPredicate: return(Find(((SqlQuery.Predicate.Expr)element).Expr1, find)); case QueryElementType.NotExprPredicate: return(Find(((SqlQuery.Predicate.NotExpr)element).Expr1, find)); case QueryElementType.IsNullPredicate: return(Find(((SqlQuery.Predicate.IsNull)element).Expr1, find)); case QueryElementType.FromClause: return(Find(((SqlQuery.FromClause)element).Tables, find)); case QueryElementType.WhereClause: return(Find(((SqlQuery.WhereClause)element).SearchCondition, find)); case QueryElementType.GroupByClause: return(Find(((SqlQuery.GroupByClause)element).Items, find)); case QueryElementType.OrderByClause: return(Find(((SqlQuery.OrderByClause)element).Items, find)); case QueryElementType.OrderByItem: return(Find(((SqlQuery.OrderByItem)element).Expression, find)); case QueryElementType.Union: return(Find(((SqlQuery.Union)element).SqlQuery, find)); case QueryElementType.FuncLikePredicate: return(Find(((SqlQuery.Predicate.FuncLike)element).Function, find)); case QueryElementType.SqlBinaryExpression: { var bexpr = (SqlBinaryExpression)element; return (Find(bexpr.Expr1, find) ?? Find(bexpr.Expr2, find)); } case QueryElementType.SqlTable: { var table = (SqlTable)element; return (Find(table.All, find) ?? Find(table.Fields.Values, find) ?? Find(table.Joins, find) ?? Find(table.TableArguments, find)); } case QueryElementType.TableSource: { var table = (SqlQuery.TableSource)element; return (Find(table.Source, find) ?? Find(table.Joins, find)); } case QueryElementType.JoinedTable: { var join = (SqlQuery.JoinedTable)element; return (Find(join.Table, find) ?? Find(join.Condition, find)); } case QueryElementType.ExprExprPredicate: { var p = (SqlQuery.Predicate.ExprExpr)element; return (Find(p.Expr1, find) ?? Find(p.Expr2, find)); } case QueryElementType.LikePredicate: { var p = (SqlQuery.Predicate.Like)element; return (Find(p.Expr1, find) ?? Find(p.Expr2, find) ?? Find(p.Escape, find)); } case QueryElementType.BetweenPredicate: { var p = (SqlQuery.Predicate.Between)element; return (Find(p.Expr1, find) ?? Find(p.Expr2, find) ?? Find(p.Expr3, find)); } case QueryElementType.InSubQueryPredicate: { var p = (SqlQuery.Predicate.InSubQuery)element; return (Find(p.Expr1, find) ?? Find(p.SubQuery, find)); } case QueryElementType.InListPredicate: { var p = (SqlQuery.Predicate.InList)element; return (Find(p.Expr1, find) ?? Find(p.Values, find)); } case QueryElementType.SetExpression: { var s = (SqlQuery.SetExpression)element; return (Find(s.Column, find) ?? Find(s.Expression, find)); } case QueryElementType.SetClause: { var sc = (SqlQuery.SetClause)element; return (Find(sc.Into, find) ?? Find(sc.Items, find)); } case QueryElementType.SelectClause: { var sc = (SqlQuery.SelectClause)element; return (Find(sc.TakeValue, find) ?? Find(sc.SkipValue, find) ?? Find(sc.Columns, find)); } case QueryElementType.SqlQuery: { var q = (SqlQuery)element; return (Find(q.Select, find) ?? (q.QueryType == QueryType.Update || q.QueryType == QueryType.Insert ? Find(q.Set, find) : null) ?? Find(q.From, find) ?? Find(q.Where, find) ?? Find(q.GroupBy, find) ?? Find(q.Having, find) ?? Find(q.OrderBy, find) ?? (q.HasUnion ? Find(q.Unions, find) : null)); } } return(null); }
public void setFindFunc(FindFunc f) { findFunc = f; }