automapper - 何时使用值格式化程序以及何时使用值解析器

标签 automapper

我仍然对何时在 automapper 中使用 Value Formatter 和 Value Resolver 感到困惑。

假设我有一个可为空的 DateTime,我想将它转换为特定的日期格式(因此最终结果将是一个字符串)。在这种情况下我应该使用格式化程序吗?

谢谢

最佳答案

我有同样的问题,并根据作者本人的文档选择了 Value Resolver,即 Value Formatter 可能是设计错误:

https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-formatters

但是,同一位作者对此处使用的内容做出了回应:

Why does AutoMapper have an IValueFormatter when it has a seemingly much more powerful ValueResolver?

关于automapper - 何时使用值格式化程序以及何时使用值解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474108/

相关文章:

c# - 使用 MVC3 中的存储库模式和 Entity Framework 将域模型转换为 ViewModel 并再次返回

c# - 如何传入异步函数以在函数类中接收值

c# - 使用自动映射器将字符串类型列表映射到具有字符串属性的对象列表

asp.net-core - 在 DI 实例上使用 AutoMapper 8 ProjectTo

automapper - 使用 AutoMapper 进行条件投影

c# - 使用 DTO 和实体是否违反 DRY 原则?

c# - 如何使用 AutoMapper 映射食谱与成分

c# - 使用自动映射器从两个项目映射

entity-framework - Automapper 延迟加载。 Entity Framework

c# - 通过 id 获取项目并使用自动映射器将其标题映射到字符串