Get all the defined mappings from an AutoMapper defined mapping
I'm using Automapper 7.0 and the syntax is different now. For example,
void Dump(TypeMap map)
{
Console.WriteLine("---------------------------------------------------------------------");
Console.WriteLine(map.SourceType + " ==> " + map.DestinationType);
foreach (var m in map.GetPropertyMaps())
{
Console.WriteLine(m.SourceMember.Name + " ==> " + m.DestinationProperty.Name);
}
}
And then you can call it using:
Dump(Mapper.Instance.ConfigurationProvider.FindTypeMapFor(typeof(CDModel), typeof(CD)));
or if you want to dump out everything, then do like this.
foreach (var map in Mapper.Instance.ConfigurationProvider.GetAllTypeMaps())
{
Dump(map);
}
Going along the same path as what you were doing ...
foreach( var propertMap in map.GetPropertyMaps() )
{
var dest = propertMap.DestinationProperty.MemberInfo;
var source = propertMap.SourceMember;
}
How exactly do you want the expressions? Are you wanting the underlying Lambas?
If so look at
propertMap.GetSourceValueResolvers()
I also find var map = Mapper.GetAllTypeMaps();
to be useful too, as you can search for the SourceType or DestinationType.