【问题标题】:Dynamic Ignore Member in Automapper 6.2.2Automapper 6.2.2 中的动态忽略成员
【发布时间】:2018-11-07 23:05:19
【问题描述】:

当我这样做时

TypeMap typeMap = (TypeMap)mappingExpression.GetType().GetField("_typeMap",
 BindingFlags.NonPublic | BindingFlags.Instance).GetValue(mappingExpression);

AutoMapper 4.0.4 已成功获取 typeMap。但是在 automapper 6.2.2 中这不起作用。 GetField("_typeMap", BindingFlags.NonPublic | BindingFlags.Instance) 函数返回 null。

【问题讨论】:

    标签: c# mapping automapper automapping automapper-6


    【解决方案1】:

    我想要做的是返回一个 TypeMap 类型的对象。所以我可以忽略我给参数字符串的成员。它妨碍了查找 TypeMap。这就是我解决问题的方法。

    MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg=>
    {
       cfg.CreateMap<Source,Target>();
    });
    TypeMap typeMap = mapperConfiguration.CheckIfMapExists (sourceType, destinationType);
    

    这会给你一个 TypeMap

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2011-01-27
      • 2017-10-12
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多