diff --git a/src/Perspex.Base/PerspexProperty.cs b/src/Perspex.Base/PerspexProperty.cs index 9ce204ef4b..94f9baf5ba 100644 --- a/src/Perspex.Base/PerspexProperty.cs +++ b/src/Perspex.Base/PerspexProperty.cs @@ -36,23 +36,22 @@ namespace Perspex /// /// The overridden default values for the property, by type. /// - private readonly Dictionary _defaultValues = new Dictionary(); + private readonly Dictionary _defaultValues; /// /// Observable fired when this property changes on any . /// - private readonly Subject _initialized = new Subject(); + private readonly Subject _initialized; /// /// Observable fired when this property changes on any . /// - private readonly Subject _changed = new Subject(); + private readonly Subject _changed; /// /// The validation functions for the property, by type. /// - private readonly Dictionary> _validation = - new Dictionary>(); + private readonly Dictionary> _validation; /// /// Gets the ID of the property. @@ -95,6 +94,11 @@ namespace Perspex throw new ArgumentException("'name' may not contain periods."); } + _defaultValues = new Dictionary(); + _initialized = new Subject(); + _changed = new Subject(); + _validation = new Dictionary>(); + Name = name; PropertyType = valueType; OwnerType = ownerType; @@ -136,6 +140,11 @@ namespace Perspex throw new ArgumentException("'name' may not contain periods."); } + _defaultValues = new Dictionary(); + _initialized = new Subject(); + _changed = new Subject(); + _validation = new Dictionary>(); + Name = name; PropertyType = valueType; OwnerType = ownerType; @@ -161,22 +170,15 @@ namespace Perspex "This method cannot be called on direct PerspexProperties."); } - //Name = name; - //PropertyType = valueType; - //OwnerType = ownerType; - //_defaultValues.Add(ownerType, defaultValue); - //Inherits = inherits; - //DefaultBindingMode = defaultBindingMode; - //IsAttached = isAttached; - //Notifying = notifying; - //_id = s_nextId++; - + _defaultValues = source._defaultValues; + _initialized = source._initialized; + _changed = source._changed; + _validation = source._validation; Name = source.Name; PropertyType = source.PropertyType; OwnerType = ownerType; _defaultValue = source._defaultValue; - _defaultValues = source._defaultValues; Inherits = source.Inherits; DefaultBindingMode = source.DefaultBindingMode; IsAttached = false; @@ -208,6 +210,11 @@ namespace Perspex "This method can only be called on direct PerspexProperties."); } + _defaultValues = source._defaultValues; + _initialized = source._initialized; + _changed = source._changed; + _validation = source._validation; + Name = source.Name; PropertyType = source.PropertyType; OwnerType = ownerType; diff --git a/tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs b/tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs index c858152da5..b37cb49323 100644 --- a/tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs +++ b/tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs @@ -170,6 +170,16 @@ namespace Perspex.Base.UnitTests Assert.Equal(typeof(Class3), p2.OwnerType); } + [Fact] + public void AddOwnered_Properties_Should_Share_Observables() + { + var p1 = new PerspexProperty("p1", typeof(Class1)); + var p2 = p1.AddOwner(); + + Assert.Same(p1.Changed, p2.Changed); + Assert.Same(p1.Initialized, p2.Initialized); + } + [Fact] public void AddOwnered_Direct_Property_Should_Equal_Original() { @@ -190,6 +200,16 @@ namespace Perspex.Base.UnitTests Assert.Equal(typeof(Class3), p2.OwnerType); } + [Fact] + public void AddOwnered_Direct_Properties_Should_Share_Observables() + { + var p1 = new PerspexProperty("d1", typeof(Class1), o => null, (o, v) => { }); + var p2 = p1.AddOwner(o => null, (o, v) => { }); + + Assert.Same(p1.Changed, p2.Changed); + Assert.Same(p1.Initialized, p2.Initialized); + } + [Fact] public void AddOwner_With_Getter_And_Setter_On_Standard_Property_Should_Throw() {