Browse Source

Make PriorityValue internal.

Want to add computed/readonly values in the near future which will not
use PriorityValue.
pull/58/head
Steven Kirk 11 years ago
parent
commit
fe6e021cb5
  1. 17
      Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs
  2. 17
      Perspex.Base/Diagnostics/PerspexPropertyBinding.cs
  3. 21
      Perspex.Base/Diagnostics/PerspexPropertyValue.cs
  4. 2
      Perspex.Base/Perspex.Base.csproj
  5. 33
      Perspex.Base/PerspexObject.cs
  6. 11
      Perspex.Base/PriorityValue.cs
  7. 3
      Perspex.Base/Properties/AssemblyInfo.cs
  8. 4
      Perspex.Diagnostics/Debug.cs
  9. 14
      Perspex.Diagnostics/ViewModels/PropertyDetails.cs
  10. 13
      Tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs

17
Perspex.Base/Diagnostics/IPerspexPropertyBinding.cs

@ -1,17 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="IPerspexPropertyBinding.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Diagnostics
{
public interface IPerspexPropertyBinding
{
string Description { get; }
int Priority { get; }
object Value { get; }
}
}

17
Perspex.Base/Diagnostics/PerspexPropertyBinding.cs

@ -1,17 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="PerspexPropertyBinding.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Diagnostics
{
internal class PerspexPropertyBinding : IPerspexPropertyBinding
{
public string Description { get; set; }
public int Priority { get; set; }
public object Value { get; set; }
}
}

21
Perspex.Base/Diagnostics/PerspexPropertyValue.cs

@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------
// <copyright file="PerspexPropertyValue.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
@ -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; }
}
}

2
Perspex.Base/Perspex.Base.csproj

@ -37,8 +37,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Binding.cs" />
<Compile Include="Diagnostics\PerspexPropertyBinding.cs" />
<Compile Include="Diagnostics\IPerspexPropertyBinding.cs" />
<Compile Include="PriorityBindingEntry.cs" />
<Compile Include="Collections\IPerspexList.cs" />
<Compile Include="Collections\PerspexReadOnlyListView.cs" />

33
Perspex.Base/PerspexObject.cs

@ -94,20 +94,16 @@ namespace Perspex
/// </summary>
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);
}
}

11
Perspex.Base/PriorityValue.cs

@ -25,7 +25,7 @@ namespace Perspex
/// has a higher priority. Each time the value changes, the <see cref="Changed"/> observable is
/// fired with the old and new values.
/// </remarks>
public class PriorityValue
internal class PriorityValue
{
/// <summary>
/// The name of the property.
@ -160,18 +160,13 @@ namespace Perspex
/// Gets the currently active bindings on this object.
/// </summary>
/// <returns>An enumerable collection of bindings.</returns>
public IEnumerable<IPerspexPropertyBinding> GetBindings()
public IEnumerable<PriorityBindingEntry> 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;
}
}
}

3
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")]

4
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("]");
}
}

14
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

13
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]

Loading…
Cancel
Save