當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryExpressionSyntax.WithLeft方法代碼示例

本文整理匯總了C#中BinaryExpressionSyntax.WithLeft方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryExpressionSyntax.WithLeft方法的具體用法?C# BinaryExpressionSyntax.WithLeft怎麽用?C# BinaryExpressionSyntax.WithLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinaryExpressionSyntax的用法示例。


在下文中一共展示了BinaryExpressionSyntax.WithLeft方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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

示例3: TransformExpression

 private static BinaryExpressionSyntax TransformExpression(BinaryExpressionSyntax binaryExpression)
 {
     var newLeft = binaryExpression.Right.WithTriviaFrom(binaryExpression.Left);
     var newRight = binaryExpression.Left.WithTriviaFrom(binaryExpression.Right);
     return binaryExpression.WithLeft(newLeft).WithRight(newRight).WithOperatorToken(GetCorrectOperatorToken(binaryExpression.OperatorToken));
 }
開發者ID:peteri,項目名稱:StyleCopAnalyzers,代碼行數:6,代碼來源:SA1131CodeFixProvider.cs


注:本文中的BinaryExpressionSyntax.WithLeft方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。