0
'누락 된 유형 맵 구성 또는 지원되지 않는 매핑'이라는 일반 오류가 발생합니다. 이지도를 만들려고 할 때. 어떤 아이디어?Automapper 클래스에서 Enum으로 매핑
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;
}
}
이 작동하지 마십시오.
감사합니다.