AutoMapper and flattening nested arrays

前端 未结 3 1156
傲寒
傲寒 2020-12-09 00:31

I\'m trying to use AutoMapper to flatten multiple levels of arrays.

Consider the following source classes:

class X {
    public string A { get; set;         


        
3条回答
  •  孤街浪徒
    2020-12-09 01:07

    For anyone else coming across this post by searching how to Flatten object structure with AutoMapper - the new AutoMapper supports flattening with IncludeMembers() syntax.

    Source: http://docs.automapper.org/en/stable/Flattening.html

    So the original issue could be solved like this:

    Mapper.CreateMap();
    Mapper.CreateMap().IncludeMembers(src => src.D);
    Mapper.CreateMap().IncludeMembers(src => src.B);
    

提交回复
热议问题