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


C# SyntaxNode.IsKind方法代码示例

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


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

示例1: AddAnchorIndentationOperations

            public override void AddAnchorIndentationOperations(List<AnchorIndentationOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<AnchorIndentationOperation> nextOperation)
            {
                if (node.IsKind(SyntaxKind.SimpleLambdaExpression) || node.IsKind(SyntaxKind.ParenthesizedLambdaExpression) || node.IsKind(SyntaxKind.AnonymousMethodExpression))
                {
                    return;
                }

                nextOperation.Invoke(list);
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:9,代码来源:CSharpMethodExtractor.FormattingProvider.cs

示例2: IsCandidate

 protected override bool IsCandidate(SyntaxNode node, Diagnostic diagnostic)
 {
     return node.IsKind(SyntaxKind.IdentifierName) ||
            node.IsKind(SyntaxKind.MethodDeclaration) ||
            node.IsKind(SyntaxKind.InvocationExpression) ||
            node.IsKind(SyntaxKind.CastExpression) ||
            node is LiteralExpressionSyntax ||
            node is SimpleNameSyntax ||
            node is ExpressionSyntax;
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:10,代码来源:GenerateMethodCodeFixProvider.cs

示例3: FieldOrPropertyInitializer

        public FieldOrPropertyInitializer(FieldSymbol fieldOpt, SyntaxNode syntax, int precedingInitializersLength)
        {
            Debug.Assert(syntax.IsKind(SyntaxKind.EqualsValueClause) && fieldOpt != null || syntax is StatementSyntax);

            FieldOpt = fieldOpt;
            Syntax = syntax.GetReference();
            PrecedingInitializersLength = precedingInitializersLength;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:8,代码来源:FieldOrPropertyInitializer.cs

示例4: GetTargetNode

        protected override SyntaxNode GetTargetNode(SyntaxNode node)
        {
            if (node.IsKind(SyntaxKind.MemberBindingExpression))
            {
                var nameNode = node.ChildNodes().FirstOrDefault(n => n.IsKind(SyntaxKind.IdentifierName));
                if (nameNode != null)
                {
                    return nameNode;
                }
            }

            return base.GetTargetNode(node);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:GenerateVariableCodeFixProvider.cs

示例5: GetCodeFixAsync

        protected override async Task<CodeAction> GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken)
        {
            // Check if node is return statement
            if (!node.IsKind(SyntaxKind.ReturnStatement))
            {
                return null;
            }

            var returnStatement = node as ReturnStatementSyntax;
            var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            ITypeSymbol methodReturnType;
            if (!TryGetMethodReturnType(node, model, cancellationToken, out methodReturnType))
            {
                return null;
            }

            ITypeSymbol returnExpressionType;
            if (!TryGetExpressionType(model, returnStatement.Expression, out returnExpressionType))
            {
                return null;
            }

            var typeArguments = methodReturnType.GetAllTypeArguments();

            var shouldOfferYieldReturn = typeArguments.Length != 1 ?
                IsCorrectTypeForYieldReturn(returnExpressionType, methodReturnType, model) :
                IsCorrectTypeForYieldReturn(typeArguments.Single(), returnExpressionType, methodReturnType, model);

            if (!shouldOfferYieldReturn)
            {
                return null;
            }

            var yieldStatement = SyntaxFactory.YieldStatement(
                    SyntaxKind.YieldReturnStatement,
                    returnStatement.Expression)
                .WithAdditionalAnnotations(Formatter.Annotation);

            root = root.ReplaceNode(returnStatement, yieldStatement);
            return new MyCodeAction(CSharpFeaturesResources.ChangeToYieldReturn, document.WithSyntaxRoot(root));
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:42,代码来源:CSharpAddYieldCodeFixProvider.cs

示例6: IsNamedArgumentName

        /// <summary>
        /// Is the node the name of a named argument of an invocation, object creation expression, 
        /// constructor initializer, or element access, but not an attribute.
        /// </summary>
        public static bool IsNamedArgumentName(SyntaxNode node)
        {
            // An argument name is an IdentifierName inside a NameColon, inside an Argument, inside an ArgumentList, inside an
            // Invocation, ObjectCreation, ObjectInitializer, or ElementAccess.

            if (!node.IsKind(IdentifierName))
                return false;

            var parent1 = node.Parent;
            if (parent1 == null || !parent1.IsKind(NameColon))
                return false;

            var parent2 = parent1.Parent;
            if (parent2 == null || !(parent2.IsKind(Argument) || parent2.IsKind(AttributeArgument)))
                return false;

            var parent3 = parent2.Parent;
            if (parent3 == null || !(parent3 is BaseArgumentListSyntax || parent3.IsKind(AttributeArgumentList)))
                return false;

            var parent4 = parent3.Parent;
            if (parent4 == null)
                return false;

            switch (parent4.Kind())
            {
                case InvocationExpression:
                case ObjectCreationExpression:
                case ObjectInitializerExpression:
                case ElementAccessExpression:
                case Attribute:
                case BaseConstructorInitializer:
                case ThisConstructorInitializer:
                    return true;
                default:
                    return false;
            }
        }
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:42,代码来源:SyntaxFacts.cs

示例7: IsLocalDeclarationStatement

 public bool IsLocalDeclarationStatement(SyntaxNode node)
 {
     return node.IsKind(SyntaxKind.LocalDeclarationStatement);
 }
开发者ID:genlu,项目名称:roslyn,代码行数:4,代码来源:CSharpSyntaxFactsService.cs

示例8: InferTypeForFirstParameterOfLambda

            private ITypeSymbol InferTypeForFirstParameterOfLambda(
                string parameterName,
                SyntaxNode node)
            {
                if (node.IsKind(SyntaxKind.IdentifierName))
                {
                    var identifierName = (IdentifierNameSyntax)node;
                    if (identifierName.Identifier.ValueText.Equals(parameterName) &&
                        SemanticModel.GetSymbolInfo(identifierName.Identifier).Symbol?.Kind == SymbolKind.Parameter)
                    {
                        return InferTypes(identifierName).FirstOrDefault().InferredType;
                    }
                }
                else
                {
                    foreach (var child in node.ChildNodesAndTokens())
                    {
                        if (child.IsNode)
                        {
                            var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
                            if (type != null)
                            {
                                return type;
                            }
                        }
                    }
                }

                return null;
            }
开发者ID:tvsonar,项目名称:roslyn,代码行数:30,代码来源:CSharpTypeInferenceService.TypeInferrer.cs

示例9: IsMethodOrAnonymousFunction

 protected override bool IsMethodOrAnonymousFunction(SyntaxNode node)
 {
     return node.IsKind(SyntaxKind.MethodDeclaration) || node.IsAnyLambdaOrAnonymousMethod();
 }
开发者ID:tvsonar,项目名称:roslyn,代码行数:4,代码来源:CSharpMakeMethodAsynchronousCodeFixProvider.cs

示例10: IsNameOrMemberAccessButNoExpression

        private static bool IsNameOrMemberAccessButNoExpression(SyntaxNode node)
        {
            if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression))
            {
                var memberAccess = (MemberAccessExpressionSyntax)node;

                return memberAccess.Expression.IsKind(SyntaxKind.IdentifierName) ||
                    IsNameOrMemberAccessButNoExpression(memberAccess.Expression);
            }

            return node.IsKind(SyntaxKind.IdentifierName);
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:12,代码来源:ExpressionSyntaxExtensions.cs

示例11: IsInferredAnonymousObjectMemberDeclarator

 public bool IsInferredAnonymousObjectMemberDeclarator(SyntaxNode node)
 {
     return node.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator) &&
         ((AnonymousObjectMemberDeclaratorSyntax)node).NameEquals == null;
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:5,代码来源:CSharpSyntaxFactsService.cs

示例12: AddIndentBlockOperations

            public override void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<IndentBlockOperation> nextOperation)
            {
                // these nodes should be from syntax tree from ITextSnapshot.
                Contract.Requires(node.SyntaxTree != null);
                Contract.Requires(node.SyntaxTree.GetText() != null);

                nextOperation.Invoke(list);

                ReplaceCaseIndentationRules(list, node);

                if (node is BaseParameterListSyntax ||
                    node is TypeArgumentListSyntax ||
                    node is TypeParameterListSyntax ||
                    node.IsKind(SyntaxKind.Interpolation))
                {
                    AddIndentBlockOperations(list, node);
                    return;
                }

                var argument = node as BaseArgumentListSyntax;
                if (argument != null && argument.Parent.Kind() != SyntaxKind.ThisConstructorInitializer)
                {
                    AddIndentBlockOperations(list, argument);
                    return;
                }

                // only valid if the user has started to actually type a constructor initializer
                var constructorInitializer = node as ConstructorInitializerSyntax;
                if (constructorInitializer != null &&
                    constructorInitializer.ArgumentList.OpenParenToken.Kind() != SyntaxKind.None &&
                    !constructorInitializer.ThisOrBaseKeyword.IsMissing)
                {
                    var text = node.SyntaxTree.GetText();

                    // 3 different cases
                    // first case : this or base is the first token on line
                    // second case : colon is the first token on line
                    var colonIsFirstTokenOnLine = !constructorInitializer.ColonToken.IsMissing && constructorInitializer.ColonToken.IsFirstTokenOnLine(text);
                    var thisOrBaseIsFirstTokenOnLine = !constructorInitializer.ThisOrBaseKeyword.IsMissing && constructorInitializer.ThisOrBaseKeyword.IsFirstTokenOnLine(text);

                    if (colonIsFirstTokenOnLine || thisOrBaseIsFirstTokenOnLine)
                    {
                        list.Add(FormattingOperations.CreateRelativeIndentBlockOperation(
                            constructorInitializer.ThisOrBaseKeyword,
                            constructorInitializer.ArgumentList.OpenParenToken.GetNextToken(includeZeroWidth: true),
                            constructorInitializer.ArgumentList.CloseParenToken.GetPreviousToken(includeZeroWidth: true),
                            indentationDelta: 1,
                            option: IndentBlockOption.RelativePosition));
                    }
                    else
                    {
                        // third case : none of them are the first token on the line
                        AddIndentBlockOperations(list, constructorInitializer.ArgumentList);
                    }
                }
            }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:56,代码来源:CSharpIndentationService.cs

示例13: TryGetEffectiveGetterBody

        public static SyntaxNode TryGetEffectiveGetterBody(SyntaxNode declaration)
        {
            if (declaration.IsKind(SyntaxKind.PropertyDeclaration))
            {
                var property = (PropertyDeclarationSyntax)declaration;
                return TryGetEffectiveGetterBody(property.ExpressionBody, property.AccessorList);
            }

            if (declaration.IsKind(SyntaxKind.IndexerDeclaration))
            {
                var indexer = (IndexerDeclarationSyntax)declaration;
                return TryGetEffectiveGetterBody(indexer.ExpressionBody, indexer.AccessorList);
            }

            return null;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:16,代码来源:SyntaxUtilities.cs

示例14: IsParameterlessConstructor

        public static bool IsParameterlessConstructor(SyntaxNode declaration)
        {
            if (!declaration.IsKind(SyntaxKind.ConstructorDeclaration))
            {
                return false;
            }

            var ctor = (ConstructorDeclarationSyntax)declaration;
            return ctor.ParameterList.Parameters.Count == 0;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:10,代码来源:SyntaxUtilities.cs

示例15: IsIteratorMethod

        public static bool IsIteratorMethod(SyntaxNode declaration)
        {
            // lambdas and expression-bodied methods can't be iterators:
            if (!declaration.IsKind(SyntaxKind.MethodDeclaration))
            {
                return false;
            }

            // enumerate statements:
            return declaration.DescendantNodes(n => !(n is ExpressionSyntax))
                   .Any(n => n.IsKind(SyntaxKind.YieldBreakStatement) || n.IsKind(SyntaxKind.YieldReturnStatement));
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:SyntaxUtilities.cs


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