Skip to content

refactor: define the file header and collection materialiser once - #440

Open
kevin-mcmanus wants to merge 1 commit into
Tim-Maes:masterfrom
kevin-mcmanus:refactor/share-generator-helpers
Open

kevin-mcmanus wants to merge 1 commit into
Tim-Maes:masterfrom
kevin-mcmanus:refactor/share-generator-helpers

Conversation

@kevin-mcmanus

Copy link
Copy Markdown

Small refactor. No behaviour change.

The generated-file header had four implementations — CodeBuilder, FlattenCodeBuilder, WrapperCodeBuilder, GenerateDtosGenerator — and they were subtly different. Each named its own generator; GenerateDtos carried no version and appended #nullable enable; FlattenCodeBuilder read the assembly version by reflection rather than through FacetConstants. So a single shared header would have silently rewritten three generators' output. The shared helper takes the generator name and whether to include a version, and every call site keeps its exact previous text.

WrapCollectionProjection maps a collection shape to its materialising call and is the single place deciding which collection types Facet supports. It was private to ExpressionBuilder; it moves to GeneratorUtilities, with ExpressionBuilder delegating to it.

Verified by emitting every generated file for Facet.Tests on master and on this branch and diffing: 823 files, byte-for-byte identical.

This PR supports my proposal for #143, which needs both helpers, but it stands on its own.

No test file is touched, and the suite passes — though the 823-file diff above is the stronger evidence.

Checklist

  • I read the contributing guide and followed the code of conduct.
  • I added or updated tests when behavior changed.
  • I updated documentation, samples, or release notes when needed.
  • I ran dotnet test locally.
  • My change is ready for review.

Two helpers existed in several copies across the generators.

The auto-generated file header had four implementations (facet, flatten,
wrapper, GenerateDtos). They were not identical: each named its own
generator, GenerateDtos carried no version and appended #nullable enable,
and flatten read the assembly version by reflection rather than through
FacetConstants. So the shared helper takes the generator name and whether
to include a version, and each call site keeps its exact previous text.

WrapCollectionProjection — which maps a collection shape to its
materialising call, and is the single place that decides which collection
types are supported — was private to ExpressionBuilder. It moves to
GeneratorUtilities, with ExpressionBuilder delegating to it.

No behaviour change. Verified by emitting every generated file for
Facet.Tests before and after: 823 files, byte-for-byte identical.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kevin-mcmanus
kevin-mcmanus marked this pull request as ready for review October 12, 2026 14:46
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.

1 participant