automapper - AutoMapper 如何映射 CamelCase 字典到 PascalCase C# 对象
问题描述
我正在尝试将Dictionary<string, object>
使用 Camel 套管键入的属性映射到具有 Pascal 套管的 C# 对象:
var id = Guid.NewGuid();
var dto = new Dictionary<string, object> {
{ "id", id.ToString() },
{ "value", "some value" },
};
var mapper = new MapperConfiguration(cfg => { }).CreateMapper();
var result = mapper.Map<TestClass>(dto);
var expected = new TestClass {
Id = id,
Value = "some value",
};
result.Should().BeEquivalentTo(expected);
如果我将字典键作为 PascalCase,它可以开箱即用。我猜我需要一个 custom INamingConvention
,但文档并不清楚它应该是什么样子......
有人可以帮我吗?
使用 Automapper v7.0.1
是的,我可以做很长的路并手动映射它,我知道
编辑
AutoMapper 的 github 存储库中有一个已关闭的问题:https ://github.com/AutoMapper/AutoMapper/issues/2903
解决方案
推荐阅读
- javascript - 两个表共享输入
- angular-cli - ng serve 命令先显示错误,最后编译成功
- database - 如何处理数据库中的现金预支差旅费用?
- react-admin - React-admin:嵌套项目出错
- functional-programming - 有没有更好的功能方法来处理带有错误检查的向量?
- react-native - StackNavigation 道具未按预期工作
- android - 如何在选定的卡片视图上点击波纹和其他前景?
- wordpress - 强制 Woocommerce 按属性过滤以仅显示搜索词在标题中的属性
- audio - 处理坚持 pause() 不是一个函数,当它非常重要时
- python - 从图像中去除噪点