API Proposal: IncrementalGeneratorPostInitializationContext.AddEmbeddedAttributeDefinition
#76584
Labels
api-ready-for-review
API is ready for review, it is NOT ready for implementation
Area-Analyzers
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Feature - Source Generators
Source Generators
Feature Request
untriaged
Issues and PRs which have not yet been triaged by a lead
Background and Motivation
Generator authors have issues with user-visible marker types (usually used to drive
ForAttributeWithMetadataName
) being visible in multiple compilations, which causes warnings to be issued. The compiler already has a solution for this for its own generated types:Microsoft.CodeAnalysis.EmbeddedAttribute
. In #76523, we allowed this type to be provided by users, so that generator authors will be able to take advantage of the attribute for their own scenarios. However, the definition that must be followed is very specific, and we think it's likely that generator authors may struggle to get it entirely correct, including remembering thepartial
modifier so that other generators can safely add their own copies. We therefore propose an API to allow generator authors to add the attribute directly, entirely correctly.Proposed API
Usage Examples
Alternative Designs
We considered other alternatives, such as moving the warning location to where a generator author could suppress it, but these other approaches were all much more complicated.
EmbeddedAttribute
is a battle-tested solution that the compiler has used for years, so we think it's the best approach.Risks
The text was updated successfully, but these errors were encountered: