如何使用自动映射器将枚举列表映射到字符串列表
How to map enum list to string list with automapper
我有 class A 和 class B:
class A
{
public List<TypeEnum> Types { get; set; }
...
}
class B
{
public List<string> TypesString { get; set; }
...
}
我正在尝试将列表映射到列表:
CreateMap()
.ForMemebr(目标 => destination.TypesString, m => m.ConvertUsing(源 => ((byte)source.Types).ToString()))
结果:
期望的结果应该是从枚举列表成功映射到字符串列表,例如:List<string> => ["1","2","3","5"]
我该怎么做?
尝试以下映射配置:
CreateMap<ClassA, CLassB>().ForMember(destination => destination.TypesString,
opt => opt.MapFrom(s => s.Types.Select(x => ((byte)x))));
我有 class A 和 class B:
class A
{
public List<TypeEnum> Types { get; set; }
...
}
class B
{
public List<string> TypesString { get; set; }
...
}
我正在尝试将列表映射到列表:
CreateMap
结果:
期望的结果应该是从枚举列表成功映射到字符串列表,例如:List<string> => ["1","2","3","5"]
我该怎么做?
尝试以下映射配置:
CreateMap<ClassA, CLassB>().ForMember(destination => destination.TypesString,
opt => opt.MapFrom(s => s.Types.Select(x => ((byte)x))));