File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,15 @@ public sealed partial class ObservableValidatorValidateAllPropertiesGenerator :
20
20
/// <inheritdoc/>
21
21
public void Initialize ( IncrementalGeneratorInitializationContext context )
22
22
{
23
- // Get all class declarations
23
+ // Get all class declarations. We intentionally skip generating code for abstract types, as that would never be used.
24
+ // The methods that are generated by this generator are retrieved through reflection using the type of the invoking
25
+ // instance as discriminator, which means a type that is abstract could never be used (since it couldn't be instantiated).
24
26
IncrementalValuesProvider < INamedTypeSymbol > typeSymbols =
25
27
context . SyntaxProvider
26
28
. CreateSyntaxProvider (
27
29
static ( node , _ ) => node is ClassDeclarationSyntax ,
28
30
static ( context , _ ) => ( context . Node , Symbol : ( INamedTypeSymbol ) context . SemanticModel . GetDeclaredSymbol ( context . Node ) ! ) )
29
- . Where ( static item => item . Node . IsFirstSyntaxDeclarationForSymbol ( item . Symbol ) )
31
+ . Where ( static item => ! item . Symbol . IsAbstract && item . Node . IsFirstSyntaxDeclarationForSymbol ( item . Symbol ) )
30
32
. Select ( static ( item , _ ) => item . Symbol ) ;
31
33
32
34
// Get the types that inherit from ObservableValidator and gather their info
Original file line number Diff line number Diff line change @@ -25,12 +25,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
25
25
// definitions (it might happen if a recipient has partial declarations). To do this, all pairs
26
26
// of class declarations and associated symbols are gathered, and then only the pair where the
27
27
// class declaration is the first syntax reference for the associated symbol is kept.
28
+ // Just like with the ObservableValidator generator, we also intentionally skip abstract types.
28
29
IncrementalValuesProvider < INamedTypeSymbol > typeSymbols =
29
30
context . SyntaxProvider
30
31
. CreateSyntaxProvider (
31
32
static ( node , _ ) => node is ClassDeclarationSyntax ,
32
33
static ( context , _ ) => ( context . Node , Symbol : ( INamedTypeSymbol ) context . SemanticModel . GetDeclaredSymbol ( context . Node ) ! ) )
33
- . Where ( static item => item . Node . IsFirstSyntaxDeclarationForSymbol ( item . Symbol ) )
34
+ . Where ( static item => ! item . Symbol . IsAbstract && item . Node . IsFirstSyntaxDeclarationForSymbol ( item . Symbol ) )
34
35
. Select ( static ( item , _ ) => item . Symbol ) ;
35
36
36
37
// Get the target IRecipient<TMessage> interfaces and filter out other types
You can’t perform that action at this time.
0 commit comments