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


C# NameSyntax.Kind方法代码示例

本文整理汇总了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;
                }
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:33,代码来源:CSharpCodeModelService.NodeNameGenerator.cs

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

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


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