-
Version: AutoMapper 12.0.0, .NET SDK 7.0.100.Expected behaviorconstructor ignored and properties mapped Actual behavior
Remove D's ctor to workaround the issue. Steps to reproduceusing AutoMapper;
using System.Diagnostics;
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<S, D>()
.ForMember(d => d.Names, o => o.MapFrom((s,d) =>
{
return s.Names.Split(',').Select(name => name.Trim().ToUpper());
}))
;
});
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
var s = new S
{
Names = "Foo,Bar"
};
var d = mapper.Map<D>(s);
Debug.Assert(d.Names.Count == 2);
Debug.Assert(d.Names.ToArray()[0] == "FOO");
Debug.Assert(d.Names.ToArray()[1] == "BAR");
Console.ReadLine();
public class S
{
public string Names { get; set; }
}
public class D
{
public D(List<string> names)
{
Names = names;
}
public List<string> Names { get; set; }
} |
Beta Was this translation helpful? Give feedback.
Answered by
vzalamea
Nov 16, 2022
Replies: 1 comment
-
Had to disable constructor mapping. cfg.DisableConstructorMapping(); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vzalamea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had to disable constructor mapping.