@@ -43,14 +43,14 @@ private static string InheritDoc(ISymbol source) =>
4343
4444 public static string ? GetInterfaceNameFor ( ITypeSymbol typeSymbol )
4545 {
46- if (
47- typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
48- is not ClassDeclarationSyntax classSyntax
49- || typeSymbol is not INamedTypeSymbol
50- )
46+ var declarationAndNamedTypeSymbol = GetClassDeclarationMetadata ( typeSymbol ) ;
47+ if ( declarationAndNamedTypeSymbol == null )
5148 {
5249 return null ;
5350 }
51+
52+ var ( classSyntax , _) = declarationAndNamedTypeSymbol . Value ;
53+
5454 var symbolDetails = GetSymbolDetails ( typeSymbol , classSyntax ) ;
5555
5656 return $ "global::{ symbolDetails . NamespaceName } .{ symbolDetails . InterfaceName } ";
@@ -64,15 +64,14 @@ public static string BuildInterfaceFor(
6464 List < string > generatedInterfaceNames
6565 )
6666 {
67- if (
68- typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
69- is not ClassDeclarationSyntax classSyntax
70- || typeSymbol is not INamedTypeSymbol namedTypeSymbol
71- )
67+ var declarationAndNamedTypeSymbol = GetClassDeclarationMetadata ( typeSymbol ) ;
68+ if ( declarationAndNamedTypeSymbol == null )
7269 {
7370 return string . Empty ;
7471 }
7572
73+ var ( classSyntax , namedTypeSymbol ) = declarationAndNamedTypeSymbol . Value ;
74+
7675 var symbolDetails = GetSymbolDetails ( typeSymbol , classSyntax ) ;
7776 var interfaceGenerator = new InterfaceBuilder (
7877 symbolDetails . NamespaceName ,
@@ -101,6 +100,23 @@ is not ClassDeclarationSyntax classSyntax
101100 return generatedCode ;
102101 }
103102
103+ private static (
104+ ClassDeclarationSyntax Syntax ,
105+ INamedTypeSymbol NamedTypeSymbol
106+ ) ? GetClassDeclarationMetadata ( ITypeSymbol typeSymbol )
107+ {
108+ if (
109+ typeSymbol . DeclaringSyntaxReferences . First ( ) . GetSyntax ( )
110+ is not ClassDeclarationSyntax classSyntax
111+ || typeSymbol is not INamedTypeSymbol namedTypeSymbol
112+ )
113+ {
114+ return null ;
115+ }
116+
117+ return ( classSyntax , namedTypeSymbol ) ;
118+ }
119+
104120 private static GeneratedSymbolDetails GetSymbolDetails (
105121 ITypeSymbol typeSymbol ,
106122 ClassDeclarationSyntax classSyntax
0 commit comments