private static ConditionalExpression ReadIf(XmlExpressionReader reader, Expression ifFalse)
        {
            var        childs = reader.ReadChildExpressions(0, 2);
            Expression test, ifTrue;

            if (childs == null || childs.Length == 0)
            {
                throw new MissingNodeException(Resource1.Read_NotTestValueNode, reader.Node, null);
            }
            if (childs.Length == 1)
            {
                throw new ExpressionReadException(Resource1.Read_NotBodyNode, reader.Node);
            }
            test   = childs[0];
            ifTrue = childs[1];

            var elseIfNodes = reader.Node.SelectNodes("x:elseIf", reader.nsmgr);

            for (int i = elseIfNodes.Count - 1; i >= 0; i--)
            {
                var child = elseIfNodes[i];
                reader.ReadStartExpression(child);
                ifFalse = ReadIf(reader, ifFalse);
                reader.ReadEndExpression();
            }

            if (childs.Length == 1)
            {
                return(If(test, null, ifFalse));
            }

            return(If(test, ifTrue, ifFalse));
        }
 private static ParameterExpression[] ReadDefineVariables(XmlExpressionReader reader)
 {
     return(FilterChildNodeTypes(reader.Node).Select(o =>
     {
         reader.ReadStartExpression(o);
         var expr = ReadDefineVariable(reader);
         reader.ReadEndExpression();
         return expr;
     }).ToArray());
 }
        private static Expression ReadIf(XmlExpressionReader reader)
        {
            Expression ifFalse = null;

            var elseNode = reader.Node.SelectSingleNode("x:else", reader.nsmgr);

            if (elseNode != null)
            {
                var child = FilterChildNodeTypes(elseNode).FirstOrDefault();
                if (child != null)
                {
                    reader.ReadStartExpression(child);
                    ifFalse = reader.ReadExpression();
                    reader.ReadEndExpression();
                }
            }

            return(ReadIf(reader, ifFalse));
        }
        private static Expression ReadSwitch(XmlExpressionReader reader)
        {
            var childs = reader.FilterChildNodeTypes();
            var first  = childs.FirstOrDefault();

            if (first == null)
            {
                throw new MissingNodeException(Resource1.Read_NotTestValueNode, reader.Node, null);
            }
            Expression testValue;

            Expression defaultBody = null;

            reader.ReadStartExpression(first);
            testValue = reader.ReadExpression();
            reader.ReadEndExpression();

            List <SwitchCase> cases = new List <SwitchCase>();

            foreach (XmlNode child in childs.Skip(1))
            {
                if (child.LocalName == "case")
                {
                    reader.ReadStartExpression(child);
                    var exprs = reader.ReadChildExpressions();

                    if (exprs == null || exprs.Length == 0)
                    {
                        throw new MissingNodeException(Resource1.Read_NotTestValueNode, child, null);
                    }
                    if (exprs.Length < 2)
                    {
                        throw new NotBodyNodeException(child);
                    }

                    var        testValues = exprs.Take(exprs.Length - 1);
                    var        body       = exprs.Last();
                    SwitchCase sc         = new SwitchCase(testValues, body);
                    cases.Add(sc);

                    reader.ReadEndExpression();
                }
                else if (child.LocalName == "default")
                {
                    reader.ReadStartExpression(child);
                    var exprs = reader.ReadChildExpressions();
                    if (exprs == null || exprs.Length == 0)
                    {
                        throw new NotBodyNodeException(child);
                    }
                    if (defaultBody != null)
                    {
                        throw new DuplicateNodeException(child);
                    }
                    defaultBody = exprs.First();
                    reader.ReadEndExpression();
                }
            }

            return(Switch(testValue, defaultBody, cases));
        }