-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Source/destination types
public class INodeSettings
{
public string IP { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public int RelayIndex { get; set; }
public bool InvertSignal { get; set; }
}
public record INodePowerLine(
string EndPoint,
string Login,
string Password,
int RelayIndex,
bool Inverted
);Mapping configuration
CreateMap<INodeSettings, INodePowerLine>()
.ForCtorParam(nameof(INodePowerLine.EndPoint), opt => opt.MapFrom(s => s.IP))
.ForCtorParam(nameof(INodePowerLine.Inverted), opt => opt.MapFrom(s => s.InvertSignal))
.ReverseMap();Version: 13.0.1
Expected behavior
config.AssertConfigurationIsValid() should throw an exception because the reverse mapping (from INodePowerLine to INodeSettings) is invalid -- the fields IP and InvertSignal got default values anyway.
Actual behavior
Steps to reproduce
Test:
var config = new MapperConfiguration(cfg =>
{
cfg.AddProfile<DefaultProfile>();
});
config.AssertConfigurationIsValid();Prove that the reverse mapping from INodePowerLine to INodeSettings is invalid -- the fields IP and InvertSignal got default values:
var mapper = config.CreateMapper();
var settings = new INodeSettings
{
IP = "192.168.1.23:50",
Login = "admin",
Password = "pass",
RelayIndex = 14,
InvertSignal = true
};
settings.Dump();
var powerLine = mapper.Map<INodePowerLine>(settings);
powerLine.Dump();
var settings2 = mapper.Map<INodeSettings>(powerLine);
settings2.Dump();Also LINQPad snippet: https://share.linqpad.net/t3lacfn7.linq
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels