I have base class
public abstract class DtoBase //NOTICE that this class is abstract
{
//some DTO specific things
}
public class concreteA_Dto : DtoBase
{
//some properties from A
}
public class concreteB_Dto : DtoBase
{
//some properties from B
}
and then i have some classes and they dont know each other and
public class concreteA //NOTICE that there is NO base class
{
//some properties from A
}
public class concreteB
{
//some properties from B
}
What i want is to Use Automapper this way:
private DtoBase GetResourceDto(object value)
{
return Mapper.Map<DtoBase>(value);
}
So far my mapping looks like this:
CreateMap<concreteA, DtoBase>()
.Include<concreteA, concreteA_Dto>();
CreateMap<concreteA, concreteA_Dto>();
But when i call method GetResourceDto with some instance of concreteA i will get
Automapper exception:
Mapping types:
concreteA-> DtoBase
#NAMESPACE.concreteA -> #NAMESPACE.DtoBase
Destination path:
DtoBase
with inner exception
Instances of abstract classes cannot be created.
Note that #NAMESPACE is my namespace of class
How to perform proper mapping that will avoid this exception ?
Idea behind this is that concreteA and concreteB can dynamicaly grow in time and there might be concreteC, concreteD etc. I dont mind adding mappings for more concrete classes