質問

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