-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
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);