@@ -61,7 +61,7 @@ private protected TransitiveMembersGenerator(string fullyQualifiedAttributeMetad
6161 public void Initialize ( IncrementalGeneratorInitializationContext context )
6262 {
6363 // Gather all generation info, and any diagnostics
64- IncrementalValuesProvider < Result < ( HierarchyInfo Hierarchy , bool IsSealed , TInfo ? Info ) > > generationInfoWithErrors =
64+ IncrementalValuesProvider < Result < ( HierarchyInfo Hierarchy , MetadataInfo ? MetadataInfo , TInfo ? Info ) > > generationInfoWithErrors =
6565 context . SyntaxProvider
6666 . ForAttributeWithMetadataName (
6767 this . fullyQualifiedAttributeMetadataName ,
@@ -81,28 +81,29 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
8181 // If there are any diagnostics, there's no need to compute the hierarchy info at all, just return them
8282 if ( diagnostics . Length > 0 )
8383 {
84- return new Result < ( HierarchyInfo , bool , TInfo ? ) > ( default , diagnostics ) ;
84+ return new Result < ( HierarchyInfo , MetadataInfo ? , TInfo ? ) > ( default , diagnostics ) ;
8585 }
8686
8787 HierarchyInfo hierarchy = HierarchyInfo . From ( typeSymbol ) ;
88+ MetadataInfo metadataInfo = new ( typeSymbol . IsSealed , true ) ;
8889
89- return new Result < ( HierarchyInfo , bool , TInfo ? ) > ( ( hierarchy , typeSymbol . IsSealed , info ) , diagnostics ) ;
90+ return new Result < ( HierarchyInfo , MetadataInfo ? , TInfo ? ) > ( ( hierarchy , metadataInfo , info ) , diagnostics ) ;
9091 } )
9192 . Where ( static item => item is not null ) ! ;
9293
9394 // Emit the diagnostic, if needed
9495 context . ReportDiagnostics ( generationInfoWithErrors . Select ( static ( item , _ ) => item . Errors ) ) ;
9596
9697 // Get the filtered sequence to enable caching
97- IncrementalValuesProvider < ( HierarchyInfo Hierarchy , bool IsSealed , TInfo Info ) > generationInfo =
98+ IncrementalValuesProvider < ( HierarchyInfo Hierarchy , MetadataInfo MetadataInfo , TInfo Info ) > generationInfo =
9899 generationInfoWithErrors
99100 . Where ( static item => item . Errors . IsEmpty )
100101 . Select ( static ( item , _ ) => item . Value ) ! ;
101102
102103 // Generate the required members
103104 context . RegisterSourceOutput ( generationInfo , ( context , item ) =>
104105 {
105- ImmutableArray < MemberDeclarationSyntax > sourceMemberDeclarations = item . IsSealed ? this . sealedMemberDeclarations : this . nonSealedMemberDeclarations ;
106+ ImmutableArray < MemberDeclarationSyntax > sourceMemberDeclarations = item . MetadataInfo . IsSealed ? this . sealedMemberDeclarations : this . nonSealedMemberDeclarations ;
106107 ImmutableArray < MemberDeclarationSyntax > filteredMemberDeclarations = FilterDeclaredMembers ( item . Info , sourceMemberDeclarations ) ;
107108 CompilationUnitSyntax compilationUnit = item . Hierarchy . GetCompilationUnit ( filteredMemberDeclarations , this . classDeclaration . BaseList ) ;
108109
@@ -128,4 +129,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
128129 /// <param name="memberDeclarations">The input sequence of <see cref="MemberDeclarationSyntax"/> instances to generate.</param>
129130 /// <returns>A sequence of <see cref="MemberDeclarationSyntax"/> nodes to emit in the generated file.</returns>
130131 protected abstract ImmutableArray < MemberDeclarationSyntax > FilterDeclaredMembers ( TInfo info , ImmutableArray < MemberDeclarationSyntax > memberDeclarations ) ;
131- }
132+
133+ /// <summary>
134+ /// A small record for metadata info on types to generate.
135+ /// </summary>
136+ /// <param name="IsSealed">Whether the target type is sealed.</param>
137+ /// <param name="IsNullabilitySupported">Whether nullability attributes are supported.</param>
138+ private sealed record MetadataInfo ( bool IsSealed , bool IsNullabilitySupported ) ;
139+ }
0 commit comments