public static MemberExpression ReplaceParameter(this ParameterExpression param, MemberExpression expr) { var path = expr.ToString(); var index = path.IndexOf('.'); path = path.Substring(index + 1); return(param.CreateMemberExpresion(path)); }
public static LambdaExpression CreateLambdaExpresion(this ParameterExpression param, IList <MemberExpression> list) { var type = param.Type.CreateDynamicType(list); var memberExprList = new List <MemberAssignment>(); foreach (var expr in list) { var str = expr.ToString(); str = str.Substring(str.IndexOf('.') + 1); var info = type.GetProperty(str); var memberExpr = param.CreateMemberExpresion(str); memberExprList.Add(Expression.Bind(info, memberExpr)); } var memberInit = Expression.MemberInit(Expression.New(type), memberExprList); return(Expression.Lambda(memberInit, param)); }