Last active
March 14, 2017 22:09
-
-
Save rmaziarka/cb64757fcdfc3f341336bf0fe6767895 to your computer and use it in GitHub Desktop.
Map with CreateMissingTypeMaps flag set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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