You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a SyntaxReceiver and register it in the generator
Add a file in the AdditionalFiles
Try to access the AdditionalFiles from the SyntaxReceiver
Expected Behavior:
I would expect to be able to access the AdditionalFiles
Actual Behavior:
I am not able to access the AdditionalFiles
Rationale:
The standard workflow for code generators is to use a SyntaxReceiver to identify the portions of the syntax trees useful to generate new code.
In many cases, we can use a generated attribute to annotate the portions of code that a SyntaxReceiver should capture.
In other cases, it is not possible to annotate the code because it has been generated using T4Templates or because it comes from external tools that can generate file.
In these cases, it would make sense to access the AdditionalFiles from the SyntaxReceiver in order to minimize the amount of data provided to the generator.
Since the AdditionalFiles are not available in a SyntaxReceiver, the generator must do all the processing inside the Execute method which forces processing all the SyntaxTrees instead of just the ones that are captured by a SyntaxReceiver.
It's not even possible to make the pre-processing in the Initialize method as the AdditionalFiles are not accessible there.
The text was updated successfully, but these errors were encountered:
Sorry for the late response @jaredpar. One week in a conference, another sick :-(
I am using Source Generators
Here is the example of the SyntaxReceiver.
I have other cases where the _rootInterfaceName cannot be hardcoded but should be configured at project level.
AdditionalFiles look like a greate place to put this string, but apparently I can't access the AdditionalFiles from a ISyntaxReceiver
internalclassSiblingConfigurationSyntaxReceiver:ISyntaxReceiver{privateconststring_rootInterfaceName="IEntityTypeConfiguration";publicList<ClassDeclarationSyntax>ConfigurationClasses=new();publicSiblingConfigurationSyntaxReceiver(){}publicvoidOnVisitSyntaxNode(SyntaxNodesyntaxNode){BaseTypeDeclarationSyntax?typeDeclaration= GeneratorsCommon.GetTypeDeclaration(syntaxNode);// dbcontext configurations are always classesif(typeDeclaration is not ClassDeclarationSyntax classDeclaration)return;//((classDeclaration.BaseList?.Types[0] as BaseTypeSyntax).Type as SimpleNameSyntax).Identifier.TextboolisConfiguration= classDeclaration.BaseList?.Types
.Any(t =>(t?.Type as SimpleNameSyntax)?.Identifier.Text ==_rootInterfaceName)??false;if(!isConfiguration)return;
ConfigurationClasses.Add(classDeclaration);}}
Version Used: 4.10.0
Steps to Reproduce:
SyntaxReceiver
and register it in the generatorAdditionalFiles
SyntaxReceiver
Expected Behavior:
I would expect to be able to access the
AdditionalFiles
Actual Behavior:
I am not able to access the
AdditionalFiles
Rationale:
The standard workflow for code generators is to use a
SyntaxReceiver
to identify the portions of the syntax trees useful to generate new code.In many cases, we can use a generated attribute to annotate the portions of code that a
SyntaxReceiver
should capture.In other cases, it is not possible to annotate the code because it has been generated using T4Templates or because it comes from external tools that can generate file.
In these cases, it would make sense to access the
AdditionalFiles
from theSyntaxReceiver
in order to minimize the amount of data provided to the generator.Since the
AdditionalFiles
are not available in aSyntaxReceiver
, the generator must do all the processing inside theExecute
method which forces processing all theSyntaxTrees
instead of just the ones that are captured by aSyntaxReceiver
.It's not even possible to make the pre-processing in the
Initialize
method as theAdditionalFiles
are not accessible there.The text was updated successfully, but these errors were encountered: