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


C# SyntaxToken.CSharpKind方法代码示例

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


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

示例1: FindAppropriateRangeWorker

        private static ValueTuple<SyntaxToken, SyntaxToken>? FindAppropriateRangeWorker(SyntaxToken endToken, bool useDefaultRange)
        {
            // special token that we know how to find proper starting token
            switch (endToken.CSharpKind())
            {
                case SyntaxKind.CloseBraceToken:
                    {
                        return FindAppropriateRangeForCloseBrace(endToken);
                    }

                case SyntaxKind.SemicolonToken:
                    {
                        return FindAppropriateRangeForSemicolon(endToken);
                    }

                case SyntaxKind.ColonToken:
                    {
                        return FindAppropriateRangeForColon(endToken);
                    }

                default:
                    {
                        // default case
                        if (!useDefaultRange)
                        {
                            return null;
                        }

                        // if given token is skipped token, don't bother to find appropriate
                        // starting point
                        if (endToken.CSharpKind() == SyntaxKind.SkippedTokensTrivia)
                        {
                            return null;
                        }

                        var parent = endToken.Parent;
                        if (parent == null)
                        {
                            // if there is no parent setup yet, nothing we can do here.
                            return null;
                        }

                        // if we are called due to things in trivia or literals, don't bother
                        // finding a starting token
                        if (parent.CSharpKind() == SyntaxKind.StringLiteralExpression ||
                            parent.CSharpKind() == SyntaxKind.CharacterLiteralExpression)
                        {
                            return null;
                        }

                        // format whole node that containing the end token + its previous one
                        // to do indentation
                        return ValueTuple.Create(GetAppropriatePreviousToken(parent.GetFirstToken()), parent.GetLastToken());
                    }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:56,代码来源:FormattingRangeHelper.cs

示例2: IsOperator

        public bool IsOperator(SyntaxToken token)
        {
            var kind = token.CSharpKind();

            return
                (SyntaxFacts.IsAnyUnaryExpression(kind) &&
                    (token.Parent is PrefixUnaryExpressionSyntax || token.Parent is PostfixUnaryExpressionSyntax)) ||
                (SyntaxFacts.IsBinaryExpression(kind) && token.Parent is BinaryExpressionSyntax);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:9,代码来源:CSharpSyntaxFactsService.cs

示例3: VisitToken

            public override void VisitToken(SyntaxToken token)
            {
                // trivia is not considered, only the raw form of the token

                this.hash = Hash.Combine((int)token.CSharpKind(), this.hash);

                switch (token.CSharpKind())
                {
                    case SyntaxKind.IdentifierToken:
                        this.hash = Hash.Combine(token.ValueText.GetHashCode(), this.hash);
                        break;

                    case SyntaxKind.NumericLiteralToken:
                    case SyntaxKind.CharacterLiteralToken:
                    case SyntaxKind.StringLiteralToken:
                        this.hash = Hash.Combine(token.ToString().GetHashCode(), this.hash);
                        break;
                }
            }
开发者ID:nagyist,项目名称:roslyn,代码行数:19,代码来源:CSharpSyntaxVersionService.cs

示例4: GetAdjustSpacesOperation

        private AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previousToken, SyntaxToken currentToken, NextOperation<AdjustSpacesOperation> nextOperation)
        {
            if (previousToken.CSharpKind() == SyntaxKind.HashToken && SyntaxFacts.IsPreprocessorKeyword(currentToken.CSharpKind()))
            {
                return CreateAdjustSpacesOperation(space: 0, option: AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            if (previousToken.CSharpKind() == SyntaxKind.RegionKeyword && currentToken.CSharpKind() == SyntaxKind.EndOfDirectiveToken)
            {
                return CreateAdjustSpacesOperation(space: 1, option: AdjustSpacesOption.PreserveSpaces);
            }

            if (currentToken.CSharpKind() == SyntaxKind.EndOfDirectiveToken)
            {
                return CreateAdjustSpacesOperation(space: 0, option: AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            return nextOperation.Invoke();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:StructuredTriviaFormattingRule.cs

示例5: GetAdjustNewLinesOperation

        public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
        {
            // * <End Of File> case for C#, make sure we don't insert new line between * and <End of
            // File> tokens.
            if (currentToken.CSharpKind() == SyntaxKind.EndOfFileToken)
            {
                return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
            }

            return nextOperation.Invoke();
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:EndOfFileTokenFormattingRule.cs

示例6: GetAdjustSpacesOperation

        public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustSpacesOperation> nextOperation)
        {
            // * <End Of File) case
            // for C#, make sure we have nothing between these two tokens
            if (currentToken.CSharpKind() == SyntaxKind.EndOfFileToken)
            {
                return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            return nextOperation.Invoke();
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:EndOfFileTokenFormattingRule.cs

示例7: GetClassification

        /// <summary>
        /// Determine the classification type for a given token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns>The correct syntactic classification for the token.</returns>
        public static string GetClassification(SyntaxToken token)
        {
            if (SyntaxFacts.IsKeywordKind(token.CSharpKind()))
            {
                return ClassificationTypeNames.Keyword;
            }
            else if (SyntaxFacts.IsPunctuation(token.CSharpKind()))
            {
                return GetClassificationForPunctuation(token);
            }
            else if (token.CSharpKind() == SyntaxKind.IdentifierToken)
            {
                return GetClassificationForIdentifer(token);
            }
            else if (token.CSharpKind() == SyntaxKind.StringLiteralToken || token.CSharpKind() == SyntaxKind.CharacterLiteralToken)
            {
                return token.IsVerbatimStringLiteral()
                    ? ClassificationTypeNames.VerbatimStringLiteral
                    : ClassificationTypeNames.StringLiteral;
            }
            else if (token.CSharpKind() == SyntaxKind.NumericLiteralToken)
            {
                return ClassificationTypeNames.NumericLiteral;
            }

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

示例8: AddIndentBlockOperation

        protected void AddIndentBlockOperation(
            List<IndentBlockOperation> list,
            SyntaxToken startToken,
            SyntaxToken endToken,
            IndentBlockOption option = IndentBlockOption.RelativePosition)
        {
            if (startToken.CSharpKind() == SyntaxKind.None || endToken.CSharpKind() == SyntaxKind.None)
            {
                return;
            }

            list.Add(FormattingOperations.CreateIndentBlockOperation(startToken, endToken, indentationDelta: 1, option: option));
        }
开发者ID:pheede,项目名称:roslyn,代码行数:13,代码来源:BaseFormattingRule.cs

示例9: VisitToken

        public override SyntaxToken VisitToken(SyntaxToken token)
        {
            switch (token.CSharpKind())
            {
                case SyntaxKind.OpenBraceToken:
                    if (token.GetPreviousToken().CSharpKind() == SyntaxKind.CloseParenToken)
                    {
                        return token.WithLeadingTrivia(SyntaxFactory.ElasticLineFeed);
                    }
                    break;
            }

            return token;
        }
开发者ID:MartinJohns,项目名称:RoslynDemo,代码行数:14,代码来源:Program.cs

示例10: Add

            private void Add(SyntaxToken syntaxToken)
            {
                if (syntaxToken.CSharpKind() == SyntaxKind.IdentifierToken)
                {
                    var identifier = syntaxToken.ValueText;
                    List<SyntaxToken> list;
                    if (!map.TryGetValue(identifier, out list))
                    {
                        list = new List<SyntaxToken>();
                        map.Add(identifier, list);
                    }

                    list.Add(syntaxToken);
                }
            }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:15,代码来源:MemberDeclarationSyntaxExtensions.DeclarationFinder.cs

示例11: SourceLocalSymbol

        private SourceLocalSymbol(
            MethodSymbol containingMethod,
            Binder binder,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            EqualsValueClauseSyntax initializer,
            ExpressionSyntax collection,
            LocalDeclarationKind declarationKind)
        {
            Debug.Assert(identifierToken.CSharpKind() != SyntaxKind.None);
            Debug.Assert(declarationKind != LocalDeclarationKind.CompilerGenerated);

            this.binder = binder;
            this.containingMethod = containingMethod;
            this.identifierToken = identifierToken;
            this.typeSyntax = typeSyntax;
            this.initializer = initializer;
            this.collection = collection;
            this.declarationKind = declarationKind;

            // create this eagerly as it will always be needed for the EnsureSingleDefinition
            this.locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
        }
开发者ID:riversky,项目名称:roslyn,代码行数:23,代码来源:SourceLocalSymbol.cs

示例12: AddUnindentBlockOperation

        protected void AddUnindentBlockOperation(
            List<IndentBlockOperation> list,
            SyntaxToken startToken,
            SyntaxToken endToken,
            bool includeTriviaAtEnd = false,
            IndentBlockOption option = IndentBlockOption.RelativePosition)
        {
            if (startToken.CSharpKind() == SyntaxKind.None || endToken.CSharpKind() == SyntaxKind.None)
            {
                return;
            }

            if (includeTriviaAtEnd)
            {
                list.Add(FormattingOperations.CreateIndentBlockOperation(startToken, endToken, indentationDelta: -1, option: option));
            }
            else
            {
                var startPosition = CommonFormattingHelpers.GetStartPositionOfSpan(startToken);
                var endPosition = endToken.Span.End;

                list.Add(FormattingOperations.CreateIndentBlockOperation(startToken, endToken, TextSpan.FromBounds(startPosition, endPosition), indentationDelta: -1, option: option));
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:24,代码来源:BaseFormattingRule.cs

示例13: SourceLocalSymbol

        private SourceLocalSymbol(
            Symbol containingSymbol,
            Binder binder,
            TypeSyntax typeSyntax,
            SyntaxToken identifierToken,
            LocalDeclarationKind declarationKind)
        {
            Debug.Assert(identifierToken.CSharpKind() != SyntaxKind.None);
            Debug.Assert(declarationKind != LocalDeclarationKind.None);

            this.binder = binder;
            this.containingSymbol = containingSymbol;
            this.identifierToken = identifierToken;
            this.typeSyntax = typeSyntax;
            this.declarationKind = declarationKind;

            // create this eagerly as it will always be needed for the EnsureSingleDefinition
            this.locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:19,代码来源:SourceLocalSymbol.cs

示例14: GetAdjustNewLinesOperation

        public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
        {
            var operation = nextOperation.Invoke();

            // else condition is actually handled in the GetAdjustSpacesOperation()

            // For Object Initialization Expression
            if (previousToken.CSharpKind() == SyntaxKind.CommaToken && previousToken.Parent.CSharpKind() == SyntaxKind.ObjectInitializerExpression)
            {
                if (optionSet.GetOption(CSharpFormattingOptions.NewLineForMembersInObjectInit))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    // we never force it to move up unless it is already on same line
                    return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
                }
            }

            // For Anonymous Object Creation Expression
            if (previousToken.CSharpKind() == SyntaxKind.CommaToken && previousToken.Parent.CSharpKind() == SyntaxKind.AnonymousObjectCreationExpression)
            {
                if (optionSet.GetOption(CSharpFormattingOptions.NewLineForMembersInAnonymousTypes))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    // we never force it to move up unless it is already on same line
                    return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
                }
            }

            // } else in the if else context
            if (previousToken.IsKind(SyntaxKind.CloseBraceToken) && currentToken.IsKind(SyntaxKind.ElseKeyword))
            {
                if (optionSet.GetOption(CSharpFormattingOptions.NewLineForElse))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    return null;
                }
            }

            // * catch in the try catch context
            if (currentToken.CSharpKind() == SyntaxKind.CatchKeyword)
            {
                if (optionSet.GetOption(CSharpFormattingOptions.NewLineForCatch))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    return null;
                }
            }

            // * Finally
            if (currentToken.CSharpKind() == SyntaxKind.FinallyKeyword)
            {
                if (optionSet.GetOption(CSharpFormattingOptions.NewLineForFinally))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    return null;
                }
            }

            // * { - in the type declaration context
            if (currentToken.CSharpKind() == SyntaxKind.OpenBraceToken && (currentToken.Parent is BaseTypeDeclarationSyntax || currentToken.Parent is NamespaceDeclarationSyntax))
            {
                if (optionSet.GetOption(CSharpFormattingOptions.OpenBracesInNewLineForTypes))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    return null;
                }
            }

            // new { - Anonymous object creation
            if (currentToken.CSharpKind() == SyntaxKind.OpenBraceToken && currentToken.Parent != null && currentToken.Parent.CSharpKind() == SyntaxKind.AnonymousObjectCreationExpression)
            {
                if (optionSet.GetOption(CSharpFormattingOptions.OpenBracesInNewLineForAnonymousType))
                {
                    return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                }
                else
                {
                    return null;
                }
            }

            // new { - Object Initialization
//.........这里部分代码省略.........
开发者ID:riversky,项目名称:roslyn,代码行数:101,代码来源:NewLineUserSettingFormattingRule.cs

示例15: EnsureToken

 private static SyntaxToken EnsureToken(SyntaxToken token, bool prependNewLineIfMissing = false, bool appendNewLineIfMissing = false)
 {
     if (token.IsMissing)
     {
         var leadingTrivia = prependNewLineIfMissing ? token.LeadingTrivia.Insert(0, SyntaxFactory.CarriageReturnLineFeed) : token.LeadingTrivia;
         var trailingTrivia = appendNewLineIfMissing ? token.TrailingTrivia.Insert(0, SyntaxFactory.CarriageReturnLineFeed) : token.TrailingTrivia;
         return SyntaxFactory.Token(leadingTrivia, token.CSharpKind(), trailingTrivia).WithAdditionalAnnotations(Formatter.Annotation);
     }
     
     return token;
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:TypeDeclarationSyntaxExtensions.cs


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