LinkedProperties.cs 978 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. namespace InABox.Core
  6. {
  7. public static class LinkedProperties
  8. {
  9. private static readonly List<ILinkedProperty> _LinkedProperties = new List<ILinkedProperty>();
  10. public static void Register<TLinkedEntity, TEntityLink, TType>(Expression<Func<TLinkedEntity,TEntityLink>> path, Expression<Func<TEntityLink, TType>> source,
  11. Expression<Func<TLinkedEntity, TType>> target)
  12. {
  13. var map = new LinkedProperty<TLinkedEntity, TEntityLink, TType>(path, source, target);
  14. if (!_LinkedProperties.Any(x => x.Equals(map)))
  15. _LinkedProperties.Add(map);
  16. }
  17. public static IEnumerable<ILinkedProperty> Find(object parent, object path)
  18. {
  19. return _LinkedProperties.Where(x => (x.Type == parent.GetType()) && (CoreUtils.GetPropertyValue(parent,x.Path) == path));
  20. }
  21. }
  22. }