Skip to content

Conversation

@DocSvartz
Copy link
Contributor

@DocSvartz DocSvartz commented Dec 12, 2025

Need Help :

  • Is the struct immutable ?
  • Are there any other types that would be considered immutable?
  • Help with adapter name
  • Help with description of adapter

@DocSvartz DocSvartz marked this pull request as draft December 12, 2025 11:53
@DocSvartz
Copy link
Contributor Author

Is the struct immutable ?

Yes, but in fact in Mapster it works wit it as a mutable object.
Mapping process can be retarget into an "Records mapping algorithm"

Comment on lines +37 to +73
/// <summary>
/// Adapt the source object to an existing destination object.
/// </summary>
/// <param name="source">Source object to adapt.</param>
/// <param name="destination">Destination object to populate.</param>
/// <param name="sourceType">The type of the source object.</param>
/// <param name="destinationType">The type of the destination object.</param>
/// <returns>Adapted destination type.</returns>
public static object? Adapt(this object source, object destination, Type sourceType, Type destinationType)
{
return Adapt(source, destination, sourceType, destinationType, TypeAdapterConfig.GlobalSettings);
}

/// <summary>
/// Adapt the source object to an existing destination object.
/// </summary>
/// <param name="source">Source object to adapt.</param>
/// <param name="destination">Destination object to populate.</param>
/// <param name="sourceType">The type of the source object.</param>
/// <param name="destinationType">The type of the destination object.</param>
/// <param name="config">Configuration</param>
/// <returns>Adapted destination type.</returns>
public static object? Adapt(this object source, object destination, Type sourceType, Type destinationType, TypeAdapterConfig config)
{
var del = config.GetMapToTargetFunction(sourceType, destinationType);
if (sourceType.GetTypeInfo().IsVisible && destinationType.GetTypeInfo().IsVisible)
{
dynamic fn = del;
return fn((dynamic)source, (dynamic)destination);
}
else
{
//NOTE: if type is non-public, we cannot use dynamic
//DynamicInvoke is slow, but works with non-public
return del.DynamicInvoke(source, destination);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stagep @DevTKSS I also think these two adapters should be marked as deprecated and then removed in future versions.
But we'll need to double-check that the generic version works in all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember exactly if this is the case here.
But in fact, generic and non-generic adapters behave differently. 😂

@DocSvartz
Copy link
Contributor Author

Are there any other types that would be considered immutable?

There's another problem. There are settings that make any type seem "immutable".

.ConstructUsing()

Maybe:
.MapToTargetWith()
.BeforeMapping() .AfterMapping();

@DevTKSS
Copy link
Collaborator

DevTKSS commented Dec 31, 2025

Hey @DocSvartz, It would be way easier to follow your PR and give you better Feedback when needed, if you would have included some more information 😅
For example, just copied this PR template quickly (I could look into adding one to our Templates if you like me to for the future 👍 ) could you at least include info about the Issue this is about and the "Before" and "After" Behaviour you have in mind?

**GitHub Issue:** closes #

<!-- Link to relevant GitHub issue if applicable. All PRs should be associated with an issue, unless the change is documentation related. -->

## PR Type:

<!--
Copy the labels that apply to this PR and paste them above:

- 🐞 Bugfix
- ✨ Feature
- 🎨 Code style update (formatting)
- 🔄 Refactoring (no functional changes, no api changes)
- 🏗️ Build or CI related changes
- 📚 Documentation content changes
- 🤖 Project automation
- 💬 Other... (Please describe)

-->


## What is the current behavior? 🤔

<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->


## What is the new behavior? 🚀

<!-- Please describe the new behavior after your modifications. -->

## PR Checklist ✅

Please check if your PR fulfills the following requirements:

- [ ] 📝 Commits must be following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification.
- [ ] 🧪 Added [Runtime tests, UI tests, or a manual test sample](https://github.com/**/blob/master/docs/articles/contributing/*.md) for the changes have been added (for bug fixes / features) (if applicable)
- [ ] 📚 Docs have been added/updated which fit [documentation template](https://github.com/**/blob/master/docs/.feature-template.md) (for bug fixes / features)
- [ ] 🖼️ Validated PR `Screenshots Compare Test Run` results.
- [ ] ❗ Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below.
     Please note that breaking changes are likely to be rejected -->

## Other information ℹ️

<!-- Please provide any additional information if necessary -->

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapt(source, destination) does not work when destination is a C# record

2 participants