using System.Collections.Generic; using System.Linq.Expressions; namespace Abp.Specifications { /// /// Represents the parameter rebinder used for rebinding the parameters /// for the given expressions. This is part of the solution which solves /// the expression parameter problem when going to Entity Framework. /// For more information about this solution please refer to http://blogs.msdn.com/b/meek/archive/2008/05/02/linq-to-entities-combining-predicates.aspx. /// internal class ParameterRebinder : ExpressionVisitor { private readonly Dictionary _map; internal ParameterRebinder(Dictionary map) { _map = map ?? new Dictionary(); } internal static Expression ReplaceParameters(Dictionary map, Expression exp) { return new ParameterRebinder(map).Visit(exp); } protected override Expression VisitParameter(ParameterExpression p) { ParameterExpression replacement; if (_map.TryGetValue(p, out replacement)) { p = replacement; } return base.VisitParameter(p); } } }