Automapper configuration for interesting nested object scenario -
i have interesting scenario , answer isn't jumping out @ me. i've looked other similar questions none seem address type of issue.
before ask, not have control on source class layout.
my source object looks 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 destination looks this:
class destination {    string string1    string string2    string string3    string string4    string string5    string string6    string string7 } in reality, inner1 huge class , perfect match - except couple exceptions. i'd use automapper directly copy inner1 destination using default matching, copy inner2.foo destination.string6 , inner2.bar destination.string7.
edit: should add right mapping inner1 destination , doing couple manual property copies outside of automapper.
any suggestions appreciated.
guessing have this:
mapper.createmap<inner1, destination>(); ... var inner1 = getinner1(); var destination = mapper.map<destination>(inner1); // manual hydration on destination using inner2 instance... you might able away this:
mapper.createmap<inner1, destination>(); mapper.createmap<inner2, destination>()     .formember(d => d.string6, o => o.resolveusing(s => s.foo))     .formember(d => d.string7, o => o.resolveusing(s => s.bar)) ; ... var inner1 = getinner1(); var destination = mapper.map<destination>(inner1);  var inner2 = getinner2(); mapper.map(inner2, destination); 
Comments
Post a Comment