Browse Source

Fixes a bug where properties would be added multiple times to the global AvaloniaPropertyRegistry._properties list.

pull/2270/head
mstr2 7 years ago
parent
commit
9d3fd84a7a
  1. 10
      src/Avalonia.Base/AvaloniaPropertyRegistry.cs
  2. 12
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs

10
src/Avalonia.Base/AvaloniaPropertyRegistry.cs

@ -13,7 +13,7 @@ namespace Avalonia
/// </summary>
public class AvaloniaPropertyRegistry
{
private readonly IList<AvaloniaProperty> _properties =
private readonly List<AvaloniaProperty> _properties =
new List<AvaloniaProperty>();
private readonly Dictionary<Type, Dictionary<int, AvaloniaProperty>> _registered =
new Dictionary<Type, Dictionary<int, AvaloniaProperty>>();
@ -30,6 +30,11 @@ namespace Avalonia
public static AvaloniaPropertyRegistry Instance { get; }
= new AvaloniaPropertyRegistry();
/// <summary>
/// Gets a list of all registered properties.
/// </summary>
internal IReadOnlyList<AvaloniaProperty> Properties => _properties;
/// <summary>
/// Gets all non-attached <see cref="AvaloniaProperty"/>s registered on a type.
/// </summary>
@ -250,8 +255,7 @@ namespace Avalonia
{
inner.Add(property.Id, property);
}
_properties.Add(property);
_attachedCache.Clear();
}
}

12
tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs

@ -19,6 +19,18 @@ namespace Avalonia.Base.UnitTests
p = AttachedOwner.AttachedProperty;
}
[Fact]
public void Registered_Properties_Count_Reflects_Newly_Added_Attached_Property()
{
var registry = new AvaloniaPropertyRegistry();
var metadata = new StyledPropertyMetadata<int>();
var property = new AttachedProperty<int>("test", typeof(object), metadata, true);
registry.Register(typeof(object), property);
registry.RegisterAttached(typeof(AvaloniaPropertyRegistryTests), property);
Assert.Equal(1, registry.Properties.Count);
}
[Fact]
public void GetRegistered_Returns_Registered_Properties()
{

Loading…
Cancel
Save