c# - 使用 Automapper,Profile 中的 Type.GetType 总是返回 null
问题描述
使用 Automapper,Type.GetType 总是在配置文件中返回 null。
这是我的个人资料:
public NotificationProfile()
{
CreateMap<Notification, NotificationDto>()
.ForMember(
dest => dest.Discriminator,
opts => opts.MapFrom(src => Type.GetType(src.EntityType).Name)
);
}
在调试中,在即时窗口中,当我这样做时它可以工作:
Type.GetType("MyProject.Api.Controllers.Samples.Dtos.SampleDetailsDto").Name =>SampleDetailsDto`
但是 Discriminator 的属性值在这里始终为 Null:
Mapper.Map<GroupedResult<Notification>, GroupedResult<NotificationDto, Guid?>>(result)
有没有办法在配置文件绑定中使用“ Type.GetType ”?
谢谢
ps:我也在github上打开了一个问题(https://github.com/AutoMapper/AutoMapper/issues/2890)
解决方案
推荐阅读
- javascript - 在 R 中单击传单中的按钮时显示摘要统计信息
- python - python-binance:获取所有订单,不指定符号
- salesforce - 即使案例停止,如何处理里程碑计时器仍在闪电运行?在销售人员中
- java - “无法连接到 Browsermob-Proxy 出现代理错误。” 在Linux中
- php - 如何在codeigniter中获取Ajax成功函数数据
- angular - 如何在打字稿/角度程序上使用 hubspot Conversations sdk?
- javascript - 要求使 div 可拖动而不是放在屏幕外
- go - 使用 ssh golang 包解析 ssh 密钥
- error-handling - 最后会在 XMPP 中类比吗?
- map-projections - Openlayers 矢量源投影反向 Y 轴