Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created July 5, 2017 16:02
Show Gist options
  • Save lbargaoanu/8331afb734df500249f089fccad26fff to your computer and use it in GitHub Desktop.
Save lbargaoanu/8331afb734df500249f089fccad26fff to your computer and use it in GitHub Desktop.
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