Automapper: passing parameter to Map method

Another possible option while using the Map method would be the usage of the Items dictionary. Example:

int someValue = 5;
var dto = Mapper.Map<Message>(message, 
    opts => opts.Items["Timestamp"] = message.SentTime.AddMinutes(someValue));

It's a little bit less code and has the advantage of dynamically specified fields.


You can't do exactly what you want, but you can get pretty close by specifying mapping options when you call Map. Ignore the property in your config:

cfg.CreateMap<Message, MessageDto>()
    .ForMember(dest => dest.Timestamp, opt => opt.Ignore());

Then pass in options when you call your map:

int someValue = 5;
var dto = Mapper.Map<Message, MessageDto>(message, opt => 
    opt.AfterMap((src, dest) => dest.TimeStamp = src.SendTime.AddMinutes(someValue)));

Note that you need to use the Mapper.Map<TSrc, TDest> overload to use this syntax.