MapperLongExt.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 TDtoResult? MapDto2Dto<TDto,TDtoResult>(this TDto? dto)
  21. where TDto : class, IDto, new()
  22. where TDtoResult : class, IDto, new()
  23. {
  24. if (dto == null) return null;
  25. return MapperLong.Instance.Map<TDto, TDtoResult>(dto);
  26. }
  27. public static void CopyToDto<TDto, TDao>(this TDto? @from, TDao? to)
  28. where TDao : class, IDao<long>, new()
  29. where TDto : class, IDto, new()
  30. {
  31. if (@from == null) return;
  32. if (to == null) return;
  33. MapperLong.Instance.Update(@from,to);
  34. }
  35. public static void CopyToDto<TDto, TDao>(this TDao? @from, TDto? to)
  36. where TDao : class, IDao<long>, new()
  37. where TDto : class, IDto, new()
  38. {
  39. if (to == null) return;
  40. if (@from == null) return;
  41. MapperLong.Instance.Update(@from,to);
  42. }
  43. public static List<TDto> MapList<TDao, TDto>(this IQueryable<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 IEnumerable<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 List<TDto> MapList<TDao, TDto>(this IList<TDao>? dao)
  58. where TDao : class, IDao<long>, new()
  59. where TDto : class, IDto, new()
  60. {
  61. if (dao == null) return new List<TDto>();
  62. return MapperLong.Instance.MapList<TDao, TDto>(dao);
  63. }
  64. public static IQueryable<TDao> MapListDto<TDto,TDao>(this IEnumerable<TDto>? dto)
  65. where TDao : class, IDao<long>, new()
  66. where TDto : class, IDto, new()
  67. {
  68. if (dto == null) return new List<TDao>().AsQueryable();
  69. return MapperLong.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
  70. }
  71. }
  72. }