diff --git a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs index 11b1096052..6f57dfbf13 100644 --- a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs +++ b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs @@ -13,7 +13,7 @@ namespace Avalonia /// public class AvaloniaPropertyRegistry { - private readonly IList _properties = + private readonly List _properties = new List(); private readonly Dictionary> _registered = new Dictionary>(); @@ -30,6 +30,11 @@ namespace Avalonia public static AvaloniaPropertyRegistry Instance { get; } = new AvaloniaPropertyRegistry(); + /// + /// Gets a list of all registered properties. + /// + internal IReadOnlyList Properties => _properties; + /// /// Gets all non-attached s registered on a type. /// @@ -250,8 +255,7 @@ namespace Avalonia { inner.Add(property.Id, property); } - - _properties.Add(property); + _attachedCache.Clear(); } } diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs index c34e26ac5c..8220b7d6e7 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs +++ b/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(); + var property = new AttachedProperty("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() {