Skip to content

Commit

Permalink
IEnumerable == and Equals changes - #fixes 309 - MvvmCross#309
Browse files Browse the repository at this point in the history
  • Loading branch information
slodge committed Jul 5, 2013
1 parent 9fc394f commit ccfc44b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ private void SpinnerItemSelected(object sender, AdapterView.ItemSelectedEventArg

var newValue = spinner.Adapter.GetRawItem(e.Position);

if (!newValue.Equals(_currentValue))
bool changed;
if (newValue == null)
{
_currentValue = newValue;
FireValueChanged(newValue);
changed = (_currentValue != null);
}
else
{
changed = !(newValue.Equals(_currentValue));
}

if (!changed)
{
return;
}

_currentValue = newValue;
FireValueChanged(newValue);
}

public override void SetValue(object value)
Expand All @@ -48,7 +60,13 @@ public override void SetValue(object value)
if (spinner == null)
return;

if (value != null && !value.Equals(_currentValue))
if (value == null)
{
MvxBindingTrace.Warning("Null values not permitted in spinner SelectedItem binding currently");
return;
}

if (!value.Equals(_currentValue))
{
var index = spinner.Adapter.GetPosition(value);
if (index < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public static int GetPosition(this IEnumerable items, object item)
return -1;
}

if (enumerator.Current == item)
if (enumerator.Current == null)
{
if (item == null)
return i;
}
// Note: do *not* use == here - see https://github.com/slodge/MvvmCross/issues/309
else if (enumerator.Current.Equals(item))
{
return i;
}
Expand Down

0 comments on commit ccfc44b

Please sign in to comment.