标签:
http://www.cnblogs.com/lori/p/3327898.html
/// <summary> /// AutoMapper扩展方法 /// </summary> public static class AutoMapperExtension { /// <summary> /// 集合对集合 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="self"></param> /// <returns></returns> public static List<TResult> MapTo<TResult>(this IEnumerable self) { if (self == null) throw new ArgumentNullException(); Mapper.CreateMap(self.GetType(), typeof(TResult)); return (List<TResult>)Mapper.Map(self, self.GetType(), typeof(List<TResult>)); } /// <summary> /// 对象对对象 /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="self"></param> /// <returns></returns> public static TResult MapTo<TResult>(this object self) { if (self == null) throw new ArgumentNullException(); Mapper.CreateMap(self.GetType(), typeof(TResult)); return (TResult)Mapper.Map(self, self.GetType(), typeof(TResult)); } }
标签:
原文地址:http://www.cnblogs.com/shiningrise/p/5615767.html