There is a question, that describes what i want to get very precisely, but they are using inline mapping.
Source/destination types
public class SrcInner
{
public int A {get;set;} // imagine here 100500 properties
}
public class SrcOuter
{
public int B {get;set;}
public SrcInner C {get;set}
}
public class Dest
{
public int A {get;set;} // so here imagine 100500 same properties, as in SrcInner
public int B {get;set;}
}
Mapping configuration
public static void AddMapper(this IServiceCollection services)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SrcInner, Dest>();
cfg.CreateMap<SrcOuter, Dest>();
});
var mapper = config.CreateMapper();
services.AddSingleton(mapper);
}
Expected behavior
Both A and B properties are filled after mapping.
Actual behavior
Only B property is filled after mapping.
Steps to reproduce
public class Foo
{
IMapper Mapper{get;set;}
public Foo(IMapper mapper) // comes through dependency injection
{
Mapper = mapper;
}
public Bar()
{
var test = new SrcOuter()
{
B = 10;
C = new SrcInner()
{
A = 10;
}
}
var testDest = new Dest();
mapper.Map(test, Dest);
}
}
Is there a proper way to set configuration that way, so such mapping will work?
UPDATE
Is there a way to map Dest to SrcOuter with filling SrcInner?