Merge pull request #80 from xamarin/bleroy-fix-nre-pvm
Fix null ref when getting ValueSource if value is null
This commit is contained in:
Коммит
870cbce82b
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
@ -160,6 +160,27 @@ namespace Xamarin.PropertyEditing.Tests
|
|||
Assert.That (changed, Is.True, "PropertyChanged was not raised for Value when values began to disagree");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValueSourceDefaultWhenValuesDisagree ()
|
||||
{
|
||||
TValue value = GetNonDefaultRandomTestValue ();
|
||||
TValue otherValue = GetRandomTestValue ();
|
||||
while (Equals (otherValue, value))
|
||||
otherValue = GetRandomTestValue ();
|
||||
|
||||
var vm = GetBasicTestModel (value);
|
||||
Assume.That (vm.Value, Is.EqualTo (value));
|
||||
|
||||
var editor = GetBasicEditor (otherValue);
|
||||
|
||||
vm.Editors.Add (editor);
|
||||
|
||||
Assume.That (vm.Value, Is.EqualTo (default (TValue)));
|
||||
Assume.That (vm.MultipleValues, Is.True);
|
||||
|
||||
Assert.That (vm.ValueSource, Is.EqualTo (ValueSource.Default));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Description ("Once an editor is removed we should not listen for its property changes")]
|
||||
public async Task UnsubscribedValueChanged ()
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Xamarin.PropertyEditing.ViewModels
|
|||
UpdateCurrentValue ();
|
||||
}
|
||||
|
||||
public ValueSource ValueSource => this.value.Source;
|
||||
public ValueSource ValueSource => this.value != null ? this.value.Source : ValueSource.Default;
|
||||
|
||||
public TValue Value
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ namespace Xamarin.PropertyEditing.ViewModels
|
|||
MultipleValues = disagree;
|
||||
|
||||
// The public setter for Value is a local set for binding
|
||||
SetCurrentValue ((currentValue != null) ? currentValue : null);
|
||||
SetCurrentValue (currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче