@@ -969,48 +969,51 @@ static void GatherForwardedAttributes(
969
969
in ImmutableArrayBuilder < AttributeInfo > fieldAttributesInfo ,
970
970
in ImmutableArrayBuilder < AttributeInfo > propertyAttributesInfo )
971
971
{
972
- foreach ( SyntaxReference syntaxReference in methodSymbol . DeclaringSyntaxReferences )
972
+ // Get the single syntax reference for the input method symbol (there should be only one)
973
+ if ( methodSymbol . DeclaringSyntaxReferences is not [ SyntaxReference syntaxReference ] )
973
974
{
974
- // Try to get the target method declaration syntax node
975
- if ( syntaxReference . GetSyntax ( token ) is not MethodDeclarationSyntax methodDeclaration )
975
+ return ;
976
+ }
977
+
978
+ // Try to get the target method declaration syntax node
979
+ if ( syntaxReference . GetSyntax ( token ) is not MethodDeclarationSyntax methodDeclaration )
980
+ {
981
+ return ;
982
+ }
983
+
984
+ // Gather explicit forwarded attributes info
985
+ foreach ( AttributeListSyntax attributeList in methodDeclaration . AttributeLists )
986
+ {
987
+ // Same as in the [ObservableProperty] generator, except we're also looking for fields here
988
+ if ( attributeList . Target ? . Identifier is not SyntaxToken ( SyntaxKind . PropertyKeyword or SyntaxKind . FieldKeyword ) )
976
989
{
977
990
continue ;
978
991
}
979
992
980
- // Gather explicit forwarded attributes info
981
- foreach ( AttributeListSyntax attributeList in methodDeclaration . AttributeLists )
993
+ foreach ( AttributeSyntax attribute in attributeList . Attributes )
982
994
{
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 ) )
995
+ // Get the symbol info for the attribute (once again just like in the [ObservableProperty] generator)
996
+ if ( ! semanticModel . GetSymbolInfo ( attribute , token ) . TryGetAttributeTypeSymbol ( out INamedTypeSymbol ? attributeTypeSymbol ) )
985
997
{
998
+ diagnostics . Add (
999
+ InvalidFieldOrPropertyTargetedAttributeOnRelayCommandMethod ,
1000
+ attribute ,
1001
+ methodSymbol ,
1002
+ attribute . Name ) ;
1003
+
986
1004
continue ;
987
1005
}
988
1006
989
- foreach ( AttributeSyntax attribute in attributeList . Attributes )
1007
+ AttributeInfo attributeInfo = AttributeInfo . From ( attributeTypeSymbol , semanticModel , attribute . ArgumentList ? . Arguments ?? Enumerable . Empty < AttributeArgumentSyntax > ( ) , token ) ;
1008
+
1009
+ // Add the new attribute info to the right builder
1010
+ if ( attributeList . Target ? . Identifier is SyntaxToken ( SyntaxKind . FieldKeyword ) )
1011
+ {
1012
+ fieldAttributesInfo . Add ( attributeInfo ) ;
1013
+ }
1014
+ else
990
1015
{
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
- }
1016
+ propertyAttributesInfo . Add ( attributeInfo ) ;
1014
1017
}
1015
1018
}
1016
1019
}
0 commit comments