Browse Source

Merge branch 'bindings' into xaml-datatemplates

pull/237/head
Steven Kirk 11 years ago
parent
commit
19b7fc53da
  1. 23
      src/Markup/Perspex.Markup/Binding/PropertyAccessorNode.cs
  2. 15
      tests/Perspex.Markup.UnitTests/Binding/ExpressionObserverTests_Property.cs

23
src/Markup/Perspex.Markup/Binding/PropertyAccessorNode.cs

@ -46,7 +46,7 @@ namespace Perspex.Markup.Binding
if (target != null)
{
_propertyInfo = target.GetType().GetTypeInfo().GetDeclaredProperty(PropertyName);
_propertyInfo = FindProperty(target, PropertyName);
if (_propertyInfo != null)
{
@ -82,6 +82,27 @@ namespace Perspex.Markup.Binding
}
}
private static PropertyInfo FindProperty(object target, string propertyName)
{
var typeInfo = target.GetType().GetTypeInfo();
do
{
var result = typeInfo.GetDeclaredProperty(propertyName);
if (result != null)
{
return result;
}
else
{
typeInfo = typeInfo.BaseType?.GetTypeInfo();
}
} while (typeInfo != null);
return null;
}
private void ReadValue(object target)
{
var value = _propertyInfo.GetValue(target);

15
tests/Perspex.Markup.UnitTests/Binding/ExpressionObserverTests_Property.cs

@ -22,6 +22,17 @@ namespace Perspex.Markup.UnitTests.Binding
Assert.Equal("foo", result.Value);
}
[Fact]
public async void Should_Get_Simple_Property_From_Base_Class()
{
var data = new Class3 { Foo = "foo" };
var target = new ExpressionObserver(data, "Foo");
var result = await target.Take(1);
Assert.True(result.HasValue);
Assert.Equal("foo", result.Value);
}
[Fact]
public async void Should_Get_Simple_Property_Chain()
{
@ -235,6 +246,10 @@ namespace Perspex.Markup.UnitTests.Binding
}
}
private class Class3 : Class1
{
}
private class WithoutBar : NotifyingBase, INext
{
}

Loading…
Cancel
Save