Example #1
0
        /// <summary>
        /// Returns the recursive list of expressions (whether binary, unary, or relational)
        /// within the current XML element. Returns NULL if there is a failure.
        /// </summary>
        public static IList <Expression> AllExpressonsAsXml(XElement xExpression)
        {
            IList <Expression> expressions = new List <Expression>();

            foreach (XElement xExpressionRelation in XmlHelper.Children(xExpression, "ExpressionRelational"))
            {
                ExpressionRelational expressionRelational = new ExpressionRelational();
                if (!expressionRelational.ReadAsXml(xExpressionRelation))
                {
                    return(null);
                }

                expressions.Add(expressionRelational);
            }

            foreach (XElement xExpressionBinary in XmlHelper.Children(xExpression, "ExpressionBinary"))
            {
                ExpressionBinary expressionBinary = new ExpressionBinary();
                if (!expressionBinary.ReadAsXml(xExpressionBinary))
                {
                    return(null);
                }

                expressions.Add(expressionBinary);
            }

            foreach (XElement xExpressionUnary in XmlHelper.Children(xExpression, "ExpressionUnary"))
            {
                ExpressionUnary expressionUnary = new ExpressionUnary();
                if (!expressionUnary.ReadAsXml(xExpressionUnary))
                {
                    return(null);
                }

                expressions.Add(expressionUnary);
            }

            return(expressions);
        }
        /// <summary>
        /// Parses and returns a relational expression.
        /// </summary>
        private static Expression ParseRelational(IList <string> expressionTokens, ref int index)
        {
            IList <Expression> operands = new List <Expression>();
            Expression         operand  = ParseOperand(expressionTokens, ref index);

            if (operand != null)
            {
                operands.Add(operand);
            }

            string relationalOperator = Token(expressionTokens, index, true);

            if (RelationalOperators.Contains(relationalOperator))
            {
                index++;
                operand = ParseOperand(expressionTokens, ref index);
                if (operand != null)
                {
                    operands.Add(operand);
                }
            }

            return(ExpressionRelational.Build(operands, relationalOperator));
        }