csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
namespace Perspex.Xaml.DataBinding.ChangeTracking
|
|
{
|
|
using System;
|
|
using System.Reflection;
|
|
using Glass;
|
|
|
|
public class PropertyMountPoint
|
|
{
|
|
private readonly TargettedProperty referencedTargettedProperty;
|
|
|
|
public PropertyMountPoint(object origin, PropertyPath propertyPath)
|
|
{
|
|
Guard.ThrowIfNull(origin, nameof(origin));
|
|
Guard.ThrowIfNull(propertyPath, nameof(propertyPath));
|
|
|
|
this.referencedTargettedProperty = GetReferencedPropertyInfo(origin, propertyPath, 0);
|
|
}
|
|
|
|
private static TargettedProperty GetReferencedPropertyInfo(object current, PropertyPath propertyPath, int level)
|
|
{
|
|
var typeInfo = current.GetType().GetTypeInfo();
|
|
var leftPropertyInfo = typeInfo.GetDeclaredProperty(propertyPath.Chunks[level]);
|
|
|
|
if (level == propertyPath.Chunks.Length - 1)
|
|
{
|
|
return new TargettedProperty(current, leftPropertyInfo);
|
|
}
|
|
|
|
var nextInstance = leftPropertyInfo.GetValue(current);
|
|
|
|
return GetReferencedPropertyInfo(nextInstance, propertyPath, level + 1);
|
|
}
|
|
|
|
public object Value
|
|
{
|
|
get
|
|
{
|
|
return referencedTargettedProperty.Value;
|
|
}
|
|
set
|
|
{
|
|
referencedTargettedProperty.Value = value;
|
|
}
|
|
}
|
|
|
|
public Type ProperyType => referencedTargettedProperty.PropertyType;
|
|
}
|
|
}
|