123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using AutoMapper;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WMS.Util
- {
- public static class AutoMapperExt
- {
- private static readonly IMapper _mapper;
- static AutoMapperExt()
- {
- var config = new MapperConfiguration(cfg =>
- {
- //cfg.CreateMap<SourceClass, DestinationClass>();
- //cfg.CreateMap<SubSourceClass, SubDestinationClass>();
- });
-
- _mapper = config.CreateMapper();
- }
- public static TDestination Map<TDestination>(object source)
- {
-
- return _mapper.Map<TDestination>(source);
- }
- public static TDestination Map<TSource, TDestination>(TSource source)
- {
- return _mapper.Map<TSource, TDestination>(source);
- }
- public static List<TDestination> MapToList<TDestination>(this IEnumerable source)
- {
- return _mapper.Map<List<TDestination>>(source);
- }
- public static List<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source)
- {
- return _mapper.Map<List<TSource>, List<TDestination>>(source.ToList());
- }
- /// <summary>
- /// DataReader映射
- /// </summary>
- public static IEnumerable<T> DataReaderMapTo<T>(this IDataReader reader)
- {
- return _mapper.Map<IDataReader, IEnumerable<T>>(reader);
- }
- }
-
- }
|