开发者

EmitMapper: Map array of derived classes

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开发者_C百科 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