|
@@ -4,33 +4,51 @@ using System.Reflection;
|
|
|
|
|
|
namespace InABox.Core
|
|
|
{
|
|
|
- public class LinkedProperty
|
|
|
+ public interface ILinkedProperty
|
|
|
{
|
|
|
- private LinkedProperty(PropertyInfo source, PropertyInfo target)
|
|
|
+ Type Type { get; }
|
|
|
+ String Path { get; }
|
|
|
+ String Source { get; }
|
|
|
+ String Target { get; }
|
|
|
+ void Update(object? from, object? to);
|
|
|
+ bool Equals(object obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ public class LinkedProperty<TLinkedEntity, TEntityLink, TType> : ILinkedProperty
|
|
|
+ {
|
|
|
+ public Type Type => typeof(TLinkedEntity);
|
|
|
+ public String Path { get; }
|
|
|
+ public String Source { get; }
|
|
|
+ public String Target { get; }
|
|
|
+
|
|
|
+ public LinkedProperty(Expression<Func<TLinkedEntity, TEntityLink>> path,
|
|
|
+ Expression<Func<TEntityLink, TType>> source,
|
|
|
+ Expression<Func<TLinkedEntity, TType>> target)
|
|
|
{
|
|
|
- Source = source;
|
|
|
- Target = target;
|
|
|
+ Path = CoreUtils.GetFullPropertyName(path, ".");
|
|
|
+ Source = CoreUtils.GetFullPropertyName(source, ".");
|
|
|
+ Target = CoreUtils.GetFullPropertyName(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)
|
|
|
+ public void Update(object? from, object? to)
|
|
|
{
|
|
|
- return new LinkedProperty(
|
|
|
- CoreUtils.GetPropertyFromExpression(source),
|
|
|
- CoreUtils.GetPropertyFromExpression(target)
|
|
|
- );
|
|
|
+ if (from != null && to != null)
|
|
|
+ {
|
|
|
+ var value = CoreUtils.GetPropertyValue(from, Source);
|
|
|
+ CoreUtils.SetPropertyValue(to, Target, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void Update(object from, object to)
|
|
|
+ public override bool Equals(object obj)
|
|
|
{
|
|
|
- if (from != null && to != null)
|
|
|
+ if (obj is ILinkedProperty src)
|
|
|
{
|
|
|
- var value = Source.GetValue(from);
|
|
|
- Target.SetValue(to, value);
|
|
|
+ return
|
|
|
+ String.Equals(src.Path,Path)
|
|
|
+ && String.Equals(src.Source, Source)
|
|
|
+ && String.Equals(src.Target, Target);
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
}
|