@@ -178,28 +178,32 @@ public bool Equals(ClassDeclarationSyntax? x, ClassDeclarationSyntax? y)
178178
179179 string xNamespace = GetNamespace ( x ) ;
180180 string yNamespace = GetNamespace ( y ) ;
181- return x . Identifier . ValueText == y . Identifier . ValueText && xNamespace == yNamespace ;
181+ string xParentClassName = GetParentClassName ( x ) ;
182+ string yParentClassName = GetParentClassName ( y ) ;
183+ return x . Identifier . ValueText == y . Identifier . ValueText && xNamespace == yNamespace && xParentClassName == yParentClassName ;
182184 }
183185
184186 public int GetHashCode ( ClassDeclarationSyntax obj )
185187 {
186188 if ( ReferenceEquals ( obj , null ) ) return 0 ;
187189
188- int hashClassName = obj . Identifier . ValueText . GetHashCode ( ) ;
189- int hashNamespace = GetNamespace ( obj ) . GetHashCode ( ) ;
190-
191- return hashClassName ^ hashNamespace ;
190+ return $ "{ GetNamespace ( obj ) } .{ GetParentClassName ( obj ) } .{ obj . Identifier . ValueText } ". GetHashCode ( ) ;
192191 }
193192
194193 private static string GetNamespace ( ClassDeclarationSyntax classDeclaration )
195194 {
196195 SyntaxNode ? namespaceDeclaration = classDeclaration . Parent ;
197- while ( namespaceDeclaration != null && namespaceDeclaration is not NamespaceDeclarationSyntax )
196+ while ( namespaceDeclaration is { } nd && nd is not BaseNamespaceDeclarationSyntax )
198197 {
199198 namespaceDeclaration = namespaceDeclaration . Parent ;
200199 }
201200
202- return namespaceDeclaration is NamespaceDeclarationSyntax namespaceSyntax ? namespaceSyntax . Name . ToString ( ) : string . Empty ;
201+ return namespaceDeclaration switch
202+ {
203+ NamespaceDeclarationSyntax namespaceSyntax => namespaceSyntax . Name . ToString ( ) ,
204+ FileScopedNamespaceDeclarationSyntax fileScopedNamespaceSyntax => fileScopedNamespaceSyntax . Name . ToString ( ) ,
205+ _ => string . Empty
206+ } ;
203207 }
204208 }
205209 }
0 commit comments