문제

I have a destination type with a string[] property.

Animal
  string[] Barks;

My source object is:

  AnimalDTO
     List<BarkTypes> Barks;

How do I map BarkTypes.NameOfBark to the string[] Barks?

Something like this:?

Mapper.CreateMap<AnimalDTO, Animal>()
   .ForMember(dest => dest.Barks, y => y.MapFrom(x=>x.??????))
도움이 되었습니까?

해결책

You want ResolveUsing:

Mapper.CreateMap<AnimalDTO, Animal>()
      .ForMember(dest => dest.Barks,
                    y => y.ResolveUsing(x=>x.Barks
                                            .Select(b=>b.NameOfBark)
                                            .ToArray())
              )

다른 팁

Completely untested, but:

Mapper.CreateMap<AnimalDTO, Animal>()
   .ForMember(dest => dest.Barks, 
              y => y.MapFrom(x=>x.Barks
                                 .Select(z => z.NameOfBark)
                                 .ToArray());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top