Created
July 5, 2017 16:02
-
-
Save lbargaoanu/8331afb734df500249f089fccad26fff to your computer and use it in GitHub Desktop.
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
static void Main(string[] args) | |
{ | |
var config = new MapperConfiguration(cfg => | |
{ | |
cfg.CreateMap<A, ADto>().ForMember(_ => _.ListOfB, _ => _.UseDestinationValue()); | |
cfg.CreateMap<B, BDto>(); | |
cfg.CreateMap<B1, B1Dto>().IncludeBase<B, BDto>(); | |
}); | |
config.AssertConfigurationIsValid(); | |
var mapper = config.CreateMapper(); | |
var source_a = new A(); | |
var b = new B(); | |
var b1 = new B1(); | |
source_a.ListOfB.AddRange(new B[] { b, b, b1, b1 }); | |
var target_a = mapper.Map<ADto>(source_a).Dump(); | |
} | |
class A { public List<B> ListOfB = new List<B>(); } | |
class B | |
{ | |
public Guid Id = Guid.NewGuid(); | |
} | |
class B1 : B { } | |
class ADto { public List<BDto> ListOfB = new List<BDto>(); } | |
class BDto | |
{ | |
public Guid Id = Guid.NewGuid(); | |
} | |
class B1Dto : BDto { } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment