How to use attribute-based member ignoring (e.g. [IgnoreMap]
) in conjunction with the MemberList.Source
option in Automapper 9.0? The IgnoreMap attribute seems to be ...ignored - the following example throws:
public class Source
{
public string PropertyA { get; set; }
[IgnoreMap]
public string IgnoredProperty { get; set; }
}
public class Destination
{
public string PropertyA { get; set; }
public string PropertyC { get; set; }
}
public class MyProfile : Profile
{
public MyProfile()
{
CreateMap<Source, Destination>(MemberList.Source);
}
}
when configuring using the MapperConfiguration.AssertConfigurationIsValid()
. It throws AssertConfigurationIsValid as if [IgnoreMap]
was not there:
Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters ================================================================== Source -> Destination (Source member list) Mapping.Source -> Mapping.Destination (Source member list)
Unmapped properties: IgnoredProperty
I have also tried [Ignore]
[NotMapped]
attributes, however the result was the same.