Exemplo n.º 1
0
        internal static QExprGroup CreateExprGroup(string groupOperator, CallInfo callInfo, object[] args)
        {
            if(callInfo != null
                && args != null
                && args.Length > 0
                && callInfo.ArgumentCount == args.Length)
            {
                int argsCount = args.Length;
                int namedArgsCount = callInfo.ArgumentNames.Count;

                QExpr[] qexprs = new QExpr[namedArgsCount];
                QExprGroup[] qgroups = new QExprGroup[argsCount - namedArgsCount];

                for (int i = 0; i < argsCount - namedArgsCount; i++)
                {
                    QExprGroup qgroup = args[i] as QExprGroup;
                    if (qgroup == null)
                        throw new Exception("An unnamed Q parameter must be of type QPredicate");

                    qgroups[i] = qgroup;
                }

                for (int i = 0; i < namedArgsCount; i++)
                {
                    string[] lhsAndOp = callInfo.ArgumentNames[i].Split(CUSTOM_QUERY_SYNTAX_SEP, StringSplitOptions.None);
                    if (lhsAndOp == null || lhsAndOp.Length == 0 || lhsAndOp.Length < 1)
                        throw new Exception("A Q parameter name must be composed of field name & operator name separated by '__' (double underscore)");

                    qexprs[i] = new QExpr(lhsAndOp[0],
                        lhsAndOp.Length >= 2 ? lhsAndOp[lhsAndOp.Length - 1] : Constants.QueryCompareOps.EXACT,
                        args[argsCount - namedArgsCount + i]);
                }

                QExprGroup exprGroup;

                if (groupOperator == Constants.QUERY_AND)
                    exprGroup = new AndExprGroup();
                else
                    exprGroup = new OrExprGroup();

                if (qgroups != null)
                    exprGroup.SubGroups.AddRange(qgroups);

                if (qexprs != null)
                    exprGroup.Expressions.AddRange(qexprs);

                return exprGroup;
            }

            return null;
        }
Exemplo n.º 2
0
        public static QExprGroup Combine(QExprGroup subGroup1, QExprGroup subGroup2, string groupOperator = Constants.QUERY_AND)
        {
            QExprGroup group;
            if (groupOperator == Constants.QUERY_AND)
                group = new AndExprGroup();
            else
                group = new OrExprGroup();

            if (subGroup1 != null)
                group.SubGroups.Add(subGroup1);

            if (subGroup2 != null)
                group.SubGroups.Add(subGroup2);

            return group;
        }