diff --git a/src/Perspex.Base/PerspexProperty.cs b/src/Perspex.Base/PerspexProperty.cs index 71dd7bb0fbd..e88c7f4418f 100644 --- a/src/Perspex.Base/PerspexProperty.cs +++ b/src/Perspex.Base/PerspexProperty.cs @@ -22,7 +22,6 @@ public class PerspexProperty : IEquatable public static readonly object UnsetValue = new Unset(); private static int s_nextId = 1; - private readonly int _id; private readonly Subject _initialized; private readonly Subject _changed; private readonly PropertyMetadata _defaultMetadata; @@ -61,7 +60,7 @@ protected PerspexProperty( PropertyType = valueType; OwnerType = ownerType; Notifying = notifying; - _id = s_nextId++; + Id = s_nextId++; _metadata.Add(ownerType, metadata); _defaultMetadata = metadata; @@ -85,7 +84,7 @@ protected PerspexProperty(PerspexProperty source, Type ownerType) PropertyType = source.PropertyType; OwnerType = ownerType; Notifying = source.Notifying; - _id = source._id; + Id = source.Id; _defaultMetadata = source._defaultMetadata; } @@ -164,6 +163,11 @@ protected PerspexProperty(PerspexProperty source, Type ownerType) /// public Action Notifying { get; } + /// + /// Gets the integer ID that represents this property. + /// + internal int Id { get; } + /// /// Provides access to a property's binding via the /// indexer. @@ -392,13 +396,13 @@ public override bool Equals(object obj) /// public bool Equals(PerspexProperty other) { - return other != null && _id == other._id; + return other != null && Id == other.Id; } /// public override int GetHashCode() { - return _id; + return Id; } /// diff --git a/src/Perspex.Base/PerspexPropertyRegistry.cs b/src/Perspex.Base/PerspexPropertyRegistry.cs index 871837331ac..25a1013abb1 100644 --- a/src/Perspex.Base/PerspexPropertyRegistry.cs +++ b/src/Perspex.Base/PerspexPropertyRegistry.cs @@ -17,14 +17,14 @@ public class PerspexPropertyRegistry /// /// The registered properties by type. /// - private readonly Dictionary> _registered = - new Dictionary>(); + private readonly Dictionary> _registered = + new Dictionary>(); /// /// The registered attached properties by owner type. /// - private readonly Dictionary> _attached = - new Dictionary>(); + private readonly Dictionary> _attached = + new Dictionary>(); /// /// Gets the instance @@ -39,11 +39,11 @@ public class PerspexPropertyRegistry /// A collection of definitions. public IEnumerable GetAttached(Type ownerType) { - List list; + Dictionary inner; - if (_attached.TryGetValue(ownerType, out list)) + if (_attached.TryGetValue(ownerType, out inner)) { - return list; + return inner.Values; } return Enumerable.Empty(); @@ -65,13 +65,13 @@ public IEnumerable GetRegistered(Type type) // Ensure the type's static ctor has been run. RuntimeHelpers.RunClassConstructor(type.TypeHandle); - List list; + Dictionary inner; - if (_registered.TryGetValue(type, out list)) + if (_registered.TryGetValue(type, out inner)) { - foreach (PerspexProperty p in list) + foreach (var p in inner) { - yield return p; + yield return p.Value; } } @@ -105,15 +105,15 @@ public PerspexProperty FindRegistered(Type type, PerspexProperty property) { while (type != null) { - List list; + Dictionary inner; - if (_registered.TryGetValue(type, out list)) + if (_registered.TryGetValue(type, out inner)) { - var index = list.IndexOf(property); + PerspexProperty result; - if (index != -1) + if (inner.TryGetValue(property.Id, out result)) { - return list[index]; + return result; } } @@ -250,30 +250,30 @@ public void Register(Type type, PerspexProperty property) Contract.Requires(type != null); Contract.Requires(property != null); - List list; + Dictionary inner; - if (!_registered.TryGetValue(type, out list)) + if (!_registered.TryGetValue(type, out inner)) { - list = new List(); - _registered.Add(type, list); + inner = new Dictionary(); + _registered.Add(type, inner); } - if (!list.Contains(property)) + if (!inner.ContainsKey(property.Id)) { - list.Add(property); + inner.Add(property.Id, property); } if (property.IsAttached) { - if (!_attached.TryGetValue(property.OwnerType, out list)) + if (!_attached.TryGetValue(property.OwnerType, out inner)) { - list = new List(); - _attached.Add(property.OwnerType, list); + inner = new Dictionary(); + _attached.Add(property.OwnerType, inner); } - if (!list.Contains(property)) + if (!inner.ContainsKey(property.Id)) { - list.Add(property); + inner.Add(property.Id, property); } } }