Search code examples
valueinjecter

Mapping Subclass OF DTO into ViewModel


My DTO class contains another sub class say,

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?  

Solution

  • var viewModel = new PQR_ViewModel();
    
    viewModel.InjectFrom(abc);
    viewModel.InjectFrom(abc.BCD);