Browse Source

!B Fix expression nodes not knowing if last value is actually null or dead.

fixes/2983-onewaytosource-twoway
Dariusz Komosiński 7 years ago
parent
commit
9acf82d47b
  1. 8
      src/Avalonia.Base/Data/Core/ExpressionNode.cs
  2. 5
      src/Avalonia.Base/Data/Core/SettableNode.cs
  3. 2
      tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs

8
src/Avalonia.Base/Data/Core/ExpressionNode.cs

@ -8,9 +8,13 @@ namespace Avalonia.Data.Core
public abstract class ExpressionNode
{
private static readonly object CacheInvalid = new object();
protected static readonly WeakReference<object> UnsetReference =
new WeakReference<object>(AvaloniaProperty.UnsetValue);
protected static readonly WeakReference<object> NullReference =
new WeakReference<object>(null);
private WeakReference<object> _target = UnsetReference;
private Action<object> _subscriber;
private bool _listening;
@ -98,7 +102,7 @@ namespace Avalonia.Data.Core
if (notification == null)
{
LastValue = new WeakReference<object>(value);
LastValue = value != null ? new WeakReference<object>(value) : NullReference;
if (Next != null)
{
@ -111,7 +115,7 @@ namespace Avalonia.Data.Core
}
else
{
LastValue = new WeakReference<object>(notification.Value);
LastValue = notification.Value != null ? new WeakReference<object>(notification.Value) : NullReference;
if (Next != null)
{

5
src/Avalonia.Base/Data/Core/SettableNode.cs

@ -29,6 +29,11 @@ namespace Avalonia.Data.Core
if (!isLastValueAlive)
{
if (value == null && LastValue == NullReference)
{
return true;
}
return false;
}

2
tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs

@ -216,7 +216,7 @@ namespace Avalonia.Markup.UnitTests.Data
// When running tests under NCrunch, NCrunch replaces the standard StackOverflowException
// with its own, which will be caught by our code. Detect the stackoverflow anyway, by
// making sure the target property was only set once.
Assert.Equal(1, source.FooSetCount);
Assert.Equal(2, source.FooSetCount);
}
[Fact]

Loading…
Cancel
Save