using System; using System.Linq.Expressions; using System.Reflection; namespace InABox.Core { public class LinkedProperty { private LinkedProperty(PropertyInfo source, PropertyInfo target) { Source = source; Target = target; } public PropertyInfo Source { get; } public PropertyInfo Target { get; } public static LinkedProperty Create(Expression> source, Expression> target) { return new LinkedProperty( CoreUtils.GetPropertyFromExpression(source), CoreUtils.GetPropertyFromExpression(target) ); } public void Update(object from, object to) { if (from != null && to != null) { var value = Source.GetValue(from); Target.SetValue(to, value); } } } }