• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ContextQuery.CSharpSyntaxContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery.CSharpSyntaxContext的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxContext类的具体用法?C# CSharpSyntaxContext怎么用?C# CSharpSyntaxContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CSharpSyntaxContext类属于Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery命名空间,在下文中一共展示了CSharpSyntaxContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: IsExtensionMethodParameterContext

        private static bool IsExtensionMethodParameterContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            // TODO(cyrusn): lambda/anon methods can have out/ref parameters
            if (!context.SyntaxTree.IsParameterModifierContext(context.Position, context.LeftToken, cancellationToken, allowableIndex: 0))
            {
                return false;
            }

            var token = context.LeftToken;
            var method = token.GetAncestor<MethodDeclarationSyntax>();
            var typeDecl = method.GetAncestorOrThis<TypeDeclarationSyntax>();

            if (method == null || typeDecl == null)
            {
                return false;
            }

            if (typeDecl.Kind() != SyntaxKind.ClassDeclaration)
            {
                return false;
            }

            if (!method.Modifiers.Any(t => t.Kind() == SyntaxKind.StaticKeyword))
            {
                return false;
            }

            if (!typeDecl.Modifiers.Any(t => t.Kind() == SyntaxKind.StaticKeyword))
            {
                return false;
            }

            return true;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:34,代码来源:ThisKeywordRecommender.cs


示例2: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     var syntaxTree = context.SyntaxTree;
     return
         context.IsNonAttributeExpressionContext ||
         context.IsDefiniteCastTypeContext ||
         context.IsStatementContext ||
         context.IsGlobalStatementContext ||
         context.IsObjectCreationTypeContext ||
         context.IsGenericTypeArgumentContext ||
         context.IsEnumBaseListContext ||
         context.IsIsOrAsTypeContext ||
         context.IsLocalVariableDeclarationContext ||
         context.IsFixedVariableDeclarationContext ||
         context.IsParameterTypeContext ||
         context.IsPossibleLambdaOrAnonymousMethodParameterTypeContext ||
         context.IsImplicitOrExplicitOperatorTypeContext ||
         context.IsPrimaryFunctionExpressionContext ||
         context.IsCrefContext ||
         syntaxTree.IsAfterKeyword(position, SyntaxKind.ConstKeyword, cancellationToken) ||
         syntaxTree.IsAfterKeyword(position, SyntaxKind.StackAllocKeyword, cancellationToken) ||
         context.IsDelegateReturnTypeContext ||
         syntaxTree.IsGlobalMemberDeclarationContext(position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
         context.IsMemberDeclarationContext(
             validModifiers: SyntaxKindSet.AllMemberModifiers,
             validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations,
             canBePartial: false,
             cancellationToken: cancellationToken);
 }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:29,代码来源:SByteKeywordRecommender.cs


示例3: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         context.IsStatementContext ||
         context.IsGlobalStatementContext ||
         context.IsNonAttributeExpressionContext;
 }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:7,代码来源:UncheckedKeywordRecommender.cs


示例4: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         IsInstanceExpressionOrStatement(context) ||
         IsExtensionMethodParameterContext(context, cancellationToken) ||
         IsConstructorInitializerContext(context);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:ThisKeywordRecommender.cs


示例5: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         context.IsGlobalStatementContext ||
         IsMemberDeclarationContext(context, cancellationToken) ||
         IsTypeDeclarationContext(context, cancellationToken);
 }
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:PartialKeywordRecommender.cs


