Example #1
0
        protected override Expression VisitBinary(BinaryExpression node)
        {
            using var mc = log?.Enter(LogLevel.LinqExpression, node);

            if (ExpressionTreeHelpers.SupportedComparisons.ContainsKey(node.NodeType))
            {
                foreach (var prop in TypeProperties)
                {
                    if (ExpressionTreeHelpers.IsMatchingMemberValueExpression(node, typeof(T), prop.Name))
                    {
                        object testValue = TranslateValue(prop, ExpressionTreeHelpers.GetValueFromExpression(node, typeof(T), prop.Name));
                        AddClause($"[{TranslateFieldName(prop)}] {ExpressionTreeHelpers.SupportedComparisons[node.NodeType]} '{testValue}' ");
                        return(node);
                    }
                }

                if (node.Left.NodeType == ExpressionType.Call)
                {
                    object testValue = TranslateValue(null, ExpressionTreeHelpers.GetValueFromExpression(node.Right));
                    futureComparisons.Push($"{ExpressionTreeHelpers.SupportedComparisons[node.NodeType]} '{testValue}'");
                }

                return(base.VisitBinary(node));
            }
            else if (node.NodeType == ExpressionType.OrElse || node.NodeType == ExpressionType.Or)
            {
                log?.WriteLine(LogLevel.LinqQuery, $"\t[{node.NodeType}]: {node.Left.NodeType} vs. {node.Right.NodeType}");

                AddClause("(");
                base.Visit(node.Left);
                AddClause(" OR ");
                base.Visit(node.Right);
                AddClause(")");

                return(node);
            }
            else if (node.NodeType == ExpressionType.AndAlso || node.NodeType == ExpressionType.And)
            {
                log?.WriteLine(LogLevel.LinqQuery, $"\t[{node.NodeType}]: {node.Left.NodeType} vs. {node.Right.NodeType}");

                AddClause("(");
                base.Visit(node.Left);
                AddClause(" AND ");
                base.Visit(node.Right);
                AddClause(")");

                return(node);
            }
            else
            {
                log?.WriteLine(LogLevel.LinqQuery, $"ERROR: unsupported comparison: {node.NodeType}");
                return(base.VisitBinary(node));
            }
        }