automapper list

Mapper.CreateMap<Source, Destination>();
var sources = new[]
{
new Source {Value = 5},
new Source {Value = 6},
new Source {Value = 7}
};
IEnumerable<Destination> ienumerableDest = Mapper.Map<Source[], IEnumerable<Destination>>(sources);
ICollection<Destination> icollectionDest = Mapper.Map<Source[], ICollection<Destination>>(sources);
IList<Destination> ilistDest = Mapper.Map<Source[], IList<Destination>>(sources);
List<Destination> listDest = Mapper.Map<Source[], List<Destination>>(sources);
Destination[] arrayDest = Mapper.Map<Source[], Destination[]>(sources);

如果sources不是数组的话,可以调用ToArray<Destination>()转换一下

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注