0

I would like to create a generic/common mapping that will be the equivalent of the following mappings but with single line.

cfg.CreateMap<int?, PropertyModel<int?>>().ConvertUsing<ValueToPropertyModelConverter<int?>>();

cfg.CreateMap<double?, PropertyModel<double?>>().ConvertUsing<ValueToPropertyModelConverter<double?>>();

cfg.CreateMap<string, PropertyModel<string>>().ConvertUsing<ValueToPropertyModelConverter<string>>();

I would imagine something like

cfg.CreateMap<TValue, PropertyModel<TValue>>().ConvertUsing<ValueToPropertyModelConverter<TValue>>();

Any ideas ?

Thanks !

Riana

Riana
  • 689
  • 6
  • 22
  • http://automapperdocs.readthedocs.io/en/latest/Open-Generics.html – Lucian Bargaoanu Mar 20 '18 at 13:51
  • Your link talks about mapping open generic type to another open generic type, that is not what the question was about .. – Riana Mar 20 '18 at 15:13
  • Nullable is a generic type. – Lucian Bargaoanu Mar 20 '18 at 15:20
  • Ok , but what about the last one with a string ? Same question for non nullable types .. What I would like to achieve is to create just one map that can handle all these cases . Thx – Riana Mar 20 '18 at 17:08
  • That's more complicated. You can write a [simple custom object mapper](https://github.com/AutoMapper/AutoMapper/search?utf8=%E2%9C%93&q=objectmapper&type=) to handle all cases. Or you let AM create the maps for you and then customize them with a type converter. – Lucian Bargaoanu Mar 20 '18 at 17:27
  • Ok, thanks Lucian I will take a look – Riana Mar 21 '18 at 17:48

0 Answers0