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


C# SyntaxNode.GetAncestor方法代码示例

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


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

示例1: IsInConstructor

 public bool IsInConstructor(SyntaxNode node)
 {
     return node.GetAncestor<ConstructorDeclarationSyntax>() != null;
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:4,代码来源:CSharpSyntaxFactsService.cs

示例2: GetMemberBodySpanForSpeculativeBinding

 public TextSpan GetMemberBodySpanForSpeculativeBinding(SyntaxNode node)
 {
     var parent = node.GetAncestor<DocumentationCommentTriviaSyntax>();
     Assert.Null(parent);
     return default(TextSpan);
 }
开发者ID:gustavoasoares,项目名称:roslyn,代码行数:6,代码来源:CrefCompletionProviderTests.cs

示例3: GetDisplayName

        public string GetDisplayName(SyntaxNode node, DisplayNameOptions options, string rootNamespace = null)
        {
            if (node == null)
            {
                return string.Empty;
            }

            var pooled = PooledStringBuilder.GetInstance();
            var builder = pooled.Builder;

            // return type
            var memberDeclaration = node as MemberDeclarationSyntax;
            if ((options & DisplayNameOptions.IncludeType) != 0)
            {
                var type = memberDeclaration.GetMemberType();
                if (type != null && !type.IsMissing)
                {
                    builder.Append(type);
                    builder.Append(' ');
                }
            }

            var names = ArrayBuilder<string>.GetInstance();
            // containing type(s)
            var parent = node.GetAncestor<TypeDeclarationSyntax>() ?? node.Parent;
            while (parent is TypeDeclarationSyntax)
            {
                names.Push(GetName(parent, options));
                parent = parent.Parent;
            }
            // containing namespace(s) in source (if any)
            if ((options & DisplayNameOptions.IncludeNamespaces) != 0)
            {
                while (parent != null && parent.Kind() == SyntaxKind.NamespaceDeclaration)
                {
                    names.Add(GetName(parent, options));
                    parent = parent.Parent;
                }
            }
            while (!names.IsEmpty())
            {
                var name = names.Pop();
                if (name != null)
                {
                    builder.Append(name);
                    builder.Append(dotToken);
                }
            }

            // name (including generic type parameters)
            builder.Append(GetName(node, options));

            // parameter list (if any)
            if ((options & DisplayNameOptions.IncludeParameters) != 0)
            {
                builder.Append(memberDeclaration.GetParameterList());
            }

            return pooled.ToStringAndFree();
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:60,代码来源:CSharpSyntaxFactsService.cs

示例4: GetMemberDeclaration

 private SyntaxNode GetMemberDeclaration(SyntaxNode node)
 {
     // TODO: may need to return other types like AccessorDeclarationSyntax
     return node.GetAncestor<MemberDeclarationSyntax>();
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:5,代码来源:SyntaxTreeBinding.cs


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