Ejemplo n.º 1
0
 protected override Expression VisitBinary(BinaryExpression node)
 {
     if (node.Left.Type == typeof(string) && node.Right.Type == typeof(string))
     {
         if (node.NodeType == ExpressionType.Equal)
         {
             var exp = ((LambdaExpression)MakeExpression(s => s.Equals("asdf", _comparer))).Body;
             exp = new ReplacingVisitor(((dynamic)exp).Arguments[0], ((dynamic)node).Left).Visit(exp);
             exp = new ReplacingVisitor(((dynamic)exp).Object, ((dynamic)node).Right).Visit(exp);
             return(exp);
         }
         if (node.NodeType == ExpressionType.NotEqual)
         {
             var exp = ((LambdaExpression)MakeExpression(s => !s.Equals("asdf", _comparer))).Body;
             exp = new ReplacingVisitor(((dynamic)exp).Operand.Arguments[0], ((dynamic)node).Left).Visit(exp);
             exp = new ReplacingVisitor(((dynamic)exp).Operand.Object, ((dynamic)node).Right).Visit(exp);
             return(exp);
         }
     }
     return(base.VisitBinary(node));
 }
Ejemplo n.º 2
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Method.DeclaringType == typeof(string))
            {
                if (node.Method.Name == "Contains")
                {
                    var exp = ((LambdaExpression)MakeExpression(s => s.IndexOf("asdf", _comparer) > -1)).Body;
                    exp =
                        new ReplacingVisitor(((dynamic)exp).Left.Arguments[0], ((dynamic)node).Arguments[0]).Visit(exp);
                    exp = new ReplacingVisitor(((dynamic)exp).Left.Object, ((dynamic)node).Object).Visit(exp);
                    return(exp);
                }
                if (node.Method.Name == "StartsWith")
                {
                    var exp = ((LambdaExpression)MakeExpression(s => s.IndexOf("asdf", _comparer) == 0)).Body;
                    exp =
                        new ReplacingVisitor(((dynamic)exp).Left.Arguments[0], ((dynamic)node).Arguments[0]).Visit(exp);
                    exp = new ReplacingVisitor(((dynamic)exp).Left.Object, ((dynamic)node).Object).Visit(exp);
                    return(exp);
                }
                if (node.Method.Name == "EndsWith")
                {
                    var exp = ((LambdaExpression)MakeExpression(s => s.EndsWith("asdf", _comparer))).Body;
                    exp = new ReplacingVisitor(((dynamic)exp).Arguments[0], ((dynamic)node).Arguments[0]).Visit(exp);
                    exp = new ReplacingVisitor(((dynamic)exp).Object, ((dynamic)node).Object).Visit(exp);
                    return(exp);
                }
                if (node.Method.Name == "Equals")
                {
                    var exp = ((LambdaExpression)MakeExpression(s => s.Equals("asdf", _comparer))).Body;
                    exp = new ReplacingVisitor(((dynamic)exp).Arguments[0], ((dynamic)node).Arguments[0]).Visit(exp);
                    exp = new ReplacingVisitor(((dynamic)exp).Object, ((dynamic)node).Object).Visit(exp);
                    return(exp);
                }
            }

            return(base.VisitMethodCall(node));
        }