什麼是內對象與Automapper 2.0Automapper地圖嵌套對象
映射使用溶液在此question(Automapper 1.0)
創建自定義值解析器的最佳方式
?
public class DTOObject { // MainObject public int Id { get; set; } public string Name { get; set; } // SubObject (TopObject) public string TopText { get; set; } public string TopFont { get; set; } // SubObject (BottomObject) public string BottomText { get; set; } public string BottomFont { get; set; } } public class MainObject { public int Id { get; set; } public string Name { get; set; } public SubObject TopObject { get; set; } public SubObject BottomObject { get; set; } } public class SubObject { public string SubPropText { get; set; } public string SubPropFont { get; set; } }
定製值解析器
public class CustomResolver : ValueResolver<DTOObject, SubObject>
{
protected override SubObject ResolveCore(DTOObject source)
{
return Mapper.Map<DTOObject, SubObject>(source);
}
}
你有DTOObject設計的控制? – 2012-02-02 16:09:14
是的,沒有這是一個大量使用的舊數據庫。 – 2012-02-02 19:47:31
你試圖去哪個方向,DTOObject爲MainObject或MainObject爲DTOObject? – 2012-02-02 19:58:43