using System.Collections.Generic;
public static void Main()
MapperConfiguration _config = new MapperConfiguration(cfg =>
cfg.CreateMap<UserModel, UserDefinition>()
.ForMember(d => d.Id, o => o.Ignore())
.ForMember(d => d.UserName, o => o.MapFrom(s => s.Username))
.ForMember(d => d.Contacts, o => o.MapFrom(new UserContactDefinitionListResolver()));
IMapper _mapper = _config.CreateMapper();
UserModel src = new UserModel
ContactEmail = "abc@email.com"
UserDefinition dst = _mapper.Map<UserDefinition>(src);
Console.WriteLine(JsonConvert.SerializeObject(dst, Formatting.Indented));
public class UserContactDefinitionListResolver : IValueResolver<UserModel, UserDefinition, List<UserContactDefinition>>
public List<UserContactDefinition> Resolve(UserModel src, UserDefinition dst, List<UserContactDefinition> dstMember, ResolutionContext ctx)
dstMember = new List<UserContactDefinition>();
if (!string.IsNullOrWhiteSpace(src.PhoneNumber))
dstMember.Add(new UserContactDefinition
Type = ContactType.Phone,
if (!string.IsNullOrWhiteSpace(src.ContactEmail))
dstMember.Add(new UserContactDefinition
Type = ContactType.Email,
public int Id { get; set; }
public string Username { get; set; }
public string PhoneType { get; set; }
public string PhoneNumber { get; set; }
public string EmailType { get; set; }
public string ContactEmail { get; set; }
public class UserDefinition
public int Id { get; set; }
public string UserName { get; set; }
public List<UserContactDefinition> Contacts { get; set; }
public class UserContactDefinition
public ContactType Type { get; set; }
public bool IsPrimary { get; set; }
public string Label { get; set; }
public string Value { get; set; }