| | 1 | | using AutoMapper; |
| | 2 | | using CoWorkingApp.Core.Application.Contracts.Adapters; |
| | 3 | |
|
| | 4 | | namespace CoWorkingApp.API.Infrastructure.Adapters |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Adaptador de AutoMapper que implementa la interfaz IMapperAdapter. |
| | 8 | | /// </summary> |
| | 9 | | public class AutoMapperAdapter : IMapperAdapter |
| | 10 | | { |
| | 11 | | private readonly IMapper _mapper; |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Constructor de la clase AutoMapperAdapter. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="mapper">Instancia de IMapper proporcionada por AutoMapper.</param> |
| 4 | 17 | | public AutoMapperAdapter(IMapper mapper) |
| 4 | 18 | | { |
| 4 | 19 | | _mapper = mapper ?? throw new ArgumentNullException(); |
| 3 | 20 | | } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Mapea un objeto de origen a un objeto de destino. |
| | 24 | | /// </summary> |
| | 25 | | /// <typeparam name="TSource">Tipo de objeto de origen.</typeparam> |
| | 26 | | /// <typeparam name="TDestination">Tipo de objeto de destino.</typeparam> |
| | 27 | | /// <param name="source">Objeto de origen a ser mapeado.</param> |
| | 28 | | /// <returns>Objeto de destino mapeado.</returns> |
| | 29 | | public TDestination Map<TSource, TDestination>(TSource source) |
| 1 | 30 | | { |
| 1 | 31 | | return _mapper.Map<TSource, TDestination>(source); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Mapea una colección de objetos de origen a una colección de objetos de destino. |
| | 36 | | /// </summary> |
| | 37 | | /// <typeparam name="TSource">Tipo de objeto de origen.</typeparam> |
| | 38 | | /// <typeparam name="TDestination">Tipo de objeto de destino.</typeparam> |
| | 39 | | /// <param name="source">Colección de objetos de origen a ser mapeados.</param> |
| | 40 | | /// <returns>Colección de objetos de destino mapeados.</returns> |
| | 41 | | public IEnumerable<TDestination> Map<TSource, TDestination>(IEnumerable<TSource> source) |
| 1 | 42 | | { |
| 1 | 43 | | return _mapper.Map<IEnumerable<TSource>, IEnumerable<TDestination>>(source); |
| 1 | 44 | | } |
| | 45 | | } |
| | 46 | | } |