Ejemplo n.º 1
0
            protected override StatementSyntax CreateDeclarationStatement(
                VariableInfo variable,
                CancellationToken cancellationToken,
                ExpressionSyntax initialValue = null)
            {
                var type     = variable.GetVariableType(this.SemanticDocument);
                var typeNode = type.GenerateTypeSyntax();

                var equalsValueClause = initialValue == null ? null : SyntaxFactory.EqualsValueClause(value: initialValue);

                return(SyntaxFactory.LocalDeclarationStatement(
                           SyntaxFactory.VariableDeclaration(typeNode)
                           .AddVariables(SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(variable.Name)).WithInitializer(equalsValueClause))));
            }
Ejemplo n.º 2
0
            protected override StatementSyntax CreateDeclarationStatement(
                VariableInfo variable,
                ExpressionSyntax initialValue,
                CancellationToken cancellationToken)
            {
                // Convert to 'var' if appropriate.  Note: because we're extracting out
                // to a method, the initialValue will be a method-call.  Types are not
                // apperant with method calls (i.e. as opposed to a 'new XXX()' expression,
                // where the type is apperant).
                var type     = variable.GetVariableType(this.SemanticDocument);
                var typeNode = initialValue == null
                    ? type.GenerateTypeSyntax()
                    : type.GenerateTypeSyntaxOrVar(
                    this.SemanticDocument.Document.Project.Solution.Options,
                    typeIsApperant: false);

                var equalsValueClause = initialValue == null ? null : SyntaxFactory.EqualsValueClause(value: initialValue);

                return(SyntaxFactory.LocalDeclarationStatement(
                           SyntaxFactory.VariableDeclaration(typeNode)
                           .AddVariables(SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(variable.Name)).WithInitializer(equalsValueClause))));
            }