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