I'm trying to map an array into an ICollection
of type <T>.
Basically I want to be able to do:
Mapper.CreateMap<X[], Y>();
Where Y
is Collection<T>
Any ideas?
Polymorphic element types in collectionsAutoMapper supports polymorphic arrays and collections, such that derived source/destination types are used if found.
How do I use AutoMapper? First, you need both a source and destination type to work with. The destination type's design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type's members.
Inside this article, it discusses performance and it indicates that Automapper is 7 times slower than manual mapping.
AutoMapper is used whenever there are many data properties for objects, and we need to map them between the object of source class to the object of destination class, Along with the knowledge of data structure and algorithms, a developer is required to have excellent development skills as well.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With