Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does LambdaExpression.Compile() work on iOS (Xamarin)?

Tags:

ios

xamarin

il

Since Xamarin.iOS doesn't support code generation at runtime, why do Compile() and DynamicInvoke() work as expected?

For example, the following code works fine:

var lambda = Expression.Lambda(
                          Expression.Add(
                              Expression.Constant(1),
                              Expression.Constant(2)
                          )
             );

var f = lambda.Compile();
var result = f.DynamicInvoke();

// result==3 at this point

Is Xamarin evaluating the expression tree at runtime instead of emitting IL code?

like image 387
Philippe Leybaert Avatar asked Mar 25 '15 00:03

Philippe Leybaert


1 Answers

On platforms that support code generation, Reflection.Emit-based LambdaCompiler is used.

If that's not available, the expression is interpreted using the interpreter. For example, there are classes that interpret Constant and Add.

like image 157
svick Avatar answered Oct 19 '22 21:10

svick