when Equals was overridden, GetHashCode must be overridden as well, and vice versa.
when Equals gives true, GetHashCode must give the same value on two instances, but when GetHashCode gives the same value on two instances, Equals does not have to return true (hashcode collision).
Our previous implementation compares string case insensitively, but returning hash code from the underlying string directly, which is violating rule no. 2.
Checklist
To ensure a quick review and merge, please ensure:
[ ] The PR has a understandable title and description explaining the why and what.
[ ] The PR is opened in draft if not ready for review yet.
If opened in draft, please allocate sufficient time (24 hours) after moving out of draft for review
[ ] The branch is recent enough to not have merge conflicts upon creation.
Ready to Land?
[ ] Build is completely green
Submissions with test failures require tracking issue and approval of a CODEOWNER
[ ] At least one +1 review by a CODEOWNER
[ ] All -1 reviews are confirmed resolved by the reviewer
Override/Marking reviews stale must be discussed with CODEOWNERS first
Fixes https://github.com/Azure/autorest.csharp/issues/4833
Description
Common convention for
GetHashCode
andEquals
:Equals
was overridden,GetHashCode
must be overridden as well, and vice versa.Equals
gives true,GetHashCode
must give the same value on two instances, but whenGetHashCode
gives the same value on two instances,Equals
does not have to returntrue
(hashcode collision).Our previous implementation compares string case insensitively, but returning hash code from the underlying string directly, which is violating rule no. 2.
Checklist
To ensure a quick review and merge, please ensure:
Ready to Land?