ios


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


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?
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.
The details of the Xamarin limitations are here.
You don't seem to be using anything in the Reflection.Emit namespace, which is the big no-no. Your code must still be AOT'd. Otherwise, I would imagine it would not work.
But there HAVE been examples of [native] developers thwarting the iOS static analysis tool and circumventing the dynamic code restriction. I tried to locate the article, but couldn't find it.
Anyway, I don't think your scenario exemplifies that. Your code example will still be AOT-compiled.
But you raise a really good question: at what time does the expression get evaluated?
EDIT:
Another SO answer on the same topic: What does Expression.Compile do on Monotouch?
There's also some good info on Expression.Compile() and "full AOT" here:
http://www.mono-project.com/docs/advanced/aot/
EDIT:
After reading some more, I think I know what's going on here. It's not that Expression.Compile() won't work...it's that when your iOS app bundle is subjected to the iOS static analysis tool when you submit it to the app store, it will not pass the analysis, because it is dynamically generating code. So, sure, you can use Expression.Compile(), but don't expect it to be accepted into the app store. But as mentioned by #svick, if you use the "full AOT" compile option, your Expression.Compile() will probably fail at runtime, or perhaps even fail compilation.

Related Links

Swift parse JSON with variable types
Using navigation controller from the object does NOT work exactly as using it to embed in xcode
How to use “swipe” to control segment in swift?
can not replace all occurrences of quotation (")
CNContactVCardSerialization dataWithContacts method issue
Set minimum height of table view cell?
AVPlayer stops loading tracks in lock screen
Unexpectedly found nil while unwrapping an Optional value - NSMutableURLRequest
iOS: If app is in background and local notification is arrived; which method will called automatically?
How to give constraints to a tableview when tableview cell is on xib. And table view is on storyboard
Cannot see iOS simulator traffic with charles proxy
Can't make User Defined Runtime Attributes work
The constraint does not take effect on View
Value only updating once?
HowTo disable CollectionView ScrollView Insets
How can I use UserDefaults to store from UIDatePicker?

Categories

HOME
lsf
unit-testing
azure-search
android-wear
azure-web-sites
backand
path
wxpython
redhat
winsql
python-xarray
square-connect
executable
aac
command-line-interface
nservicebus
graph-tool
embed
eigen3
api-design
drupal-commerce
oracle11gr2
smartcard
slime
ghost-blog
haml
mlr
google-distancematrix-api
line-breaks
urlrewriter.net
ssms-2014
sax
iteration
azure-redis-cache
intersystems
grouping
physics
plm
android-imageview
stl
gecko
magento2.0.2
directx-12
dokuwiki
stackexchange.exceptional
subtotal
gosublime
disqus
otroslogviewer
rft
essbase
project-centennial
tern
wp-api
log4perl
strip-tags
netbeans-7
iseries-navigator
replicate
blocking
evaluate
activity-diagram
benerator
pypyodbc
pakyow
js-of-ocaml
relaxng
jedi
folder-structure
axlsx
wss4j
error-log
ehcache-bigmemory
sslv3
excel-charts
tortoisecvs
mysql5
symfony-2.5
mui
lwuit-list
django-supervisor
bunny
textselection
mouseenter
data-quality
windows-phone-7.1
chomsky-hierarchy
hla
nsmanagedobjectmodel
uptime
neventstore
sizzle
datadesign
nspersistentdocument
wescheme
hiphop
nextpeer
data-oriented-design
having
treetop
custom-tag
myisam
cassandra-0.7
custom-protocol
xquery-update
net-ssh
gedcom
palm-pre
corporate-policy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App