我有以下课程:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string[] Bookmarks { get; set; }
}
public class PersonEntry
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class PersonEntryWithBookmarks
{
public PersonEntry Entry { get; set; }
public string[] Bookmarks { get; set; }
}
我想创建以下映射:
Mapper.Map<PersonEntryWithBookmarks, Person>(person)
如何将源中的Entry
属性映射到Person
中的所有属性(除了Bookmarks
)和Bookmarks
属性,从源到{{人物中的1}}属性?
答案 0 :(得分:1)
Mapper.CreateMap<PersonEntry, Person>();
Mapper.CreateMap<PersonEntryWithBookmarks, Person>()
.AfterMap((src, dest) => Mapper.Map<PersonEntry, Person>(src.Entry, dest));
var person = Mapper.Map<PersonEntryWithBookmarks, Person>(personEntryWithBookmarks);
将自动为您映射书签。