コード例 #1
0
            protected override async Task <GeneratedCode> CreateGeneratedCodeAsync(OperationStatus status, SemanticDocument newDocument, CancellationToken cancellationToken)
            {
                if (status.Succeeded())
                {
                    // in hybrid code cases such as extract method, formatter will have some difficulties on where it breaks lines in two.
                    // here, we explicitly insert newline at the end of "{" of auto generated method decl so that anchor knows how to find out
                    // indentation of inserted statements (from users code) with user code style preserved
                    var root             = newDocument.Root;
                    var methodDefinition = root.GetAnnotatedNodes <MethodDeclarationSyntax>(this.MethodDefinitionAnnotation).First();

                    var newMethodDefinition = TweakNewLinesInMethod(methodDefinition);

                    newDocument = await newDocument.WithSyntaxRootAsync(
                        root.ReplaceNode(methodDefinition, newMethodDefinition), cancellationToken).ConfigureAwait(false);
                }

                return(await base.CreateGeneratedCodeAsync(status, newDocument, cancellationToken).ConfigureAwait(false));
            }