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


C# SyntaxNode.CSharpKind方法代码示例

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


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

示例1: PositionalSyntaxReference

                public PositionalSyntaxReference(SyntaxNode node)
                {
                    this.tree = node.SyntaxTree;
                    this.textSpan = node.Span;
                    this.kind = node.CSharpKind();

                    System.Diagnostics.Debug.Assert(textSpan.Length > 0);
                }
开发者ID:riversky,项目名称:roslyn,代码行数:8,代码来源:CSharpSyntaxTreeFactoryService.PositionalSyntaxReference.cs

示例2: IsControlBlock

        private bool IsControlBlock(SyntaxNode node)
        {
            var parent = node != null ? node.Parent : null;

            return (node != null && node.CSharpKind() == SyntaxKind.SwitchStatement) ||
                   (parent != null &&
                   (parent.CSharpKind() == SyntaxKind.IfStatement || parent.CSharpKind() == SyntaxKind.ElseClause ||
                    parent.CSharpKind() == SyntaxKind.WhileStatement || parent.CSharpKind() == SyntaxKind.DoStatement ||
                    parent.CSharpKind() == SyntaxKind.ForEachStatement || parent.CSharpKind() == SyntaxKind.UsingStatement ||
                    parent.CSharpKind() == SyntaxKind.ForStatement || parent.CSharpKind() == SyntaxKind.TryStatement ||
                    parent.CSharpKind() == SyntaxKind.CatchClause || parent.CSharpKind() == SyntaxKind.FinallyClause ||
                    parent.CSharpKind() == SyntaxKind.LockStatement));
        }
开发者ID:riversky,项目名称:roslyn,代码行数:13,代码来源:NewLineUserSettingFormattingRule.cs

