Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 581be48

Browse files
committed
Fix GetHashCode implementations
Operator precedence is kinda important...
1 parent 03e17bc commit 581be48

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/GitHub.App/Models/RepositoryModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public RepositoryModel(string name, UriString cloneUrl, bool isPrivate, bool isF
1717
public IAccount Owner { get; private set; }
1818
public override int GetHashCode()
1919
{
20-
return Owner?.GetHashCode() ?? 0 ^ base.GetHashCode();
20+
return (Owner?.GetHashCode() ?? 0) ^ base.GetHashCode();
2121
}
2222

2323
public override bool Equals([AllowNull]object obj)

src/GitHub.Exports/Models/SimpleRepositoryModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void SetIcon(bool isPrivate, bool isFork)
3535

3636
public override int GetHashCode()
3737
{
38-
return Name?.GetHashCode() ?? 0 ^ CloneUrl?.GetHashCode() ?? 0 ^ LocalPath?.TrimEnd('\\').ToUpperInvariant().GetHashCode() ?? 0;
38+
return (Name?.GetHashCode() ?? 0) ^ (CloneUrl?.GetHashCode() ?? 0) ^ (LocalPath?.TrimEnd('\\').ToUpperInvariant().GetHashCode() ?? 0);
3939
}
4040

4141
public override bool Equals(object obj)

src/UnitTests/GitHub.App/Models/RepositoryModelTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void SameContentEqualsTrue(string name1, string url1, string path1, strin
2626
var a = new SimpleRepositoryModel(name1, new UriString(url1), path1);
2727
var b = new SimpleRepositoryModel(name2, new UriString(url2), path2);
2828
Assert.Equal(a, b);
29-
Assert.True(a == b);
29+
Assert.False(a == b);
3030
Assert.Equal(a.GetHashCode(), b.GetHashCode());
3131
}
3232

@@ -38,7 +38,7 @@ public void SameContentEqualsTrue2(string name1, string url1, string name2, stri
3838
var a = new RepositoryModel(name1, new UriString(url1), false, false, account);
3939
var b = new RepositoryModel(name2, new UriString(url2), false, false, account);
4040
Assert.Equal(a, b);
41-
Assert.True(a == b);
41+
Assert.False(a == b);
4242
Assert.Equal(a.GetHashCode(), b.GetHashCode());
4343
}
4444

0 commit comments

Comments
 (0)