【问题标题】:override void Configure() in Automapper Profile giving compile error "AutoMapperBootstrap.Configure()': no suitable method found to override"覆盖 Automapper 配置文件中的 void Configure() 给出编译错误“AutoMapperBootstrap.Configure()':找不到合适的方法来覆盖”
【发布时间】:2017-09-21 07:13:19
【问题描述】:
public class AutoMapperBootstrap : AutoMapper.Profile
{
    protected override void Configure()
    {
        //ReplaceMemberName("Z", "A");
        //CreateMap<Source, Destination>(); 
    }
    public override string ProfileName
    {
        get { return this.GetType().Name; }
    }
}

我的 MVC 应用程序的 App_Start 文件夹中有这个 AutoMapperBootstrap 类。

在“配置”方法中,它给出了编译器错误-“没有合适的方法来覆盖”,我得到了配置方法的错误,而不是 ProfileName 的错误

我在自定义 Automapper 配置文件中的配置文件的 StackOverflow 覆盖配置方法中看到了很多示例。

但是为什么我得到这个编译器错误。

请告诉我我犯了什么错误??

或者是最新版本的 Automapper 没有这个 Configure 方法被覆盖。

注意:我已经从 Nuget 下载了最新的 Automapper 版本 6.1.1.0 到我的应用程序中。

【问题讨论】:

  • 尝试将你的代码从Configure移动到构造函数

标签: automapper profile


【解决方案1】:

较新版本的 AutoMapper have a different method 用于设置配置文件。我正在使用此处描述的方法在 .net 项目的类库中设置自动化。

namespace Project.Helpers
{
    public class NewMapperProfile : Profile
    {
        public NewMapperProfile()
        {
            CreateMap<ClassA, ClassB>();
        }
    }
}

【讨论】:

  • 所以,我确实发现 AutoMapper 的最新版本不再使用“覆盖配置”方法。另外,我测试了上述创建配置文件的方法,它可以工作。我希望这会有所帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-07
  • 2020-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多