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


C# BinaryExpressionSyntax.WithRight方法代码示例

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


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

示例1: VisitBinaryExpression

        public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
        {
            node = node.WithLeft((ExpressionSyntax)base.Visit((SyntaxNode)node.Left));
            node = node.WithRight((ExpressionSyntax)base.Visit((SyntaxNode)node.Right));

            switch (node.Left.Kind)
            {
                case SyntaxKind.CharacterLiteralExpression:
                case SyntaxKind.FalseLiteralExpression:
                case SyntaxKind.NumericLiteralExpression:
                case SyntaxKind.StringLiteralExpression:
                case SyntaxKind.TrueLiteralExpression:
                    break;
                default:
                    return node;
            }
            switch (node.Right.Kind)
            {
                case SyntaxKind.CharacterLiteralExpression:
                case SyntaxKind.FalseLiteralExpression:
                case SyntaxKind.NumericLiteralExpression:
                case SyntaxKind.StringLiteralExpression:
                case SyntaxKind.TrueLiteralExpression:
                    break;
                default:
                    return node;
            }

            dynamic nodeValue = (dynamic)session.Execute(node.ToFullString());
            if (nodeValue is String)
            {
                return Syntax.LiteralExpression(SyntaxKind.StringLiteralExpression, Syntax.Literal(nodeValue));
            }
            else if (nodeValue is Char)
            {
                return Syntax.LiteralExpression(SyntaxKind.CharacterLiteralExpression, Syntax.Literal(nodeValue));
            }
            else if (nodeValue is Boolean)
            {
                if (nodeValue == true)
                {
                    return Syntax.LiteralExpression(SyntaxKind.TrueLiteralExpression, Syntax.Token(SyntaxKind.TrueKeyword));
                }
                else
                {
                    return Syntax.LiteralExpression(SyntaxKind.FalseLiteralExpression, Syntax.Token(SyntaxKind.FalseKeyword));
                }
            }
            return Syntax.LiteralExpression(SyntaxKind.NumericLiteralExpression, Syntax.Literal(nodeValue));
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:50,代码来源:CondenseLiteralsRewriter.cs

示例2: VisitBinaryExpression

        public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
        {
            Tristate leftState = _expressionEvaluator.EvaluateExpression(node.Left);
            Tristate rightState = _expressionEvaluator.EvaluateExpression(node.Right);

            var left = (ExpressionSyntax)node.Left.Accept(this);
            var right = (ExpressionSyntax)node.Right.Accept(this);

            if (node.Left != left)
            {
                node = node.WithLeft(left);
            }

            if (node.Right != right)
            {
                node = node.WithRight(right);
            }

            if (leftState != Tristate.Varying && rightState != Tristate.Varying)
            {
                return node;
            }

            ExpressionSyntax newExpression = null;

            if (node.Kind() == SyntaxKind.LogicalAndExpression)
            {
                if (leftState == Tristate.True)
                {
                    // true && varying == varying
                    newExpression = right;
                }
                else if (rightState == Tristate.True)
                {
                    // varying && true == varying
                    newExpression = left;
                }
            }
            else if (node.Kind() == SyntaxKind.LogicalOrExpression)
            {
                if (leftState == Tristate.False)
                {
                    // false || varying == varying
                    newExpression = right;
                }
                else if (rightState == Tristate.False)
                {
                    // varying || false == varying
                    newExpression = left;
                }
            }

            if (newExpression != null)
            {
                return newExpression
                    .WithLeadingTrivia(node.GetLeadingTrivia())
                    .WithTrailingTrivia(node.GetTrailingTrivia());
            }

            return node;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:61,代码来源:PreprocessorExpressionSimplifier.cs


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