给定以下类:
public class User
{
public int Id {get;set;}
public PersonName Name {get;set;}
}
public class PersonName
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
public class UserDto
{
public int Id {get;set;}
public string FirstName {get;set;}
}
以下是映射配置:
Mapper.CreateMap<User, UserDto>()
.ForMember(destination => destination.FirstName,
options => options.MapFrom(source => source.Name.FirstName))
是否有可能根据目标对象上的属性来解析源属性的名称:
类似于以下内容:
Assert.AreEqual(GetSourcePropertyName<User, UserDto>("FirstName"), "Name.FirstName")