Source/destination types
public class Destination
{
public bool Toggle { get; set; }
}
public class Source
{
public bool? Toggle { get; set; }
}
Mapping configuration
public class TestProfile : Profile
{
public TestProfile()
{
AllowNullCollections = true;
AllowNullDestinationValues = true;
CreateMap<Source, Destination>()
.ForAllMembers(expression => expression.Condition((src, dst, srcMember) => srcMember != null));
}
}
Version: 11.0.1
11.0.1
Expected behavior
In the ForAllMembers condition the srcMember should be of type bool? (for the Source.Toggle property) and the condition should evaluate to false (given Toggle = null as in the example program below). The destination thing should therefore stay unmodified.
Actual behavior
The srcMember is of type bool, so the information that the input was null gets lost. The ForAllMembers condition evaluates to true changing the destination thingy.
Steps to reproduce
public class Program
{
static void Main(string[] args)
{
var config = new MapperConfiguration(cfg => cfg.AddProfile<TestProfile>());
var mapper = config.CreateMapper();
var thing = new Destination()
{
Toggle = true
};
var update = new Source()
{
Toggle = null
};
Console.WriteLine(thing.Toggle); // True
mapper.Map(update, thing);
Console.WriteLine(thing.Toggle); // False
}
}
Source/destination types
Mapping configuration
Version: 11.0.1
11.0.1
Expected behavior
In the ForAllMembers condition the
srcMembershould be of typebool?(for theSource.Toggleproperty) and the condition should evaluate tofalse(givenToggle = nullas in the example program below). The destination thing should therefore stay unmodified.Actual behavior
The
srcMemberis of typebool, so the information that the input wasnullgets lost. The ForAllMembers condition evaluates totruechanging the destination thingy.Steps to reproduce