first of all thanks for this nice piece of code, I love the emit mapper ;)
When I use the flattering config and have null objects in the members chain on my source object I get NullReferenceExceptions.
Just change the test methode for testing the flattering config as follows:
public void TestFlattering()
var source = new ModelObject
BaseDate = DateTime.Now,
Sub = new ModelSubObject
ProperName = "Some name",
SubSub = new ModelSubSubObject
IAmACoolProperty = "Cool daddy-o"
Sub2 = new ModelSubObject
ProperName = "Sub 2 name"
SubWithExtraName = null /*new ModelSubObject
ProperName = "Some other name"
var mapper = ObjectMapperManager.DefaultInstance.GetMapper<ModelObject, ModelDto>(
var b = mapper.Map(source);
In an older post IGibson wrote that I could use the ConstructBy method to avoid NullReferenceExceptions. (In http://emitmapper.codeplex.com/discussions/231361)
But I don't now how.. can someone please explain me how I can avoid this NullReferenceExceptions?