コード例 #1
0
        internal static async Task <Document> AddNewDocumentationCommentsAsync(Document document, DocumentationCommentGeneratorSettings settings = null, bool skipNamespaceDeclaration = true, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var rewriter = new AddNewDocumentationCommentRewriter(settings, skipNamespaceDeclaration);

            SyntaxNode newRoot = rewriter.Visit(root);

            return(document.WithSyntaxRoot(newRoot));
        }
コード例 #2
0
        public static SyntaxTriviaList Generate(IndexerDeclarationSyntax indexerDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (indexerDeclaration == null)
            {
                throw new ArgumentNullException(nameof(indexerDeclaration));
            }

            return(Generate(
                       default(TypeParameterListSyntax),
                       indexerDeclaration.ParameterList,
                       generateReturns: true,
                       settings: settings));
        }
コード例 #3
0
        public static SyntaxTriviaList Generate(MemberDeclarationSyntax memberDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (memberDeclaration == null)
            {
                throw new ArgumentNullException(nameof(memberDeclaration));
            }

            switch (memberDeclaration.Kind())
            {
            case SyntaxKind.NamespaceDeclaration:
                return(Generate((NamespaceDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.ClassDeclaration:
                return(Generate((ClassDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.StructDeclaration:
                return(Generate((StructDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.InterfaceDeclaration:
                return(Generate((InterfaceDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.EnumDeclaration:
                return(Generate((EnumDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.DelegateDeclaration:
                return(Generate((DelegateDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.EnumMemberDeclaration:
                return(Generate((EnumMemberDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.FieldDeclaration:
                return(Generate((FieldDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.EventFieldDeclaration:
                return(Generate((EventFieldDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.MethodDeclaration:
                return(Generate((MethodDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.OperatorDeclaration:
                return(Generate((OperatorDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.ConversionOperatorDeclaration:
                return(Generate((ConversionOperatorDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.ConstructorDeclaration:
                return(Generate((ConstructorDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.DestructorDeclaration:
                return(Generate((DestructorDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.PropertyDeclaration:
                return(Generate((PropertyDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.EventDeclaration:
                return(Generate((EventDeclarationSyntax)memberDeclaration, settings));

            case SyntaxKind.IndexerDeclaration:
                return(Generate((IndexerDeclarationSyntax)memberDeclaration, settings));

            default:
                throw new ArgumentException("", nameof(memberDeclaration));
            }
        }
コード例 #4
0
        public static SyntaxTriviaList Generate(ConversionOperatorDeclarationSyntax conversionOperatorDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (conversionOperatorDeclaration == null)
            {
                throw new ArgumentNullException(nameof(conversionOperatorDeclaration));
            }

            return(Generate(
                       default(TypeParameterListSyntax),
                       conversionOperatorDeclaration.ParameterList,
                       generateReturns: false,
                       settings: settings));
        }
コード例 #5
0
        public static SyntaxTriviaList Generate(EventDeclarationSyntax eventDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (eventDeclaration == null)
            {
                throw new ArgumentNullException(nameof(eventDeclaration));
            }

            return(Generate(settings: settings));
        }
コード例 #6
0
        public static SyntaxTriviaList Generate(MethodDeclarationSyntax methodDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (methodDeclaration == null)
            {
                throw new ArgumentNullException(nameof(methodDeclaration));
            }

            return(Generate(
                       methodDeclaration.TypeParameterList,
                       methodDeclaration.ParameterList,
                       generateReturns: !methodDeclaration.ReturnsVoid(),
                       settings: settings));
        }
コード例 #7
0
        public static SyntaxTriviaList Generate(DelegateDeclarationSyntax delegateDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (delegateDeclaration == null)
            {
                throw new ArgumentNullException(nameof(delegateDeclaration));
            }

            return(Generate(
                       delegateDeclaration.TypeParameterList,
                       delegateDeclaration.ParameterList,
                       generateReturns: false,
                       settings: settings));
        }
コード例 #8
0
        public static SyntaxTriviaList Generate(InterfaceDeclarationSyntax interfaceDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (interfaceDeclaration == null)
            {
                throw new ArgumentNullException(nameof(interfaceDeclaration));
            }

            return(Generate(
                       interfaceDeclaration.TypeParameterList,
                       default(ParameterListSyntax),
                       generateReturns: false,
                       settings: settings));
        }
コード例 #9
0
        public static MemberDeclarationSyntax GenerateAndAttach(MemberDeclarationSyntax memberDeclaration, DocumentationCommentGeneratorSettings settings = null)
        {
            if (memberDeclaration == null)
            {
                throw new ArgumentNullException(nameof(memberDeclaration));
            }

            SyntaxTriviaList leadingTrivia = memberDeclaration.GetLeadingTrivia();

            int index = 0;

            string indent = "";

            if (leadingTrivia.Any())
            {
                index = leadingTrivia.Count - 1;

                for (int i = leadingTrivia.Count - 1; i >= 0; i--)
                {
                    if (leadingTrivia[i].IsWhitespaceTrivia())
                    {
                        index = i;
                    }
                    else
                    {
                        break;
                    }
                }

                indent = string.Concat(leadingTrivia.Skip(index));
            }

            settings = settings ?? DocumentationCommentGeneratorSettings.Default;

            settings = settings.WithIndent(indent);

            SyntaxTriviaList comment = Generate(memberDeclaration, settings);

            SyntaxTriviaList newLeadingTrivia = leadingTrivia.InsertRange(index, comment);

            return(memberDeclaration.WithLeadingTrivia(newLeadingTrivia));
        }
コード例 #10
0
        public static async Task <Document> GenerateAndAttachAsync(Document document, DocumentationCommentGeneratorSettings settings = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            SyntaxNode newRoot = GenerateDocumentationCommentSyntaxRewriter.GenerateAndAttach(root, settings);

            return(document.WithSyntaxRoot(newRoot));
        }