Replies: 2 comments 11 replies
-
This is probably more for https://github.com/dotnet/roslyn/discussions/ as it doesn't look like a C# design conversation. In the couple of SGs I wrote, I just store the relevant part of the output in the model as a string blob. Then I don't have to worry about saving every little detail, which can be a whole bunch of properties, methods, their types and parameter types, etc. |
Beta Was this translation helpful? Give feedback.
-
Do not do this. The cookbook is very clear that symbols should not be included in your model for a reason. If any of that info that you inspected during codegen changes, then your codegen needs to change as well; if you exclude that from your model, then your generator will get out of date in the ide. In addition, you risk rooting arbitrary amounts of old memory, and violating other invariants. |
Beta Was this translation helpful? Give feedback.
-
The “augment user code” design in the incremental generators cookbook does not explain what to do if semantic/symbol information is needed during the code generation.
For example, say I need to use detailed information about the type of each property in a class. When extracting my equatable Model from the attribute’s TargetNode, I can include a string representing the type of the property as part of my Model, and use that to test equality for the purpose of managing the incremental cache. It seems easy.
But the string representation of the type is not sufficient if I need to do a deeper analysis of the type while generating code. For example, say I need to know whether the type is a reference or value type, its nullability, whether it is assignable to a certain base type or interface.
It’s true that I could do this deeper analysis as part of extracting the Model in the pipeline. But wouldn’t that take up cpu time that may go to waste? The solution would seem to be to include the semantic information (or even the entire syntaxNode) in the Model but omit it from the equality comparison. Then the reference to the syntaxNode or semantic information can be dropped after it is used to generate the code. The text representation (of the property type, in this example) would still need to be included as well since it is needed for the equality comparison.
Thoughts on this approach? If this is correct then it may make a useful addition to the cookbook.
Beta Was this translation helpful? Give feedback.
All reactions