AutoMapper:运行时类型跳过给定成员

AutoMapper: runtime types skip given members

有没有办法配置 AutoMapper 在使用它映射运行时类型时跳过某些属性。 我创建了一个地图

Mapper.CreateMap(typeA, typeB)

然后,如果我需要跳过 属性,我会添加

.ForMember("propertyA", prop => prop.Ignore)

这很好。问题是如何为更多属性实现这一点,而这些属性在编码时是未知的。 所以我需要跳过某些列表中的所有属性。 基本上我想我需要这样的东西:

.ForAllMembers(opt => opt.Condition(prop => !skipThese.Contains(prop.MemberName)))

所以,经过一番搜索,我将其作为扩展方法完成:

    public static IMappingExpression<TSource, TDestination> ExcludingThese<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression, List<String> exclude)
    {
        foreach (String stringVar in exclude)
        {
            expression.ForMember(stringVar, excl => excl.Ignore());
        }
        return expression;
    }