Skip to content

Instantly share code, notes, and snippets.

@rmaziarka
Last active March 14, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmaziarka/cb64757fcdfc3f341336bf0fe6767895 to your computer and use it in GitHub Desktop.
Save rmaziarka/cb64757fcdfc3f341336bf0fe6767895 to your computer and use it in GitHub Desktop.
Map with CreateMissingTypeMaps flag set
void Main()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMissingTypeMaps = true;
cfg.AddProfile(new DestinationProfile());
});
var source = new Source();
var destination = new Destination() { Flag = false };
Mapper.Map(source, destination);
var specificDestination = new SpecificDestination() { Flag = false };
Mapper.Map(source, specificDestination);
destination.Flag.Dump(); // TRUE
specificDestination.Flag.Dump(); // FALSE
}
public class Source
{
}
public class Destination
{
public bool Flag { get; set;}
}
public class SpecificDestination : Destination
{
}
public class DestinationProfile : Profile
{
public DestinationProfile()
{
this.CreateMap<Source, Destination>()
.ForMember(el => el.Flag, m => m.UseValue(true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment