[IIncrementalGenerator] Multiple files same symbol #71575
-
Structureconsidering following project structure:
Use caseI'm trying to create an incremental generator that generates a code when the symbol has an attribute that implements a specific interface. The IssueFrom the tests I have done, I see that the generator is invoked for each file that makes up the symbol, creating duplicate code. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You'll need your incremental generator pipeline to .Collect all the elements and process them in aggregate to know what to merge and what to filter or throw out. Note:
You should use .ForAttributeWithMetadataName for this purpose. It's normally around 100x faster and uses around 100x memory to accomplish the same task. As a bonus, it is symbol (not syntax) based. So you'd only get this symbol a single time, even though it has multiple parts spread across multiple files. |
Beta Was this translation helpful? Give feedback.
You'll need your incremental generator pipeline to .Collect all the elements and process them in aggregate to know what to merge and what to filter or throw out.
Note:
You should use .ForAttributeWithMetadataName for this purpose. It's normally around 100x faster and uses around 100x memory to accomplish the same task. As a bonus, it is symbol (not syntax) based. So you'd only get this symbol a single time, even though it has multiple parts spread across multiple files.