草庐IT

MapperConfiguration

全部标签

c# - Automapper 说 Mapper.Map 已过时,全局映射?

我在我的项目中定义了一个全局Automapper配置,它允许我使用Mapper.Map(sourceObject);在我的代码中。(请参阅下面我的配置。)我更新了NuGet包,我看到了Mapper.Map已过时/已弃用的消息。我回到GitHub上的Automapper,看到了这样的例子:[Test]publicvoidExample(){varconfig=newMapperConfiguration(cfg=>{cfg.CreateMap().FixRootDest();cfg.CreateMap().FixRootDest();});config.AssertConfigurati

c# - Automapper 说 Mapper.Map 已过时,全局映射?

我在我的项目中定义了一个全局Automapper配置,它允许我使用Mapper.Map(sourceObject);在我的代码中。(请参阅下面我的配置。)我更新了NuGet包,我看到了Mapper.Map已过时/已弃用的消息。我回到GitHub上的Automapper,看到了这样的例子:[Test]publicvoidExample(){varconfig=newMapperConfiguration(cfg=>{cfg.CreateMap().FixRootDest();cfg.CreateMap().FixRootDest();});config.AssertConfigurati

c# - 如何在AutoMapper的MapperConfiguration中使用mapper.Map?

我需要使用AutoMapper将一个对象映射到另一个对象。棘手的问题是如何访问映射配置内部或自定义类型转换器内部的映射器实例(IMapper实例)?下面的代码不起作用,但它是我想要实现的示例-请注意mapper.Map调用并假设映射Customer=>CustomerDto和Customer=>DetailedCustomerDto已定义。varconfig=newMapperConfiguration(cfg=>cfg.CreateMap().ForMember(dst=>dst.Customer,src=>src.ResolveUsing(o=>{returno.Type==1?m