我需要:
// SOURCE
class A {
public B B;
public C C;
}
class B { public int X; }
class C { public int Y; }
// DESTINATION
class D {
public int X;
public int Y;
}
// I want to configure following operation
// without mapping each (X and Y) fields explicitly.
D.X = A.B.X;
D.Y = A.C.Y;
// here is the essence of what I am trying to accomplish.
Mapper.CreateMap<B, D>();
Mapper.CreateMap<C, D>();
var map = Mapper.CreateMap<A, D>();
map.ForMember(dst => dst, opt => opt.MapFrom(src => src.B));
map.ForMember(dst => dst, opt => opt.MapFrom(src => src.C));
有什么建议么?
注意:我知道如果我将 DX 更改为 D.BX 并将 DY 更改为 D.CY 它将起作用。我想在不添加 D 属性前缀的情况下完成此操作。我也可以通过使用地图的“填充”版本来实现这一点。