Repository navigation
Keep a file's assembly attributes and comments below C# 10 [patch] - #79
Merged
Merged
Conversation
The block-scoped namespace path copied only the usings and classes into the template it wrote inside the block, so a file's assembly:/module: attributes, comments and documentation vanished for C# 7.3-9 consumers with no diagnostic. Write them before the namespace block, with the usings too when there are attributes so the attributes can be named through them, as CodeBlocker does for a file-scoped namespace. Fixes #77 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5chbrSDfDAQ2U7T5G
|
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.



Fixes #77
What was wrong
Below C# 10,
WriteSourceFilerebuilt the template inside anamespace { }block, but the rebuilt copy held onlyUsingsandClasses. Anyassembly:/module:attributes, fileCommentsandDocumentationon the template were dropped with no diagnostic. For example, a C# 7.3 consumer never got anInternalsVisibleToorCLSCompliantthat the generator emitted.Change
GeneratorBase.WriteSourceFile, block path only:using System;then[assembly: CLSCompliant(true)]), which is the same order CodeBlocker uses for a file-scoped namespace. A file without attributes still keeps its usings inside the block, as before.Output at C# 7.3:
Tests
AttributedThingsGenerator: one using, anassembly: CLSCompliant(true)attribute named through that using, and a file comment.AFilesAssemblyAttributesAndCommentsAreKeptAtEveryLanguageVersion(C# 7.3, 9, 10, Latest): the output compiles with no errors, the compiled assembly carriesCLSCompliantAttribute, and the comment is present.AFilesAssemblyAttributesAndCommentsPrecedeABlockScopedNamespace(C# 7.3, 9): the comment, the using and the attribute all come beforenamespace Generated {.Generated by Claude Code