/// <summary> /// IComparer.Compare() implementation. /// </summary> /// <param name="x">Object to compare.</param> /// <param name="y">Object to compare.</param> /// <returns> /// Returns 0 - if equal, -1 - if x < y, +1 - if x > y. /// </returns> public int Compare(object x, object y) { if (x == y) { return(0); } if (x == null) { return(-1); } if (y == null) { return(1); } if (x is string sa && y is string sb) { return(SimpleCaseFolding.CompareUsingSimpleCaseFolding(sa, sb)); } if (x is IComparable ia) { return(ia.CompareTo(y)); } throw new ArgumentException("SR.Argument_ImplementIComparable"); }
/// <summary> /// IEqualityComparer<string>.Equals() implementation. /// </summary> /// <param name="x">Left object to compare.</param> /// <param name="y">Right object to compare.</param> /// <returns> /// Returns true if equal. /// </returns> public bool Equals(string x, string y) { if (object.ReferenceEquals(x, y)) { return(true); } if (x == null || y == null) { return(false); } return(SimpleCaseFolding.CompareUsingSimpleCaseFolding(x, y) == 0); }
/// <summary> /// IComparer<string>.GetHashCode() implementation. /// </summary> /// <param name="x">Left object to compare.</param> /// <param name="y">Right object to compare.</param> /// <returns> /// Returns 0 - if equal, -1 - if x < y, +1 - if x > y. /// </returns> public int Compare(string x, string y) { if (object.ReferenceEquals(x, y)) { return(0); } if (x == null) { return(-1); } if (y == null) { return(1); } return(SimpleCaseFolding.CompareUsingSimpleCaseFolding(x, y)); }