首页 > 解决方案 > Xamarin - AutoMapper 在初始化后添加配置文件

问题描述

我有一个使用 Automapper 的 Xamarin 应用程序,但我有很多profiles.

如果我尝试profiles在应用程序 Init 中加载所有这些,则需要几秒钟。

我想用一些基本配置文件初始化映射器,然后当我需要其他配置文件时,我想将它们添加到主配置中。

public static MapperConfiguration InitAutoMapper()
{
    MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg =>
    {
        cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
        cfg.DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();

        cfg.AddProfile<BaseProfile>();
        cfg.AddProfile<ComboProfile>();
    });

    return mapperConfiguration;
}

public class MyViewModel : BaseViewModel {
    public MyViewModel() {
        // How can I add here the "MyViewModelProfile" to mapperConfiguration?
    }
}

我怎样才能做到这一点?

编辑

与使用的配置文件和解析器链接。

标签: c#xamarinautomapper

解决方案


推荐阅读