Add TryMap (Runtime Target Type) #1919
Closed
randellhodges
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
|
Thanks for the suggestion. Since Mapperly is source-generated (all mappings need to be known at compile-time), a |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Just like the existing map that can be generated:
https://mapperly.riok.app/docs/configuration/generic-mapping/#runtime-target-type-parameter
Add ability to generate a TryMap, something like:
public static partial bool TryMap(object source, Type targetType, out object result);Why?
I'm playing around with replacing Automapper and we use DI and IMapper everywhere. I can't quickly just remove that, so I started using the ideas here, which is mostly working for me:
#397 (comment)
Inside the MapperlyMapperAsAutomapper there is just a single
private MapperlyMapper _mapper = new();Ideally, I'd use DI to inject X number of map classes and then I can try do a TryMap call on each of them until I get a result. These would be discovered when setting up the DI container and some of them could be inside various assemblies.
I would probably cache which instance resolved my map so that next time I can just look that up and not have to loop thru everything, but that is an optimization on my side.
Beta Was this translation helpful? Give feedback.
All reactions