Test types

You can check if a mapper/matcher/projector supports a map for two given types by using the methods.

IMapper:

  • mapper.CanMapNew<Source, Destination>()
  • mapper.CanMapMerge<Source, Destination>()

IAsyncMapper:

  • asyncMapper.CanMapAsyncNew<Source, Destination>()
  • asyncMapper.CanMapAsyncMerge<Source, Destination>()

IMatcher:

  • matcher.CanMatch<Source, Destination>()

IProjector:

  • projector.CanProject<Source, Destination>()

This will check and will return true if the mapper/matcher can map the two given types.

You can also check for open generic types by passing the runtime Types with typeof().

mapper.CanMapNew(typeof(MyGenericClass<>), typeof(MyGenericClassDto<>));

Even if the functions above return true for two given types and MappingOptions, it is not guaranteed that the actual map will succeed. So you should only use them to check if two given types cannot be mapped.

List types

You can also retrieve a list of all available maps for a given mapper/projector (if supported by it), by using the extension methods.

IMapper:

  • mapper.GetNewMaps()
  • mapper.GetMergeMaps()

IAsyncMapper:

  • asyncMapper.GetAsyncNewMaps()
  • asyncMapper.GetAsyncMergeMaps()

IProjector:

  • projector.GetMaps()

This should return a list of types (source and destination) which can be mapped by the mapper. It will be empty for dynamic mappers which map based on rules. For performance reasons duplicate types may be returned.