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


C# SyntaxNode.AncestorsAndSelf方法代码示例

本文整理汇总了C#中SyntaxNode.AncestorsAndSelf方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.AncestorsAndSelf方法的具体用法?C# SyntaxNode.AncestorsAndSelf怎么用?C# SyntaxNode.AncestorsAndSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxNode的用法示例。


在下文中一共展示了SyntaxNode.AncestorsAndSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOutsideTypeQualifiedName

        private string GetOutsideTypeQualifiedName(SyntaxNode node)
        {
            // Get the name space name enclosing this node.
            string namespaceName = node.AncestorsAndSelf().
                // ancestors whose kind is name space node.
                Where(n => n.Kind == SyntaxKind.NamespaceDeclaration).
                // conver to the syntax and get the name.
                Select(n => (NamespaceDeclarationSyntax)n).First().Name.PlainName;

            // Get the class name enclosing this node.
            var classesNames = node.AncestorsAndSelf().
                // ancestors whose kind is class node.
                Where(n => n.Kind == SyntaxKind.ClassDeclaration).
                // convert each one to the kind class node syntax.
                Select(n => (ClassDeclarationSyntax)n).
                // order all the class decs by their length, in decending order.
                OrderByDescending(n => n.Span.Length).
                // select their names.
                Select(n => n.Identifier.ValueText);

            // Combine all the names to get the scope string.
            var qualifiedName = namespaceName + "." + StringUtil.ConcatenateAll(".", classesNames);
            logger.Info(qualifiedName);
            return qualifiedName;
        }
开发者ID:nkcsgexi,项目名称:ghostfactor1,代码行数:25,代码来源:QualifiedNameAnalyzer.cs

示例2: TryGetStatementEnclosingInvocation

 /// <summary>
 /// Try to get the statement syntax node that is enclosing the given method invocation.
 /// </summary>
 /// <param name="invocation"></param>
 /// <param name="statement"></param>
 /// <returns></returns>
 private bool TryGetStatementEnclosingInvocation(SyntaxNode invocation, out SyntaxNode statement)
 {
     var statements = invocation.AncestorsAndSelf().OfType<StatementSyntax>().ToList();
     if(statements.Any())
     {
         statement = statements.First();
         return true;
     }
     statement = null;
     return false;
 }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:17,代码来源:InMethodInlineDetector.cs


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