From 039991da684187c5d64104ca310a14a6793b496f Mon Sep 17 00:00:00 2001 From: mstr2 Date: Wed, 13 Feb 2019 03:54:04 +0100 Subject: [PATCH] Fixed a bug where AddOwner would add a property to AvaloniaPropertyRegistry's property list more than once --- src/Avalonia.Base/AvaloniaPropertyRegistry.cs | 12 ++++++++---- .../AvaloniaPropertyRegistryTests.cs | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs index 6f57dfbf13..5fcdf76c0f 100644 --- a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs +++ b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs @@ -13,8 +13,8 @@ namespace Avalonia /// public class AvaloniaPropertyRegistry { - private readonly List _properties = - new List(); + private readonly Dictionary _properties = + new Dictionary(); private readonly Dictionary> _registered = new Dictionary>(); private readonly Dictionary> _attached = @@ -33,7 +33,7 @@ namespace Avalonia /// /// Gets a list of all registered properties. /// - internal IReadOnlyList Properties => _properties; + internal IReadOnlyCollection Properties => _properties.Values; /// /// Gets all non-attached s registered on a type. @@ -220,7 +220,11 @@ namespace Avalonia inner.Add(property.Id, property); } - _properties.Add(property); + if (!_properties.ContainsKey(property.Id)) + { + _properties.Add(property.Id, property); + } + _registeredCache.Clear(); } diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs index 8220b7d6e7..d11319114f 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs @@ -27,6 +27,7 @@ namespace Avalonia.Base.UnitTests var property = new AttachedProperty("test", typeof(object), metadata, true); registry.Register(typeof(object), property); registry.RegisterAttached(typeof(AvaloniaPropertyRegistryTests), property); + property.AddOwner(); Assert.Equal(1, registry.Properties.Count); } @@ -150,5 +151,9 @@ namespace Avalonia.Base.UnitTests private class AttachedOwner2 : AttachedOwner { } + + private class Class4 : AvaloniaObject + { + } } }