使用自定义转换器发射映射器展平
本文关键字:映射 发射 自定义 转换器 | 更新日期: 2023-09-27 18:27:10
由于某种原因,在使用EmitMapper Samples中的FlatteringConfig时,不调用自定义转换器的Convertr函数。当使用DefaultMapConfig时,会调用它。
配置:
var userMapper = ObjectMapperManager.DefaultInstance.GetMapper<User, UserModel>(
new FlatteringConfig().ConvertGeneric(typeof(IList<>), typeof(IList<>),
new DefaultCustomConverterProvider(typeof(EntityListToModelListConverter<,>))));
对潜在的原因有什么想法吗?
解决方案
看看我在下面的答案
因为FlatteringConfig覆盖GetMappingOperations
函数,所以它不调用分配自定义转换器的FilterOpertations
函数。因此,在GetMappingOperations
中添加FilterOperations
函数调用就解决了这个问题。