123456789101112131415161718192021222324252627282930313233343536 |
- 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<TEntityLink, TLinkedEntity>(Expression<Func<TEntityLink, object>> source,
- Expression<Func<TLinkedEntity, object>> 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);
- }
- }
- }
- }
|