Automapper: Adding configuration for all types

Created on 12 Jul 2016  Â·  5Comments  Â·  Source: AutoMapper/AutoMapper

I wanna add MaxDepth(0) to all mapped types as the followings:

CreateMap<AdvertisementStatistic, AdvertisementStatisticModel>().MaxDepth(0);
...
...
...

Is it an option to add this feature to all types simpler instead of adding .MaxDepth(0); at the end of each type in version 5?

All 5 comments

Have you looked at ForAllMaps?

On Tuesday, July 12, 2016, Mohammmad Dayyan [email protected]
wrote:

I wanna add MaxDepth(0) to all mapped types as the followings:

CreateMap().MaxDepth(0);
...
...
...

Is it an option to add this feature to all types simpler instead of adding
.MaxDepth(0); at the end of each type ?

—
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/1510, or mute the thread
https://github.com/notifications/unsubscribe/AAGYMqA4LySF402UZO4a6Fu8gjvHrXPGks5qU47JgaJpZM4JKXOq
.

And instead of MaxDepth, PreserveReferences might help.

What is PreserverReferences?

It preserves references in case you have deep, circular maps.

You can do:

cfg.CreateMap<Foo, Bar>();
cfg.ForAllMaps((typeMap, mapConfig) => mapConfig.MaxDepth(0));

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndyAyersMS picture AndyAyersMS  Â·  5Comments

vadimshaporov picture vadimshaporov  Â·  7Comments

Hamidnch picture Hamidnch  Â·  3Comments

jbogard picture jbogard  Â·  7Comments

JobaDiniz picture JobaDiniz  Â·  5Comments