本文整理汇总了C#中SyntaxNode.DescendantNodesAndSelf方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.DescendantNodesAndSelf方法的具体用法?C# SyntaxNode.DescendantNodesAndSelf怎么用?C# SyntaxNode.DescendantNodesAndSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.DescendantNodesAndSelf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessNode
private List<Diagnostic> ProcessNode(Document document, SemanticModel model, SyntaxNode node, List<Diagnostic> result, CancellationToken cancellationToken)
{
Diagnostic diagnostic;
Func<SyntaxNode, bool> descendIntoChildren = n =>
{
if (!IsRegularCandidate(n) ||
!TrySimplifyTypeNameExpression(document, model, n, out diagnostic, cancellationToken))
{
return true;
}
result = result ?? new List<Diagnostic>();
result.Add(diagnostic);
return false;
};
// find regular node first - search from top to down. once found one, don't get into its children
foreach (var candidate in node.DescendantNodesAndSelf(descendIntoChildren))
{
cancellationToken.ThrowIfCancellationRequested();
}
// now search structure trivia
foreach (var candidate in node.DescendantNodesAndSelf(descendIntoChildren: n => !IsCrefCandidate(n), descendIntoTrivia: true))
{
cancellationToken.ThrowIfCancellationRequested();
if (IsCrefCandidate(candidate) &&
TrySimplifyTypeNameExpression(document, model, candidate, out diagnostic, cancellationToken))
{
result = result ?? new List<Diagnostic>();
result.Add(diagnostic);
}
}
return result;
}
示例2: GetAllStatements
private static IEnumerable<StatementSyntax> GetAllStatements(SyntaxNode node)
{
return node.DescendantNodesAndSelf().OfType<StatementSyntax>();
}
示例3: GetAllExpressions
private static IEnumerable<ExpressionSyntax> GetAllExpressions(SyntaxNode node)
{
return node.DescendantNodesAndSelf(descendIntoTrivia: true).OfType<ExpressionSyntax>();
}
示例4: GetAwaitExpressions
public static ImmutableArray<SyntaxNode> GetAwaitExpressions(SyntaxNode body)
{
// skip lambda bodies:
return ImmutableArray.CreateRange(body.DescendantNodesAndSelf(LambdaUtilities.IsNotLambda).Where(n => n.IsKind(SyntaxKind.AwaitExpression)));
}