Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
140 stars 160 forks source link

fix for `GetHashCode` on extensible strings #4842

Closed ArcturusZhang closed 1 week ago

ArcturusZhang commented 2 weeks ago

Fixes https://github.com/Azure/autorest.csharp/issues/4833

Description

Common convention for GetHashCode and Equals:

  1. when Equals was overridden, GetHashCode must be overridden as well, and vice versa.
  2. 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:

Ready to Land?