MapperLongExt.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Quadarax.Foundation.Core.Data.Interface.Entity;
  2. namespace Quadarax.Application.QLiberace.Base.Mapper
  3. {
  4. public static class MapperLongExt
  5. {
  6. public static TDto? Map<TDao, TDto>(this TDao? dao)
  7. where TDao : class, IDao<long>, new()
  8. where TDto : class, IDto, new()
  9. {
  10. if (dao == null) return null;
  11. return MapperLong.Instance.Map<TDao, TDto>(dao);
  12. }
  13. public static TDao? MapDto<TDto, TDao>(this TDto? dto)
  14. where TDao : class, IDao<long>, new()
  15. where TDto : class, IDto, new()
  16. {
  17. if (dto == null) return null;
  18. return MapperLong.Instance.Map<TDto, TDao>(dto);
  19. }
  20. public static void CopyToDto<TDto, TDao>(this TDto? @from, TDao? to)
  21. where TDao : class, IDao<long>, new()
  22. where TDto : class, IDto, new()
  23. {
  24. if (@from == null) return;
  25. if (to == null) return;
  26. MapperLong.Instance.Update(@from,to);
  27. }
  28. public static void CopyToDto<TDto, TDao>(this TDao? @from, TDto? to)
  29. where TDao : class, IDao<long>, new()
  30. where TDto : class, IDto, new()
  31. {
  32. if (to == null) return;
  33. if (@from == null) return;
  34. MapperLong.Instance.Update(@from,to);
  35. }
  36. public static List<TDto> MapList<TDao, TDto>(this IQueryable<TDao>? dao)
  37. where TDao : class, IDao<long>, new()
  38. where TDto : class, IDto, new()
  39. {
  40. if (dao == null) return new List<TDto>();
  41. return MapperLong.Instance.MapList<TDao, TDto>(dao);
  42. }
  43. public static List<TDto> MapList<TDao, TDto>(this IEnumerable<TDao>? dao)
  44. where TDao : class, IDao<long>, new()
  45. where TDto : class, IDto, new()
  46. {
  47. if (dao == null) return new List<TDto>();
  48. return MapperLong.Instance.MapList<TDao, TDto>(dao);
  49. }
  50. public static List<TDto> MapList<TDao, TDto>(this IList<TDao>? dao)
  51. where TDao : class, IDao<long>, new()
  52. where TDto : class, IDto, new()
  53. {
  54. if (dao == null) return new List<TDto>();
  55. return MapperLong.Instance.MapList<TDao, TDto>(dao);
  56. }
  57. public static IQueryable<TDao> MapListDto<TDto,TDao>(this IEnumerable<TDto>? dto)
  58. where TDao : class, IDao<long>, new()
  59. where TDto : class, IDto, new()
  60. {
  61. if (dto == null) return new List<TDao>().AsQueryable();
  62. return MapperLong.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
  63. }
  64. }
  65. }