Automapper 9配置

在以前版本的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的参数传递?

ysqysq1 回答:Automapper 9配置

您可以使用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://www.f2er.com/3073172.html

大家都在问