Skip to content

Conversation

@roohial57
Copy link

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);
});

@DocSvartz
Copy link
Contributor

@roohial57 Great job 👍

@andrerav @stagep I think this should be part of Mapster.Fluent, what do you think about this?

@roohial57
Copy link
Author

@roohial57 Great job 👍

@andrerav @stagep I think this should be part of Mapster.Fluent, what do you think about this?

I do not have any idea; what do you think?

@DocSvartz DocSvartz merged commit 9103951 into MapsterMapper:development Nov 29, 2025
1 check passed
@roohial57
Copy link
Author

I really enjoyed this collaboration and hope to be even more helpful to the Mapster project in the future.
If needed, I can also submit this as a pull request to fluent-mapster.
@DocSvartz

@DocSvartz
Copy link
Contributor

DocSvartz commented Nov 30, 2025

@roohial57 Thank you for your contribution to Mapster.

If needed, I can also submit this as a pull request to fluent-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants