Uh oh!
There was an error while loading. Please reload this page.
Add Adapt extensions with temporary TypeAdapterConfig and TypeAdapter… - #828
Conversation
…Setter without modifying GlobalSettings
DocSvartz
commented
Nov 25, 2025
@roohial57 Great job 👍 @andrerav@stagep I think this should be part of Mapster.Fluent, what do you think about this? |
Uh oh!
There was an error while loading. Please reload this page.
roohial57
commented
Nov 26, 2025
I do not have any idea; what do you think? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
roohial57
commented
Nov 29, 2025
I really enjoyed this collaboration and hope to be even more helpful to the Mapster project in the future. |
@roohial57 Thank you for your contribution to Mapster.
Since no one has spoken out against including this in the main project, there's no need to include it in the fluent mapster. Thanks. |
This PR introduces two new overloads of the Adapt extension method in Mapster that make applying a small, temporary configuration extremely simple and concise:
Purpose:
Allow mapping with a temporary TypeAdapterConfig or a dedicated TypeAdapterSetter without modifying GlobalSettings.
Key Features:
Simplifies one-off mappings with minimal configuration.
Does not affect GlobalSettings, keeping existing mappings intact.
Supports both generic mapping (TSource -> TDestination) and mapping with a temporary configuration.
Tests:
Includes MSTest + Shouldly tests covering:
Mapping with temporary config
Mapping with setter
Ensuring GlobalSettings remain unchanged
Mapping with object initializer
Usage Example:
var result = source.Adapt(cfg =>
{
cfg.NewConfig<SourceDto, DestinationDto>()
.Map(dest => dest.Id, src => 42);
});
var result2 = source.Adapt<SourceDto, DestinationDto>(setter =>
{
setter.Map(dest => dest.Id, src => 99);
});