问题
I'm trying to map a Dictionary<string, object>
where properties are keyed with Camel casing to a C# object with Pascal casing:
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);
If I put the dictionary keys as PascalCase, it works out of the box. I'm guessing I need a custom INamingConvention, but the documentation isn't quite clear about what it should be like...
Can someone help me with that?
using Automapper v7.0.1
Yes, I could do it the long way and map it manually, I know
Edit
There is a closed issue in AutoMapper's github repo: https://github.com/AutoMapper/AutoMapper/issues/2903
来源:https://stackoverflow.com/questions/52430461/automapper-how-to-map-a-camelcase-dictionarystring-object-to-a-pascalcase-c-s