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


C# ExpressionSyntax.IsParentKind方法代码示例

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


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

示例1: IsAmbiguousCast

        private static bool IsAmbiguousCast(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
        {
            // Can't simplify a type name in a cast expression if it would then cause the cast to be
            // parsed differently.  For example:  (Foo::Bar)+1  is a cast.  But if that simplifies to
            // (Bar)+1  then that's an arithmetic expression.
            if (expression.IsParentKind(SyntaxKind.CastExpression))
            {
                var castExpression = (CastExpressionSyntax)expression.Parent;
                if (castExpression.Type == expression)
                {
                    var newCastExpression = castExpression.ReplaceNode(castExpression.Type, simplifiedNode);
                    var reparsedCastExpression = SyntaxFactory.ParseExpression(newCastExpression.ToString());

                    if (!reparsedCastExpression.IsKind(SyntaxKind.CastExpression))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:22,代码来源:ExpressionSyntaxExtensions.cs

示例2: IsNonNameSyntaxInUsingDirective

 private static bool IsNonNameSyntaxInUsingDirective(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
 {
     return
         expression.IsParentKind(SyntaxKind.UsingDirective) &&
         !(simplifiedNode is NameSyntax);
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:6,代码来源:ExpressionSyntaxExtensions.cs

示例3: IsNextExpressionPotentiallyAmbiguous

        private static bool IsNextExpressionPotentiallyAmbiguous(ExpressionSyntax node)
        {
            ExpressionSyntax nextExpression = null;

            if (node.IsParentKind(SyntaxKind.Argument))
            {
                var argument = (ArgumentSyntax)node.Parent;
                var argumentList = argument.Parent as ArgumentListSyntax;
                if (argumentList != null)
                {
                    var argumentIndex = argumentList.Arguments.IndexOf(argument);
                    if (argumentIndex >= 0 && argumentIndex < argumentList.Arguments.Count - 1)
                    {
                        nextExpression = argumentList.Arguments[argumentIndex + 1].Expression;
                    }
                }
            }
            else if (node.Parent is InitializerExpressionSyntax)
            {
                var initializer = (InitializerExpressionSyntax)node.Parent;
                var expressionIndex = initializer.Expressions.IndexOf(node);
                if (expressionIndex >= 0 && expressionIndex < initializer.Expressions.Count - 1)
                {
                    nextExpression = initializer.Expressions[expressionIndex + 1];
                }
            }

            if (nextExpression == null ||
                !nextExpression.IsKind(SyntaxKind.GreaterThanExpression))
            {
                return false;
            }

            var greaterThanExpression = (BinaryExpressionSyntax)nextExpression;

            return IsSimpleOrDottedName(greaterThanExpression.Left)
                && greaterThanExpression.Right.IsKind(SyntaxKind.ParenthesizedExpression);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:38,代码来源:ParenthesizedExpressionSyntaxExtensions.cs

示例4: IsPreviousExpressionPotentiallyAmbiguous

        private static bool IsPreviousExpressionPotentiallyAmbiguous(ExpressionSyntax node)
        {
            ExpressionSyntax previousExpression = null;

            if (node.IsParentKind(SyntaxKind.Argument))
            {
                var argument = (ArgumentSyntax)node.Parent;
                var argumentList = argument.Parent as ArgumentListSyntax;
                if (argumentList != null)
                {
                    var argumentIndex = argumentList.Arguments.IndexOf(argument);
                    if (argumentIndex > 0)
                    {
                        previousExpression = argumentList.Arguments[argumentIndex - 1].Expression;
                    }
                }
            }
            else if (node.Parent is InitializerExpressionSyntax)
            {
                var initializer = (InitializerExpressionSyntax)node.Parent;
                var expressionIndex = initializer.Expressions.IndexOf(node);
                if (expressionIndex > 0)
                {
                    previousExpression = initializer.Expressions[expressionIndex - 1];
                }
            }

            if (previousExpression == null ||
                !previousExpression.IsKind(SyntaxKind.LessThanExpression))
            {
                return false;
            }

            var lessThanExpression = (BinaryExpressionSyntax)previousExpression;

            return IsSimpleOrDottedName(lessThanExpression.Left)
                && IsSimpleOrDottedName(lessThanExpression.Right);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:38,代码来源:ParenthesizedExpressionSyntaxExtensions.cs

示例5: IsDynamicInvocation

        private static bool IsDynamicInvocation(ExpressionSyntax castExpression, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (castExpression.IsParentKind(SyntaxKind.Argument) &&
                castExpression.Parent.Parent.IsKind(SyntaxKind.ArgumentList, SyntaxKind.BracketedArgumentList) &&
                castExpression.Parent.Parent.Parent.IsKind(SyntaxKind.InvocationExpression, SyntaxKind.ElementAccessExpression))
            {
                var typeInfo = default(TypeInfo);

                if (castExpression.Parent.Parent.IsParentKind(SyntaxKind.InvocationExpression))
                {
                    typeInfo = semanticModel.GetTypeInfo((InvocationExpressionSyntax)castExpression.Parent.Parent.Parent, cancellationToken);
                }

                if (castExpression.Parent.Parent.IsParentKind(SyntaxKind.ElementAccessExpression))
                {
                    typeInfo = semanticModel.GetTypeInfo((ElementAccessExpressionSyntax)castExpression.Parent.Parent.Parent, cancellationToken);
                }

                if (typeInfo.Type != null && typeInfo.Type.Kind == SymbolKind.DynamicType)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:26,代码来源:CastExpressionSyntaxExtensions.cs

示例6: CollectMemberAccessExpressionTerms

        private static void CollectMemberAccessExpressionTerms(int position, ExpressionSyntax expression, IList<string> terms, ref ExpressionType expressionType)
        {
            var flags = ExpressionType.Invalid;

            // These operators always have a RHS of a name node, which we know would
            // "claim" to be a valid term, but is not valid without the LHS present.
            // So, we don't bother collecting anything from the RHS...
            var memberAccess = (MemberAccessExpressionSyntax)expression;
            CollectExpressionTerms(position, memberAccess.Expression, terms, ref flags);

            // If the LHS says it's a valid term, then we add it ONLY if our PARENT
            // is NOT another dot/arrow.  This allows the expression 'a.b.c.d' to
            // add both 'a.b.c.d' and 'a.b.c', but not 'a.b' and 'a'.
            if ((flags & ExpressionType.ValidTerm) == ExpressionType.ValidTerm &&
                !expression.IsParentKind(SyntaxKind.MemberAccessExpression) &&
                !expression.IsParentKind(SyntaxKind.PointerMemberAccessExpression))
            {
                terms.Add(ConvertToString(memberAccess.Expression));
            }

            // And this expression itself is a valid term if the LHS is a valid
            // expression, and its PARENT is not an invocation.
            if ((flags & ExpressionType.ValidExpression) == ExpressionType.ValidExpression &&
                !expression.IsParentKind(SyntaxKind.InvocationExpression))
            {
                expressionType = ExpressionType.ValidTerm;
            }
            else
            {
                expressionType = ExpressionType.ValidExpression;
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:32,代码来源:ProximityExpressionsGetterTestFile.cs


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