Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Source/TimeWarp.State.SourceGenerator/ActionSetMethodGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,32 @@ public bool Equals(ClassDeclarationSyntax? x, ClassDeclarationSyntax? y)

string xNamespace = GetNamespace(x);
string yNamespace = GetNamespace(y);
return x.Identifier.ValueText == y.Identifier.ValueText && xNamespace == yNamespace;
string xParentClassName = GetParentClassName(x);
string yParentClassName = GetParentClassName(y);
return x.Identifier.ValueText == y.Identifier.ValueText && xNamespace == yNamespace && xParentClassName == yParentClassName;
}

public int GetHashCode(ClassDeclarationSyntax obj)
{
if (ReferenceEquals(obj, null)) return 0;

int hashClassName = obj.Identifier.ValueText.GetHashCode();
int hashNamespace = GetNamespace(obj).GetHashCode();

return hashClassName ^ hashNamespace;
return $"{GetNamespace(obj)}.{GetParentClassName(obj)}.{obj.Identifier.ValueText}".GetHashCode();
}

private static string GetNamespace(ClassDeclarationSyntax classDeclaration)
{
SyntaxNode? namespaceDeclaration = classDeclaration.Parent;
while (namespaceDeclaration != null && namespaceDeclaration is not NamespaceDeclarationSyntax)
while (namespaceDeclaration is { } nd && nd is not BaseNamespaceDeclarationSyntax)
{
namespaceDeclaration = namespaceDeclaration.Parent;
}

return namespaceDeclaration is NamespaceDeclarationSyntax namespaceSyntax ? namespaceSyntax.Name.ToString() : string.Empty;
return namespaceDeclaration switch
{
NamespaceDeclarationSyntax namespaceSyntax => namespaceSyntax.Name.ToString(),
FileScopedNamespaceDeclarationSyntax fileScopedNamespaceSyntax => fileScopedNamespaceSyntax.Name.ToString(),
_ => string.Empty
};
}
}
}
Expand Down
Loading