示例6: GetSymbolsForCurrentContext

        private static IEnumerable<ISymbol> GetSymbolsForCurrentContext(
            CSharpSyntaxContext context,
            bool filterOutOfScopeLocals,
            CancellationToken cancellationToken)
        {
            if (context.IsGlobalStatementContext)
            {
                // Script and interactive
                return GetSymbolsForGlobalStatementContext(context, cancellationToken);
            }
            else if (context.IsAnyExpressionContext || context.IsStatementContext)
            {
                return GetSymbolsForExpressionOrStatementContext(context, filterOutOfScopeLocals, cancellationToken);
            }
            else if (context.IsTypeContext || context.IsNamespaceContext)
            {
                return GetSymbolsForTypeOrNamespaceContext(context, cancellationToken);
            }
            else if (context.IsLabelContext)
            {
                return GetSymbolsForLabelContext(context, cancellationToken);
            }
            else if (context.IsTypeArgumentOfConstraintContext)
            {
                return GetSymbolsForTypeArgumentOfConstraintClause(context, cancellationToken);
            }
            else if (context.IsDestructorTypeContext)
            {
                return SpecializedCollections.SingletonEnumerable(context.SemanticModel.GetDeclaredSymbol(context.ContainingTypeOrEnumDeclaration, cancellationToken));
            }

            return SpecializedCollections.EmptyEnumerable<ISymbol>();
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:33,代码来源:CSharpRecommendationService.cs


示例7: IsValidContext

        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.IsAnyExpressionContext || context.IsStatementContext)
            {
                foreach (var node in context.LeftToken.GetAncestors<SyntaxNode>())
                {
					if (node.IsAnyLambdaOrAnonymousMethod())
                    {
                        return true;
                    }

                    if (node.IsKind(SyntaxKind.QueryExpression))
                    {
                        return false;
                    }

                    if (node.IsKind(SyntaxKind.LockStatement))
                    {
                        var lockStatement = (LockStatementSyntax)node;
                        if (lockStatement.Statement != null &&
                            !lockStatement.Statement.IsMissing &&
                            lockStatement.Statement.Span.Contains(position))
                        {
                            return false;
                        }
                    }
                }

                return true;
            }

            return false;
        }
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:33,代码来源:AwaitKeywordRecommender.cs


示例8: IsValidContext

        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.IsStatementContext ||
                context.IsGlobalStatementContext)
            {
                return true;
            }

            // do {
            // } |

            // do {
            // } w|

            // Note: the case of
            //   do
            //     Foo();
            //   |
            // is taken care of in the IsStatementContext case.

            var token = context.TargetToken;

            if (token.Kind() == SyntaxKind.CloseBraceToken &&
                token.Parent.IsKind(SyntaxKind.Block) &&
                token.Parent.IsParentKind(SyntaxKind.DoStatement))
            {
                return true;
            }

            return false;
        }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:31,代码来源:WhileKeywordRecommender.cs


示例9: IsValidContext

        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            // cases:
            //   join a in expr o1 |
            //   join a in expr o1 e|

            var token = context.TargetToken;

            var join = token.GetAncestor<JoinClauseSyntax>();
            if (join == null)
            {
                return false;
            }

            var lastToken = join.LeftExpression.GetLastToken(includeSkipped: true);

            // join a in expr |
            if (join.LeftExpression.Width() > 0 &&
                token == lastToken)
            {
                return true;
            }

            return false;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:EqualsKeywordRecommender.cs


示例10: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         IsValidContextForAccessor(context) ||
         IsValidContextForType(context, cancellationToken) ||
         IsValidContextForMember(context, cancellationToken);
 }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:7,代码来源:ProtectedKeywordRecommender.cs


