@@ -44,14 +44,14 @@ private static string InheritDoc(ISymbol source) =>
4444
4545 public static string ? GetInterfaceNameFor ( ITypeSymbol typeSymbol )
4646 {
47- if (
48- typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
49- is not ClassDeclarationSyntax classSyntax
50- || typeSymbol is not INamedTypeSymbol
51- )
47+ var declarationAndNamedTypeSymbol = GetClassDeclarationMetadata ( typeSymbol ) ;
48+ if ( declarationAndNamedTypeSymbol == null )
5249 {
5350 return null ;
5451 }
52+
53+ var ( classSyntax , _) = declarationAndNamedTypeSymbol . Value ;
54+
5555 var symbolDetails = GetSymbolDetails ( typeSymbol , classSyntax ) ;
5656
5757 return $ "global::{ symbolDetails . NamespaceName } .{ symbolDetails . InterfaceName } ";
@@ -65,14 +65,14 @@ public static string BuildInterfaceFor(
6565 List < string > generatedInterfaceNames
6666 )
6767 {
68- if (
69- typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
70- is not ClassDeclarationSyntax classSyntax
71- || typeSymbol is not INamedTypeSymbol namedTypeSymbol
72- )
68+ var declarationAndNamedTypeSymbol = GetClassDeclarationMetadata ( typeSymbol ) ;
69+ if ( declarationAndNamedTypeSymbol == null )
7370 {
7471 return string . Empty ;
7572 }
73+
74+ var ( classSyntax , namedTypeSymbol ) = declarationAndNamedTypeSymbol . Value ;
75+
7676 var generationAttribute = GetGenerationAttribute ( typeSymbol ) ;
7777 var asInternal = GetAsInternal ( generationAttribute ) ;
7878 var symbolDetails = GetSymbolDetails ( typeSymbol , classSyntax ) ;
@@ -103,6 +103,23 @@ is not ClassDeclarationSyntax classSyntax
103103 return generatedCode ;
104104 }
105105
106+ private static (
107+ ClassDeclarationSyntax Syntax ,
108+ INamedTypeSymbol NamedTypeSymbol
109+ ) ? GetClassDeclarationMetadata ( ITypeSymbol typeSymbol )
110+ {
111+ if (
112+ typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
113+ is not ClassDeclarationSyntax classSyntax
114+ || typeSymbol is not INamedTypeSymbol namedTypeSymbol
115+ )
116+ {
117+ return null ;
118+ }
119+
120+ return ( classSyntax , namedTypeSymbol ) ;
121+ }
122+
106123 private static AttributeData ? GetGenerationAttribute ( ISymbol typeSymbol )
107124 {
108125 return typeSymbol
0 commit comments