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


C# SyntaxToken.ToString方法代码示例

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


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

示例1: HoistVariable

 protected SyntaxNode HoistVariable(CSharpSyntaxNode node, ref SyntaxToken identifier, TypeSyntax type)
 {
     if (hoistedVariables.ContainsKey(identifier.ToString()))
     {
         var newName = GenerateNewName(identifier);
         var newIdentifier = SyntaxFactory.Identifier(newName);
         identifier = newIdentifier;
     }
     hoistedVariables[identifier.ToString()] = type;
     return node;
 }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:11,代码来源:StateGenerator.cs

示例2: GetTextChangeSpan

 private TextSpan GetTextChangeSpan(SyntaxToken stringLiteral, int position)
 {
     return PathCompletionUtilities.GetTextChangeSpan(
         quotedPath: stringLiteral.ToString(),
         quotedPathStart: stringLiteral.SpanStart,
         position: position);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AbstractReferenceDirectiveCompletionProvider.cs

示例3: GetPathThroughLastSlash

 private string GetPathThroughLastSlash(SyntaxToken stringLiteral, int position)
 {
     return PathCompletionUtilities.GetPathThroughLastSlash(
         quotedPath: stringLiteral.ToString(),
         quotedPathStart: stringLiteral.SpanStart,
         position: position);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:ReferenceDirectiveCompletionProvider.cs

示例4: VisitToken

            public override void VisitToken(SyntaxToken token)
            {
                if (token.Kind == SyntaxKind.XmlTextLiteralNewLineToken)
                {
                    return;
                }

                VisitLeadingTrivia(token);
                arg.Append(token.ToString());
                VisitTrailingTrivia(token);
            }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:DocumentationCommentTriviaSyntax.cs

示例5: GenerateNewName

 private string GenerateNewName(SyntaxToken identifier)
 {
     var counter = 2;
     do
     {
         var currentName = identifier.ToString() + counter++;
         if (!hoistedVariables.ContainsKey(currentName))
         {
             return currentName;
         }
     }
     while (true);
 }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:13,代码来源:StateGenerator.cs

示例6: GetRenameInfo

        internal static IInlineRenameInfo GetRenameInfo(
            IEnumerable<IRefactorNotifyService> refactorNotifyServices,
            Document document, SyntaxToken triggerToken, CancellationToken cancellationToken)
        {
            var syntaxFactsService = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
            if (syntaxFactsService.IsKeyword(triggerToken))
            {
                return new FailureInlineRenameInfo(EditorFeaturesResources.You_must_rename_an_identifier);
            }

            var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
            var semanticFacts = document.GetLanguageService<ISemanticFactsService>();

            var tokenRenameInfo = RenameUtilities.GetTokenRenameInfo(semanticFacts, semanticModel, triggerToken, cancellationToken);

            // Rename was invoked on a member group reference in a nameof expression.
            // Trigger the rename on any of the candidate symbols but force the 
            // RenameOverloads option to be on.
            var triggerSymbol = tokenRenameInfo.HasSymbols ? tokenRenameInfo.Symbols.First() : null;
            if (triggerSymbol == null)
            {
                return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
            }

            // see https://github.com/dotnet/roslyn/issues/10898
            // we are disabling rename for tuple fields for now
            // 1) compiler does not return correct location information in these symbols
            // 2) renaming tuple fields seems a complex enough thing to require some design
            if (triggerSymbol.ContainingType?.IsTupleType == true)
            {
                return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
            }

            // If rename is invoked on a member group reference in a nameof expression, then the
            // RenameOverloads option should be forced on.
            var forceRenameOverloads = tokenRenameInfo.IsMemberGroup;

            if (syntaxFactsService.IsTypeNamedVarInVariableOrFieldDeclaration(triggerToken, triggerToken.Parent))
            {
                // To check if var in this context is a real type, or the keyword, we need to 
                // speculatively bind the identifier "var". If it returns a symbol, it's a real type,
                // if not, it's the keyword.
                // see bugs 659683 (compiler API) and 659705 (rename/workspace api) for examples
                var symbolForVar = semanticModel.GetSpeculativeSymbolInfo(
                    triggerToken.SpanStart,
                    triggerToken.Parent,
                    SpeculativeBindingOption.BindAsTypeOrNamespace).Symbol;

                if (symbolForVar == null)
                {
                    return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
                }
            }

            var symbol = RenameLocations.ReferenceProcessing.GetRenamableSymbolAsync(document, triggerToken.SpanStart, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
            if (symbol == null)
            {
                return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
            }

            if (symbol.Kind == SymbolKind.Alias && symbol.IsExtern)
            {
                return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
            }

            // Cannot rename constructors in VB.  TODO: this logic should be in the VB subclass of this type.
            var workspace = document.Project.Solution.Workspace;
            if (symbol != null &&
                symbol.Kind == SymbolKind.NamedType &&
                symbol.Language == LanguageNames.VisualBasic &&
                triggerToken.ToString().Equals("New", StringComparison.OrdinalIgnoreCase))
            {
                var originalSymbol = SymbolFinder.FindSymbolAtPositionAsync(semanticModel, triggerToken.SpanStart, workspace, cancellationToken: cancellationToken)
                    .WaitAndGetResult(cancellationToken);

                if (originalSymbol != null && originalSymbol.IsConstructor())
                {
                    return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
                }
            }

            if (syntaxFactsService.IsTypeNamedDynamic(triggerToken, triggerToken.Parent))
            {
                if (symbol.Kind == SymbolKind.DynamicType)
                {
                    return new FailureInlineRenameInfo(EditorFeaturesResources.You_cannot_rename_this_element);
                }
            }

            // we allow implicit locals and parameters of Event handlers
            if (symbol.IsImplicitlyDeclared &&
                symbol.Kind != SymbolKind.Local &&
                !(symbol.Kind == SymbolKind.Parameter &&
                  symbol.ContainingSymbol.Kind == SymbolKind.Method &&
                  symbol.ContainingType != null &&
                  symbol.ContainingType.IsDelegateType() &&
                  symbol.ContainingType.AssociatedSymbol != null))
            {
                // We enable the parameter in RaiseEvent, if the Event is declared with a signature. If the Event is declared as a 
                // delegate type, we do not have a connection between the delegate type and the event.
//.........这里部分代码省略.........
开发者ID:Rickinio,项目名称:roslyn,代码行数:101,代码来源:AbstractEditorInlineRenameService.cs

示例7: GetTokenType

            TokenType GetTokenType(SyntaxToken token)
            {
                var declarationSymbol = _model.GetDeclaredSymbol(token.Parent);
                if (declarationSymbol == null)
                {
                    // The token isnt part of a declaration node, so try to get symbol info.
                    var referenceSymbol = _model.GetSymbolInfo(token.Parent).Symbol;
                    if (referenceSymbol == null)
                    {
                        // we couldnt find symbol information for the node, so we will look at all symbols in scope by name.
                        var namedSymbols = _model.LookupSymbols(token.SpanStart, null, token.ToString(), true);
                        if (namedSymbols.Length == 1)
                            return TokenType.Reference(namedSymbols[0]);

                        return TokenType.Unknown();
                    }

                    return TokenType.Reference(referenceSymbol);
                }

                // The token is part of a declaration syntax node.
                return TokenType.Declaration(declarationSymbol);
            }
开发者ID:Runt-Editor,项目名称:Runt,代码行数:23,代码来源:Highlighter.cs

示例8: IsValidIdentifier

        private static bool IsValidIdentifier(SyntaxToken token)
        {
            // Identifiers are obviously valid identifiers
            if (token.Kind == SyntaxKind.IdentifierToken)
                return true;

            var token_string = token.ToString ();

            if (token_string.Length > 0 && TokenFacts.IsIdentifierStartChar (token_string[0])) {
                if (token_string[0] != '_')
                    return true;

                // If the first character is an underscore, we have to have another character after it
                if (token_string.Length > 1 && TokenFacts.IsIdentifierAdditionalChar (token_string[1]))
                    return true;
            }

            return false;
        }
开发者ID:jpobst,项目名称:Mokii,代码行数:19,代码来源:NameParser.cs

示例9: AtEndOfIncompleteStringOrCharLiteral

        private static bool AtEndOfIncompleteStringOrCharLiteral(SyntaxToken token, int position, char lastChar)
        {
            if (!token.IsKind(SyntaxKind.StringLiteralToken, SyntaxKind.CharacterLiteralToken))
            {
                throw new ArgumentException(CSharpWorkspaceResources.Expected_string_or_char_literal, nameof(token));
            }

            int startLength = 1;
            if (token.IsVerbatimStringLiteral())
            {
                startLength = 2;
            }

            return position == token.Span.End &&
                (token.Span.Length == startLength || (token.Span.Length > startLength && token.ToString().Cast<char>().LastOrDefault() != lastChar));
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:16,代码来源:SyntaxTreeExtensions.cs

示例10: GetPathThroughLastSlash

 private static string GetPathThroughLastSlash(SyntaxToken stringLiteral, int position)
 {
     return PathCompletionUtilities.GetPathThroughLastSlash(stringLiteral.ToString(), stringLiteral.SpanStart, position);
 }
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:4,代码来源:AbstractReferenceDirectiveCompletionProvider.cs

示例11: checkIdentifierIsInterface

 private bool checkIdentifierIsInterface(SyntaxToken token)
 {
     return token.ToString().StartsWith("I");
 }
开发者ID:nobuoka,项目名称:WindowsRuntimeTSDeclaration,代码行数:4,代码来源:TsDeclarationGenerator.cs

示例12: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            if (token.IsKeyword() ||
                (token.Kind == SyntaxKind.IdentifierToken && token.ToString() == "var"))
            {
                formatter.SetForegroundBrush(keywordBrush, token.Span.Start, token.Span.Length);
                return;
            }

            switch (token.Kind)
            {
                case SyntaxKind.StringLiteralToken:
                case SyntaxKind.StringLiteralExpression:
                    formatter.SetForegroundBrush(stringBrush, token.Span.Start, token.Span.Length);
                    break;
                case SyntaxKind.IdentifierToken:
                    if (token.Parent is IdentifierNameSyntax)
                    {
                        var parentToken = ((IdentifierNameSyntax)token.Parent);
                        string tokenName = parentToken.ToString();
                        if (parentToken.Parent is ObjectCreationExpressionSyntax ||
                            parentToken.Parent is TypeArgumentListSyntax)
                        {
                            formatter.SetForegroundBrush(typeBrush, token.Span.Start, token.Span.Length);
                        }
                    }
                    break;
                case SyntaxKind.SingleLineCommentTrivia:
                case SyntaxKind.MultiLineCommentTrivia:
                    formatter.SetForegroundBrush(triviaBrush, token.Span.Start, token.Span.Length);
                    break;
            }
        }
开发者ID:aelij,项目名称:svcperf,代码行数:33,代码来源:CSharpTextBox.cs

示例13: IsActualContextualKeyword

        private static bool IsActualContextualKeyword(SyntaxToken token)
        {
            if (token.Parent.IsKind(SyntaxKind.LabeledStatement))
            {
                var statement = (LabeledStatementSyntax)token.Parent;
                if (statement.Identifier == token)
                {
                    return false;
                }
            }

            // Ensure that the text and value text are the same. Otherwise, the identifier might
            // be escaped. I.e. "var", but not "@var"
            if (token.ToString() != token.ValueText)
            {
                return false;
            }

            // Standard cases.  We can just check the parent and see if we're
            // in the right position to be considered a contextual keyword
            if (token.Parent != null)
            {
                switch (token.ValueText)
                {
                    case FromKeyword:
                        var fromClause = token.Parent.FirstAncestorOrSelf<FromClauseSyntax>();
                        return fromClause != null && fromClause.FromKeyword == token;

                    case VarKeyword:
                        // we allow var any time it looks like a variable declaration, and is not in a
                        // field or event field.
                        return
                            token.Parent is IdentifierNameSyntax &&
                            (token.Parent.Parent is VariableDeclarationSyntax || token.Parent.Parent is DeclarationExpressionSyntax) &&
                            !(token.Parent.Parent.Parent is FieldDeclarationSyntax) &&
                            !(token.Parent.Parent.Parent is EventFieldDeclarationSyntax);
                }
            }

            return false;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:41,代码来源:ClassificationHelpers.cs

示例14: AtEndOfIncompleteStringOrCharLiteral

        private static bool AtEndOfIncompleteStringOrCharLiteral(SyntaxToken token, int position, char lastChar)
        {
            if (!IsKind(token, SyntaxKind.StringLiteralToken, SyntaxKind.CharacterLiteralToken))
            {
                throw new ArgumentException("ExpectedStringOrCharLiteral", nameof(token));
            }

            int startLength = 1;
            if (token.IsVerbatimStringLiteral())
            {
                startLength = 2;
            }

            return position == token.Span.End &&
                   (token.Span.Length == startLength ||
                    (token.Span.Length > startLength && token.ToString().LastOrDefault() != lastChar));
        }
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:17,代码来源:ReferenceDirectiveCompletionProvider.cs

示例15: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            var s = token.ToString();

            switch (token.Kind())
            {
                case SyntaxKind.UsingKeyword:
                    s = "@" + token.ToString() + " ";
                    break;

                case SyntaxKind.ClassKeyword:

                    if ((token.Parent as ClassDeclarationSyntax).IsHiddenClassDeclaration())
                    {
                        s = "";
                    }
                    else
                    {
                        s = @"<script type='text/javascript' name='";
                    }
                    break;

                case SyntaxKind.IdentifierToken:

                    var p = (token.Parent as ClassDeclarationSyntax);
                    if (p == null)
                    { }
                    else
                    {
                        if (p.IsHiddenClassDeclaration())
                        {
                            s = "";
                        }
                        else
                        {
                            s = token.ToString() + "'>" + newLine;
                        }
                    }

                    var p1 = token.HasParent<IdentifierNameSyntax, SimpleBaseTypeSyntax, BaseListSyntax>();
                    s = Reset_If_Not_Null(p1, s);

                    var p3 = token.Parent as MethodDeclarationSyntax;
                    s = Reset_If_IsHiddenMethodDeclaration(p3, s);

                    var p11 = token.HasParent<IdentifierNameSyntax, TypeArgumentListSyntax>();
                    s = Reset_If_Not_Null(p11, s);

                    var p14 = token.HasParent<IdentifierNameSyntax, VariableDeclarationSyntax>();
                    if (p14 == null)
                    {
                    }
                    else
                    {
                        s = "var ";
                    }

                    var p141 = token.HasParent<IdentifierNameSyntax, ParameterSyntax>();
                    s = Reset_If_Not_Null(p141, s);

                    break;

                case SyntaxKind.SemicolonToken:

                    s += newLine;
                    break;

                case SyntaxKind.ColonToken:

                    var p4 = token.HasParent<BaseListSyntax, ClassDeclarationSyntax>();
                    s = Reset_If_Not_Null(p4, s);
                    break;
                case SyntaxKind.CommaToken:

                    var p41 = token.Parent as TypeArgumentListSyntax;
                    s = Reset_If_Not_Null(p41, s);
                    break;

                case SyntaxKind.OpenBraceToken:

                    s = s + newLine;
                    var p5 = token.Parent as ClassDeclarationSyntax;
                    s = Reset_If_Not_Null(p5, s);

                    var p2 = token.HasParent<BlockSyntax, MethodDeclarationSyntax>();
                    s = Reset_If_IsHiddenMethodDeclaration(p2, s);
                    break;

                case SyntaxKind.CloseBraceToken:
                    s = s + newLine + newLine;
                    var p6 = token.HasParent<BlockSyntax, MethodDeclarationSyntax>();
                    s = Reset_If_IsHiddenMethodDeclaration(p6, s);

                    var p55 = token.Parent as ClassDeclarationSyntax;
                    if (p55 == null)
                    { }
                    else
                    {
                        s = "</script>";
                    }
//.........这里部分代码省略.........
开发者ID:ghostnguyen,项目名称:daccf960-44f9-4f95-91c4-b1aba37effe1,代码行数:101,代码来源:Syntax2Str2.cs


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