AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

EqualityComparison based on the index of item in collection #161

Closed gabh closed 2 years ago

gabh commented 2 years ago

Hello,

Wanted to know if it is possible to do EqualityComparison based on index of item in respective collection?

Basically, if below 2 scenarios can be accomplished or not:

Secnario 1: When srcCollection.Count > destCollection.Count Assuming srcCollection has 3 items and destCollection has 2 items, should result into: srcCollection[0] gets mapped to destCollection[0] srcCollection[1] gets mapped to destCollection[1] srcCollection[2] gets mapped into new item in destCollection at index 2

Secnario 2: When srcCollection.Count < destCollection.Count Assuming srcCollection has 2 items and destCollection has 3 items, should result into: srcCollection[0] gets mapped to destCollection[0] srcCollection[1] gets mapped to destCollection[1] Item in destCollection at index 2 gets removed

Actually, my srcCollection is property of the ViewModel coming from client-side and items in it need to be mapped onto the destCollection (which is property of the Domain model) on the server-side. The srcCollection contains objects that do not have any Id because it was not exposed to client-side in the first place.