12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- namespace InABox.Core
- {
- public static class LinkedProperties
- {
- private static readonly List<ILinkedProperty> _LinkedProperties = new List<ILinkedProperty>();
- public static IEnumerable<ILinkedProperty> All => _LinkedProperties;
-
- public static void Register<TLinkedEntity, TEntityLink, TType>(Expression<Func<TLinkedEntity,TEntityLink>> path, Expression<Func<TEntityLink, TType>> source,
- Expression<Func<TLinkedEntity, TType>> target)
- {
- var map = new LinkedProperty<TLinkedEntity, TEntityLink, TType>(path, source, target);
- if (!_LinkedProperties.Any(x => x.Equals(map)))
- _LinkedProperties.Add(map);
- }
- public static IEnumerable<ILinkedProperty> Find(object parent, object path)
- {
- var all = _LinkedProperties.Where(x => x.Type == parent.GetType());
- var filtered = all.Where(x => CoreUtils.GetPropertyValue(parent,x.Path)?.GetType() == path?.GetType());
- return filtered;
- }
-
- }
- }
|