Is there a clean way to do this?
Expression<Func<int, string>> exTyped = i => "My int = " + i;
LambdaExpression lambda = exTyped;
//later on:
object input = 4;
object result = ExecuteLambdaSomeHow(lambda, input);
//result should be "My int = 4"
This should work for different types.
var func = new Func<int, string>(x => { return string.Format("My int = {0}", x); });
? – Basiestring.Format()
would do it :) – BasieDynamicInvoke
). If it is possible, I would try to avoid this (because you have no compile time check; thus it is very much possible you get runtime errors). – Tenuis