예제 #1
0
        private async Task <Document> ParseDocsForInterfaceDefinition(Document document, InterfaceDeclarationSyntax interfaceDefinition, CancellationToken cancellationToken)
        {
            var firstToken    = interfaceDefinition.GetFirstToken();
            var leadingTrivia = firstToken.LeadingTrivia;
            var trimmedLocal  = interfaceDefinition.ReplaceToken(
                firstToken, firstToken.WithLeadingTrivia(SyntaxTriviaList.Empty));

            MemberDeclarationSyntax newMemberNode     = null;
            MemberDeclarationSyntax currentMemberNode = null;

            if (interfaceDefinition != null && interfaceDefinition.Members != null)
            {
                foreach (var methodDefinition in interfaceDefinition.Members)
                {
                    if (!methodDefinition.GetLeadingTrivia().AnyDocumentationTrivia())
                    {
                        currentMemberNode = methodDefinition;
                        newMemberNode     = methodDefinition.WithLeadingTrivia(SyntaxTokenExtension.CreateCommentTrivia(interfaceDefinitionDocMessage));
                        break;
                    }
                }
            }

            var formattedLocal = newMemberNode.WithAdditionalAnnotations(Formatter.Annotation);

            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var newRoot = root.ReplaceNode(currentMemberNode, formattedLocal);

            return(document.WithSyntaxRoot(newRoot));
        }
        private async Task <Document> ParseDocsForInterfaceDefinition(Document document, InterfaceDeclarationSyntax interfaceDefinition, CancellationToken cancellationToken)
        {
            var firstToken    = interfaceDefinition.GetFirstToken();
            var leadingTrivia = firstToken.LeadingTrivia;
            var trimmedLocal  = interfaceDefinition.ReplaceToken(
                firstToken, firstToken.WithLeadingTrivia(SyntaxTriviaList.Empty));

            var newLocal = trimmedLocal.WithLeadingTrivia(SyntaxTokenExtension.CreateCommentTrivia(interfaceDefinitionDocMessage));

            var formattedLocal = newLocal.WithAdditionalAnnotations(Formatter.Annotation);

            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var newRoot = root.ReplaceNode(interfaceDefinition, formattedLocal);

            // Return document with transformed tree.
            return(document.WithSyntaxRoot(newRoot));
        }