当我升级到 Automapper 5.1.1 时,使用只读属性定义的集合的映射停止工作(使用 Automapper 4.2.1 可以正常工作)
这是一个示例代码,您可以尝试使用两个版本的 Automapper 来验证行为更改。使用 automapper 5.1.1 result.MyList 有零个元素。
class TestAutomapper
{
public static void Test()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Test, TestDto>();
});
var test = new Test();
test.MyList.Add(1);
var result= Mapper.Map<TestDto>(test);
}
}
public class Test
{
public List<int> MyList { get; } = new List<int>();
}
public class TestDto
{
public List<int> MyList { get; } = new List<int>();
}
如何使用 Automapper 5.1.1 使地图正常工作?