I have used Automapper for some time now, and it works very neat. I have the following mapping:
Mapper.CreateMap<Models.MyModel,Entities.MyEntity>();
Is there any way, any method that, provided typeof(Models.MyModel)
will return typeof(Entities.MyEntity)
?
You can get all the registered TypeMap
s (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:
[Test]
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With