protected override Expression VisitBinary(BinaryExpression binary)
            {
                if ((binary.NodeType == ExpressionType.Assign) &&
                    (binary.Left.NodeType == ExpressionType.Parameter) &&
                    !JoinedAssignedVariables.Contains(binary.Left) &&
                    !_assignedAssignments.Contains(binary))
                {
                    var variable = (ParameterExpression)binary.Left;

                    if (VariableHasNotYetBeenAccessed(variable))
                    {
                        if (_constructs.Any())
                        {
                            _constructsByAssignment.Add(binary, _constructs.Peek());
                        }

                        JoinedAssignments.Add(binary);
                        _accessedVariables.Add(variable);
                        JoinedAssignedVariables.Add(variable);
                    }

                    AddAssignmentIfAppropriate(binary.Right);
                }

                return(base.VisitBinary(binary));
            }
        private static string TranslateAddition(BinaryExpression binary, TranslationContext context)
        {
            if ((binary.Left.Type != typeof(string)) && (binary.Right.Type != typeof(string)))
            {
                return(Translate(binary, context));
            }

            return(new[] { binary.Left, binary.Right }.ToStringConcatenation(context));
        }
        private static string Translate(BinaryExpression binary, TranslationContext context)
        {
            var left      = TranslateOperand(binary.Left, context);
            var @operator = GetOperator(binary);
            var right     = TranslateOperand(binary.Right, context);

            var operation = $"{left} {@operator} {right}";

            return(AdjustForCheckedOperatorIfAppropriate(binary.NodeType, operation));
        }
        private static bool IsNotRelevantBinary(Expression condition, out BinaryExpression binary)
        {
            switch (condition.NodeType)
            {
            case ExpressionType.And:
            case ExpressionType.AndAlso:
            case ExpressionType.Or:
            case ExpressionType.OrElse:
                binary = (BinaryExpression)condition;
                return(false);
            }

            binary = null;
            return(true);
        }
예제 #5
0
        private static bool UseFullTypeName(BinaryExpression assignment)
        {
            if ((assignment.Left.Type != assignment.Right.Type) ||
                (assignment.Right.NodeType == ExpressionType.Lambda))
            {
                return(true);
            }

            if (assignment.Right.NodeType != ExpressionType.Conditional)
            {
                return(false);
            }

            var conditional = (ConditionalExpression)assignment.Right;

            return(conditional.IfTrue.Type != conditional.IfFalse.Type);
        }
        private static bool TryGetStandaloneBoolean(BinaryExpression comparison, out StandaloneBoolean standalone)
        {
            if (IsBooleanConstant(comparison.Right))
            {
                standalone = new StandaloneBoolean(comparison.Left, comparison.NodeType, comparison.Right);
                return(true);
            }

            if (IsBooleanConstant(comparison.Left))
            {
                standalone = new StandaloneBoolean(comparison.Right, comparison.NodeType, comparison.Left);
                return(true);
            }

            standalone = null;
            return(false);
        }
예제 #7
0
 private static string GetVariableTypeName(BinaryExpression assignment)
 {
     return(UseFullTypeName(assignment) ? assignment.Left.Type.GetFriendlyName() : "var");
 }
 private static string TranslateEqualityComparison(BinaryExpression comparison, TranslationContext context)
 {
     return(TryGetStandaloneBoolean(comparison, out var standalone)
         ? Translate(standalone, context)
         : Translate(comparison, context));
 }