I have an interesting scenario and the answer isn’t jumping out at me. I’ve looked for other similar questions but none seem to address this type of issue.
Before you ask, I do not have control over the source class layout.
My source object looks like this:
class Class1
{
string string1
string string2
string string3
string string4
string string5
string string6
}
class Class2
{
string foo
string bar
}
class Class3 //The source object!!
{
Class1 Inner1
Class2 Inner2
}
And my destination looks like this:
class Destination
{
string string1
string string2
string string3
string string4
string string5
string string6
string string7
}
In reality, Inner1 is a huge class and almost a perfect match – except for a couple exceptions. I’d like to use Automapper to directly copy everything from Inner1 to Destination using default matching, but also copy Inner2.foo to Destination.string6 and Inner2.bar to Destination.string7.
EDIT: I should add that right now I am mapping Inner1 to Destination and then doing a couple manual property copies outside of Automapper.
Any suggestions are appreciated.
Guessing you currently have something like this:
You might be able to get away with this: