示例#1
0
 public void Visit(CaseBooleanStatement statement, CommonTree tree)
 {
     SetLine(statement, tree);
     Parent(tree).Children.Add(statement);
     VisitChildren(tree);
 }
        public void Visit(CaseBooleanStatement statement)
        {
            var domArg = new CodeDomArg();

            CodeMemberMethod method = new CodeMemberMethod();

            method.Name       = "Case_" + domArg.MethodIdentifier;
            method.Attributes = MemberAttributes.Private;
            method.ReturnType = new CodeTypeReference(typeof(object));
            GenerateCallStatement(method.Statements, statement.Line.Line);

            foreach (var childArg in statement.BooleanStatements)
            {
                domArg = VisitChild(childArg, new CodeDomArg()
                {
                    Scope = _codeStack.Peek().Scope
                });
                if (domArg.Tag != null)
                {
                    _codeStack.Peek().Tag = domArg.Tag;
                }

                method.Statements.AddRange(domArg.ParentStatements);
            }

            if (statement.ElseStatement == null)
            {
                method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
            }
            else
            {
                domArg = VisitChild(statement.ElseStatement, new CodeDomArg()
                {
                    Scope = _codeStack.Peek().Scope
                });
                if (domArg.Tag != null)
                {
                    _codeStack.Peek().Tag = domArg.Tag;
                }

                method.Statements.Add(new CodeMethodReturnStatement(domArg.CodeExpression));
            }

            _codeStack.Peek()
            .ParentStatements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("result"),
                                                                 "AddColumn",
                                                                 new CodePrimitiveExpression("(No column name)")));

            var methodcall = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(null, method.Name));
            var rowParam   = new CodeParameterDeclarationExpression(_codeStack.Peek().Scope.CodeDomReference.TypeArguments[0], "row");

            method.Parameters.Add(rowParam);
            methodcall.Parameters.Add(new CodeVariableReferenceExpression("row"));

            if (_codeStack.Peek().Tag != null) //pick statement
            {
                var htmlNodeParam = new CodeParameterDeclarationExpression(new CodeTypeReference("HtmlNode"), "node");
                methodcall.Parameters.Add(new CodeVariableReferenceExpression("node"));
                method.Parameters.Add(htmlNodeParam);
            }

            _mainType.Type.Members.Add(method);
            _codeStack.Peek().CodeExpression = methodcall;
        }