@@ -96,7 +96,12 @@ protected override IReadOnlyList<MethodBodyStatement> BuildAttributes()
9696 // Process each output-library provider recursively to discover types from methods and properties.
9797 foreach ( var provider in contextEligibleOutputProviders )
9898 {
99- CollectBuildableTypeProvidersRecursive ( provider , contextEligibleOutputProviders , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
99+ if ( ImplementsModelReaderWriter ( provider ) )
100+ {
101+ buildableProviders . Add ( provider ) ;
102+ }
103+
104+ CollectBuildableTypeProvidersRecursive ( provider , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
100105 }
101106
102107 return ( buildableTypes , buildableProviders ) ;
@@ -123,7 +128,6 @@ private void CollectBuildableTypesRecursive(
123128 /// </summary>
124129 private void CollectBuildableTypeProvidersRecursive (
125130 TypeProvider currentProvider ,
126- HashSet < TypeProvider > contextEligibleOutputProviders ,
127131 HashSet < CSharpType > visitedTypes ,
128132 HashSet < TypeProvider > visitedTypeProviders ,
129133 HashSet < TypeProvider > buildableProviders ,
@@ -135,23 +139,15 @@ private void CollectBuildableTypeProvidersRecursive(
135139 return ;
136140 }
137141
138- // Only add providers that the output library asked this context to build; base providers outside
139- // that set are still traversed for their properties but do not get standalone context entries.
140- if ( contextEligibleOutputProviders . Contains ( currentProvider ) && ImplementsModelReaderWriter ( currentProvider ) )
141- {
142- buildableProviders . Add ( currentProvider ) ;
143- }
144-
145142 // Process all providers to discover types from methods and properties
146143 if ( currentProvider is not null )
147144 {
148- CollectBuildableTypesRecursiveCore ( currentProvider , contextEligibleOutputProviders , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
145+ CollectBuildableTypesRecursiveCore ( currentProvider , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
149146 }
150147 }
151148
152149 private void CollectBuildableTypesRecursiveCore (
153150 TypeProvider provider ,
154- HashSet < TypeProvider > contextEligibleOutputProviders ,
155151 HashSet < CSharpType > visitedTypes ,
156152 HashSet < TypeProvider > visitedTypeProviders ,
157153 HashSet < TypeProvider > buildableProviders ,
@@ -188,9 +184,7 @@ private void CollectBuildableTypesRecursiveCore(
188184
189185 if ( provider is ModelProvider modelProvider && modelProvider . BaseModelProvider != null )
190186 {
191- // Base-model traversal can visit providers that were not in the initial output-library
192- // set, so the recursive call still needs the context eligibility filter.
193- CollectBuildableTypeProvidersRecursive ( modelProvider . BaseModelProvider , contextEligibleOutputProviders , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
187+ CollectBuildableTypeProvidersRecursive ( modelProvider . BaseModelProvider , visitedTypes , visitedTypeProviders , buildableProviders , buildableTypes ) ;
194188 }
195189 else
196190 {
0 commit comments