@@ -61,7 +61,7 @@ private protected TransitiveMembersGenerator(string fullyQualifiedAttributeMetad
61
61
public void Initialize ( IncrementalGeneratorInitializationContext context )
62
62
{
63
63
// 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 =
65
65
context . SyntaxProvider
66
66
. ForAttributeWithMetadataName (
67
67
this . fullyQualifiedAttributeMetadataName ,
@@ -81,28 +81,29 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
81
81
// If there are any diagnostics, there's no need to compute the hierarchy info at all, just return them
82
82
if ( diagnostics . Length > 0 )
83
83
{
84
- return new Result < ( HierarchyInfo , bool , TInfo ? ) > ( default , diagnostics ) ;
84
+ return new Result < ( HierarchyInfo , MetadataInfo ? , TInfo ? ) > ( default , diagnostics ) ;
85
85
}
86
86
87
87
HierarchyInfo hierarchy = HierarchyInfo . From ( typeSymbol ) ;
88
+ MetadataInfo metadataInfo = new ( typeSymbol . IsSealed , true ) ;
88
89
89
- return new Result < ( HierarchyInfo , bool , TInfo ? ) > ( ( hierarchy , typeSymbol . IsSealed , info ) , diagnostics ) ;
90
+ return new Result < ( HierarchyInfo , MetadataInfo ? , TInfo ? ) > ( ( hierarchy , metadataInfo , info ) , diagnostics ) ;
90
91
} )
91
92
. Where ( static item => item is not null ) ! ;
92
93
93
94
// Emit the diagnostic, if needed
94
95
context . ReportDiagnostics ( generationInfoWithErrors . Select ( static ( item , _ ) => item . Errors ) ) ;
95
96
96
97
// 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 =
98
99
generationInfoWithErrors
99
100
. Where ( static item => item . Errors . IsEmpty )
100
101
. Select ( static ( item , _ ) => item . Value ) ! ;
101
102
102
103
// Generate the required members
103
104
context . RegisterSourceOutput ( generationInfo , ( context , item ) =>
104
105
{
105
- ImmutableArray < MemberDeclarationSyntax > sourceMemberDeclarations = item . IsSealed ? this . sealedMemberDeclarations : this . nonSealedMemberDeclarations ;
106
+ ImmutableArray < MemberDeclarationSyntax > sourceMemberDeclarations = item . MetadataInfo . IsSealed ? this . sealedMemberDeclarations : this . nonSealedMemberDeclarations ;
106
107
ImmutableArray < MemberDeclarationSyntax > filteredMemberDeclarations = FilterDeclaredMembers ( item . Info , sourceMemberDeclarations ) ;
107
108
CompilationUnitSyntax compilationUnit = item . Hierarchy . GetCompilationUnit ( filteredMemberDeclarations , this . classDeclaration . BaseList ) ;
108
109
@@ -128,4 +129,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
128
129
/// <param name="memberDeclarations">The input sequence of <see cref="MemberDeclarationSyntax"/> instances to generate.</param>
129
130
/// <returns>A sequence of <see cref="MemberDeclarationSyntax"/> nodes to emit in the generated file.</returns>
130
131
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