Example #1
0
        public override SyntaxList <StatementSyntax> VisitWithBlock(VBSyntax.WithBlockSyntax node)
        {
            var withExpression       = (ExpressionSyntax)node.WithStatement.Expression.Accept(_expressionVisitor);
            var generateVariableName = !_semanticModel.GetTypeInfo(node.WithStatement.Expression).Type.IsValueType;

            ExpressionSyntax       lhsExpression;
            List <StatementSyntax> prefixDeclarations = new List <StatementSyntax>();

            if (generateVariableName)
            {
                string uniqueVariableNameInScope = GetUniqueVariableNameInScope(node, "withBlock");
                lhsExpression =
                    SyntaxFactory.IdentifierName(uniqueVariableNameInScope);
                prefixDeclarations.Add(
                    CreateLocalVariableDeclarationAndAssignment(uniqueVariableNameInScope, withExpression));
            }
            else
            {
                lhsExpression = withExpression;
            }

            _withBlockLhs.Push(lhsExpression);
            try {
                var statements = node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor));

                IEnumerable <StatementSyntax> statementSyntaxs = prefixDeclarations.Concat(statements).ToArray();
                return(generateVariableName
                    ? SingleStatement(SyntaxFactory.Block(statementSyntaxs))
                    : SyntaxFactory.List(statementSyntaxs));
            } finally {
                _withBlockLhs.Pop();
            }
        }
            public override SyntaxList <StatementSyntax> VisitWithBlock(VBSyntax.WithBlockSyntax node)
            {
                var withExpression = (ExpressionSyntax)node.WithStatement.Expression.Accept(_nodesVisitor);

                _withBlockTempVariableNames.Push(GetUniqueVariableNameInScope(node, "withBlock"));
                try {
                    var declaration = CreateLocalVariableDeclarationAndAssignment(_withBlockTempVariableNames.Peek(), withExpression);
                    var statements  = node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor));

                    return(SingleStatement(SyntaxFactory.Block(new[] { declaration }.Concat(statements).ToArray())));
                } finally {
                    _withBlockTempVariableNames.Pop();
                }
            }
Example #3
0
            public override SyntaxList <StatementSyntax> VisitWithBlock(VBSyntax.WithBlockSyntax node)
            {
                var withExpression = (ExpressionSyntax)node.WithStatement.Expression.Accept(nodesVisitor);

                withBlockTempVariableNames.Push(GetUniqueVariableNameInScope(node, "withBlock"));
                try {
                    var variableDeclaratorSyntax = SyntaxFactory.VariableDeclarator(
                        SyntaxFactory.Identifier(withBlockTempVariableNames.Peek()), null,
                        SyntaxFactory.EqualsValueClause(withExpression));
                    var declaration = SyntaxFactory.LocalDeclarationStatement(SyntaxFactory.VariableDeclaration(
                                                                                  SyntaxFactory.IdentifierName("var"),
                                                                                  SyntaxFactory.SingletonSeparatedList(variableDeclaratorSyntax)));
                    var statements = node.Statements.SelectMany(s => s.Accept(this));

                    return(SingleStatement(SyntaxFactory.Block(new[] { declaration }.Concat(statements).ToArray())));
                } finally {
                    withBlockTempVariableNames.Pop();
                }
            }
Example #4
0
            public override SyntaxList <StatementSyntax> VisitWithBlock(VBSyntax.WithBlockSyntax node)
            {
                var name = SyntaxFactory.ParseName(node.WithStatement.Expression.ToString());

                var statements = new List <StatementSyntax>();

                foreach (var stmVB in node.Statements)
                {
                    var stmCS = stmVB.Accept(this);
                    foreach (ExpressionStatementSyntax item in stmCS)
                    {
                        InvocationExpressionSyntax    ioc = (InvocationExpressionSyntax)item.Expression;
                        MemberBindingExpressionSyntax mb  = (MemberBindingExpressionSyntax)ioc.Expression;

                        var mas = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, name, mb.Name);

                        var r = SyntaxFactory.InvocationExpression(mas, ioc.ArgumentList);
                        statements.Add(SyntaxFactory.ExpressionStatement(r));
                    }
                }

                return(SyntaxFactory.List <StatementSyntax>(statements));
            }
 public override SyntaxList <StatementSyntax> VisitWithBlock(VBSyntax.WithBlockSyntax node) => AddLocalVariables(node);
Example #6
0
 public override Task <SyntaxList <StatementSyntax> > VisitWithBlock(VBSyntax.WithBlockSyntax node) => AddLocalVariablesAsync(node);