You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that #1089 is solved, we can include the suffix visitor I was talking about in that issue.
This is safer and more clear than using the current SuffixExtensions.Suffix because it only applies to Expression<Func<T, object>> instead of any object.
It also allows me to build a list of fields (of type Expression<Func<T, object>>) and apply a suffix to that whole list (useful for mapping multiple string fields with multiple analysers).
// put this anywhere you wantpublicstaticExpression<Func<T,object>>AppendSuffix<T>(thisExpression<Func<T,object>>property,stringsuffix){varnewBody=newSuffixExprVisitor(suffix).Visit(property.Body);returnExpression.Lambda<Func<T,object>>(newBody,property.Parameters[0]);}/// <summary>/// Calls <see cref="SuffixExtensions.Suffix"/> on a member expression./// </summary>privateclassSuffixExprVisitor:ExpressionVisitor{readonlystringSuffix;publicSuffixExprVisitor(stringsuffix){Suffix=suffix;}protectedoverrideExpressionVisitMember(MemberExpressionnode){returnExpression.Call(typeof(SuffixExtensions),"Suffix",null,node,Expression.Constant(Suffix));}protectedoverrideExpressionVisitUnary(UnaryExpressionnode){// allow rewriting child expressionsreturnnode;}}
The text was updated successfully, but these errors were encountered:
Now that #1089 is solved, we can include the suffix visitor I was talking about in that issue.
This is safer and more clear than using the current
SuffixExtensions.Suffix
because it only applies toExpression<Func<T, object>>
instead of anyobject
.It also allows me to build a list of fields (of type
Expression<Func<T, object>>
) and apply a suffix to that whole list (useful for mapping multiple string fields with multiple analysers).The text was updated successfully, but these errors were encountered: