本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.DescendantTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.DescendantTrivia方法的具体用法?C# SyntaxNode.DescendantTrivia怎么用?C# SyntaxNode.DescendantTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.DescendantTrivia方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLastDocumentationCommentExteriorTrivia
private static SyntaxTrivia GetLastDocumentationCommentExteriorTrivia(SyntaxNode node)
{
return node
.DescendantTrivia(descendIntoTrivia: true)
.Where(trivia => trivia.IsKind(SyntaxKind.DocumentationCommentExteriorTrivia))
.LastOrDefault();
}
示例2: RemoveImproperDocumentationTrivia
private static SyntaxNode RemoveImproperDocumentationTrivia(SyntaxNode node)
{
IEnumerable<SyntaxTrivia> commentTrivia = from t in node.DescendantTrivia()
where t.Kind() == SyntaxKind.DocumentationCommentTrivia
select t;
SyntaxNode newRoot = node.ReplaceTrivia(commentTrivia, (t1, t2) => default(SyntaxTrivia));
return newRoot;
}
示例3: GetUncomment
private string GetUncomment(SyntaxNode root)
{
var comment =
from c in root.DescendantTrivia()
where c.Kind() == SyntaxKind.MultiLineCommentTrivia
where c.ToString().StartsWith(uncommentPrefix)
select GetUncommentBody(c);
return comment.FirstOrDefault();
}
示例4: HasImplementation
private static bool HasImplementation(SyntaxNode syntaxRoot)
{
bool hasImplementation = true;
foreach (var trivia in syntaxRoot.DescendantTrivia())
{
if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
{
if (trivia.ToFullString().Contains("TODO: Implement analysis"))
{
hasImplementation = false;
}
}
}
return hasImplementation;
}
示例5: LocateExcludedSpans
private static bool LocateExcludedSpans(SyntaxNode root, out ImmutableArray<TextSpan> excludedSpans)
{
ImmutableArray<TextSpan>.Builder builder = ImmutableArray.CreateBuilder<TextSpan>();
// Locate disabled text
foreach (var trivia in root.DescendantTrivia(descendIntoTrivia: true))
{
if (trivia.IsKind(SyntaxKind.DisabledTextTrivia))
{
builder.Add(trivia.Span);
}
else if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
{
if (trivia.ToString().StartsWith("////"))
{
// Exclude comments starting with //// because they could contain commented code which contains
// string or character literals, and we don't want to change the contents of those strings.
builder.Add(trivia.Span);
}
}
}
// Locate string literals
foreach (var token in root.DescendantTokens(descendIntoTrivia: true))
{
switch (token.Kind())
{
case SyntaxKind.XmlTextLiteralToken:
if (token.Parent.IsKind(SyntaxKind.XmlCDataSection))
{
builder.Add(token.Span);
}
break;
case SyntaxKind.CharacterLiteralToken:
case SyntaxKind.StringLiteralToken:
case SyntaxKind.InterpolatedStringTextToken:
builder.Add(token.Span);
break;
default:
break;
}
}
// Sort the results
builder.Sort();
// Combine adjacent and overlapping spans
ReduceTextSpans(builder);
excludedSpans = builder.ToImmutable();
return true;
}