Source/destination types
class Person
{
public int Age { get; set; }
public int Age2 => DateTime.Now.Year - Birthday.Year;
public DateTime Birthday { get; set; }
public string Name { get; set; }
}
class PersonDto
{
public int AgeV { get; set; }
public string NameV { get; set; }
}
Mapping configuration
class Program
{
static void Main(string[] args)
{
Mapper.Initialize(cfg => {
cfg.AddMemberConfiguration()
.AddName<PrePostfixName>(_ => _.AddStrings(n => n.DestinationPostfixes, "V"));
cfg.CreateMap<Person, PersonDto>()
.ForMember("AgeV", m => m.MapFrom("Age2")) //AgeV = 0
//.ForMember(d => d.AgeV, m => m.MapFrom(e => e.Age2)) //AgeV = 17
;
});
Person p = new Person { Birthday = new DateTime(2000, 1,1),Name = "Shy"};
var dto = Mapper.Map<PersonDto>(p);
Console.WriteLine(dto.AgeV);
Console.Read();
}
}
The ForMember Expression overload is working fine.
Version: 6.2.2
Expected behavior
dto.AgeV will be 17.
Actual behavior
dto.AgeV is 0. It is mapped from Person.Age.
Steps to reproduce
Person p = new Person { Birthday = new DateTime(2000, 1,1),Name = "Shy"};
var dto = Mapper.Map<PersonDto>(p);
Source/destination types
Mapping configuration
The
ForMemberExpression overload is working fine.Version: 6.2.2
Expected behavior
dto.AgeVwill be17.Actual behavior
dto.AgeVis0. It is mapped fromPerson.Age.Steps to reproduce