| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Quadarax.Foundation.Core.Data.Interface.Entity;
- namespace Quadarax.Foundation.Core.Data.Mapper
- {
- public static class MapperGuidExt
- {
- public static TDto? Map<TDao, TDto>(this TDao dao)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- return Mapper<MapperGuid>.Instance.Map<TDao, TDto>(dao);
- }
- public static TDao? MapDto<TDto, TDao>(this TDto dto)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- return Mapper<MapperGuid>.Instance.Map<TDto, TDao>(dto);
- }
- public static void CopyToDto<TDto, TDao>(this TDto @from, TDao? to)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- if (to == null) return;
- Mapper<MapperGuid>.Instance.Update(@from,to);
- }
- public static void CopyToDto<TDto, TDao>(this TDao @from, TDto? to)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- if (to == null) return;
- Mapper<MapperGuid>.Instance.Update(@from,to);
- }
- public static List<TDto>? MapList<TDao, TDto>(this IQueryable<TDao> dao)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- return Mapper<MapperGuid>.Instance.MapList<TDao, TDto>(dao);
- }
- public static List<TDto>? MapList<TDao, TDto>(this IEnumerable<TDao> dao)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- return Mapper<MapperGuid>.Instance.MapList<TDao, TDto>(dao);
- }
- public static IQueryable<TDao> MapListDto<TDto,TDao>(this IEnumerable<TDto> dto)
- where TDao : class, IDao<Guid>, new()
- where TDto : class, IDto, new()
- {
- return (Mapper<MapperGuid>.Instance.MapList<TDto, TDao>(dto?.AsQueryable()) ?? throw new InvalidOperationException()).AsQueryable();
- }
- }
- }
|