当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxNode.DescendantNodes方法代码示例

本文整理汇总了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);
        }
开发者ID:jonrad,项目名称:FluentValidationDocumenter,代码行数:26,代码来源:WhenClosureTokenizer.cs

示例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);
        }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:17,代码来源:ASTUtil.cs

示例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);
        }
开发者ID:jonrad,项目名称:FluentValidationDocumenter,代码行数:16,代码来源:RuleForTokenizer.cs

示例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;
            }
开发者ID:riversky,项目名称:roslyn,代码行数:19,代码来源:CSharpCA1821DiagnosticAnalyzer.cs

示例5: GetStatementsInNode

 public static IEnumerable<SyntaxNode> GetStatementsInNode(SyntaxNode block)
 {
     return block.DescendantNodes().Where(n => n is StatementSyntax);
 }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:4,代码来源:ASTUtil.cs

示例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);
 }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:7,代码来源:ASTUtil.cs

示例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;
                }
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:25,代码来源:StatementSyntaxComparer.cs

示例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));
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:SyntaxUtilities.cs

示例9: GetNodes

 protected override IEnumerable<SyntaxNode> GetNodes(SyntaxNode root)
 {
     return root.DescendantNodes().OfType<TypeDeclarationSyntax>();
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:4,代码来源:CA1052CSharpDiagnosticProvider.cs

示例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);
 }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:7,代码来源:SimpleExtractMethodDetector.cs

示例11: GetDecendantOfKind

 private IEnumerable<SyntaxNode> GetDecendantOfKind(SyntaxNode parent, SyntaxKind kind)
 {
     return parent.DescendantNodes().Where(n => n.Kind == kind);
 }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:4,代码来源:DocumentAnalyzer.cs

示例12: GetReturnedIdentifiers

 private IEnumerable<string> GetReturnedIdentifiers(SyntaxNode method)
 {
     var returnStatements = method.DescendantNodes().OfType<ReturnStatementSyntax>();
     return returnStatements.Select(s => s.Expression.GetText());
 }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:5,代码来源:ReturnTypeChecker.cs

示例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));
    }
开发者ID:cdycdr,项目名称:RoslynGenerators,代码行数:8,代码来源:AsyncGenerator.cs

示例15: GetBlockOfMethod

 public static SyntaxNode GetBlockOfMethod(SyntaxNode method)
 {
     return method.DescendantNodes().FirstOrDefault(n => n.Kind == SyntaxKind.Block);
 }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:4,代码来源:ASTUtil.cs


注:本文中的SyntaxNode.DescendantNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。