//public static Converter converter(MethodInfo m) //{ // var src = Expression.Parameter(typeof(object), "src"); // var convert = Expression.Convert(src, m.GetParameters()[0].ParameterType); // var callResult = Expression.Call(null, m, convert); // var result = Expression.Convert(callResult, typeof(object)); // return Expression.Lambda<Converter>(result, src).Compile(); //} //public static Converter<TDst> converter<TDst>(MethodInfo m) //{ // var src = Expression.Parameter(typeof(object), "src"); // var convert = Expression.Convert(src, m.GetParameters()[0].ParameterType); // var callResult = Expression.Call(null, m, convert); // return Expression.Lambda<Converter<TDst>>(callResult, src).Compile(); //} /// <summary> /// Creates an expression from a parameterless function delegate delegate /// </summary> /// <typeparam name="T">The delegate return type</typeparam> /// <param name="f"></param> /// <returns></returns> public static Expression <Func <T> > funcx <T>(Func <T> f) => FuncExpression.make(f);
/// <summary> /// Creates an expression from a 2-argument function delegate /// </summary> /// <typeparam name="X1">The type of the delegate's first argument</typeparam> /// <typeparam name="X2">The type of the delegate's second argument</typeparam> /// <typeparam name="Y">The delegate return type</typeparam> /// <param name="f"></param> /// <returns></returns> public static Expression <Func <X1, X2, Y> > funcx <X1, X2, Y>(Func <X1, X2, Y> f) => FuncExpression.make(f);
static FuncExpression <X, Y> Converter() => FuncExpression.make((X x) => (Y)Convert.ChangeType(x, typeof(Y)));