using AutoMapper; namespace DS.Module.Core.Extensions; /// /// AutoMapper扩展类 /// public static class AutoMapperExtension { /// /// 对象映射 /// public static TOut MapTo(this TIn source) { if (source == null) return default(TOut); var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = config.CreateMapper(); return mapper.Map(source); } /// /// 对象映射(自定义) /// public static TOut MapTo(this TIn source, Profile profile) { if (source == null) return default(TOut); var config = new MapperConfiguration(cfg => cfg.AddProfile(profile)); var mapper = config.CreateMapper(); return mapper.Map(source); } /// /// 集合映射 /// /// /// /// /// public static IEnumerable MapToList(this IEnumerable source) { if (source == null) return new List(); var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = config.CreateMapper(); return mapper.Map>(source); } /// /// 集合映射(自定义) /// /// /// /// /// /// public static IEnumerable MapToList(this IEnumerable source, Profile profile) { if (source == null) return new List(); var config = new MapperConfiguration(cfg => cfg.AddProfile(profile)); var mapper = config.CreateMapper(); return mapper.Map>(source); } }