[英]Mapping collections using AutoMapper
I'm trying to map an array into an ICollection
of type <T>.
我正在尝试将数组映射到类型
<T>.
的ICollection
<T>.
Basically I want to be able to do: 基本上我希望能够做到:
Mapper.CreateMap<X[], Y>();
Where Y
is Collection<T>
其中
Y
是Collection<T>
Any ideas? 有任何想法吗?
You don't need to setup your mapping for collections, just the element types. 您不需要为集合设置映射,只需要设置元素类型。 So just:
所以就:
Mapper.CreateMap<X, Y>();
Mapper.Map<X[], Collection<Y>>(objectToMap);
See here for more info: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home 有关详细信息,请参阅此处: http : //automapper.codeplex.com/wikipage?title = Lists%20and%20Arrays &referringTitle = Home
Now it looks like you can use: 现在看起来你可以使用:
Mapper.CreateMap<X,Y>();
var listOfX = Mapper.Map<List<X>>(someIEnumerableOfY);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.