在以前的AutoMapper版本中,我曾经能够像这样配置AutoMapper:
public static class AutoMapperFactory
{
public static IConfigurationProvider CreateMapperConfiguration()
{
var config = new MapperConfiguration(cfg =>
{
//Scan *.UI assembly for AutoMapper Profiles
var assembly = Assembly.GetAssembly(typeof(AutoMapperFactory));
cfg.AddProfiles(assembly);
cfg.IgnoreAllUnmapped();
});
return config;
}
}现在,说cfg.AddProfiles(assembly)的行给了我错误:Argument 1: cannot convert from 'System.Reflection.Assembly' to 'System.Collections.Generic.IEnumerable<AutoMapper.Profile>
如何使IEnumerable<AutoMapper.Profile>作为AddProfiles的参数传递
发布于 2019-11-19 13:38:39
您可以使用addMaps而不是addProfile,如下所示:
public static class AutoMapperFactory
{
public static IConfigurationProvider CreateMapperConfiguration()
{
var config = new MapperConfiguration(cfg =>
{
//Scan *.UI assembly for AutoMapper Profiles
var assembly = Assembly.GetAssembly(typeof(AutoMapperFactory));
cfg.AddMaps(assembly);
cfg.IgnoreAllUnmapped();
});
return config;
}
}如文件所述:
配置文件中的
配置仅适用于配置文件内的映射。应用于根配置的配置应用于所有创建的映射。
并且可以创建为具有特定类型映射的类。
https://stackoverflow.com/questions/58935195
复制相似问题