如何告诉AutoMapper忽略(而不是map)基类属性?

时间:2016-05-12 22:11:34

标签: c# automapper

我们正在使用基于具有一些属性的特殊类的ViewModel。这些属性在模型中没有映射属性。如何告诉AutoMapper全局忽略这些属性?这是我尝试过但我仍然得到与这些属性相关的错误。另外,有没有办法在CreateMap中传递多个要忽略的属性?

public class AutoMapperConfig
{
    public static MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg =>
    {
          cfg.AddProfile(new MappingProfile());
          cfg.ShouldMapProperty = pi => !pi.Name.InList("HiddenSwitch","ErrorMessage",
                                   "SuccessMessage", "WarningMessage","DuplicateForm");
    });

   public static IMapper Mapper;

   public static void Configure()
   {
       Mapper = mapperConfiguration.CreateMapper();
       mapperConfiguration.AssertConfigurationIsValid();
   }
}

0 个答案:

没有答案