using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; namespace Bowin.Common.Linq { public sealed class ParameterRebinder : ExpressionVisitor { private readonly Dictionary map; public ParameterRebinder(Dictionary map) { this.map = map ?? new Dictionary(); } public static Expression ReplaceParameters(Dictionary map, Expression exp) { return new ParameterRebinder(map).Visit(exp); } protected override Expression VisitParameter(ParameterExpression p) { ParameterExpression expression; if (this.map.TryGetValue(p, out expression)) { p = expression; } return base.VisitParameter(p); } } }