I have a source DTO like this
public class Member
{
public string MemberId {get;set;}
public string MemberType {get;set;}
public string Name {g
I saw the example of conditionally mapping, but it maps the field it performs the conditional check on. I want to check the condition and map a different field.
Try using such config:
cfg.CreateMap()
.ForMember(dest => PersonMember.PersonMemberId, opt => {
opt.Condition(src => src.MemberType == "Person");
opt.MapFrom(src => src.MemberId);
});
cfg.CreateMap()
.ForMember(dest => CompanyMember.CompanyMemberId, opt => {
opt.Condition(src => src.MemberType == "Company");
opt.MapFrom(src => src.MemberId);
});
In case you mapping from a non-compatible object Id
field will be set to 0
.