我正在使用此Using DynamicMap() and ignore null source value方法来使映射器忽略源上具有 NULL 值的属性,但这在2.1.267.0版本(当前)中似乎不起作用。
这是我的映射配置:
Mapper.CreateMap<PersonDTO, Person>().ForAllMembers(
opt => opt.Condition(srs => !srs.IsSourceValueNull));
这是我的测试:
// Arrange
var Person = new Person { FirstName = "Bruce", Surname = "Lee"};
var PersonDto = new PersonDTO { FirstName = "Jet", Surname = null };
// Act
Mapper.Map(PersonDto, Person);
// Assert
Assert.AreEqual("Jet", Person.FirstName); // Assert.AreEqual failed. Expected:<Jet>. Actual:<Bruce>.
Assert.AreEqual("Lee", Person.Surname, "Surname field with NULL value should not have been mapped");
对你起作用吗?如果是这样,你能在我的代码中发现问题吗?