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 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
Post a Comment