Display all properties of type "X" with AutoMapper

I just started using AutoMapper and still found it very simple and time-saving.

The only thing I'm not sure about is how do I match all the properties of a given type in the same way?

Is it possible to do this with AutoMapper in a single expression using lambda, as with regular matching?

+6
c # lambda model-view-controller automapper
source share
1 answer

What you are looking for is called CustomTypeConverter . They are global in volume and only need to be configured once.

Syntax:

 Mapper.CreateMap<TSourceProperty,TDestinationProperty>().ConvertUsing(argument); 

where argument can be

  • Implementation of ITypeConverter<TSourceProperty,TDestinationProperty>
  • A Func<TSourceProperty,TDestinationProperty>

Jimmy Bogard has an article about using CustomTypeConverter at http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/05/05/automapper-feature-custom-type-converters.aspx .

For more information, see the CustomTypeConverter page of the AutoMapper documentation .

Oh, and by the way (since I want an Ohm reward), you can also do this by going to the valueinjecter .

+5
source share

All Articles