5
給定以下類:自動映射:從自動對象中解析源屬性名稱
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")