我收到“缺少类型映射配置或不支持的映射”的一般错误。当我尝试创建此地图时。有任何想法吗?
Mapper.CreateMap<MyEnum, MyClass>().ConvertUsing(c =>
{
MyAttribute attribute = c.GetCustomAttribute<MyEnum, MyAttribute>();
return new MyClass()
{
Id = c.ToString(),
Name = attribute == null ? c.ToString() : attribute.DisplayName
};
});
和...
protected override void Configure()
{
base.Configure();
Mapper.CreateMap<MyEnum, MyClass>()
.ForMember(d => d.Id, opt => opt.MapFrom(s => s.ToString()))
.ForMember(d => d.Name, opt => opt.ResolveUsing<DisplayNameResolver>());
}
private class DisplayNameResolver : ValueResolver<MyEnum, string>
{
protected override string ResolveCore(MyEnum e)
{
MyAttribute attribute = e.GetCustomAttribute<MyEnum, MyAttribute>();
return attribute == null ? e.ToString() : attribute.DisplayName;
}
}
似乎不起作用。
谢谢。