【发布时间】:2020-03-18 19:16:29
【问题描述】:
我们有一个庞大的数据驱动应用程序,涉及多个系统,因此需要大量映射。 由于性能问题,我们将从 AutoMapper 迁移到 Mapster。
到目前为止,使用 Mapster 一切都很好,但是在映射 Collections 时,Mapster 返回 null 值而不是空的 Collection。
Automapper 过去默认返回空集合,但我无法弄清楚如何在 Mapster 中执行此操作。
我尝试过以下操作,但它不起作用
TypeAdapterConfig.GlobalSettings.ForDestinationType<ICollection>().IgnoreNullValues(true);
TypeAdapterConfig.GlobalSettings.ForType(typeof(ICollection), typeof(ObservableCollection<>))
.IgnoreNullValues(true);
TypeAdapterConfig.GlobalSettings.ForType(typeof(ObservableCollection<>), typeof(ICollection))
.IgnoreNullValues(true);
任何帮助都会很棒
【问题讨论】: