首页 > 代码库 > AutoMapper5.0创建对象方法更新
AutoMapper5.0创建对象方法更新
/// <summary> /// 单个对象映射 /// </summary> public static TDestination MapTo<TSource, TDestination>(TSource source) { if (source == null) return default(TDestination); Mapper.Initialize(x=>x.CreateMap(typeof(TSource), typeof(TDestination))); return Mapper.Map<TDestination>(source); } /// <summary> /// 集合列表类型映射 /// </summary> public static List<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source) { if (source == null) return default(List<TDestination>); Mapper.Initialize(x => x.CreateMap(typeof(TSource), typeof(TDestination))); return Mapper.Map<List<TDestination>>(source); } /// <summary> /// 类型映射 /// </summary> public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination) where TSource : class where TDestination : class { if (source == null) return destination; Mapper.Initialize(x => x.CreateMap(typeof(TSource), typeof(TDestination))); return Mapper.Map(source, destination); }
AutoMapper5.0创建对象方法更新
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。