Let's suppose that I have two types:
class Type1
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}
class Type2
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public TypeToIgnore Prop3 { get; set; }
}
I want to map between these two types, but ignoring all the properties that have a TypeToIgnore. This is because I am iterating through all of them using reflection and make some custom mappings on them.
Within a class which derives from Profile, I could add an Ignore for each member that I don't want to be mapped, like this:
CreateMap<Type2, Type1>().ForMember(x => x.Prop3, y => y.Ignore());
Or I could use the IgnoreMapAttribute on the properties to be ignored, but considering that on the production code, I have plenty of them, is there a much easier way to ignore some specific types at all?
You can use ShouldMapProperty in your config:
cfg.ShouldMapProperty = p => p.PropertyType != typeof(string);
Official docs on this here. Original feature request by yours truly.
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