I will be upfront by saying I just started using AutoMapper. I'm having some problems understanding if what I'm trying to do is incorrect.
I have an abstract class.
public abstract class Animal
{
public int Age { get; set; }
}
I have a class that derives from this abstract class
public class Cat : Animal
{
public string Name { get; set; }
public string Type { get; set; }
}
I have a separate class that shares values that need to be mapped to the Cat class derived from the Animal abstract class.
public class ProblemClass
{
public string Name { get; set; }
}
I have a mapper setup like so,
Mapper.CreateMap<ProblemClass, Animal>();
I've instantiated a ProblemClass item.
var problemClass = new ProblemClass();
Mapper.Map<Animal>(problemClass);
How would I go about mapping something like this? My main point of confusion is is automapper obviously cannot instantiate an abstract class, so I'm really confused how to create a generic Mapper for Animal which works with all kinds of animal sub classes derived from it.