@@ -961,52 +961,75 @@ private static void GatherForwardedAttributes(
961
961
using ImmutableArrayBuilder < AttributeInfo > fieldAttributesInfo = ImmutableArrayBuilder < AttributeInfo > . Rent ( ) ;
962
962
using ImmutableArrayBuilder < AttributeInfo > propertyAttributesInfo = ImmutableArrayBuilder < AttributeInfo > . Rent ( ) ;
963
963
964
- foreach ( SyntaxReference syntaxReference in methodSymbol . DeclaringSyntaxReferences )
964
+ static void GatherForwardedAttributes (
965
+ IMethodSymbol methodSymbol ,
966
+ SemanticModel semanticModel ,
967
+ CancellationToken token ,
968
+ in ImmutableArrayBuilder < DiagnosticInfo > diagnostics ,
969
+ in ImmutableArrayBuilder < AttributeInfo > fieldAttributesInfo ,
970
+ in ImmutableArrayBuilder < AttributeInfo > propertyAttributesInfo )
965
971
{
966
- // Try to get the target method declaration syntax node
967
- if ( syntaxReference . GetSyntax ( token ) is not MethodDeclarationSyntax methodDeclaration )
972
+ foreach ( SyntaxReference syntaxReference in methodSymbol . DeclaringSyntaxReferences )
968
973
{
969
- continue ;
970
- }
971
-
972
- // Gather explicit forwarded attributes info
973
- foreach ( AttributeListSyntax attributeList in methodDeclaration . AttributeLists )
974
- {
975
- // Same as in the [ObservableProperty] generator, except we're also looking for fields here
976
- if ( attributeList . Target ? . Identifier is not SyntaxToken ( SyntaxKind . PropertyKeyword or SyntaxKind . FieldKeyword ) )
974
+ // Try to get the target method declaration syntax node
975
+ if ( syntaxReference . GetSyntax ( token ) is not MethodDeclarationSyntax methodDeclaration )
977
976
{
978
977
continue ;
979
978
}
980
979
981
- foreach ( AttributeSyntax attribute in attributeList . Attributes )
980
+ // Gather explicit forwarded attributes info
981
+ foreach ( AttributeListSyntax attributeList in methodDeclaration . AttributeLists )
982
982
{
983
- // Get the symbol info for the attribute (once again just like in the [ObservableProperty] generator)
984
- if ( ! semanticModel . GetSymbolInfo ( attribute , token ) . TryGetAttributeTypeSymbol ( out INamedTypeSymbol ? attributeTypeSymbol ) )
983
+ // Same as in the [ObservableProperty] generator, except we're also looking for fields here
984
+ if ( attributeList . Target ? . Identifier is not SyntaxToken ( SyntaxKind . PropertyKeyword or SyntaxKind . FieldKeyword ) )
985
985
{
986
- diagnostics . Add (
987
- InvalidFieldOrPropertyTargetedAttributeOnRelayCommandMethod ,
988
- attribute ,
989
- methodSymbol ,
990
- attribute . Name ) ;
991
-
992
986
continue ;
993
987
}
994
988
995
- AttributeInfo attributeInfo = AttributeInfo . From ( attributeTypeSymbol , semanticModel , attribute . ArgumentList ? . Arguments ?? Enumerable . Empty < AttributeArgumentSyntax > ( ) , token ) ;
996
-
997
- // Add the new attribute info to the right builder
998
- if ( attributeList . Target ? . Identifier is SyntaxToken ( SyntaxKind . FieldKeyword ) )
999
- {
1000
- fieldAttributesInfo . Add ( attributeInfo ) ;
1001
- }
1002
- else
989
+ foreach ( AttributeSyntax attribute in attributeList . Attributes )
1003
990
{
1004
- propertyAttributesInfo . Add ( attributeInfo ) ;
991
+ // Get the symbol info for the attribute (once again just like in the [ObservableProperty] generator)
992
+ if ( ! semanticModel . GetSymbolInfo ( attribute , token ) . TryGetAttributeTypeSymbol ( out INamedTypeSymbol ? attributeTypeSymbol ) )
993
+ {
994
+ diagnostics . Add (
995
+ InvalidFieldOrPropertyTargetedAttributeOnRelayCommandMethod ,
996
+ attribute ,
997
+ methodSymbol ,
998
+ attribute . Name ) ;
999
+
1000
+ continue ;
1001
+ }
1002
+
1003
+ AttributeInfo attributeInfo = AttributeInfo . From ( attributeTypeSymbol , semanticModel , attribute . ArgumentList ? . Arguments ?? Enumerable . Empty < AttributeArgumentSyntax > ( ) , token ) ;
1004
+
1005
+ // Add the new attribute info to the right builder
1006
+ if ( attributeList . Target ? . Identifier is SyntaxToken ( SyntaxKind . FieldKeyword ) )
1007
+ {
1008
+ fieldAttributesInfo . Add ( attributeInfo ) ;
1009
+ }
1010
+ else
1011
+ {
1012
+ propertyAttributesInfo . Add ( attributeInfo ) ;
1013
+ }
1005
1014
}
1006
1015
}
1007
1016
}
1008
1017
}
1009
1018
1019
+ // Gather attributes from the method declaration
1020
+ GatherForwardedAttributes ( methodSymbol , semanticModel , token , in diagnostics , in fieldAttributesInfo , in propertyAttributesInfo ) ;
1021
+
1022
+ // If the method is a partial definition, also gather attributes from the implementation part
1023
+ if ( methodSymbol is { IsPartialDefinition : true , PartialImplementationPart : { } partialImplementation } )
1024
+ {
1025
+ GatherForwardedAttributes ( partialImplementation , semanticModel , token , in diagnostics , in fieldAttributesInfo , in propertyAttributesInfo ) ;
1026
+ }
1027
+ else if ( methodSymbol is { IsPartialDefinition : false , PartialDefinitionPart : { } partialDefinition } )
1028
+ {
1029
+ // If the method is a partial implementation, also gather attributes from the definition part
1030
+ GatherForwardedAttributes ( partialDefinition , semanticModel , token , in diagnostics , in fieldAttributesInfo , in propertyAttributesInfo ) ;
1031
+ }
1032
+
1010
1033
fieldAttributes = fieldAttributesInfo . ToImmutable ( ) ;
1011
1034
propertyAttributes = propertyAttributesInfo . ToImmutable ( ) ;
1012
1035
}
0 commit comments