AutoMapper: create instance of destination type if source == null -


If the source object is empty, is it possible to configure Automaker to return a new instance of the destination type?

  source source = null; Dest d1 = AutoMapper.Mapper.Map & lt; Source, Dest & gt; (Source); // d1 == null // I'm looking for a way to configure // Automap to eliminate this code: Dest d2 = AutoMapper.Mapper.Map & lt; Source, Dest & gt; (Source) ?? New destination ();  

Answer your question (partially):

Setting it to False by setting a named "ConfigurationNullDestinationValues ​​ that is set to true by default, let me know in the question Be shown behavior, for example:

  Mapper Configuration. Allow translation translation value = false; // ... source source = null; Dest d = AutoMapper.Mapper.Map & lt; Source, Dest & gt; (Source); // A new example of DI DIEST now  

This solution works fine for simple types, where the source and destination type map is well-formed. I have some problems with complex mapping (I will update the question to show an example).


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -