0
在目标类的副本是否有办法让整个源对象在我的目的地类作为一个属性的副本..饲养来源,使用Automapper
例如
来源:
class SourceClass
{
prop string Prop1 { get; set; }
prop string Prop2 { get; set; }
}
目的地:
class DestinationClass
{
prop string Prop1 { get; set; }
prop string Prop2 { get; set; }
prop SourceClass SourceClassCopy { get; set; }
}
,并使用automapper配置类似
AutoMapper.Mapper.Initialize(cfg => {
cfg.ReplaceMemberName("this", "SourceClassCopy");
cfg.CreateMap<SourceClass, DestinationClass>(); //or .ForMember("SourceClassCopy", d => d.MapFrom(s => s));
});
为什么我这样做是怎么把我有一个分层对象,并会喜欢为反向映射保留副本,因为Source类没有默认构造或者这将帮助我扭转地图。另外,源类是,我不能修改:(和有方法/接受整个源对象的函数库感谢所有帮助谢谢
是的,这工作..谢谢 – narcs