将DTO的子类映射到ViewModel

时间:2013-08-21 07:49:24

标签: valueinjecter

我的DTO类包含另一个子类,

Class ABC_DTO
{
   public String XYZ {get;set;}

   public BCD_DTO BCD {get;set;}
}

Class BCD_DTO 
{
     public string Name {get;set;}
     public string Age  {get;set;}
}


//This is Viewmodel

class PQR_ViewModel
{

    public string Name {get;set;}
    public string Age  {get;set;}
    public String XYZ {get;set;}
}


How can i map above Dto ABC_DTO into PQR_ViewModel using ValueInjecter?  

1 个答案:

答案 0 :(得分:1)

var viewModel = new PQR_ViewModel();

viewModel.InjectFrom(abc);
viewModel.InjectFrom(abc.BCD);