本文整理汇总了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();
}