Skip to content

Support mapping object factory parameters#2351

Open
skuirrels wants to merge 2 commits into
riok:mainfrom
skuirrels:feature/object-factory-map-to-parameters
Open

Support mapping object factory parameters#2351
skuirrels wants to merge 2 commits into
riok:mainfrom
skuirrels:feature/object-factory-map-to-parameters

Conversation

@skuirrels

@skuirrels skuirrels commented Jul 1, 2026

Copy link
Copy Markdown

Support mapping object factory parameters

Description

Adds ObjectFactoryAttribute.MapToParameters so object factory method parameters can be mapped from source members using the same matching rules as constructor mappings.

This enables object factories such as:

[ObjectFactory(MapToParameters = true)]
private CarDto CreateCarDto(string make, string model)
    => CarDto.Create(make, model);

The PR includes:

  • Support for direct parameter-mapped object factories.
  • Support for generic factory shapes, including target-generic and source/target-generic factory methods.
  • Fallback behavior aligned with constructor candidate selection: unmappable parameter factories fall through to the next object factory or constructor.
  • Projection/expression handling that avoids using parameter-mapped factories where they cannot be represented safely.
  • Documentation for MapToParameters and supported factory signatures.
  • Unit coverage for direct, optional-parameter, generic, fallback, and projection/expression cases.

Related issue: none. This PR was opened before the requested issue-first design discussion; I am happy to move the design discussion to an issue if preferred.

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)

Validation performed:

  • dotnet test test/Riok.Mapperly.Tests/Riok.Mapperly.Tests.csproj --filter "FullyQualifiedName~ObjectFactoryTest|FullyQualifiedName~ExpressionMappingTest"
  • dotnet test Riok.Mapperly.slnx --no-restore -m:1 --blame-crash --results-directory artifacts/TestResults/final-verification
    • Abstractions: 6 passed
    • Integration: 77 passed
    • Main tests: 1629 passed, 2 skipped

@skuirrels skuirrels marked this pull request as ready for review July 2, 2026 21:33
@latonz

latonz commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. Before we review this further, please update the PR description to use the repository’s PR template.

Also, for larger feature PRs like this, please open an issue first so the scope and intended design can be discussed before implementation.

@skuirrels

Copy link
Copy Markdown
Author

Thanks for the contribution. Before we review this further, please update the PR description to use the repository’s PR template.

Also, for larger feature PRs like this, please open an issue first so the scope and intended design can be discussed before implementation.

Hello. I updated the PR as per your template. I did raise this previously and this design was your recomendation to me.

@latonz

latonz commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The PR description still looks VERY AI generated…

Related issue: none. This PR was opened before the requested issue-first design discussion; I am happy to move the design discussion to an issue if preferred.

then

[…] I did raise this previously […]

Where did you raise it previously? Please link it.

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