首页 > 解决方案 > 使用 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

标签: c#.net-coreautomapper

解决方案


推荐阅读