AutoMapper ResolveUsing未被调用

时间:2017-12-15 16:14:33

标签: automapper

我有一个映射,我目前使用MapFrom,一切都按预期工作。

我正在尝试用MapFrom替换ResolveUsing,我发现我的解析函数根本就没有被调用。就好像代码不存在一样(当在构造函数中尝试使用断点的类表单时,它不会被命中)。

// This works as expected
CreateMap<Contact, ContactListViewModel>()
    .ForMember(dest => dest.FirstName, map =>
        map.MapFrom(s => s.RelationshipTypeId == Relationship.SELF ? s.Person.FirstName : s.FirstName))

// This doesnt. Resolver never invoked  
CreateMap<Contact, ContactListViewModel>()
    .ForMember(dest => dest.FirstName, opt => opt.ResolveUsing<CustomResolver>());

// Example resolver 
public class CustomResolver : IValueResolver<object, object, string>
{
    public CustomResolver()
    {
        // never called
    }

    public string Resolve(object source, object destination, string member, ResolutionContext context)
    {
        return ... // never invoked
    }
}

这看起来很基本,我确实有其他映射我成功使用ResolveUsing。关于我如何调试这个并确定为什么我的映射被忽略的任何想法?

0 个答案:

没有答案