With v4.2.1 I had the following extension:
public static IMappingExpression<TSource, TDestination> IgnoreUnmapped<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression)
{
var typeMap = Mapper.FindTypeMapFor<TSource, TDestination>();
if (typeMap != null)
{
foreach (var unmappedPropertyName in typeMap.GetUnmappedPropertyNames())
{
expression.ForMember(unmappedPropertyName, opt => opt.Ignore());
}
}
return expression;
}
Now with v5.0.0 the method FindTypeMapFor has moved under Mapper.Configuration. With the new way of doing things using the static API as follows:
Mapper.Initialize(cfg =>
{
cfg.CreateMap<MyModel, MyDto>().ReverseMap().IgnoreUnmapped();
});
An exception is thrown:
"Mapper not initialized. Call Initialize with appropriate configuration."
What is the alternative to ignored unmapped members without explicitly ignoring each and every member?
Yep. No idea this many people used that.
On Wednesday, June 29, 2016, Lucian Bargaoanu [email protected]
wrote:
1386 https://github.com/AutoMapper/AutoMapper/issues/1386?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/AutoMapper/AutoMapper/issues/1395#issuecomment-229293672,
or mute the thread
https://github.com/notifications/unsubscribe/AAGYMlfGC4S-7KKCHuBRYLMjbPbqwvDRks5qQi-QgaJpZM4JA14e
.
This was a handy extensions when using the static API!!
I will close this issue because using the "MemberList" enum should do the trick.
var mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new MyProfile());
// ignore all unmapped properties globally
cfg.ForAllMaps((map, exp) => exp.ForAllOtherMembers(opt => opt.Ignore()));
});
Oh please no don’t do this
On Sun, Oct 8, 2017 at 5:21 PM Dmitry Nechaev notifications@github.com
wrote:
var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new MyProfile()); // ignore all unmapped properties globally cfg.ForAllMaps((map, exp) => exp.ForAllOtherMembers(opt => opt.Ignore())); });—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/AutoMapper/AutoMapper/issues/1395#issuecomment-335042967,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGYMoPcYayH2wTJ4qnUu1exNpZpU9HPks5sqUrdgaJpZM4JA14e
.
Yes, this contradict the automapper main purpose. But if you need to make explicit only mapping and let no single property to get mapped implicitly this will do the job.
Then don’t use AutoMapper use manual mapper aka code.
On Sun, Oct 8, 2017 at 6:04 PM Dmitry Nechaev notifications@github.com
wrote:
Yes, this contradict the automapper main purpose. But if you need to make
explicit only mapping and let no single property to get mapped implicitly
this will do the job.—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/AutoMapper/AutoMapper/issues/1395#issuecomment-335045407,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGYMvWebDvTLzQJ9IUSuUOHBsuzlFwTks5sqVUSgaJpZM4JA14e
.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Then don’t use AutoMapper use manual mapper aka code.
On Sun, Oct 8, 2017 at 6:04 PM Dmitry Nechaev notifications@github.com
wrote: