Mapper.Map(source, dest) actually returns the destination object, in your case it will be personMissingStuff .
With that said, assuming that you only want to fill in the null properties in the receiver, you need to properly configure the display, not the map in which the destination property matters.
The following example does just that for class properties. For value properties, you probably need to do some additional configuration. The example uses NUnit and SharpTestsEx:
[TestFixture] public class LoadIntoInstance { public class Template { public string Name { get; set; } } public class Person { public string Name { get; set; } public string OtherData { get; set; } } [Test] public void Should_load_into_instance() { Mapper.CreateMap<Template, Person>() .ForMember(d=>d.OtherData, opt=>opt.Ignore()); Mapper.CreateMap<Person, Person>() .ForAllMembers(opt=>opt.Condition(ctx=>ctx.DestinationValue==null)); Mapper.AssertConfigurationIsValid(); var template = new Template {Name = "template"}; var basePerson = Mapper.Map<Person>(template); var noNamePerson = new Person {OtherData = "other"}; var result = Mapper.Map(basePerson, noNamePerson); result.Should().Be.SameInstanceAs(noNamePerson); result.Satisfy(r => r.Name == "template" && r.OtherData == "other"); } }
source share