c# - Execute LambdaExpression and get returned value as object -


is there clean way this?

expression<func<int, string>> extyped = => "my int = " + i; lambdaexpression lambda = extyped;  //later on:  object input = 4; object result = executelambdasomehow(lambda, input); //result should "my int = 4" 

this should work different types.

sure... need compile lambda , invoke it...

object input = 4; var compiledlambda = lambda.compile(); var result = compiledlambda.dynamicinvoke(input); 

styxxy brings excellent point... better served letting compiler out. note compiled expression in code below input , result both typed.

var input = 4; var compiledexpression = extyped.compile(); var result = compiledexpression(input); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -