AutoMapper: Mapping a collection of Object to a collection of strings
A unit test validated the following would map from IList<Tag>
to IList<string>
private class TagNameResolver : ValueResolver<IList<Tag>, IList<string>> { protected override IList<string> ResolveCore(IList<Tag> source) { var tags = new List<string>(); foreach (var tag in source) { tags.Add(tag.Name); } return tags; } }
This is a shorter way of creating the map:
.ForMember(dest => dest.Tags, opt => opt.MapFrom(so => so.Tags.Select(t=>t.Name).ToList()));