Navigate through query conditions

Sometimes you need to run through all conditions in your query to perform some operation for each condition or to find a particular one. Here is a code snippet which demonstrates this operation:

private void ScanConditionGroup(Predicate predicate, Action<SimpleCondition> condAction) 
{
    foreach (Condition cond in predicate.Conditions) {

        if (cond is SimpleCondition) {
            condAction?.Invoke(cond as SimpleCondition);
	    }
        else if (cond is Predicate) {
            ScanConditionGroup((Predicate)cond, condAction);
        }
    }
}

//to start the process just call this function for the Root condition in your query and pass the action which performs some operations over one condition:

ScanConditionGroup(query1.Root, scond => {
    var attrExpr = (EntityAttrExpr)scond.BaseExpr;

    //here is the attribute of this condition
    var attr = attrExpr.Attribute;

    //here is condition operator
    var op = scond.Operator;

    //now we run through all expressions in this condition (except the first one) and check their values
    foreach (var expr in scond.Expressions) {
	    string value = expr.Value;
	    string text = expr.Text;
    }
});