Skip to content

feat: forward additional mapping method parameters#2193

Open
Demivan wants to merge 22 commits intoriok:mainfrom
Demivan:parameter-mapping
Open

feat: forward additional mapping method parameters#2193
Demivan wants to merge 22 commits intoriok:mainfrom
Demivan:parameter-mapping

Conversation

@Demivan
Copy link

@Demivan Demivan commented Mar 19, 2026

Description

Additional parameters on mapping methods (beyond source/target/referenceHandler) are now forwarded to user-defined nested mapping methods, MapValue(Use=...), MapProperty(Use=...), and MapPropertyFromSource(Use=...) methods.
Works with queryable projections - additional parameters become captured variables in the generated expression.

Parameters are matched by name, but mappings to map them when types don't match are not generated. It is more complex to support that. Should I add type checks while that is not supported? Currently, parameter string ctx will match int ctx but will produce a non-compilable code.

Besides unit tests, I have tested it on real project and parameterized mapping methods and projections were generated correctly.

Note: I have used Claude, but I was steering is constantly - no vibecoding

Fixes #1472
Fixes #1765 (user needs to define mappings with parameters)

Supersedes #1946

Checklist

  • I did not use AI tools to generate this PR, or I have manually verified that the code is correct, optimal, and follows the project guidelines and architecture
  • I understand that low-quality, AI-generated PRs will be closed immediately without further explanation
  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

@Demivan Demivan force-pushed the parameter-mapping branch 7 times, most recently from 3105679 to 01e20d0 Compare March 20, 2026 08:55
Demivan added 18 commits March 22, 2026 18:59
…ilderContext

Always allow additional parameters in BuildUserImplementedMapping
(remove allowAdditionalParameters parameter — was true at all call
sites)
- MapPropertyFromSource(Use=...) unsatisfiable params → RMG097
- MapValue(Use=...) partially matching params → RMG096 + RMG082
- Nested mapping with multiple additional params
- MappingTarget + MapProperty(Use=...) with params
- Param consumed only by Use method → no false RMG082
- Param consumed only by nested mapping → no false RMG082
- Multiple unused params → multiple RMG082
- Init-only and constructor params from additional parameters
- Nested projection inlining with additional params
- Collection mapping test for additional parameter forwarding
fix: move diagnostics to AnalyzerReleases.Shipped.md and add diagnostic docs

Per contributing guidelines:
- Move RMG096/RMG097 from Unshipped to Shipped (Mapperly does not use Unshipped)
- Add RMG096.mdx and RMG097.mdx diagnostic documentation pages
…nal parameters

Projections with additional parameters now only pick up MapProperty/
MapPropertyFromSource configurations from element mappings whose
additional parameters match. No fallback to default element mappings
that ignore the parameters. Projections without additional parameters
continue to use the default element mapping as before.
…meters

feat: support additional parameters on external and MapPropertyFromSource Use methods

- Remove IsExternal guard from BuildArguments in
  UserImplementedMethodMapping and
  UserImplementedExistingTargetMethodMapping — external mapper methods
  now forward additional parameters like internal ones
- Always allow additional parameters in BuildUserImplementedMapping
  (remove allowAdditionalParameters parameter — was true at all call
  sites)
- Enable MapPropertyFromSource(Use=...) with additional parameters by
  discovering user-implemented methods with extra params during initial
  extraction
@Demivan Demivan force-pushed the parameter-mapping branch from 09facb6 to 4d0ce3d Compare March 22, 2026 18:00
Demivan added 4 commits March 22, 2026 21:10
… ParameterScope

When a non-empty scope is passed, Find performs a parameterized-only
lookup; otherwise it does the regular dictionary lookup. This removes
the separate FindUserMappingWithParameters method from the entire chain.
…eterizedUserMapping

Mark parameters as used directly in FindByParameters, eliminating the
need for a separate FindParameterizedUserMapping wrapper. This simplifies
FindOrBuildMapping and FindOrBuildLooseNullableMapping cascades.
@latonz latonz self-requested a review March 27, 2026 09:28
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.

Extra mapper parameters do not work with MapDerivedType Pass additional parameters to property mapper methods

1 participant