Replies: 2 comments
-
Maybe it would be easier to serialize to |
Beta Was this translation helpful? Give feedback.
0 replies
-
@lbargaoanu Thank you! JToken proved to be exactly what I was looking for. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys. I searched through Issues, Discussions, StackOverflow and Google, but I couldn't find anything relevant.
Consider the following example:
Here's what AutoMapper returns:
However, what I'm looking for is a recursive mapping of objects to
Dictionary<string, object>
, like this:The list of types that I'd like to map this way (
A
andB
in the example above) will be known at compile time, so I could manually configure AutoMapper for each of these types.I tried several approaches, with just one being moderately successful: I used
.AfterMap()
to scan through the resulting object's properties using reflection, then manually map the supported types toDictionary<string, object>
. This worked for simple cases, but quickly turned into a pile of hacks when more complex cases were considered, like nested dictionaries or lists of lists:Is there a way to make AutoMapper recursively map objects of specified types to
Dictionary<string, object>
like in the example above without resorting to complex reflection hacks? Basically I want to make AutoMapper automatically map anyIMappableToNestedDictionary
instance it finds during the mapping process toDictionary<string, object>
.Should I even be using AutoMapper here, or it's simply not the right tool for this particular use case?
Beta Was this translation helpful? Give feedback.
All reactions