Browse Source

Revert "Removed unused field."

This reverts commit 270f9718b8.
pull/3255/head
Steven Kirk 6 years ago
parent
commit
3bc1594dca
  1. 9
      src/Avalonia.Base/PropertyStore/PriorityValue.cs
  2. 8
      src/Avalonia.Base/ValueStore.cs
  3. 21
      tests/Avalonia.Base.UnitTests/PriorityValueTests.cs

9
src/Avalonia.Base/PropertyStore/PriorityValue.cs

@ -19,15 +19,18 @@ namespace Avalonia.PropertyStore
/// </remarks>
internal class PriorityValue<T> : IValue<T>, IValueSink
{
private readonly IAvaloniaObject _owner;
private readonly IValueSink _sink;
private readonly List<IPriorityValueEntry<T>> _entries = new List<IPriorityValueEntry<T>>();
private readonly Func<IAvaloniaObject, T, T>? _coerceValue;
private Optional<T> _localValue;
public PriorityValue(
IAvaloniaObject owner,
StyledPropertyBase<T> property,
IValueSink sink)
{
_owner = owner;
Property = property;
_sink = sink;
@ -39,10 +42,11 @@ namespace Avalonia.PropertyStore
}
public PriorityValue(
IAvaloniaObject owner,
StyledPropertyBase<T> property,
IValueSink sink,
IPriorityValueEntry<T> existing)
: this(property, sink)
: this(owner, property, sink)
{
existing.Reparent(this);
_entries.Add(existing);
@ -55,10 +59,11 @@ namespace Avalonia.PropertyStore
}
public PriorityValue(
IAvaloniaObject owner,
StyledPropertyBase<T> property,
IValueSink sink,
LocalValueEntry<T> existing)
: this(property, sink)
: this(owner, property, sink)
{
_localValue = existing.Value;
Value = _localValue;

8
src/Avalonia.Base/ValueStore.cs

@ -209,7 +209,7 @@ namespace Avalonia
{
if (slot is IPriorityValueEntry<T> e)
{
var priorityValue = new PriorityValue<T>(property, this, e);
var priorityValue = new PriorityValue<T>(_owner, property, this, e);
_values.SetValue(property, priorityValue);
priorityValue.SetValue(value, priority);
}
@ -227,7 +227,7 @@ namespace Avalonia
}
else
{
var priorityValue = new PriorityValue<T>(property, this, l);
var priorityValue = new PriorityValue<T>(_owner, property, this, l);
_values.SetValue(property, priorityValue);
}
}
@ -247,7 +247,7 @@ namespace Avalonia
if (slot is IPriorityValueEntry<T> e)
{
priorityValue = new PriorityValue<T>(property, this, e);
priorityValue = new PriorityValue<T>(_owner, property, this, e);
}
else if (slot is PriorityValue<T> p)
{
@ -255,7 +255,7 @@ namespace Avalonia
}
else if (slot is LocalValueEntry<T> l)
{
priorityValue = new PriorityValue<T>(property, this, l);
priorityValue = new PriorityValue<T>(_owner, property, this, l);
}
else
{

21
tests/Avalonia.Base.UnitTests/PriorityValueTests.cs

@ -21,6 +21,7 @@ namespace Avalonia.Base.UnitTests
public void Constructor_Should_Set_Value_Based_On_Initial_Entry()
{
var target = new PriorityValue<string>(
Owner,
TestProperty,
NullSink,
new ConstantValueEntry<string>(TestProperty, "1", BindingPriority.StyleTrigger));
@ -33,6 +34,7 @@ namespace Avalonia.Base.UnitTests
public void SetValue_LocalValue_Should_Not_Add_Entries()
{
var target = new PriorityValue<string>(
Owner,
TestProperty,
NullSink);
@ -46,6 +48,7 @@ namespace Avalonia.Base.UnitTests
public void SetValue_Non_LocalValue_Should_Add_Entries()
{
var target = new PriorityValue<string>(
Owner,
TestProperty,
NullSink);
@ -63,7 +66,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Binding_With_Same_Priority_Should_Be_Appended()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
@ -83,7 +86,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Binding_With_Higher_Priority_Should_Be_Appended()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
@ -103,7 +106,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Binding_With_Lower_Priority_Should_Be_Prepended()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
@ -123,7 +126,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Second_Binding_With_Lower_Priority_Should_Be_Inserted_In_Middle()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
var source3 = new Source("3");
@ -145,7 +148,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Competed_Binding_Should_Be_Removed()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
var source3 = new Source("3");
@ -168,7 +171,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void Value_Should_Come_From_Last_Entry()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
var source2 = new Source("2");
var source3 = new Source("3");
@ -183,7 +186,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void LocalValue_Should_Override_LocalValue_Binding()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
target.AddBinding(source1, BindingPriority.LocalValue).Start();
@ -195,7 +198,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void LocalValue_Should_Override_Style_Binding()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
target.AddBinding(source1, BindingPriority.Style).Start();
@ -207,7 +210,7 @@ namespace Avalonia.Base.UnitTests
[Fact]
public void LocalValue_Should_Not_Override_Animation_Binding()
{
var target = new PriorityValue<string>(TestProperty, NullSink);
var target = new PriorityValue<string>(Owner, TestProperty, NullSink);
var source1 = new Source("1");
target.AddBinding(source1, BindingPriority.Animation).Start();

Loading…
Cancel
Save