| 12345678910111213141516171819202122232425262728293031323334353637 |
- using System.Collections.Generic;
- using System.Linq.Expressions;
- namespace Abp.Specifications
- {
- /// <summary>
- /// 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.
- /// </summary>
- 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)
- {
- ParameterExpression replacement;
- if (_map.TryGetValue(p, out replacement))
- {
- p = replacement;
- }
- return base.VisitParameter(p);
- }
- }
- }
|