Hi, I am writing my linq-provider for one CMS. using ExpressionVisitor, I try to parse the expression tree, and depending on the expressions encountered, do something. The problem arose with this. Suppose there are 5 examples (they are meaningless in themselves, given purely for understanding the problem):
1. x=> x.IsBool == true 2. x=> x.IsBool != true 3. x=> x.IsBool 4. x=> !x.IsBool 5. x=> x.IsBool && x.IsBool == true The task: you need to turn each BinaryExpression into IsBool = 1/0 (as EntityFramework does).
Cases 1 and 2 are easy to understand. But what about those cases where part of the expression is simplified (redundant boolean expression)? Case 3 just goes as MemberExpression. Case 4 is similar, unless it is wrapped in UnaryExpression (here you can dodge the condition that it is UnaryExpression that contains MemberExpression - then we define our equality).
Case 5 is the most incomprehensible to me. The visitor will visit MemberExpression 2 times (left side x.IsBool, and right side from BinaryExpression x.IsBool == true). In this case, if you just define MemberExpression by the type of the boolean value, then at the output I will get something like
IsBool = 1 AND IsBool = 1 = 1 That is, in one iteration I define by the normal path that the right-hand side is BinaryExpression, and then also in MemberExpression I define by the type bool and I deduce the unnecessary.
I hope I explained the essence of the problem. I hope that is not very confusing :). I would be grateful for the help.
== true. - VladDx.IsBool == true && x.IsBool == true, andx.IsBool == true && x.IsBool == trueover with the simplifier of expressions:E && E->E- VladD