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


C# ContextQuery.CSharpSyntaxContext类代码示例

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


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


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