c# - Automapper 5.0.0 缺少 SourceValue(自定义转换器)

标签 c# automapper

将自动映射器版本从 4.2.1 更新到 5.0.0 后,出现编译错误,指出缺少 SourceValue。 这是我的例子

 public class DraftLayoutCellPropertiesConverter : ITypeConverter<DraftLayoutCell, DraftGamePeriodDraftLayoutViewModel>
    {
        public DraftGamePeriodDraftLayoutViewModel Convert(ResolutionContext context)
        {
            var input = context.SourceValue as DraftLayoutCell;
            var result = new DraftGamePeriodDraftLayoutViewModel();

            if (input != null)
            {

应该用什么替换该属性?这是做自定义转换器的最佳方式吗?我原以为更新不会破坏现有代码,因为有很多人在使用该应用程序。

最佳答案

在 Automapper 5 中,接口(interface) ITypeConverter 发生了变化,您需要更新您的实现:

public class DraftLayoutCellPropertiesConverter : ITypeConverter<DraftLayoutCell, DraftGamePeriodDraftLayoutViewModel>
{
    public DraftGamePeriodDraftLayoutViewModel Convert(DraftLayoutCell source, DraftGamePeriodDraftLayoutViewModel destination, ResolutionContext context)
    {
        var input = source;
        ...
    }
}

关于c# - Automapper 5.0.0 缺少 SourceValue(自定义转换器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38204313/

相关文章:

c# - 如何在不使用内联映射或多个 .ForMember 的情况下在 automapper 中映射嵌套对象?

c# - MSMQ 和 WebSphere MQ 消息集成

c# - 是否可以更改下方线条的颜色/文本框的边框(条目)

c# - 具有 2 个不同读者的阅读流

c# - 如何在 AutoMapper 中添加自定义逻辑?

asp.net-mvc-3 - 不在表单上时 MVC3 数据在发布时丢失?

c# - Automapper - 当源对象具有带值的属性时不映射

c# - AutoMapper,尝试并捕获映射

c# - 如何将 viewModel 绑定(bind)到 View

c# - 自定义路由 ASP.NET MVC