本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# NameSyntax.Kind方法的具体用法?C# NameSyntax.Kind怎么用?C# NameSyntax.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax
的用法示例。
在下文中一共展示了NameSyntax.Kind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendName
private static void AppendName(StringBuilder builder, NameSyntax name)
{
if (name.Kind() == SyntaxKind.QualifiedName)
{
AppendName(builder, ((QualifiedNameSyntax)name).Left);
}
switch (name.Kind())
{
case SyntaxKind.IdentifierName:
AppendDotIfNeeded(builder);
builder.Append(((IdentifierNameSyntax)name).Identifier.ValueText);
break;
case SyntaxKind.GenericName:
var genericName = (GenericNameSyntax)name;
AppendDotIfNeeded(builder);
builder.Append(genericName.Identifier.ValueText);
AppendArity(builder, genericName.Arity);
break;
case SyntaxKind.AliasQualifiedName:
var aliasQualifiedName = (AliasQualifiedNameSyntax)name;
AppendName(builder, aliasQualifiedName.Alias);
builder.Append("::");
AppendName(builder, aliasQualifiedName.Name);
break;
case SyntaxKind.QualifiedName:
AppendName(builder, ((QualifiedNameSyntax)name).Right);
break;
}
}
示例2: CompareNames
private bool CompareNames(NameSyntax oldName, NameSyntax newName)
{
if (oldName.Kind() != newName.Kind())
{
return false;
}
switch (oldName.Kind())
{
case SyntaxKind.IdentifierName:
var oldIdentifierName = (IdentifierNameSyntax)oldName;
var newIdentifierName = (IdentifierNameSyntax)newName;
return StringComparer.Ordinal.Equals(oldIdentifierName.Identifier.ToString(), newIdentifierName.Identifier.ToString());
case SyntaxKind.QualifiedName:
var oldQualifiedName = (QualifiedNameSyntax)oldName;
var newQualifiedName = (QualifiedNameSyntax)newName;
return CompareNames(oldQualifiedName.Left, newQualifiedName.Left)
&& CompareNames(oldQualifiedName.Right, oldQualifiedName.Right);
case SyntaxKind.GenericName:
var oldGenericName = (GenericNameSyntax)oldName;
var newGenericName = (GenericNameSyntax)newName;
if (!StringComparer.Ordinal.Equals(oldGenericName.Identifier.ToString(), newGenericName.Identifier.ToString()))
{
return false;
}
if (oldGenericName.Arity != newGenericName.Arity)
{
return false;
}
for (int i = 0; i < oldGenericName.Arity; i++)
{
if (!CompareTypes(oldGenericName.TypeArgumentList.Arguments[i], newGenericName.TypeArgumentList.Arguments[i]))
{
return false;
}
}
return true;
case SyntaxKind.AliasQualifiedName:
var oldAliasQualifiedName = (AliasQualifiedNameSyntax)oldName;
var newAliasQualifiedName = (AliasQualifiedNameSyntax)newName;
return CompareNames(oldAliasQualifiedName.Alias, newAliasQualifiedName.Alias)
&& CompareNames(oldAliasQualifiedName.Name, newAliasQualifiedName.Name);
}
Debug.Fail("Unknown kind: " + oldName.Kind());
return false;
}
示例3: GetDeclaredMember
private Symbol GetDeclaredMember(NamespaceOrTypeSymbol container, TextSpan declarationSpan, NameSyntax name)
{
switch (name.Kind())
{
case SyntaxKind.GenericName:
case SyntaxKind.IdentifierName:
return GetDeclaredMember(container, declarationSpan, ((SimpleNameSyntax)name).Identifier.ValueText);
case SyntaxKind.QualifiedName:
var qn = (QualifiedNameSyntax)name;
var left = GetDeclaredMember(container, declarationSpan, qn.Left) as NamespaceOrTypeSymbol;
Debug.Assert((object)left != null);
return GetDeclaredMember(left, declarationSpan, qn.Right);
case SyntaxKind.AliasQualifiedName:
// this is not supposed to happen, but we allow for errors don't we!
var an = (AliasQualifiedNameSyntax)name;
return GetDeclaredMember(container, declarationSpan, an.Name);
default:
throw ExceptionUtilities.UnexpectedValue(name.Kind());
}
}