From fe6e021cb5a52fe8ce7efe11b933e76f001538ee Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 7 May 2015 15:28:40 +0200 Subject: [PATCH] Make PriorityValue internal. Want to add computed/readonly values in the near future which will not use PriorityValue. --- .../Diagnostics/IPerspexPropertyBinding.cs | 17 ---------- .../Diagnostics/PerspexPropertyBinding.cs | 17 ---------- .../Diagnostics/PerspexPropertyValue.cs | 21 +++++------- Perspex.Base/Perspex.Base.csproj | 2 -- Perspex.Base/PerspexObject.cs | 33 +++++++++++-------- Perspex.Base/PriorityValue.cs | 11 ++----- Perspex.Base/Properties/AssemblyInfo.cs | 3 ++ Perspex.Diagnostics/Debug.cs | 4 +-- .../ViewModels/PropertyDetails.cs | 14 ++++---- .../PerspexPropertyTests.cs | 13 ++++++-- 10 files changed, 53 insertions(+), 82 deletions(-) delete mode 100644 Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs delete mode 100644 Perspex.Base/Diagnostics/PerspexPropertyBinding.cs diff --git a/Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs b/Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs deleted file mode 100644 index a27cc7e902..0000000000 --- a/Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2015 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Diagnostics -{ - public interface IPerspexPropertyBinding - { - string Description { get; } - - int Priority { get; } - - object Value { get; } - } -} \ No newline at end of file diff --git a/Perspex.Base/Diagnostics/PerspexPropertyBinding.cs b/Perspex.Base/Diagnostics/PerspexPropertyBinding.cs deleted file mode 100644 index 771fb73b40..0000000000 --- a/Perspex.Base/Diagnostics/PerspexPropertyBinding.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2015 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Diagnostics -{ - internal class PerspexPropertyBinding : IPerspexPropertyBinding - { - public string Description { get; set; } - - public int Priority { get; set; } - - public object Value { get; set; } - } -} \ No newline at end of file diff --git a/Perspex.Base/Diagnostics/PerspexPropertyValue.cs b/Perspex.Base/Diagnostics/PerspexPropertyValue.cs index ac82fce932..7a4392f3b4 100644 --- a/Perspex.Base/Diagnostics/PerspexPropertyValue.cs +++ b/Perspex.Base/Diagnostics/PerspexPropertyValue.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// -------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // @@ -8,23 +8,20 @@ namespace Perspex.Diagnostics { public class PerspexPropertyValue { - public PerspexPropertyValue(PerspexProperty property, object value) + public PerspexPropertyValue( + PerspexProperty property, + object value, + BindingPriority priority) { this.Property = property; - this.CurrentValue = value; - } - - public PerspexPropertyValue(PerspexProperty property, PriorityValue priorityValue) - { - this.Property = property; - this.CurrentValue = priorityValue.Value; - this.PriorityValue = priorityValue; + this.Value = value; + this.Priority = priority; } public PerspexProperty Property { get; private set; } - public object CurrentValue { get; private set; } + public object Value { get; private set; } - public PriorityValue PriorityValue { get; private set; } + public BindingPriority Priority { get; private set; } } } diff --git a/Perspex.Base/Perspex.Base.csproj b/Perspex.Base/Perspex.Base.csproj index 4c34b004c8..cd618b7f8f 100644 --- a/Perspex.Base/Perspex.Base.csproj +++ b/Perspex.Base/Perspex.Base.csproj @@ -37,8 +37,6 @@ - - diff --git a/Perspex.Base/PerspexObject.cs b/Perspex.Base/PerspexObject.cs index 6f62a7f874..69a504b1f5 100644 --- a/Perspex.Base/PerspexObject.cs +++ b/Perspex.Base/PerspexObject.cs @@ -94,20 +94,16 @@ namespace Perspex /// public PerspexObject() { - foreach (var p in this.GetAllValues()) + foreach (var property in this.GetRegisteredProperties()) { - var priority = p.PriorityValue != null ? - (BindingPriority)p.PriorityValue.ValuePriority : - BindingPriority.LocalValue; - var e = new PerspexPropertyChangedEventArgs( - this, - p.Property, - PerspexProperty.UnsetValue, - p.CurrentValue, - priority); + this, + property, + PerspexProperty.UnsetValue, + property.GetDefaultValue(this.GetType()), + BindingPriority.Unset); - p.Property.NotifyInitialized(e); + property.NotifyInitialized(e); } } @@ -427,11 +423,17 @@ namespace Perspex if (this.values.TryGetValue(property, out value)) { - yield return new PerspexPropertyValue(property, value); + yield return new PerspexPropertyValue( + property, + value.Value, + (BindingPriority)value.ValuePriority); } else { - yield return new PerspexPropertyValue(property, this.GetValue(property)); + yield return new PerspexPropertyValue( + property, + this.GetValue(property), + BindingPriority.Unset); } } } @@ -469,7 +471,10 @@ namespace Perspex { foreach (var value in this.values) { - yield return new PerspexPropertyValue(value.Key, value.Value); + yield return new PerspexPropertyValue( + value.Key, + value.Value.Value, + (BindingPriority)value.Value.ValuePriority); } } diff --git a/Perspex.Base/PriorityValue.cs b/Perspex.Base/PriorityValue.cs index 1ca7a85b83..7ec0bdda01 100644 --- a/Perspex.Base/PriorityValue.cs +++ b/Perspex.Base/PriorityValue.cs @@ -25,7 +25,7 @@ namespace Perspex /// has a higher priority. Each time the value changes, the observable is /// fired with the old and new values. /// - public class PriorityValue + internal class PriorityValue { /// /// The name of the property. @@ -160,18 +160,13 @@ namespace Perspex /// Gets the currently active bindings on this object. /// /// An enumerable collection of bindings. - public IEnumerable GetBindings() + public IEnumerable GetBindings() { foreach (var level in this.levels) { foreach (var binding in level.Value.Bindings) { - yield return new PerspexPropertyBinding - { - Description = binding.Description, - Priority = level.Key, - Value = binding.Value, - }; + yield return binding; } } } diff --git a/Perspex.Base/Properties/AssemblyInfo.cs b/Perspex.Base/Properties/AssemblyInfo.cs index 847139f979..b2057ea73c 100644 --- a/Perspex.Base/Properties/AssemblyInfo.cs +++ b/Perspex.Base/Properties/AssemblyInfo.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Resources; +using System.Runtime.CompilerServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -32,3 +33,5 @@ using System.Resources; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly:InternalsVisibleTo("Perspex.Base.UnitTests")] \ No newline at end of file diff --git a/Perspex.Diagnostics/Debug.cs b/Perspex.Diagnostics/Debug.cs index 80bb82c3e8..27eea5fda0 100644 --- a/Perspex.Diagnostics/Debug.cs +++ b/Perspex.Diagnostics/Debug.cs @@ -46,9 +46,9 @@ namespace Perspex.Diagnostics builder.Append(" | "); builder.Append(value.Property.Name); builder.Append(" = "); - builder.Append(value.CurrentValue ?? "(null)"); + builder.Append(value.Value ?? "(null)"); builder.Append(" ["); - builder.Append(value.PriorityValue.ValuePriority); + builder.Append(value.Priority); builder.AppendLine("]"); } } diff --git a/Perspex.Diagnostics/ViewModels/PropertyDetails.cs b/Perspex.Diagnostics/ViewModels/PropertyDetails.cs index 1da18f0995..c3570aa5c7 100644 --- a/Perspex.Diagnostics/ViewModels/PropertyDetails.cs +++ b/Perspex.Diagnostics/ViewModels/PropertyDetails.cs @@ -20,15 +20,15 @@ namespace Perspex.Diagnostics.ViewModels value.Property.Name; this.IsAttached = value.Property.IsAttached; - this.value = value.CurrentValue ?? "(null)"; - this.Priority = (value.PriorityValue != null) ? - Enum.GetName(typeof(BindingPriority), value.PriorityValue.ValuePriority) : + this.value = value.Value ?? "(null)"; + this.Priority = (value.Priority != BindingPriority.Unset) ? + value.Priority.ToString() : value.Property.Inherits ? "Inherited" : "Unset"; - if (value.PriorityValue != null) - { - value.PriorityValue.Changed.Subscribe(x => this.Value = x.Item2); - } + //if (value.PriorityValue != null) + //{ + // value.PriorityValue.Changed.Subscribe(x => this.Value = x.Item2); + //} } public string Name diff --git a/Tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs b/Tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs index 7305ad8e14..793d3396f6 100644 --- a/Tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs +++ b/Tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs @@ -89,12 +89,19 @@ namespace Perspex.Base.UnitTests [Fact] public void Initialized_Observable_Fired() { - string value = null; + bool invoked = false; + + Class1.FooProperty.Initialized.Subscribe(x => + { + Assert.Equal(PerspexProperty.UnsetValue, x.OldValue); + Assert.Equal("default", x.NewValue); + Assert.Equal(BindingPriority.Unset, x.Priority); + invoked = true; + }); - Class1.FooProperty.Initialized.Subscribe(x => value = (string)x.NewValue); var target = new Class1(); - Assert.Equal("default", value); + Assert.True(invoked); } [Fact]