public override int GetHashCode()
{
if (IsNull)
return 0;
byte[] rgbSortKey;
if (FBinarySort())
rgbSortKey = s_unicodeEncoding.GetBytes(_value.TrimEnd());
else
{
// GetHashCode should not throw just because this instance has an invalid LCID or compare options.
CompareInfo cmpInfo;
CompareOptions options;
try
{
SetCompareInfo();
cmpInfo = _cmpInfo;
options = CompareOptionsFromSqlCompareOptions(_flag);
}
catch (ArgumentException)
{
// SetCompareInfo throws this when instance's LCID is unsupported
// CompareOptionsFromSqlCompareOptions throws this when instance's options are invalid
cmpInfo = CultureInfo.InvariantCulture.CompareInfo;
options = CompareOptions.None;
}
rgbSortKey = cmpInfo.GetSortKey(_value.TrimEnd(), options).KeyData;
}
return SqlBinary.HashByteArray(rgbSortKey, rgbSortKey.Length);
}