나는 서로 매핑해야하는 두 개의 개체가 있습니다. 모양이자동 매핑 장치를 사용하여 사용자 지정 리졸버를 사용하여 목록 매핑
public class Example1
{
CustomType1 Prop { get; set; }
List<CustomType1> List { get; set; }
}
public class Example2
{
Customtype2 Prop { get; set; }
List<Customtype2> List { get; set; }
}
public class CustomType1
{
public string SomeString { get; set; }
}
public class Customtype2
{
public string FirstPartOfSomeString { get; set; }
public string SecondPartOfSomeString { get; set; }
}
CustomType1을 CustomType2에 매핑 한 CustomResolver를 하나 만들고이 리졸버를 목록에 사용하려고합니다. 예를 들어,
Mapper.CreateMap<Example1, Example2>()
.ForMember(d => d.Prop, opt => opt.ResolveUsing(myCustomResolver))
.ForMember(d => d.List, opt => opt.ResolveUsing(/*use myCustomResolver on a list here*/));
나는 같은 것을 사용하여 시도했다 :
Mapper.CreateMap<Example1, Example2>()
.ForMember(d => d.Prop, opt => opt.ResolveUsing(myCustomResolver))
.ForMember(d => d.List, opt => opt.MapFrom(s => s.List.Select(myCustomResolver.Resolve).ToList()));
을하지만 난 뭔가를 놓친 것 같다. AutoMapper로이 작업을 수행 할 수있는 방법이 있습니까?
CustomResolver 코드를 게시하십시오. –