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


C# SyntaxToken.GetText方法代码示例

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


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

示例1: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            VisitLeadingTrivia(token);
            bool isProcessed = false;

            if (token.IsKeyword())
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
                isProcessed = true;
            }
            else
            {
                switch (token.Kind)
                {
                    case SyntaxKind.IdentifierToken:
                        writeDelegate(this.GetTokenKind(token), token.GetText(), token.Span.Start);
                        isProcessed = true;
                        break;
                    default:
                        writeDelegate(TokenKind.None, token.GetText(), null);
                        isProcessed = true;
                        break;
                }
            }

            if (!isProcessed)
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
            }
            base.VisitTrailingTrivia(token);
        }
开发者ID:kris444,项目名称:SourceCodeReader,代码行数:31,代码来源:CSharpCodeNavigationSyntaxWalker.cs

示例2: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            if (token.GetText() == parameter.Text)
            {
                switch (searchTokenKind)
                {
                    case TokenKind.MethodCall:
                        var methodDeclarationSyntax = token.Parent as MethodDeclarationSyntax;
                        var methodSymbol = this.semanticModel.GetDeclaredSymbol(methodDeclarationSyntax);
                        if (methodSymbol.ToString() == parameter.FullyQualifiedName)
                        {
                            symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line);
                        }
                        break;
                    case TokenKind.ObjectCreation:
                        var classDeclarationSyntax = token.Parent as ClassDeclarationSyntax;
                        var classSymbol = this.semanticModel.GetDeclaredSymbol(classDeclarationSyntax);
                        if (classSymbol.ToString() == parameter.FullyQualifiedName)
                        {
                            symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line);
                        }
                        break;
                }

            }
            base.VisitToken(token);
        }
开发者ID:swapneeld,项目名称:SourceCodeReader,代码行数:27,代码来源:CSharpGoToDefinitionSyntaxWalker.cs

示例3: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            VisitLeadingTrivia(token);
            bool isProcessed = false;

            if (token.IsKeyword())
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
                isProcessed = true;
            }
            else
            {
                switch (token.Kind)
                {
                    case SyntaxKind.IdentifierToken:
                        TokenKind tokenKind = this.GetTokenKind(token);
                        if (tokenKind == TokenKind.None)
                        {
                            writeDelegate(TokenKind.None, token.GetText(), null);
                        }
                        else
                        {
                            try
                            {
                                string fullyQualifiedNamed = this.GetFullyQualifiedName(tokenKind, token);
                                writeDelegate(tokenKind, token.GetText(), fullyQualifiedNamed);
                            }
                            catch (Exception)
                            {
                                writeDelegate(TokenKind.None, token.GetText(),null);
                            }
                        }
                        isProcessed = true;
                        break;
                    default:
                        writeDelegate(TokenKind.None,token.GetText(), null);
                        isProcessed = true;
                        break;
                }
            }

            if (!isProcessed)
            {
                writeDelegate(TokenKind.None,token.GetText(), null);
            }
            base.VisitTrailingTrivia(token);
        }
开发者ID:swapneeld,项目名称:SourceCodeReader,代码行数:47,代码来源:CSharpCodeNavigationSyntaxWalker.cs

示例4: VisitToken

 protected override SyntaxToken VisitToken(SyntaxToken token)
 {
     if (token.Kind == SyntaxKind.IdentifierToken && token.GetText() == this.oldName)
         return Syntax.Identifier(token.LeadingTrivia,
                                     this.newName,
                                     token.TrailingTrivia);
     return token;
 }
开发者ID:dchung89,项目名称:rfactor,代码行数:8,代码来源:Renamer.cs

示例5: GetFullyQualifiedName

        private string GetFullyQualifiedName(TokenKind tokenKind, SyntaxToken token)
        {
            string result = token.GetText();
            SymbolInfo symbolInfo;

            switch (tokenKind)
            {
                case TokenKind.MethodCall:
                case TokenKind.PropertyDeclaration:
                case TokenKind.Parameter:
                case TokenKind.VariableDeclaration:
                case TokenKind.MemberAccess:
                    var identifierSyntax = token.Parent as IdentifierNameSyntax;
                    symbolInfo = this.semanticModel.GetSymbolInfo(identifierSyntax);
                    if (symbolInfo.Symbol != null)
                    {
                        result = symbolInfo.Symbol.ToString();
                    }
                    break;
                case TokenKind.ObjectCreation:

                    var objectCreationSyntax = token.Parent.Parent as ObjectCreationExpressionSyntax;
                    symbolInfo = this.semanticModel.GetSymbolInfo(objectCreationSyntax);
                    if (symbolInfo.Symbol != null)
                    {
                        result = symbolInfo.Symbol.ToString();
                    }
                    break;
                case TokenKind.None:
                default:
                    break;
            }

            return result;
        }
开发者ID:swapneeld,项目名称:SourceCodeReader,代码行数:35,代码来源:CSharpCodeNavigationSyntaxWalker.cs

示例6: GetTypeName

        /* Get the RefactoringType name of a declaration. */
        private string GetTypeName(SyntaxToken token)
        {
            var parent = GetParentDeclaratorOrParameter(token);

            logger.Debug("Declared Token: " + token.GetText());
            logger.Debug("Declarator: " + parent.GetText());

            if (parent != null)
            {
                // If this declaration is an instance declarator, get the type name of the
                // declarator.
                if (parent.Kind == SyntaxKind.VariableDeclarator)
                {
                    return GetDeclaratorTypeName(parent);
                }

                // If the declaration is a parameter, get the type name of the parameter.
                if (parent.Kind == SyntaxKind.Parameter)
                {
                    return GetParameterTypeName(parent);
                }

                // If the symbol is the identifier in the for each loop.
                if (parent.Kind == SyntaxKind.ForEachStatement)
                {
                    return GetForEachIdentifierTypeName(parent);
                }
            }

            // If not declarator, return object.
            return OBJECT;
        }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:33,代码来源:SymbolAnalyzer.cs


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