0

Is it possible using Maptser to configure the Map configuration by condition?

puplic static GetCustomConfig(condition)
{
    var config = new TypeAdapterConfig();

    config.NewConfig<BookEntity, BookModel>()
        .Map(dest => dest.Name, src => src.Title)
        .Map(dest => dest.Address, src => $"{src.Street} {src.House}")
        // other Map

    if (condition)
    {
        // add several Map to the config
    }

    return config;
}

It is planned that these named configurations will be contained in some static class, from where they will be returned differently depending on the conditions.

For some types, I have a Mapster configured via DI, but I needed custom configurations for some cases.

public static class MapsterConfig
{
    public static void MapsterSetup()
    {
        TypeAdapterConfig<Type1, Type2>
            .NewConfig()
            .Map(dest => dest.Name, src => src.Title);
    }
}
egeo
  • 171
  • 1
  • 19

0 Answers0