@@ -664,34 +664,29 @@ public bool HasOutAttribute(VBSyntax.AttributeListSyntax a)
664664
665665 public bool IsExtensionAttribute ( VBSyntax . AttributeSyntax a )
666666 {
667- // Guard against attributes from a different syntax tree (see IsOutAttribute for details).
668- if ( a . SyntaxTree != SemanticModel . SyntaxTree ) {
669- var name = a . Name . ToString ( ) ;
670- return name . Equals ( "Extension" , StringComparison . Ordinal ) ||
671- name . Equals ( "ExtensionAttribute" , StringComparison . Ordinal ) ||
672- name . EndsWith ( ".Extension" , StringComparison . Ordinal ) ||
673- name . EndsWith ( ".ExtensionAttribute" , StringComparison . Ordinal ) ;
674- }
667+ if ( a . SyntaxTree != SemanticModel . SyntaxTree )
668+ return AttributeNameMatches ( a , "Extension" ) ;
675669 return ( SemanticModel . GetTypeInfo ( a ) . ConvertedType ? . GetFullMetadataName ( ) )
676670 ? . Equals ( ExtensionAttributeType . FullName , StringComparison . Ordinal ) == true ;
677671 }
678672
679673 public bool IsOutAttribute ( VBSyntax . AttributeSyntax a )
680674 {
681- // If the attribute's syntax tree differs from the current semantic model's tree (e.g. the
682- // parameter is declared in another source file or in a metadata assembly), calling
683- // SemanticModel.GetTypeInfo on it throws "Knoten ist nicht innerhalb Syntaxbaum" /
684- // "Node is not within syntax tree". Fall back to a name-based check in that case.
685- if ( a . SyntaxTree != SemanticModel . SyntaxTree ) {
686- var name = a . Name . ToString ( ) ;
687- return name . Equals ( "Out" , StringComparison . Ordinal ) ||
688- name . Equals ( "OutAttribute" , StringComparison . Ordinal ) ||
689- name . EndsWith ( ".Out" , StringComparison . Ordinal ) ||
690- name . EndsWith ( ".OutAttribute" , StringComparison . Ordinal ) ;
691- }
675+ if ( a . SyntaxTree != SemanticModel . SyntaxTree )
676+ return AttributeNameMatches ( a , "Out" ) ;
692677 return SemanticModel . GetTypeInfo ( a ) . ConvertedType . IsOutAttribute ( ) ;
693678 }
694679
680+ // SemanticModel.GetTypeInfo throws when the node is not in its syntax tree; fall back to name matching.
681+ private static bool AttributeNameMatches ( VBSyntax . AttributeSyntax a , string shortName )
682+ {
683+ var name = a . Name . ToString ( ) ;
684+ return name . Equals ( shortName , StringComparison . Ordinal ) ||
685+ name . Equals ( shortName + "Attribute" , StringComparison . Ordinal ) ||
686+ name . EndsWith ( "." + shortName , StringComparison . Ordinal ) ||
687+ name . EndsWith ( "." + shortName + "Attribute" , StringComparison . Ordinal ) ;
688+ }
689+
695690 public ISymbol GetCsOriginalSymbolOrNull ( ISymbol symbol )
696691 {
697692 if ( symbol == null ) return null ;
0 commit comments