Until a stackoverflow question today, I hadn't actually remembered that the Android MvvmCross binding insists that classes use IList instead of IEnumerable collections.
The reason for this decision was simple - performance.
Within Android, the ListView Adapter class relies on random access to the collection and it needs to use values like Count. This is why IList was selected for binding - because IList provides the [position] operator and it provides the Count property, whereas IEnumerable can only provide random element access and element counting through step-by-step enumeration - which, obviously, is slow
However.... despite this, it appears that Silverlight and Wpf databinding allows users to use IEnumerable collections - and I *guess* it does this in a less than optimal way, but that this doesn't matter for small collection sizes...
So... Mvx Droid is now following the same route - the binding will use IList when it's available, but will drop down to step-by-step enumeration when IList is not available. This means that if you want to, then your Android code can now bind to IEnumerable. However, just beware that this is never going to be super efficient!
For a look at the changes in details, see https://github.com/slodge/MvvmCross/commit/2b2be9878b0c84d12fdf6ba5b9e7d022b4ce6e42
No comments:
Post a Comment