コード例 #1
0
        private async Task <Document> RefactorAsync(
            Document document,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            ConstructorDeclarationSyntax constructor = Constructor;

            MemberDeclarationSyntax containingMember = constructor.GetParentMember();

            SyntaxList <MemberDeclarationSyntax> members = containingMember.GetMembers();

            SyntaxList <MemberDeclarationSyntax> newMembers = members.Replace(
                constructor,
                constructor.AddBodyStatements(CreateAssignments().ToArray()));

            newMembers = newMembers.InsertRange(
                GetDeclarationIndex(members),
                CreateDeclarations());

            SyntaxNode newRoot = root.ReplaceNode(
                containingMember,
                containingMember.SetMembers(newMembers));

            return(document.WithSyntaxRoot(newRoot));
        }