更新时间:2022-05-29 23:14:01
是的,可以映射整个集合并仍然传递值.首选使用自定义值解析器,因为在您对原始帖子的评论中指出.如果仍然希望使用 AfterMap
,则可以执行以下操作,请记住,在这种情况下,您的源和目标是集合,而不是单个项目:
Yes, it is possible to map an entire collection and still pass the value. Using a custom value resolver is probably the preferred option, as pointed out in the comment on your original post. If you'd still prefer to use AfterMap
, you can do something like the following, remembering that your source and destination in this case are collections rather than individual items:
var result = mapper.Map<List<Group>, List<GroupExtended>>(groups,
opt => opt.AfterMap((src, dest) =>
{
foreach (var i in dest)
{
i.Description = "someValue";
}
}));