1

Let's assume that we have following class hierarchy

class DtoBaseClass
{ 
     public string BaseProperty {get; set;}
}

class A1 : DtoBaseClass
{ 
     public string SomeProperty {get; set;}
}

class A2 : A
{ 
     public string AnotherProperty {get; set;}
}

class DomainClass
{ 
     public string BaseProperty {get; set;}
}

class B1 : DomainClass
{ 
     public string SomeProperty {get; set;}
}

class B2 : DomainClass
{ 
     public string AnotherProperty {get; set;}
}

Also I have a service which returns an array of DtoBaseClass which really contains instances of A1 and A2. How should I map this array to array of DomainClass instances and save relation between B1 <-> A1, B2 <-> B1?

In default configuration I'll get an array of DomainClass and loose all properties of derived classes.

I use this code for mapping:

var dtoToDomainMapper =
ObjectMapperManager.DefaultInstance.GetMapper<DtoClasss[], DomainClass>();

var dtoObjects = externalService.GetObjects();
return dtoToDomainMapper.Map(dtoObjects);
John Smith
  • 103
  • 9

0 Answers0