Create an analyzer that explicitly flags naming clash for extensions#158
Merged
andrewlock merged 2 commits intomainfrom Jul 1, 2025
Merged
Create an analyzer that explicitly flags naming clash for extensions#158andrewlock merged 2 commits intomainfrom
andrewlock merged 2 commits intomainfrom
Conversation
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.
Currently, you can generate extension types that result in the same extension class being generated, which causes clashes. For example, the following generates
SomeNamespace.MyEnumExtensionstwice, one for eachenum:Ideally we would disambiguate by generating
SomeNamespace.Nested.MyEnumExtensionsas a nested class, but extension method classes can't be nested classes. Another option would be to include the class name in the generated namespace, but then there's another issue that can generate clashes. Ultimately, it would be possible to generate an extension method something likeNested_MyEnum, but there's always ways to get clashes (or you have to generate something really ugly). Plus it would be a breaking change.Given that these types of clashes are going to be rare, this PR just adds an analyzer
NEEG001that flags the fact there's a clash on the[EnumExtensions]attribute directly.This isn't strictly necessary, because generating duplicate extension classes results in a lot of compiler errors, but having an analyzer will hopefully make it more obvious exactly what's happened.