本文整理汇总了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;
}
示例2: GetMemberBodySpanForSpeculativeBinding
public TextSpan GetMemberBodySpanForSpeculativeBinding(SyntaxNode node)
{
var parent = node.GetAncestor<DocumentationCommentTriviaSyntax>();
Assert.Null(parent);
return default(TextSpan);
}
示例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();
}
示例4: GetMemberDeclaration
private SyntaxNode GetMemberDeclaration(SyntaxNode node)
{
// TODO: may need to return other types like AccessorDeclarationSyntax
return node.GetAncestor<MemberDeclarationSyntax>();
}