I have to do some object to object mapping between domain classes used in a C# project and classes which are sent to flash clients.
My first choice was Automapper. But I've had some issues with it (nested properties, no parameterless constructor defined). It turns out that it is not so easy to map a really complex type with Automapper.
Why not implement methods like the following?
ClassA GetClassAByClassB(ClassB pObj)
{
ClassA objA = new ClassA();
objA.Prop1 = pObj.Prop1;
objA.NestedType.Prop2 = pObj.Prop2;
//....Some more.....
return objA;
}
It has exactly the same level of flexibility as mapping done using Automapper. You still have to provide which property from the source object is copied into what property in destinations object. You just do this using =
instead of a lambda expression.
But if you change something in your domain classes you have to change this "mapping" part anyway. What, then, is the main advantage to using Automapper over literal mappings?