var c = new C1() { ID = 1, Name = 2 }; var d = new C2() { ID = 3, CName = 4, Des = 3 }; var im = Mapper.CreateMap<C1, C2>(); im.ForMember(f => f.CName, cname => cname.MapFrom(c1 => c1.Name)); im.ForMember(g => g.Des, des => des.MapFrom(a => a.ID)); var e = Mapper.Map<C1, C2>(c); Assert.AreEqual(c.ID,e.Des); Assert.AreEqual(e.CName,c.Name);
chain style:
Mapper.CreateMap<C1, C2>().ForMember(f => f.CName, cname => cname.MapFrom(c1 => c1.Name)).ForMember(f => f.CName, cname => cname.MapFrom(c1 => c1.Name)).ForMember(g => g.Des, des => des.MapFrom(a => a.ID));