Imagine classes like this:
class Source
{
public string Name { get; set; }
public string Code { get; set; }
}
class Destination
{
public Destination(string name, int code)
{}
}
I want to configure a mapping from Source
to Destination
. I want AutoMapper to automatically match Source.Name
to Destination
's name
constructor parameter since they have the same name (excluding naming conventions) and type. However, the second constructor parameter will need to be custom-mapped.
The best I could find so far is to just manually do all of the mappping:
Mapper.CreateMap<Source, Destination>()
.ConstructUsing(source => new Destination(source.Name, /*Custom map for "code" property*/));
However, by doing this, I lose the maintainability improvements that convention-based mapping offers.