Browse Source

Fixed a bug where AddOwner would add a property to AvaloniaPropertyRegistry's property list more than once

pull/2296/head
mstr2 7 years ago
parent
commit
039991da68
  1. 12
      src/Avalonia.Base/AvaloniaPropertyRegistry.cs
  2. 5
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs

12
src/Avalonia.Base/AvaloniaPropertyRegistry.cs

@ -13,8 +13,8 @@ namespace Avalonia
/// </summary>
public class AvaloniaPropertyRegistry
{
private readonly List<AvaloniaProperty> _properties =
new List<AvaloniaProperty>();
private readonly Dictionary<int, AvaloniaProperty> _properties =
new Dictionary<int, AvaloniaProperty>();
private readonly Dictionary<Type, Dictionary<int, AvaloniaProperty>> _registered =
new Dictionary<Type, Dictionary<int, AvaloniaProperty>>();
private readonly Dictionary<Type, Dictionary<int, AvaloniaProperty>> _attached =
@ -33,7 +33,7 @@ namespace Avalonia
/// <summary>
/// Gets a list of all registered properties.
/// </summary>
internal IReadOnlyList<AvaloniaProperty> Properties => _properties;
internal IReadOnlyCollection<AvaloniaProperty> Properties => _properties.Values;
/// <summary>
/// Gets all non-attached <see cref="AvaloniaProperty"/>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();
}

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

@ -27,6 +27,7 @@ namespace Avalonia.Base.UnitTests
var property = new AttachedProperty<int>("test", typeof(object), metadata, true);
registry.Register(typeof(object), property);
registry.RegisterAttached(typeof(AvaloniaPropertyRegistryTests), property);
property.AddOwner<Class4>();
Assert.Equal(1, registry.Properties.Count);
}
@ -150,5 +151,9 @@ namespace Avalonia.Base.UnitTests
private class AttachedOwner2 : AttachedOwner
{
}
private class Class4 : AvaloniaObject
{
}
}
}

Loading…
Cancel
Save