interface Parent
{
string A;
string C;
}
class ChildA : Parent
{
string A;
string C;
}
class ChildB : Parent
{
string A;
string C;
}
class RelatedC
{
string A;
string B;
}
//On app start
Mapper.CreateMap<Parent,RelatedC>();
//Map member A only
//In some other class
var rel // RelatedC type object, not null has data
var obj// ChildA type object, not null has data
//I want to use the above map created to map rel and obj
Mapper.Map(rel ,obj)
//only property A will be overridden by rel, other properties for obj are not changed
我想爲所有將使用接口的類使用接口映射器,我不想爲每個子類創建單獨的映射。 我該如何做到這一點?使用接口的自動映射器
你就不能這樣做'VAR OBJ = Mapper.Map(REL)'?我不認爲你需要爲每個「Parent」實現者配置映射。 –
Jasen
@Jasen不,我不能這樣做,因爲在項目中使用的obj沒有使用new實現,它具有屬性,並且使用var obj = Mapper.Map(rel)基本上會創建一個新對象。所以rel會覆蓋obj的一些屬性(將被映射的屬性) – Varun