AutoEntityCrossGenerator.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. namespace InABox.Core
  5. {
  6. public interface IAutoEntityCrossGenerator : IAutoEntityGenerator
  7. {
  8. String LeftEntity();
  9. String LeftProperty();
  10. String LeftMapping();
  11. String LeftLink();
  12. String RightEntity();
  13. String RightProperty();
  14. String RightMapping();
  15. String RightLink();
  16. }
  17. public abstract class AutoEntityCrossGenerator<TInterface, TLeft, TRight> : IAutoEntityCrossGenerator
  18. {
  19. public abstract Expression<Func<TLeft, Guid>> LeftProperty { get; }
  20. public abstract Expression<Func<TInterface, Guid>> LeftMapping { get; }
  21. public abstract Expression<Func<TLeft, Guid>> LeftLink { get; }
  22. public abstract Expression<Func<TRight, Guid>> RightProperty { get; }
  23. public abstract Expression<Func<TInterface, Guid>> RightMapping { get; }
  24. public abstract Expression<Func<TRight, Guid>> RightLink { get; }
  25. public string LeftEntity() => typeof(TLeft).EntityName().Split('.').Last();
  26. string IAutoEntityCrossGenerator.LeftProperty() => CoreUtils.GetFullPropertyName(LeftProperty, ".");
  27. string IAutoEntityCrossGenerator.LeftMapping() => CoreUtils.GetFullPropertyName(LeftMapping, ".");
  28. string IAutoEntityCrossGenerator.LeftLink() => CoreUtils.GetFullPropertyName(LeftLink, ".");
  29. public string RightEntity() => typeof(TRight).EntityName().Split('.').Last();
  30. string IAutoEntityCrossGenerator.RightProperty() => CoreUtils.GetFullPropertyName(RightProperty, ".");
  31. string IAutoEntityCrossGenerator.RightMapping() => CoreUtils.GetFullPropertyName(RightMapping, ".");
  32. string IAutoEntityCrossGenerator.RightLink() => CoreUtils.GetFullPropertyName(RightLink, ".");
  33. public abstract bool Distinct { get; }
  34. public Type Definition => typeof(TInterface);
  35. public abstract Column<TInterface>[] IDColumns { get; }
  36. IColumn[] IAutoEntityGenerator.IDColumns => IDColumns;
  37. }
  38. }