Include namespace in generated source filename to prevent duplicate hint-name collisions#44
Merged
Conversation
|
|
- Add SourceFileNameHelper.GetGeneratedFileName(namespace, class) in Generation/ using namespace_class pattern with FNV-1a hash fallback for long names - Update all 5 source generators to use SourceFileNameHelper instead of ad-hoc FileName/ClassName logic - Fix pre-existing bug: ValueConverterConstructorsSourceGenerator used _BehaviorConstructors.g.cs suffix instead of _ValueConverterConstructors.g.cs - Update all 14 verified Verify snapshots to use namespace-prefixed hint names - Add SourceFileNameHelperTests (7 unit tests) and duplicate_class_names integration test
Copilot
AI
changed the title
[WIP] Add namespace to generated source filename
Include namespace in generated source filename to prevent duplicate hint-name collisions
May 28, 2026
GeertvanHorrik
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When two classes share the same name across different namespaces (e.g.
MyNamespace1.WelcomeWizardPageandMyNamespace2.WelcomeWizardPage), all source generators produced the same hint name, causing a Roslyn exception onAddSource.Changes
New shared utility:
SourceFileNameHelperGetGeneratedFileName(namespaceName, className)replaces the per-generator ad-hoc filename logic across all five generators{Namespace_With_Dots_As_Underscores}_{ClassName}when combined length ≤ 100 chars{8-char-FNV-1a-hash-of-namespace}_{ClassName}for very long namespaces — hash is deterministic, preserving incremental build cachingGenerators updated
All five generators (
ViewModelConstructors,ViewConstructors,BehaviorConstructors,MarkupExtensionConstructors,ValueConverterConstructors) now delegate filename construction toSourceFileNameHelper.Also corrects a pre-existing bug in
ValueConverterConstructorsSourceGeneratorwhere it was emitting_BehaviorConstructors.g.csas the file suffix instead of_ValueConverterConstructors.g.cs.Tests
SourceFileNameHelperTests— 7 unit tests covering dot replacement, short/long name thresholds, determinism, and uniqueness across namespacesViewModelCtorGeneratorTests.duplicate_class_names— integration test reproducing the exact issue: twoWelcomeWizardPageViewModels in different namespaces produce distinct, non-clashing hint names