3

I've read this page, but it didn't have the answer. https://github.com/MapsterMapper/Mapster/wiki/Ignoring-members

What I want is to ignore all Id fields when the Source type is named like SomethingDto or FooDto

Something like this...

TypeAdapterConfig<TSource, TDestination>
    .NewConfig()
    .IgnoreIf((src, dest) => src.GetType.Name.EndsWith("Dto"), dest => dest.Id);

Another question, how could I set a global type mapping, then in the middle of a method, start using this new one and when the method ends, it reverts back to the original global setting? I might not want to always ignore Ids, for example.

redwards510
  • 1,802
  • 1
  • 17
  • 23

1 Answers1

1

I have something for the second half of my question. Make a clone of your global config, ignore all columns named Id or whatever, then inject that config into your Adapt<> method. Once the method exists, you revert back to global config settings.

            var mapsterConfig = TypeAdapterConfig.GlobalSettings.Clone();
            mapsterConfig.Default.Ignore("Id");
            var entity = dto.Adapt<Entity>(mapsterConfig);
redwards510
  • 1,802
  • 1
  • 17
  • 23