MapperLongExt.cs 2.6 KB

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