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


C# SyntaxToken.IsKind方法代码示例

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


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

示例1: IsInvalidToken

 protected override bool IsInvalidToken(SyntaxToken token)
 {
     // invalid token to be formatted
     return token.IsKind(SyntaxKind.None) ||
            token.IsKind(SyntaxKind.EndOfDirectiveToken) ||
            token.IsKind(SyntaxKind.EndOfFileToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:SmartTokenFormatterCommandHandler.cs

示例2: WriteIt

        public static void WriteIt(OutputWriter writer, SyntaxToken operatorToken, CSharpSyntaxNode rightExpression,
            CSharpSyntaxNode leftExpression)
        {
            if (operatorToken.IsKind(SyntaxKind.AsKeyword))
            {
                writer.Write("AsCast!(");
                writer.Write(TypeProcessor.ConvertType(rightExpression));
                writer.Write(")(");
                Core.Write(writer, leftExpression);
                writer.Write(")");
            }
            else if (operatorToken.IsKind(SyntaxKind.IsKeyword)) // isCast
            {
                var leftSymbolType = TypeProcessor.GetTypeInfo(leftExpression);
                var rightSymbolType = TypeProcessor.GetTypeInfo(rightExpression);

                if (leftSymbolType.Type.IsValueType)
                {
                    writer.Write("IsCast!(Boxed!(");
                    writer.Write(TypeProcessor.ConvertType(rightExpression));
                    writer.Write("))");
                    writer.Write("(");
                    Core.Write(writer, leftExpression);
                    writer.Write(")");
                }
                else if (rightSymbolType.Type.IsValueType)
                {
                    writer.Write("IsCast!(Boxed!(");
                    writer.Write(TypeProcessor.ConvertType(rightExpression));
                    writer.Write("))");
                    writer.Write("(");
                    Core.Write(writer, leftExpression);
                    writer.Write(")");
                }
                else
                {
                    writer.Write("(IsCast!(");
                    writer.Write(TypeProcessor.ConvertType(rightExpression));
                    writer.Write(")(");
                    Core.Write(writer, leftExpression);
                    writer.Write("))");
                }
            }
            else if (operatorToken.IsKind(SyntaxKind.QuestionQuestionToken))
            {
                writer.Write("((");
                Core.Write(writer, leftExpression);
                writer.Write(")!is null?(");
                Core.Write(writer, leftExpression);
                writer.Write("):(");
                Core.Write(writer, rightExpression);
                writer.Write("))");
            }
            else
            {

                ProcessExpression(writer, operatorToken, rightExpression, leftExpression);
            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:59,代码来源:WriteBinaryExpression.cs

示例3: TryGetInterpolatedStringExpression

            private static InterpolatedStringExpressionSyntax TryGetInterpolatedStringExpression(
                SyntaxToken token, int position)
            {
                if (token.IsKind(SyntaxKind.InterpolatedStringTextToken) ||
                    token.IsKind(SyntaxKind.InterpolatedStringEndToken) ||
                    IsInterpolationOpenBrace(token, position))
                {
                    return token.GetAncestor<InterpolatedStringExpressionSyntax>();
                }

                return null;
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:12,代码来源:SplitStringLiteralCommandHandler.StringSplitter.cs

示例4: IsTypeDeclarationContext

        public static bool IsTypeDeclarationContext(this SyntaxTree syntaxTree, SyntaxToken token)
        {
            if (token.Kind == SyntaxKind.None)
                return true;

            if (token.IsKind(SyntaxKind.OpenBraceToken))
            {
                if (token.Parent.IsKind(SyntaxKind.ClassType, SyntaxKind.StructType))
                    return true;
                if (token.Parent.IsKind(SyntaxKind.Namespace))
                    return true;
            }

            // class C {
            //   int i;
            //   |
            if (token.IsKind(SyntaxKind.SemiToken))
            {
                if (token.Parent.GetParent() is TypeDefinitionSyntax || token.Parent.GetParent() is CompilationUnitSyntax)
                {
                    return true;
                }
            }

            // class C {}
            // |

            // namespace N {}
            // |

            // class C {
            //    void Foo() {
            //    }
            //    |
            if (token.IsKind(SyntaxKind.CloseBraceToken))
            {
                if (token.Parent is TypeDefinitionSyntax)
                    return true;
                if (token.Parent.IsKind(SyntaxKind.Namespace))
                    return true;
                if (token.Parent.IsKind(SyntaxKind.Block) &&
                    token.Parent.GetParent().GetParent() is TypeDefinitionSyntax)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:tgjones,项目名称:HlslTools,代码行数:49,代码来源:SyntaxTreeExtensions.cs

示例5: ComputeReplacementToken

 private static SyntaxToken ComputeReplacementToken(SyntaxToken originalToken, SyntaxToken rewrittenToken)
 {
     if (originalToken.IsKind(SyntaxKind.InternalKeyword))
     {
         return SyntaxFactory.Token(SyntaxKind.ProtectedKeyword).WithTriviaFrom(rewrittenToken);
     }
     else if (originalToken.IsKind(SyntaxKind.ProtectedKeyword))
     {
         return SyntaxFactory.Token(SyntaxKind.InternalKeyword).WithTriviaFrom(rewrittenToken);
     }
     else
     {
         return rewrittenToken;
     }
 }
开发者ID:hickford,项目名称:StyleCopAnalyzers,代码行数:15,代码来源:SA1207CodeFixProvider.cs

示例6: FormatToken

        public IList<TextChange> FormatToken(Workspace workspace, SyntaxToken token, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(token.Kind() == SyntaxKind.None || token.Kind() == SyntaxKind.EndOfFileToken);

            // get previous token
            var previousToken = token.GetPreviousToken(includeZeroWidth: true);
            if (previousToken.Kind() == SyntaxKind.None)
            {
                // no previous token. nothing to format
                return SpecializedCollections.EmptyList<TextChange>();
            }

            // This is a heuristic to prevent brace completion from breaking user expectation/muscle memory in common scenarios (see Devdiv:823958).
            // Formatter uses FindToken on the position, which returns token to left, if there is nothing to the right and returns token to the right
            // if there exists one. If the shape is "{|}", we're including '}' in the formatting range. Avoid doing that to improve verbatim typing
            // in the following special scenarios.  
            int adjustedEndPosition = token.Span.End;
            if (token.IsKind(SyntaxKind.OpenBraceToken) &&
                (token.Parent.IsInitializerForArrayOrCollectionCreationExpression() ||
                    token.Parent is AnonymousObjectCreationExpressionSyntax))
            {
                var nextToken = token.GetNextToken(includeZeroWidth: true);
                if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
                {
                    // Format upto '{' and exclude '}'
                    adjustedEndPosition = token.SpanStart;
                }
            }

            var smartTokenformattingRules = (new SmartTokenFormattingRule()).Concat(_formattingRules);
            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(previousToken.SpanStart, adjustedEndPosition) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:32,代码来源:SmartTokenFormatter.cs

示例7: IsTriggerToken

 private bool IsTriggerToken(SyntaxToken token)
 {
     return !token.IsKind(SyntaxKind.None) &&
         token.ValueText.Length == 1 &&
         IsTriggerCharacter(token.ValueText[0]) &&
         token.Parent is TypeArgumentListSyntax &&
         token.Parent.Parent is GenericNameSyntax;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:GenericNameSignatureHelpProvider.cs

示例8: IsTriggerToken

 private bool IsTriggerToken(SyntaxToken token)
 {
     return !token.IsKind(SyntaxKind.None) &&
         token.ValueText.Length == 1 &&
         IsTriggerCharacter(token.ValueText[0]) &&
         token.Parent is ArgumentListSyntax &&
         token.Parent.Parent is ConstructorInitializerSyntax;
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:8,代码来源:ConstructorInitializerSignatureHelpProvider.cs

示例9: IsTriggerToken

 private bool IsTriggerToken(SyntaxToken token)
 {
     return !token.IsKind(SyntaxKind.None) &&
         token.ValueText.Length == 1 &&
         IsTriggerCharacter(token.ValueText[0]) &&
         token.Parent is ArgumentListSyntax &&
         token.Parent.Parent is InvocationExpressionSyntax;
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:InvocationExpressionSignatureHelpProvider.cs

示例10: IgnoreInContext

 static bool IgnoreInContext(SyntaxToken m, TokenContext context)
 {
     switch (context)
     {
         case TokenContext.InterfaceOrModule:
             return m.IsKind(CS.SyntaxKind.PublicKeyword, CS.SyntaxKind.StaticKeyword);
     }
     return false;
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:9,代码来源:CSharpConverter.cs

示例11: HandleIncrementDecrementToken

        private static void HandleIncrementDecrementToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
        {
            if (token.IsMissing)
            {
                return;
            }

            switch (token.Parent.Kind())
            {
            case SyntaxKind.PreIncrementExpression:
            case SyntaxKind.PreDecrementExpression:
                if (token.HasTrailingTrivia)
                {
                    string symbolName;
                    if (token.IsKind(SyntaxKind.MinusMinusToken))
                    {
                        symbolName = "Decrement";
                    }
                    else
                    {
                        symbolName = "Increment";
                    }

                    // {Increment|Decrement} symbol '{++|--}' must not be {followed} by a space.
                    var properties = TokenSpacingProperties.RemoveFollowing;
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, symbolName, token.Text, "followed"));
                }

                break;

            case SyntaxKind.PostIncrementExpression:
            case SyntaxKind.PostDecrementExpression:
                SyntaxToken previousToken = token.GetPreviousToken();
                if (!previousToken.IsMissing && previousToken.HasTrailingTrivia)
                {
                    string symbolName;
                    if (token.IsKind(SyntaxKind.MinusMinusToken))
                    {
                        symbolName = "Decrement";
                    }
                    else
                    {
                        symbolName = "Increment";
                    }

                    // {Increment|Decrement} symbol '{++|--}' must not be {preceded} by a space.
                    var properties = TokenSpacingProperties.RemovePreceding;
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, symbolName, token.Text, "preceded"));
                }

                break;

            default:
                return;
            }
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:56,代码来源:SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.cs

示例12: IsImplicitArrayCreation

        private bool IsImplicitArrayCreation(SemanticModel semanticModel, SyntaxToken token, int position, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression))
            {
                var type = typeInferrer.InferType(semanticModel, token.Parent, objectAsDefault: false, cancellationToken: cancellationToken);
                return type != null && type is IArrayTypeSymbol;
            }

            return false;
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:10,代码来源:CSharpSuggestionModeCompletionProvider.cs

示例13: IsStringToken

 private static bool IsStringToken(SyntaxToken token)
 {
     return token.IsKind(SyntaxKind.StringLiteralToken)
         || token.IsKind(SyntaxKind.CharacterLiteralToken)
         || token.IsKind(SyntaxKind.InterpolatedStringStartToken)
         || token.IsKind(SyntaxKind.InterpolatedVerbatimStringStartToken)
         || token.IsKind(SyntaxKind.InterpolatedStringTextToken)
         || token.IsKind(SyntaxKind.InterpolatedStringEndToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:ClassificationHelpers.cs

示例14: HasIssue

        static bool HasIssue(SyntaxNodeAnalysisContext nodeContext, out SyntaxToken sealedKeyword)
        {
            SyntaxNode node = nodeContext.Node;
            var type = node.Parent as TypeDeclarationSyntax;
            if (type == null || !type.Modifiers.Any(m => m.IsKind(SyntaxKind.SealedKeyword)))
            {
                sealedKeyword = default(SyntaxToken);
                return false;
            }

            sealedKeyword = node.GetModifiers().FirstOrDefault(m => m.IsKind(SyntaxKind.SealedKeyword));
            if (sealedKeyword.IsKind(SyntaxKind.SealedKeyword))
                return true;
            return false;
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:15,代码来源:SealedMemberInSealedClassAnalyzer.cs

示例15: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            SyntaxElementWithTrivia element;

            if (token.IsKeyword() || token.IsContextualKeyword())
            {
                // Keyword
                element = token.IsKind(SyntaxKind.PartialKeyword)
                    ? ProcessPartialKeyword(token)
                    : new SyntaxElementWithTrivia(token, SyntaxElementKind.Keyword);
            }
            else if (token.IsKind(SyntaxKind.IdentifierToken))
            {
                // Identifier

                element = ProcessSemanticSymbolIdentifier(token);
            }
            else if (IsStringLitteralToken(token))
            {
                // String litteral
                element = new SyntaxElementWithTrivia(token, SyntaxElementKind.StringLitteral);
            }
            else
            {
                // Litteral
                element = new SyntaxElementWithTrivia(token, SyntaxElementKind.Litteral);
            }

            using (_currentSyntaxElement.PostValue(element))
            {
                VisitLeadingTrivia(token);
                VisitTrailingTrivia(token);
            }

            ResultsAccumulator.Add(element);
        }
开发者ID:pgrefviau,项目名称:SourceMaster,代码行数:36,代码来源:FileSyntaxWalker.cs


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