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


C# CSharpSyntaxNode.IsKind方法代码示例

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


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

示例1: CreateSpeculative

        /// <summary>
        /// Creates a speculative SemanticModel for an initializer node (field initializer, constructor initializer, or parameter default value)
        /// that did not appear in the original source code.
        /// </summary>
        internal static InitializerSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, Symbol owner, CSharpSyntaxNode syntax, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(syntax != null);
            Debug.Assert(syntax.IsKind(SyntaxKind.EqualsValueClause) || syntax.IsKind(SyntaxKind.ThisConstructorInitializer) || syntax.IsKind(SyntaxKind.BaseConstructorInitializer));
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return new InitializerSemanticModel(parentSemanticModel.Compilation, syntax, owner, rootBinder, parentSemanticModel, position);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:InitializerSemanticModel.cs

示例2: AppendImplicitReturn

        // insert the implicit "return" statement at the end of the method body
        // Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
        // ones are going to have sequence points.
        internal static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax = null)
        {
            Debug.Assert(body != null);
            Debug.Assert(method != null);

            if (syntax == null)
            {
                syntax = body.Syntax;
            }

            Debug.Assert(body.WasCompilerGenerated || syntax.IsKind(SyntaxKind.Block) || syntax.IsKind(SyntaxKind.ArrowExpressionClause));

            BoundStatement ret = method.IsIterator
                ? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
                : BoundReturnStatement.Synthesized(syntax, null);

            // Implicitly added return for async method does not need sequence points since lowering would add one.
            if (syntax.IsKind(SyntaxKind.Block) && !method.IsAsync)
            {
                var blockSyntax = (BlockSyntax)syntax;

                ret = new BoundSequencePointWithSpan(
                    blockSyntax,
                    ret,
                    blockSyntax.CloseBraceToken.Span)
                { WasCompilerGenerated = true };
            }

            switch (body.Kind)
            {
                case BoundKind.Block:
                    return body.Update(body.Locals, body.Statements.Add(ret));

                default:
                    return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(ret, body));
            }
        }
开发者ID:nemec,项目名称:roslyn,代码行数:40,代码来源:FlowAnalysisPass.cs

示例3: Create

 /// <summary>
 /// Creates a SemanticModel for an autoprop initializer of a named type
 /// </summary>
 internal static InitializerSemanticModel Create(CSharpCompilation compilation, CSharpSyntaxNode syntax, PropertySymbol propertySymbol, Binder rootBinder)
 {
     Debug.Assert(syntax.IsKind(SyntaxKind.PropertyDeclaration));
     return new InitializerSemanticModel(compilation, syntax, propertySymbol, rootBinder);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:InitializerSemanticModel.cs

示例4: AppendImplicitReturn

        // insert the implicit "return" statement at the end of the method body
        // Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
        // ones are going to have sequence points.
        internal static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax = null)
        {
            Debug.Assert(body != null);
            Debug.Assert(method != null);

            if (syntax == null)
            {
                syntax = body.Syntax;
            }

            Debug.Assert(body.WasCompilerGenerated || syntax.IsKind(SyntaxKind.Block) || syntax.IsKind(SyntaxKind.ArrowExpressionClause));

            BoundStatement ret = method.IsIterator
                ? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
                : BoundReturnStatement.Synthesized(syntax, RefKind.None, null);

            return body.Update(body.Locals, body.LocalFunctions, body.Statements.Add(ret));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:21,代码来源:FlowAnalysisPass.cs

示例5: IsValidForHoisting

        private static bool IsValidForHoisting(ParameterSyntax parameter, CSharpSyntaxNode node)
        {
            if (node.IsKind(SyntaxKind.IdentifierName))
            {
                var identifier = (IdentifierNameSyntax)node;
                if (identifier.Identifier.Text == parameter.Identifier.Text)
                {
                    return true;
                }
            }
            else if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression))
            {
                var memberAccess = (MemberAccessExpressionSyntax)node;
                var lhs = memberAccess.Expression;
                return IsValidForHoisting(parameter, lhs);
            }

            return false;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:19,代码来源:ExpressionRewriter.cs

示例6: AssertIsLambdaScopeSyntax

        private static void AssertIsLambdaScopeSyntax(CSharpSyntaxNode syntaxOpt)
        {
            // See C# specification, chapter 3.7 Scopes.

            // static lambdas technically have the class scope so the scope syntax is null 
            if (syntaxOpt == null)
            {
                return;
            }

            // block:
            if (syntaxOpt.IsKind(SyntaxKind.Block))
            {
                return;
            }

            // switch block:
            if (syntaxOpt.IsKind(SyntaxKind.SwitchStatement))
            {
                return;
            }

            // expression-bodied member:
            if (syntaxOpt.IsKind(SyntaxKind.ArrowExpressionClause))
            {
                return;
            }

            // catch clause (including filter):
            if (syntaxOpt.IsKind(SyntaxKind.CatchClause))
            {
                return;
            }

            // class/struct containing a field/property with a declaration expression
            if (syntaxOpt.IsKind(SyntaxKind.ClassDeclaration) || syntaxOpt.IsKind(SyntaxKind.StructDeclaration))
            {
                return;
            }

            // lambda in a let clause, 
            // e.g. from item in array let a = new Func<int>(() => item)
            if (syntaxOpt.IsKind(SyntaxKind.LetClause))
            {
                return;
            }

            if (IsStatementWithEmbeddedStatementBody(syntaxOpt.Kind()))
            {
                return;
            }

            // lambda bodies:
            if (SyntaxFacts.IsLambdaBody(syntaxOpt))
            {
                return;
            }

            // lambda in a ctor initializer that refers to a ctor parameter
            if (syntaxOpt.IsKind(SyntaxKind.ConstructorDeclaration))
            {
                return;
            }

            // TODO: EE expression
            if (syntaxOpt is ExpressionSyntax && syntaxOpt.Parent.Parent == null)
            {
                return;
            }

            throw ExceptionUtilities.UnexpectedValue(syntaxOpt.Kind());
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:72,代码来源:LambdaFrame.cs


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