本文整理汇总了C#中SyntaxNode.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.DescendantNodes方法的具体用法?C# SyntaxNode.DescendantNodes怎么用?C# SyntaxNode.DescendantNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.DescendantNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public override Token Get(SyntaxNode node)
{
var valueText = node
.DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Last()
.Identifier.ValueText;
if (valueText == null)
{
throw new NotImplementedException();
}
var args = node.ChildNodes().OfType<ArgumentListSyntax>().First()
.ChildNodes().OfType<ArgumentSyntax>().ToArray();
var whenClause = args[0].ChildNodes().First();
var block = args[1]
.ChildNodes().OfType<ParenthesizedLambdaExpressionSyntax>().First()
.ChildNodes().OfType<BlockSyntax>().First();
var details = new WhenClosureDetails(whenClause, block);
return new Token("WhenClosure", details);
}
示例2: GetAllInvocationsInMethod
/* Get all the invocations of callee in the body of caller method. */
public static IEnumerable<InvocationExpressionSyntax> GetAllInvocationsInMethod(SyntaxNode caller, SyntaxNode callee, SyntaxTree tree)
{
// Create semantic model of the given tree.
SemanticModel model = CreateSemanticModel(tree);
// Get the entry of callee in the symble table.
Symbol calleeSymbol = model.GetDeclaredSymbol((MethodDeclarationSyntax)callee);
// Get all the invocations in the caller.
var allInvocations = caller.DescendantNodes().
Where(n => n.Kind == SyntaxKind.InvocationExpression).
Select(n => (InvocationExpressionSyntax) n);
// Among all the invocations, select the ones that are calling the callee symbol.
return allInvocations.Where(i => model.GetSymbolInfo(i).Symbol == calleeSymbol);
}
示例3: Get
public override Token Get(SyntaxNode node)
{
var valueText = node
.DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Last()
.Identifier.ValueText;
if (valueText == null)
{
throw new NotImplementedException();
}
valueText = Regex.Replace(valueText, "([a-z])([A-Z])", "$1 $2");
return new Token("RuleFor", valueText);
}
示例4: IsEmptyFinalizer
protected override bool IsEmptyFinalizer(SyntaxNode node, SemanticModel model)
{
foreach (var exp in node.DescendantNodes().OfType<StatementSyntax>().Where(n => !n.IsKind(SyntaxKind.Block) && !n.IsKind(SyntaxKind.EmptyStatement)))
{
// NOTE: FxCop only checks if there is any method call within a given destructor to decide an empty finalizer.
// Here in order to minimize false negatives, we conservatively treat it as non-empty finalizer if its body contains any statements.
// But, still conditional methods like Debug.Fail() will be considered as being empty as FxCop currently does.
var method = exp as ExpressionStatementSyntax;
if (method != null && HasConditionalAttribute(method.Expression, model))
{
continue;
}
return false;
}
return true;
}
示例5: GetStatementsInNode
public static IEnumerable<SyntaxNode> GetStatementsInNode(SyntaxNode block)
{
return block.DescendantNodes().Where(n => n is StatementSyntax);
}
示例6: GetMethodsDeclarations
/* Get all the method declarations contained in a root node. */
public static IEnumerable<SyntaxNode> GetMethodsDeclarations(SyntaxNode root)
{
// Do not need to parse into the method.
return root.DescendantNodes(n => n.Kind != SyntaxKind.MethodDeclaration).
Where(n => n.Kind == SyntaxKind.MethodDeclaration);
}
示例7: GetDescendants
protected internal sealed override IEnumerable<SyntaxNode> GetDescendants(SyntaxNode node)
{
if (node == _oldRoot || node == _newRoot)
{
Debug.Assert(_oldRoot != null && _newRoot != null);
var rootChild = (node == _oldRoot) ? _oldRootChild : _newRootChild;
if (HasLabel(rootChild))
{
yield return rootChild;
}
node = rootChild;
}
// TODO: avoid allocation of closure
foreach (var descendant in node.DescendantNodes(descendIntoChildren: c => !IsLeaf(c) && (c == node || !LambdaUtilities.IsLambdaBodyStatementOrExpression(c))))
{
if (!LambdaUtilities.IsLambdaBodyStatementOrExpression(descendant) && HasLabel(descendant))
{
yield return descendant;
}
}
}
示例8: IsIteratorMethod
public static bool IsIteratorMethod(SyntaxNode declaration)
{
// lambdas and expression-bodied methods can't be iterators:
if (!declaration.IsKind(SyntaxKind.MethodDeclaration))
{
return false;
}
// enumerate statements:
return declaration.DescendantNodes(n => !(n is ExpressionSyntax))
.Any(n => n.IsKind(SyntaxKind.YieldBreakStatement) || n.IsKind(SyntaxKind.YieldReturnStatement));
}
示例9: GetNodes
protected override IEnumerable<SyntaxNode> GetNodes(SyntaxNode root)
{
return root.DescendantNodes().OfType<TypeDeclarationSyntax>();
}
示例10: GetInClassMethods
private IEnumerable<SyntaxNode> GetInClassMethods(SyntaxNode root)
{
// Get the decendent whose type is method declaration, to do this, we do not need to
// parse into the method.
return root.DescendantNodes(n => n.Kind != SyntaxKind.MethodDeclaration).Where(
n => n.Kind == SyntaxKind.MethodDeclaration);
}
示例11: GetDecendantOfKind
private IEnumerable<SyntaxNode> GetDecendantOfKind(SyntaxNode parent, SyntaxKind kind)
{
return parent.DescendantNodes().Where(n => n.Kind == kind);
}
示例12: GetReturnedIdentifiers
private IEnumerable<string> GetReturnedIdentifiers(SyntaxNode method)
{
var returnStatements = method.DescendantNodes().OfType<ReturnStatementSyntax>();
return returnStatements.Select(s => s.Expression.GetText());
}
示例13: GetNodeInStructuredTrivia
private SyntaxNode GetNodeInStructuredTrivia(SyntaxNode parent)
{
// Syntax references to nonterminals in structured trivia should be uncommon.
// Provide more efficient implementation if that is not true
var descendantsIntersectingSpan = parent.DescendantNodes(this.textSpan, descendIntoTrivia: true);
return descendantsIntersectingSpan.First((node) => node.IsKind(this.kind) && node.Span == this.textSpan);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:CSharpSyntaxTreeFactoryService.PositionalSyntaxReference.cs
示例14: ComputeNewRootNode
#pragma warning restore 0414
// ReSharper restore InconsistentNaming
protected override SyntaxNode ComputeNewRootNode(SyntaxNode rootNode)
{
var namespaceDeclarations = rootNode.DescendantNodes().OfType<NamespaceDeclarationSyntax>();
return rootNode.ReplaceNodes(namespaceDeclarations, (n1, n2) => ComputeNewNamespaceDeclarationNode(n1));
}
示例15: GetBlockOfMethod
public static SyntaxNode GetBlockOfMethod(SyntaxNode method)
{
return method.DescendantNodes().FirstOrDefault(n => n.Kind == SyntaxKind.Block);
}