Esiste un modo pulito per eseguire questa operazione?Esegui LambdaExpression e ottieni il valore restituito come oggetto
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"
questo dovrebbe funzionare per diversi tipi.
Perché non solo 'var func = new Func (x => {return string.Format ("Il mio int = {0}", x);});'? –
PoweredByOrange
@PoweredByOrange Suppongo che la domanda sia semplificata. – Kevin
@Kevin Ha senso, altrimenti un semplice 'string.Format()' lo farebbe :) – PoweredByOrange