Repository navigation
Query: Refactor SearchConditionTranslatingVisitor - #7554
Conversation
7d78c88 to
f89471d
Compare
| { | ||
| Expression newLeft; | ||
| Expression newRight; | ||
| // Visit the children |
There was a problem hiding this comment.
remove this comment - seems inaccurate (visit children comes later)
|
|
||
| newLeft = AdjustExpressionType(Visit(expression.Left), expression.Left.Type); | ||
| newRight = AdjustExpressionType(Visit(expression.Right), expression.Right.Type); | ||
| // Update the node |
There was a problem hiding this comment.
remove this comment as seems redundant - fairly obvious what the code is doing here
|
|
||
| return expression.Update(newLeft, expression.Conversion, newRight); | ||
| // Do conversion | ||
| return _isSearchCondition |
There was a problem hiding this comment.
This pattern in repeated several times, consider DRYing it up.
|
|
||
| protected override Expression VisitConditional(ConditionalExpression expression) | ||
| { | ||
| // Visit the children |
| _isSearchCondition = parentIsSearchCondition; | ||
|
|
||
| var newExpression = Expression.Condition(test, ifTrue, ifFalse); | ||
| // Update the node |
| } | ||
|
|
||
| if (expression.NodeType == ExpressionType.Not) | ||
| // Visit the children |
| expression.Operand, | ||
| Expression.Constant(false, expression.Operand.Type)); | ||
| } | ||
| // Update the node |
| if (_isSearchCondition) | ||
| { | ||
| var parentIsSearchCondition = _isSearchCondition; | ||
| // Visit the children |
| } | ||
|
|
||
| protected override Expression VisitParameter(ParameterExpression expression) | ||
| private static Expression MakeCompareToExpression(Expression expression, bool compareTo) |
There was a problem hiding this comment.
nit: maybe 'Build' or 'Create' instead of 'Make'
|
Does it make sense to move from "SearchCondition" to "Predicate" for consistency? |
|
|
||
| return Expression.Equal(newExpression, Expression.Constant(true, typeof(bool))); | ||
| } | ||
| newExpression = new SearchConditionTranslatingVisitor(searchCondition).Convert(newExpression); |
There was a problem hiding this comment.
Can we call Visit instead on Convert?
There was a problem hiding this comment.
I find the naming confusing. Is it that this visitor is a predicate translator that performs a different translation when the target expression is a search condition?
There was a problem hiding this comment.
I also need suggestions for name. Visit would be starting method for every expression. But the code block should be applied only at top level or starting expression. I moved the extra handling at top level inside the visitor to make it more contained in itself.
There was a problem hiding this comment.
How about Translate as method name?
This is visitor which converts value to search condition or vice-versa as needed. It is applied to predicates/join conditions & projections. After thinking more about name of the visitor,
I believe it shouldn't be named with Predicate.
There was a problem hiding this comment.
Translate is fine. I was looking for symmetry with the 3 lines above, but I see why it needs a custom entry point method.
How about something like:
new BooleanExpressionTranslatingVisitor().Translate(expression, searchCondition: false);|
|
||
| private class SearchConditionTranslatingVisitor : RelinqExpressionVisitor | ||
| { | ||
| /* |
There was a problem hiding this comment.
Put this in /// Summary doc comment
|
It was named "SearchCondition" because T-Sql uses that term. I am fine with using "Predicate" or anything else also. |
f89471d to
f8a2918
Compare
|
|
||
| return Expression.Equal(newExpression, Expression.Constant(true, typeof(bool))); | ||
| } | ||
| newExpression = new SearchConditionTranslatingVisitor(searchCondition).Convert(newExpression); |
There was a problem hiding this comment.
Translate is fine. I was looking for symmetry with the 3 lines above, but I see why it needs a custom entry point method.
How about something like:
new BooleanExpressionTranslatingVisitor().Translate(expression, searchCondition: false);b2ab380 to
98a8049
Compare
98a8049 to
1649ad0
Compare
Resolves issue #7271
part of #7520