Dynamic Ignore Member in Automapper 6.2.2

194 Views Asked by At

When i did this

TypeMap typeMap = (TypeMap)mappingExpression.GetType().GetField("_typeMap",
 BindingFlags.NonPublic | BindingFlags.Instance).GetValue(mappingExpression);

AutoMapper 4.0.4 was getting the typeMap successfully. But in the automapper 6.2.2 this does not work. GetField("_typeMap", BindingFlags.NonPublic | BindingFlags.Instance) function returns null.

1

There are 1 best solutions below

0
On BEST ANSWER

What I want to do is return an object of type TypeMap. So I could ignore the members I gave parameter strings. It was in the way of finding the TypeMap. That's how I solved my problem.

MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg=>
{
   cfg.CreateMap<Source,Target>();
});
TypeMap typeMap = mapperConfiguration.CheckIfMapExists (sourceType, destinationType);

This gives you a TypeMap