New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MvxEnumerableExtensions.GetPosition - The operator '==' is not having the expected result (IMHO) #309
Comments
Thanks. This sounds familiar... Linked to #135 I know at some point we changed https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/Target/MvxSpinnerSelectedItemBinding.cs While in the area we'd also need to check other files and double check our
I believe last time this came up I looked at the Android and the underlying Java default implementations will use things like |
As a further note,
I'm not 100% sure that we should actually be using |
Phew.... scratch that last comment - looks like phew... |
Mini heart attack there... :) |
I believe this is working in 3.0.9 - plus I think it should be covered by the ApiExample - https://github.com/slodge/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Droid/Resources/Layout/Test_Spinner.axml (this binds to Thanks again Closing Stuart |
Fix the solution. Get the build going again.
In an Android App, I have a
IDictionary
binded to the ItemsSource ofMvxSpinner
and I also have a property binded to the SelectedItem of the spinner.If I try to set the Selecteditem through the ViewModel, the code reaches the
GetPosition
method in theMvxEnumerableExtensions
.As the ItemsSource is not a IList, it reaches the following code (Line 58)
if (enumerator.Current == item) { return i; }
As the comparison is beeing made by two
object
, the operator '==' will useSystem.Object.ReferenceEquals
. This will only return true, if the objects are the same instance. In my case apparently they are not the same instance but they are equal objects( if I useenumerator.Current.Equals(item)
it returnstrue
)So that makes me think that we should use the Equals instead of the '==' operator.
My change sugestion is as follows:
The text was updated successfully, but these errors were encountered: