// This magic is courtesy of this StackOverflow post. // https://stackoverflow.com/questions/38316519/replace-parameter-type-in-lambda-expression // I made some tweaks to adapt it to our needs - @haacked public static Expression <Func <TTarget, bool> > Convert <TSource, TTarget>( this Expression <Func <TSource, bool> > root) { var visitor = new ParameterTypeVisitor <TSource, TTarget>(); return((Expression <Func <TTarget, bool> >)visitor.Visit(root)); }
public static Func <TTarget, TConst> Convert <TSource, TTarget, TConst>(Expression <Func <TSource, TConst> > root) { var visitor = new ParameterTypeVisitor <TSource, TTarget>(); var expression = (Expression <Func <TTarget, TConst> >)visitor.Visit(root); return(expression?.Compile()); }