@@ -38,6 +38,10 @@ public class ProjectionExpressionGenerator : IIncrementalGenerator
3838
3939 public void Initialize ( IncrementalGeneratorInitializationContext context )
4040 {
41+ // Snapshot global MSBuild defaults once per generator run.
42+ var globalOptions = context . AnalyzerConfigOptionsProvider
43+ . Select ( static ( opts , _ ) => new ProjectableGlobalOptions ( opts . GlobalOptions ) ) ;
44+
4145 // Extract only pure stable data from the attribute in the transform.
4246 // No live Roslyn objects (no AttributeData, SemanticModel, Compilation, ISymbol) —
4347 // those are always new instances and defeat incremental caching entirely.
@@ -50,14 +54,23 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5054 Attribute : new ProjectableAttributeData ( c . Attributes [ 0 ] )
5155 ) ) ;
5256
53- var compilationAndMemberPairs = memberDeclarations
57+ // Flatten (Member, Attribute) + GlobalOptions into a single named tuple.
58+ var memberDeclarationsWithGlobalOptions = memberDeclarations
59+ . Combine ( globalOptions )
60+ . Select ( static ( pair , _ ) => (
61+ Member : pair . Left . Member ,
62+ Attribute : pair . Left . Attribute ,
63+ GlobalOptions : pair . Right
64+ ) ) ;
65+
66+ var compilationAndMemberPairs = memberDeclarationsWithGlobalOptions
5467 . Combine ( context . CompilationProvider )
5568 . WithComparer ( new MemberDeclarationSyntaxAndCompilationEqualityComparer ( ) ) ;
5669
5770 context . RegisterSourceOutput ( compilationAndMemberPairs ,
5871 static ( spc , source ) =>
5972 {
60- var ( ( member , attribute ) , compilation ) = source ;
73+ var ( ( member , attribute , globalOptions ) , compilation ) = source ;
6174 var semanticModel = compilation . GetSemanticModel ( member . SyntaxTree ) ;
6275 var memberSymbol = semanticModel . GetDeclaredSymbol ( member ) ;
6376
@@ -66,13 +79,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
6679 return ;
6780 }
6881
69- Execute ( member , semanticModel , memberSymbol , attribute , compilation , spc ) ;
82+ Execute ( member , semanticModel , memberSymbol , attribute , globalOptions , compilation , spc ) ;
7083 } ) ;
7184
7285 // Build the projection registry: collect all entries and emit a single registry file
7386 var registryEntries = compilationAndMemberPairs . Select (
7487 static ( source , cancellationToken ) => {
75- var ( ( member , _) , compilation ) = source ;
88+ var ( ( member , _, _ ) , compilation ) = source ;
7689
7790 var semanticModel = compilation . GetSemanticModel ( member . SyntaxTree ) ;
7891 var memberSymbol = semanticModel . GetDeclaredSymbol ( member , cancellationToken ) ;
@@ -170,11 +183,12 @@ private static void Execute(
170183 SemanticModel semanticModel ,
171184 ISymbol memberSymbol ,
172185 ProjectableAttributeData projectableAttribute ,
186+ ProjectableGlobalOptions globalOptions ,
173187 Compilation ? compilation ,
174188 SourceProductionContext context )
175189 {
176190 var projectable = ProjectableInterpreter . GetDescriptor (
177- semanticModel , member , memberSymbol , projectableAttribute , context , compilation ) ;
191+ semanticModel , member , memberSymbol , projectableAttribute , globalOptions , context , compilation ) ;
178192
179193 if ( projectable is null )
180194 {
0 commit comments