当前位置: 首页>>代码示例>>C#>>正文


C# CSharpSyntaxNode.GetLeadingTrivia方法代码示例

本文整理汇总了C#中CSharpSyntaxNode.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode.GetLeadingTrivia方法的具体用法?C# CSharpSyntaxNode.GetLeadingTrivia怎么用?C# CSharpSyntaxNode.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSharpSyntaxNode的用法示例。


在下文中一共展示了CSharpSyntaxNode.GetLeadingTrivia方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDocumentationCommentTriviaFromSyntaxNode

        internal static ImmutableArray<DocumentationCommentTriviaSyntax> GetDocumentationCommentTriviaFromSyntaxNode(CSharpSyntaxNode syntaxNode, DiagnosticBag diagnostics)
        {
            if (syntaxNode.SyntaxTree.Options.DocumentationMode < DocumentationMode.Parse)
            {
                return ImmutableArray<DocumentationCommentTriviaSyntax>.Empty;
            }

            // All declarators in a declaration get the same doc comment.
            // (As a consequence, the same duplicate diagnostics are produced for each declarator.)
            if (syntaxNode.Kind == SyntaxKind.VariableDeclarator)
            {
                CSharpSyntaxNode curr = syntaxNode;
                while ((object)curr != null)
                {
                    SyntaxKind kind = curr.Kind;
                    if (kind == SyntaxKind.FieldDeclaration || kind == SyntaxKind.EventFieldDeclaration)
                    {
                        break;
                    }

                    curr = curr.Parent;
                }

                if ((object)curr != null)
                {
                    syntaxNode = curr;
                }
            }

            ArrayBuilder<DocumentationCommentTriviaSyntax> builder = null;
            bool seenOtherTrivia = false;
            foreach (var trivia in syntaxNode.GetLeadingTrivia().Reverse())
            {
                switch (trivia.CSharpKind())
                {
                    case SyntaxKind.SingleLineDocumentationCommentTrivia:
                    case SyntaxKind.MultiLineDocumentationCommentTrivia:
                        {
                            if (seenOtherTrivia)
                            {
                                // In most cases, unprocessed doc comments are reported by UnprocessedDocumentationCommentFinder.
                                // However, in places where doc comments *are* allowed, it's easier to determine which will
                                // be unprocessed here.
                                var tree = (SyntaxTree)trivia.SyntaxTree;
                                if (tree.ReportDocumentationCommentDiagnostics())
                                {
                                    int start = trivia.Position; // FullSpan start to include /** or ///
                                    const int length = 1; //Match dev11: span is just one character
                                    diagnostics.Add(ErrorCode.WRN_UnprocessedXMLComment, new SourceLocation(tree, new TextSpan(start, length)));
                                }
                            }
                            else
                            {
                                if (builder == null)
                                {
                                    builder = ArrayBuilder<DocumentationCommentTriviaSyntax>.GetInstance();
                                }

                                builder.Add((DocumentationCommentTriviaSyntax)trivia.GetStructure());
                            }
                            break;
                        }
                    case SyntaxKind.WhitespaceTrivia:
                    case SyntaxKind.EndOfLineTrivia:
                        // These can legally appear between doc comments.
                        break;
                    default:
                        // For some reason, dev11 ignores trivia between the last doc comment and the
                        // symbol declaration.  (e.g. can have regular comment between doc comment and decl).
                        if (builder != null)
                        {
                            seenOtherTrivia = true;
                        }
                        break;
                }
            }

            if (builder == null)
            {
                return ImmutableArray<DocumentationCommentTriviaSyntax>.Empty;
            }

            builder.ReverseContents();
            return builder.ToImmutableAndFree();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:85,代码来源:SourceDocumentationCommentUtils.cs


注:本文中的CSharpSyntaxNode.GetLeadingTrivia方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。