[Microsoft.Gen.Logging] Fully qualify classification types - #7689
Open
Rimobul wants to merge 1 commit into
Open
Conversation
Fixes dotnet#7157 Use SymbolDisplayFormat.FullyQualifiedFormat for the classification attributes collected from parameters, properties, base types and record constructor parameters, and emit the DataClassification field type with a global:: prefix as well. The global:: prefix is stripped before deriving the field name, so generated field names are unchanged.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Microsoft.Gen.Logging source generator to emit globally-qualified (global::) type names for data-classification attributes (and the generated DataClassification field type) to avoid namespace-collision compilation failures like the one reported in #7157.
Changes:
- Switch classification-attribute type rendering to
SymbolDisplayFormat.FullyQualifiedFormatwhen collecting attributes from parameters, properties, and base types. - Emit the generated
DataClassificationbacking fields using aglobal::-qualifiedDataClassificationtype, while preserving existing generated field naming by strippingglobal::before encoding. - Add a regression test that runs the generator over a full compilation and verifies the emitted source matches the expected snapshot and compiles cleanly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Generators/Microsoft.Gen.Logging/Verified/AttributeParserTests.DataClassificationAttributeNamespaceIsGloballyQualified.verified.txt | New verified snapshot asserting global:: qualification in generated output. |
| test/Generators/Microsoft.Gen.Logging/Unit/AttributeParserTests.cs | Adds compilation-based regression test + snapshot verification for the namespace-collision scenario. |
| src/Generators/Microsoft.Gen.Logging/Parsing/Parser.LogProperties.cs | Ensures classification attribute types gathered from properties/base types are fully qualified. |
| src/Generators/Microsoft.Gen.Logging/Parsing/Parser.cs | Ensures classification attribute types gathered from parameters are fully qualified. |
| src/Generators/Microsoft.Gen.Logging/Emission/Emitter.cs | Emits DataClassification field type with global:: and preserves field naming by stripping global:: for encoding. |
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 #7157
Use SymbolDisplayFormat.FullyQualifiedFormat for the classification attributes collected from parameters, properties, base types and record constructor parameters, and emit the DataClassification field type with a global:: prefix as well. The global:: prefix is stripped before deriving the field name, so generated field names are unchanged.
Microsoft Reviewers: Open in CodeFlow