AutoMapper: create instance of destination type if source == null
问题 Is it possible to configure AutoMapper to return a new instance of the destination type if the source object is null? Source source = null; Dest d1 = AutoMapper.Mapper.Map<Source, Dest>(source); // d1 == null // I'm looking for a way to configure AutoMapper to // eliminate this code: Dest d2 = AutoMapper.Mapper.Map<Source, Dest>(source) ?? new Dest(); 回答1: Answering my own question (partially): AutoMapper has a configuration property named AllowNullDestinationValues which is set to true by