Does EmitMapper support flattening?

Oct 18, 2010 at 8:09 PM

Does EmitMapper flatten an object the way AutoMapper does?

For example, can you have it automatically map:

public class Customer { string Name }
public class Order { Customer Customer }


public class OrderDto { string CustomerName }
Jul 17, 2011 at 4:54 PM

Check this out and

Nov 26, 2011 at 9:59 AM

is it possible to have bidirectional mapping (both dto2bo and bo2dto)?

Dec 8, 2011 at 12:00 PM

Yes it is. I just submitted a patch for this ( All you need to do is define an UnflatteningConfig which inherits from FlatteringConfig but reverses the mappings it generates. I also added a bool for the FlatteringConfig constructor that allows members that are not matched to be ignored. You could put both configs in my patch into a different namespace and call them from your code without having to recompile EmitMapper itself.

One more thing. In my example I new up the nested objects as to avoid NullReferenceExceptions. If you did't want to do this then you can use the ConstructBy method of Config to ensure any nested objects are newed up. EmitMapper will not be creating the nested objects it will just call the properties on them.