using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutoMapper; namespace MyCode.Project.Infrastructure.Common { public class AutoMapperHelper { /// /// 映射单个实体 /// /// 目标对象 /// 数据来源对象 /// 数据原变量 /// public static T AutoMappToSingle(F fromData) { var datatype = fromData.GetType(); Mapper.Initialize(x => { x.CreateMap (); }); var result = Mapper.Map(fromData); return result; } /// /// 映射LIST /// /// 目标对象List /// 数据来源对象List /// 数据原变量List /// public static List AutoMappToList(List fromData) { var datatype = fromData.GetType(); Mapper.Initialize(x => { x.CreateMap(); }); var result = Mapper.Map>(fromData); return result; } } }