示例11: IsValidContextInForEachClause

        private bool IsValidContextInForEachClause(CSharpSyntaxContext context)
        {
            // cases:
            //   foreach (var v |
            //   foreach (var v i|
            //   foreach (var (x, y) |

            var token = context.TargetToken;

            if (token.Kind() == SyntaxKind.IdentifierToken)
            {
                var statement = token.Parent as ForEachStatementSyntax;
                if (statement != null && token == statement.Identifier)
                {
                    return true;
                }
            }
            else if (token.Kind() == SyntaxKind.CloseParenToken)
            {
                var statement = token.GetAncestor<ForEachComponentStatementSyntax>();
                if (statement != null && token.Span.End == statement.VariableComponent.Span.End)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:28,代码来源:InKeywordRecommender.cs


示例12: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         context.IsStatementContext ||
         context.TargetToken.IsAfterYieldKeyword() ||
         IsAttributeContext(context, cancellationToken);
 }
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:ReturnKeywordRecommender.cs


示例13: IsMemberDeclarationContext

 private static bool IsMemberDeclarationContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         context.TargetToken.IsUnsafeContext() &&
        (context.SyntaxTree.IsGlobalMemberDeclarationContext(context.Position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
        context.IsMemberDeclarationContext(validModifiers: s_validModifiers, validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken));
 }
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:FixedKeywordRecommender.cs


示例14: IsInBreakableConstructContext

        private static bool IsInBreakableConstructContext(CSharpSyntaxContext context)
        {
            if (!context.IsStatementContext)
            {
                return false;
            }

            // allowed if we're inside a loop/switch construct.

            var token = context.LeftToken;
            foreach (var v in token.GetAncestors<SyntaxNode>())
            {
                if (v.IsAnyLambdaOrAnonymousMethod())
                {
                    // if we hit a lambda while walking up, then we can't
                    // 'continue' any outer loops.
                    return false;
                }

                if (v.IsBreakableConstruct())
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:27,代码来源:BreakKeywordRecommender.cs


示例15: IsValidContext

        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            // cases:
            //   group e |
            //   group e b|

            var token = context.LeftToken;
            var group = token.GetAncestor<GroupClauseSyntax>();

            if (group == null)
            {
                return false;
            }

            var lastToken = group.GroupExpression.GetLastToken(includeSkipped: true);

            // group e |
            if (!token.IntersectsWith(position) &&
                token == lastToken)
            {
                return true;
            }

            // group e b|
            if (token.IntersectsWith(position) &&
                token.Kind() == SyntaxKind.IdentifierToken &&
                token.GetPreviousToken(includeSkipped: true) == lastToken)
            {
                return true;
            }

            return false;
        }
开发者ID:robbert229,项目名称:omnisharp-roslyn,代码行数:33,代码来源:ByKeywordRecommender.cs


示例16: CheckResultAsync

 private async Task CheckResultAsync(bool absent, int position, CSharpSyntaxContext context, SemanticModel semanticModel, int? matchPriority)
 {
     if (absent)
     {
         if (RecommendKeywordsAsync != null)
         {
             var keywords = await RecommendKeywordsAsync(position, context);
             Assert.True(keywords == null || !keywords.Any(), "Keywords must be null or empty.");
         }
     }
     else
     {
         if (RecommendKeywordsAsync == null)
         {
             Assert.False(true, "No recommender for: " + keywordText);
         }
         else
         {
             var result = (await RecommendKeywordsAsync(position, context)).Single();
             Assert.NotNull(result);
             Assert.Equal(keywordText, result.Keyword);
             if (matchPriority != null)
             {
                 Assert.Equal(matchPriority.Value, result.MatchPriority);
             }
         }
     }
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:28,代码来源:RecommenderTests.cs


示例17: IsValidContextInJoinClause

        private bool IsValidContextInJoinClause(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            var token = context.TargetToken;

            if (token.Kind() == SyntaxKind.IdentifierToken)
            {
                var joinClause = token.Parent.FirstAncestorOrSelf<JoinClauseSyntax>();
                if (joinClause != null)
                {
                    // case:
                    //   join int x |
                    if (token == joinClause.Identifier && joinClause.Type != null)
                    {
                        return true;
                    }

                    // case:
                    //   join x |
                    if (joinClause.Type != null &&
                        joinClause.Type.IsKind(SyntaxKind.IdentifierName) &&
                        token == ((IdentifierNameSyntax)joinClause.Type).Identifier &&
                        !joinClause.Type.IsPotentialTypeName(context.SemanticModel, cancellationToken))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:30,代码来源:InKeywordRecommender.cs


示例18: IsValidContext

 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         IsValidContextForJoin(context) ||
         IsValidContextForSelect(context) ||
         IsValidContextForGroup(context);
 }
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:7,代码来源:IntoKeywordRecommender.cs


示例19: IsValidContextForGroup

        private bool IsValidContextForGroup(CSharpSyntaxContext context)
        {
            var token = context.TargetToken;

            var group = token.GetAncestor<GroupClauseSyntax>();
            if (group == null)
            {
                return false;
            }

            if (group.ByExpression.Width() == 0 ||
                group.GroupExpression.Width() == 0)
            {
                return false;
            }

            var lastToken = group.ByExpression.GetLastToken(includeSkipped: true);

            if (lastToken == token)
            {
                return true;
            }

            return false;
        }
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:25,代码来源:IntoKeywordRecommender.cs


示例20: IsValidContextInFromClause

        private bool IsValidContextInFromClause(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            var token = context.TargetToken;

            if (token.Kind() == SyntaxKind.IdentifierToken)
            {
                // case:
                //   from x |
                if (token.GetPreviousToken(includeSkipped: true).IsKindOrHasMatchingText(SyntaxKind.FromKeyword))
                {
                    var typeSyntax = token.Parent as TypeSyntax;
                    if (!typeSyntax.IsPotentialTypeName(context.SemanticModel, cancellationToken))
                    {
                        return true;
                    }
                }

                var fromClause = token.Parent as FromClauseSyntax;
                if (fromClause != null)
                {
                    // case:
                    //   from int x |
                    if (token == fromClause.Identifier && fromClause.Type != null)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:31,代码来源:InKeywordRecommender.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Symbols.ArrayTypeSymbol类代码示例发布时间:2022-05-26
下一篇:
C# ExpressionEvaluator.EENamedTypeSymbol类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap