MapperExt.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Quadarax.Foundation.Core.Data.Interface.Entity;
  5. namespace Quadarax.Foundation.Core.Data.Mapper
  6. {
  7. /*
  8. public static class MapperExt
  9. {
  10. public static TDto Map<TDao, TDto, TKey>(this TDao dao)
  11. where TDao : class, IDao<TKey>, new()
  12. where TDto : class, IDto, new()
  13. where TKey : IEquatable<TKey>
  14. {
  15. if (dao == null) return null;
  16. return Mapper.Instance.Map<TDao, TDto>(dao);
  17. }
  18. public static TDao MapDto<TDto, TDao, TKey>(this TDto dto)
  19. where TDao : class, IDao<TKey>, new()
  20. where TDto : class, IDto, new()
  21. where TKey : IEquatable<TKey>
  22. {
  23. if (dto == null) return null;
  24. return Mapper.Instance.Map<TDto, TDao>(dto);
  25. }
  26. public static List<TDto> MapList<TDao, TDto, TKey>(this IQueryable<TDao> dao)
  27. where TDao : class, IDao<TKey>, new()
  28. where TDto : class, IDto, new()
  29. where TKey : IEquatable<TKey>
  30. {
  31. if (dao == null) return new List<TDto>();
  32. return Mapper.Instance.MapList<TDao, TDto>(dao);
  33. }
  34. public static List<TDto> MapList<TDao, TDto,TKey>(this IEnumerable<TDao> dao)
  35. where TDao : class, IDao<TKey>, new()
  36. where TDto : class, IDto, new()
  37. where TKey : IEquatable<TKey>
  38. {
  39. if (dao == null) return new List<TDto>();
  40. return Mapper.Instance.MapList<TDao, TDto>(dao);
  41. }
  42. public static IQueryable<TDao> MapListDto<TDto,TDao,TKey>(this IEnumerable<TDto> dto)
  43. where TDao : class, IDao<TKey>, new()
  44. where TDto : class, IDto, new()
  45. where TKey : IEquatable<TKey>
  46. {
  47. if (dto == null) return new List<TDao>().AsQueryable();
  48. return Mapper.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
  49. }
  50. }
  51. */
  52. }