You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
namespace TradeUsedSale.Repositories.Utils
|
|
|
|
|
{
|
|
|
|
|
internal class ParameterRebinder : ExpressionVisitor
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<ParameterExpression, ParameterExpression> _map;
|
|
|
|
|
|
|
|
|
|
internal ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map)
|
|
|
|
|
{
|
|
|
|
|
_map = map ?? new Dictionary<ParameterExpression, ParameterExpression>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map,
|
|
|
|
|
Expression exp)
|
|
|
|
|
{
|
|
|
|
|
return new ParameterRebinder(map).Visit(exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Expression VisitParameter(ParameterExpression p)
|
|
|
|
|
{
|
|
|
|
|
if (_map.TryGetValue(p, out var replacement))
|
|
|
|
|
{
|
|
|
|
|
p = replacement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.VisitParameter(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|