本文整理汇总了C#中SyntaxNode.DescendantTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.DescendantTokens方法的具体用法?C# SyntaxNode.DescendantTokens怎么用?C# SyntaxNode.DescendantTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.DescendantTokens方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintAllTokens
/// <summary>
/// Print all the tokens.
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private string PrintAllTokens(SyntaxNode node)
{
var tokens = node.DescendantTokens();
var sb = new StringBuilder();
foreach (var token in tokens)
{
sb.AppendLine(token.Kind.ToString()+ " " + token.GetText());
}
return sb.ToString();
}
示例2: AreEquivalentIgnoringLambdaBodies
/// <summary>
/// Compares content of two nodes ignoring lambda bodies and trivia.
/// </summary>
public static bool AreEquivalentIgnoringLambdaBodies(SyntaxNode oldNode, SyntaxNode newNode)
{
// all tokens that don't belong to a lambda body:
var oldTokens = oldNode.DescendantTokens(node => node == oldNode || !IsLambdaBodyStatementOrExpression(node));
var newTokens = newNode.DescendantTokens(node => node == newNode || !IsLambdaBodyStatementOrExpression(node));
return oldTokens.SequenceEqual(newTokens, SyntaxFactory.AreEquivalent);
}
示例3: GetIdentifierOrGlobalNamespaceTokensWithText
private static ImmutableArray<SyntaxToken> GetIdentifierOrGlobalNamespaceTokensWithText(
ISyntaxFactsService syntaxFacts, Document document, VersionStamp version, SyntaxNode root, SourceText sourceText,
string text, CancellationToken cancellationToken)
{
Func<SyntaxToken, bool> candidate = t =>
syntaxFacts.IsGlobalNamespaceKeyword(t) || (syntaxFacts.IsIdentifier(t) && syntaxFacts.TextMatch(t.ValueText, text));
// identifier is not escaped
if (sourceText != null)
{
return GetTokensFromText(syntaxFacts, document, version, root, sourceText, text, candidate, cancellationToken);
}
// identifier is escaped
return root.DescendantTokens(descendIntoTrivia: true).Where(candidate).ToImmutableArray();
}
示例4: GetFlattenedNodeText
private string GetFlattenedNodeText(SyntaxNode node)
{
const int cutoff = 30;
var lastEnd = node.Span.Start;
var sb = new StringBuilder();
foreach (var token in node.DescendantTokens(descendIntoTrivia: false))
{
if (token.Span.Start - lastEnd > 0)
{
sb.Append(" ");
}
sb.Append(token.ToString());
lastEnd = token.Span.End;
if (sb.Length > cutoff)
{
break;
}
}
return sb.ToString() + (sb.Length > cutoff ? " ..." : string.Empty);
}