Last active
March 14, 2017 22:09
-
-
Save rmaziarka/5527c959e698ebcf32a4baacb35c4de4 to your computer and use it in GitHub Desktop.
Map with CreateMissingTypeMaps flag unset
This file contains 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 = false; | |
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(); // TRUE | |
} | |
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