automapper布尔属性为yes或no

时间:2022-08-04 10:01:02

For a mapping between TypeA and TypeB i would like all the boolean properties to be mapped to 'Yes' or 'No'. I don't want to override the <bool, string> mapping since i want that just for the mapping between TypeA and TypeB. And I would not like to use .ForMember for each TypeA's boolean property since they are a lot. Maybe there is a trick with ForAllMembers but I cannot make it works.

对于TypeA和TypeB之间的映射,我希望将所有布尔属性映射到“是”或“否”。我不想覆盖 映射,因为我只想要TypeA和TypeB之间的映射。而且我不想为每个TypeA的布尔属性使用.ForMember,因为它们很多。也许ForAllMembers有一个技巧,但我不能让它工作。 ,string>

1 个解决方案

#1


0  

have you tried adding a mapper between Bool and String and registering it in the engine? It may be that simple, but I don't remember.

您是否尝试在Bool和String之间添加映射器并在引擎中注册?这可能很简单,但我不记得了。

you could also create a ValueConverter and then inform the mappings to use the converter. It's been awhile since i used AM, but this sounds about right.

您还可以创建ValueConverter,然后通知映射使用转换器。自从我使用AM以来已经有一段时间了,但这听起来不错。

#1


0  

have you tried adding a mapper between Bool and String and registering it in the engine? It may be that simple, but I don't remember.

您是否尝试在Bool和String之间添加映射器并在引擎中注册?这可能很简单,但我不记得了。

you could also create a ValueConverter and then inform the mappings to use the converter. It's been awhile since i used AM, but this sounds about right.

您还可以创建ValueConverter,然后通知映射使用转换器。自从我使用AM以来已经有一段时间了,但这听起来不错。