开发者

C# Expression Tree's always wrapping with ()

开发者 https://www.devze.com 2023-03-18 21:29 出处:网络
I\'m trying to create an Expression tree that will determine if a line in a word document is deleted or not.

I'm trying to create an Expression tree that will determine if a line in a word document is deleted or not.

I'm looping through a collection of dependencies where I have a comparisonExpression:

comparisonExpression = Expression.Equal(Expression.Constant(attribute.AttributeValue), Expression.Constant(dependency.AttributeValue));

As I loop through I have a dependencyExpression (which is the overall expression) that gets appended too.

dependencyExpression = Expression.And(dependencyExpression, compariso开发者_JAVA技巧nExpression);

Now if I have 3 dependencies the result will be:

((("29 5/8" (753mm)" == "29 5/8" (753mm)") And ("43" (1092mm)" == "43" (1092mm)")) Or ("Red" == "Black"))

when it really should be like:

(("29 5/8" (753mm)" == "29 5/8" (753mm)") And ("43" (1092mm)" == "43" (1092mm)") Or ("Red" == "Black"))

Every time I do any Expression.Whatever() it always adds the parenthesis on the outside. Is there a way to control this?

Thanks.


The boolean operators are binary meaning that they take two operands. The evaluating system needs some kind of precedence to determine how to evaluate the expression.

Note that

(F and T) or T = T
F and (T or T) = F

How should the evaluator know which version is the correct one if you only pass him

F and T or T

That is why you need to tell him with parentheses which expression to evaluate first.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号