Misu Costel Misu Costel - 27 days ago 6
C# Question

Get destination type from Automapper.Mapper

I have used Automapper for some time now, and it works very neat.
I have the following mapping:


Is there any way, any method that, provided
will return

Answer Source

You can get all the registered TypeMaps (Automapper's type for storing source-destination type pairs and other mapping related information) with the Mapper.GetAllTypeMaps() method.

Using the typemaps you can search for you source type:

public void Test()
    Mapper.CreateMap<Models.MyModel, Entities.MyEntity>();
    var destination = Mapper.GetAllTypeMaps()
                            .First(t => t.SourceType == typeof(Models.MyModel));
    Assert.AreEqual(typeof (Entities.MyEntity), destination.DestinationType);