using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Xzy.KnowledgeBase.Domain.Map { public static class MapperExtend { /// /// Entity集合转DTO集合 /// /// /// /// public static List ToDTOList(this object value) { if (value == null) return new List(); return Mapper.Map>(value); } /// /// Entity转DTO /// /// /// /// public static T ToDTO(this object value) { if (value == null) return default(T); return Mapper.Map(value); } /// /// 给已有对象map,适合update场景,如需过滤空值需要在AutoMapProfile 设置 /// /// /// /// /// public static T MapTo(this object self, T result) { if (self == null) return default(T); return (T)Mapper.Map(self, result, self.GetType(), typeof(T)); } } }