迁移到最新版本的AutoMapper(从v8到v9)后,ProjectTo方法出现问题。从ICollection投影到IReadOnlyCollection时,出现System.ArgumentException:“参数类型不匹配”。
public class Source
{
public ICollection<int> Collection { get; set; } = new HashSet<int>();
}
public class Destination
{
public IReadOnlyCollection<int> Collection { get; set; } = new HashSet<int>();
}
public class Profile : AutoMapper.Profile
{
public Profile() { CreateMap<Source, Destination>(); }
}
//This line throws exception
var mapped = mapper.ProjectTo<Destination>(src);
我只是想知道这是预期的行为还是错误。我在变更日志中没有发现任何相关更改。