示例3: SimplifyName

        private static SyntaxNode SimplifyName(
            SyntaxNode node,
            SemanticModel semanticModel,
            OptionSet optionSet,
            CancellationToken cancellationToken)
        {
            SyntaxNode replacementNode;
            TextSpan issueSpan;

            if (node.CSharpKind() == SyntaxKind.QualifiedCref)
            {
                var crefSyntax = (QualifiedCrefSyntax)node;
                CrefSyntax crefReplacement;

                if (!crefSyntax.TryReduceOrSimplifyExplicitName(semanticModel, out crefReplacement, out issueSpan, cancellationToken))
                {
                    return node;
                }

                replacementNode = crefReplacement;
            }
            else
            {
                var expressionSyntax = (ExpressionSyntax)node;
                ExpressionSyntax expressionReplacement;
                if (!expressionSyntax.TryReduceOrSimplifyExplicitName(semanticModel, out expressionReplacement, out issueSpan, optionSet, cancellationToken))
                {
                    return node;
                }

                replacementNode = expressionReplacement;
            }

            node = node.CopyAnnotationsTo(replacementNode).WithAdditionalAnnotations(Formatter.Annotation);
            return node.WithoutAnnotations(Simplifier.Annotation);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:36,代码来源:CSharpNameReducer.cs

示例4: RemoveAllMembers

        private static SyntaxNode RemoveAllMembers(SyntaxNode declaration)
        {
            switch (declaration.CSharpKind())
            {
                case SyntaxKind.CompilationUnit:
                    return ((CompilationUnitSyntax)declaration).WithMembers(default(SyntaxList<MemberDeclarationSyntax>));

                case SyntaxKind.NamespaceDeclaration:
                    return ((NamespaceDeclarationSyntax)declaration).WithMembers(default(SyntaxList<MemberDeclarationSyntax>));

                default:
                    return declaration;
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:14,代码来源:NamespaceGenerator.cs

示例5: ForNode

        // TODO: Work out a way to handle multiple uses within a single invocation, e.g. x * x,
        // as well as making it easier to get usages in execution order, e.g. Foo(x, Bar(x)) should
        // know that Bar is used first.
        internal static ParameterUsage ForNode(SyntaxNode node, SemanticModel model, ISymbol parameter)
        {
            // TODO: Parameter dereferencing, e.g. myParameter.X?
            var symbol = model.GetSymbolInfo(node).Symbol;
            IMethodSymbol invokedMethod = symbol as IMethodSymbol;
            ArgumentListSyntax argumentList = null;
            switch (node.CSharpKind())
            {
                case SyntaxKind.BaseConstructorInitializer:
                case SyntaxKind.ThisConstructorInitializer:
                    argumentList = ((ConstructorInitializerSyntax)node).ArgumentList;
                    break;
                case SyntaxKind.InvocationExpression:
                    var invocation = ((InvocationExpressionSyntax) node);
                    // Handle x.Foo() calls where x is the parameter.
                    if (invocation.Expression != null)
                    {
                        var invocationSymbol = model.GetSymbolInfo(invocation.Expression).Symbol;
                        if (ReferenceEquals(invocationSymbol, parameter))
                        {
                            return new ParameterUsage { UsageNode = node };
                        }
                    }
                    argumentList = ((InvocationExpressionSyntax)node).ArgumentList;
                    break;
                case SyntaxKind.SimpleMemberAccessExpression:
                    // Handle x.Foo calls where x is the parameter.
                    var accessSyntax = (MemberAccessExpressionSyntax) node;
                    var accessSymbol = model.GetSymbolInfo(accessSyntax.Expression).Symbol;
                    return ReferenceEquals(accessSymbol, parameter)
                        ? new ParameterUsage { UsageNode = node } : null;
                case SyntaxKind.ObjectCreationExpression:
                    argumentList = ((ObjectCreationExpressionSyntax)node).ArgumentList;
                    break;
                // TODO: Compound assignment operators?
                default:
                    // Listing all the operators separately is a pain.
                    var binaryExpression = node as BinaryExpressionSyntax;
                    if (binaryExpression == null || invokedMethod == null)
                    {
                        return null;
                    }
                    return ForArgument(binaryExpression.Left, 0, model, invokedMethod, parameter)
                           ?? ForArgument(binaryExpression.Right, 1, model, invokedMethod, parameter);
            }
            if (invokedMethod == null)
            {
                return null;
            }
            if (argumentList != null)
            {
                var arguments = argumentList.Arguments;
                for (int i = 0; i < arguments.Count; i++)
                {
                    var possibleResult = ForArgument(arguments[i].Expression, i, model, invokedMethod, parameter);
                    if (possibleResult != null)
                    {
                        return possibleResult;
                    }
                }
            }

            return null;
        }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:67,代码来源:ParameterUsage.cs

示例6: Visit

            // Visits all SyntaxNodes.
            public override void Visit(SyntaxNode node)
            {
                // If you need to visit all SyntaxNodes of a particular base type that can never
                // appear directly in a syntax tree then this would be the place to check for that.
                // For example, TypeDeclarationSyntax is a base type for all the type declarations (like 
                // ClassDeclarationSyntax and StructDeclarationSyntax) that can appear in a syntax tree.
                if (node is TypeDeclarationSyntax)
                {
                    Results.AppendLine();
                    Results.Append("Visiting ");
                    Results.Append(node.GetType().Name);
                    Results.Append(" (Kind = ");
                    Results.Append(node.CSharpKind().ToString());
                    Results.Append(")");
                }

                base.Visit(node);
            }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:19,代码来源:FAQ.cs

示例7: IsSpecialContainingNode

 private static bool IsSpecialContainingNode(SyntaxNode node)
 {
     return
         node.CSharpKind() == SyntaxKind.IfStatement ||
         node.CSharpKind() == SyntaxKind.ElseClause ||
         node.CSharpKind() == SyntaxKind.WhileStatement ||
         node.CSharpKind() == SyntaxKind.ForStatement ||
         node.CSharpKind() == SyntaxKind.ForEachStatement ||
         node.CSharpKind() == SyntaxKind.UsingStatement ||
         node.CSharpKind() == SyntaxKind.DoStatement ||
         node.CSharpKind() == SyntaxKind.TryStatement ||
         node.CSharpKind() == SyntaxKind.CatchClause ||
         node.CSharpKind() == SyntaxKind.FinallyClause ||
         node.CSharpKind() == SyntaxKind.LabeledStatement;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:15,代码来源:FormattingRangeHelper.cs

示例8: NodeIsNotContainedInLambdaExpression

        /// <summary>
        /// Check that the path from the given node to the top node does not contain a simple or parenthesized lambda expression.
        ///
        /// Note: when topNode is not an ancestor of node, behavior is undefined.
        /// </summary>
        /// <param name="node">Node to check</param>
        /// <param name="topNode">Top level node to check the path to</param>
        /// <returns>true if the node is not contained in a lambda expression</returns>
        private static bool NodeIsNotContainedInLambdaExpression(SyntaxNode node, SyntaxNode topNode)
        {
            while (node != null && node != topNode)
            {
                if (node.CSharpKind() == SyntaxKind.SimpleLambdaExpression ||
                    node.CSharpKind() == SyntaxKind.ParenthesizedLambdaExpression)
                {
                    return false;
                }

                node = node.Parent;
            }

            return true;
        }
开发者ID:modulexcite,项目名称:Asyncifier,代码行数:23,代码来源:CodeRefactoringProvider.cs


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