Ejemplo n.º 1
0
            private async Task <IEnumerable <SyntaxNode> > CreateStatementsOrInitializerToInsertAtCallSiteAsync(CancellationToken cancellationToken)
            {
                var selectedNode = this.GetFirstStatementOrInitializerSelectedAtCallSite();

                // field initializer, constructor initializer, expression bodied member case
                if (selectedNode is ConstructorInitializerSyntax ||
                    selectedNode is FieldDeclarationSyntax ||
                    IsExpressionBodiedMember(selectedNode))
                {
                    var statement = await GetStatementOrInitializerContainingInvocationToExtractedMethodAsync(this.CallSiteAnnotation, cancellationToken).ConfigureAwait(false);

                    return(SpecializedCollections.SingletonEnumerable(statement));
                }

                // regular case
                var semanticModel = this.SemanticDocument.SemanticModel;
                var context       = this.InsertionPoint.GetContext();
                var postProcessor = new PostProcessor(semanticModel, context.SpanStart);
                var statements    = SpecializedCollections.EmptyEnumerable <StatementSyntax>();

                statements = AddSplitOrMoveDeclarationOutStatementsToCallSite(statements, cancellationToken);
                statements = postProcessor.MergeDeclarationStatements(statements);
                statements = AddAssignmentStatementToCallSite(statements, cancellationToken);
                statements = await AddInvocationAtCallSiteAsync(statements, cancellationToken).ConfigureAwait(false);

                statements = AddReturnIfUnreachable(statements, cancellationToken);

                return(statements);
            }
Ejemplo n.º 2
0
            private IEnumerable <StatementSyntax> SplitOrMoveDeclarationIntoMethodDefinition(
                IEnumerable <StatementSyntax> statements,
                CancellationToken cancellationToken)
            {
                var semanticModel = this.SemanticDocument.SemanticModel;
                var context       = this.InsertionPoint.GetContext();
                var postProcessor = new PostProcessor(semanticModel, context.SpanStart);

                var declStatements = CreateDeclarationStatements(AnalyzerResult.GetVariablesToSplitOrMoveIntoMethodDefinition(cancellationToken), cancellationToken);

                declStatements = postProcessor.MergeDeclarationStatements(declStatements);

                return(declStatements.Concat(statements));
            }