Browse Source

Fix PerspexProperty.IsSet.

pull/242/merge
Steven Kirk 10 years ago
parent
commit
c9d08fd691
  1. 9
      src/Perspex.Base/PerspexObject.cs
  2. 29
      tests/Perspex.Base.UnitTests/PerspexObjectTests_Metadata.cs

9
src/Perspex.Base/PerspexObject.cs

@ -457,8 +457,15 @@ namespace Perspex
public bool IsSet(PerspexProperty property)
{
Contract.Requires<ArgumentNullException>(property != null);
PriorityValue value;
if (_values.TryGetValue(property, out value))
{
return value.Value != PerspexProperty.UnsetValue;
}
return _values.ContainsKey(property);
return false;
}
/// <summary>

29
tests/Perspex.Base.UnitTests/PerspexObjectTests_Metadata.cs

@ -42,6 +42,35 @@ namespace Perspex.Base.UnitTests
Assert.Equal(new[] { "Attached" }, names);
}
[Fact]
public void IsSet_Returns_False_For_Unset_Property()
{
var target = new Class1();
Assert.False(target.IsSet(Class1.FooProperty));
}
[Fact]
public void IsSet_Returns_False_For_Set_Property()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "foo");
Assert.True(target.IsSet(Class1.FooProperty));
}
[Fact]
public void IsSet_Returns_False_For_Cleared_Property()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "foo");
target.SetValue(Class1.FooProperty, PerspexProperty.UnsetValue);
Assert.False(target.IsSet(Class1.FooProperty));
}
private class Class1 : PerspexObject
{
public static readonly PerspexProperty<string> FooProperty =

Loading…
Cancel
Save