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


C# SyntaxNode.TypeSwitch方法代码示例

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


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

示例1: Check

 public bool Check(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
 {
     return node.TypeSwitch(
         (ExpressionSyntax expression) => CheckExpression(semanticModel, expression, cancellationToken),
         (BlockSyntax block) => CheckBlock(semanticModel, block, cancellationToken),
         (StatementSyntax statement) => CheckStatement(semanticModel, statement, cancellationToken),
         (GlobalStatementSyntax globalStatement) => CheckGlobalStatement(semanticModel, globalStatement, cancellationToken));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:CSharpSelectionValidator.Validator.cs

示例2: RemoveAsyncTokenAndFixReturnType

 protected override SyntaxNode RemoveAsyncTokenAndFixReturnType(IMethodSymbol methodSymbolOpt, SyntaxNode node, ITypeSymbol taskType, ITypeSymbol taskOfTType)
 {
     return node.TypeSwitch(
         (MethodDeclarationSyntax method) => FixMethod(methodSymbolOpt, method, taskType, taskOfTType),
         (AnonymousMethodExpressionSyntax method) => FixAnonymousMethod(method),
         (ParenthesizedLambdaExpressionSyntax lambda) => FixParenthesizedLambda(lambda),
         (SimpleLambdaExpressionSyntax lambda) => FixSimpleLambda(lambda),
         _ => node);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:CSharpMakeMethodSynchronousCodeFixProvider.cs

示例3: CheckLocation

        /// <summary>
        /// make sure current location is okay to put semicolon
        /// </summary>
        private static bool CheckLocation(SourceText text, int position, SyntaxNode owningNode, SyntaxToken lastToken)
        {
            var line = text.Lines.GetLineFromPosition(position);

            // if caret is at the end of the line and containing statement is expression statement
            // don't do anything
            if (position == line.End && owningNode is ExpressionStatementSyntax)
            {
                return false;
            }

            var locatedAtTheEndOfLine = LocatedAtTheEndOfLine(line, lastToken);

            // make sure that there is no trailing text after last token on the line if it is not at the end of the line
            if (!locatedAtTheEndOfLine)
            {
                var endingString = text.ToString(TextSpan.FromBounds(lastToken.Span.End, line.End));
                if (!string.IsNullOrWhiteSpace(endingString))
                {
                    return false;
                }
            }

            // check whether using has contents
            if (owningNode.TypeSwitch((UsingDirectiveSyntax u) => u.Name == null || u.Name.IsMissing))
            {
                return false;
            }

            // make sure there is no open string literals
            var previousToken = lastToken.GetPreviousToken();
            if (previousToken.Kind() == SyntaxKind.StringLiteralToken && previousToken.ToString().Last() != '"')
            {
                return false;
            }

            if (previousToken.Kind() == SyntaxKind.CharacterLiteralToken && previousToken.ToString().Last() != '\'')
            {
                return false;
            }

            // now, check embedded statement case
            if (owningNode.IsEmbeddedStatementOwner())
            {
                var embeddedStatement = owningNode.GetEmbeddedStatement();
                if (embeddedStatement == null || embeddedStatement.Span.IsEmpty)
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:56,代码来源:AutomaticLineEnderCommandHandler.cs

示例4: ConvertToAsync

 private Task<SyntaxNode> ConvertToAsync(SyntaxNode node, SemanticModel semanticModel, Document document, CancellationToken cancellationToken)
 {
     return node.TypeSwitch(
         (MethodDeclarationSyntax methodNode) => ConvertMethodToAsync(document, semanticModel, methodNode, cancellationToken),
         (ParenthesizedLambdaExpressionSyntax parenthesizedLambda) => Task.FromResult(ConvertParenthesizedLambdaToAsync(parenthesizedLambda)),
         (SimpleLambdaExpressionSyntax simpleLambda) => Task.FromResult(ConvertSimpleLambdaToAsync(simpleLambda)),
         (AnonymousMethodExpressionSyntax anonymousMethod) => Task.FromResult(ConvertAnonymousMethodToAsync(anonymousMethod)),
         @default => Task.FromResult<SyntaxNode>(null));
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:9,代码来源:CSharpAddAsyncCodeFixProvider.cs


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