/// <summary> /// Checks if two version ranges are equivalent. This follows the rules of the version comparer /// when checking the bounds. /// </summary> public bool Equals(VersionRangeBase x, VersionRangeBase y) { // same object if (Object.ReferenceEquals(x, y)) { return true; } // null checks if (Object.ReferenceEquals(y, null) || Object.ReferenceEquals(x, null)) { return false; } return x.IncludePrerelease == y.IncludePrerelease && x.IsMinInclusive == y.IsMinInclusive && y.IsMaxInclusive == x.IsMaxInclusive && _versionComparer.Equals(y.MinVersion, x.MinVersion) && _versionComparer.Equals(y.MaxVersion, x.MaxVersion); }
/// <summary> /// Creates a legacy string that is compatible with NuGet 2.8.3 /// </summary> private string GetLegacyString(VersionRangeBase range) { StringBuilder sb = new StringBuilder(); sb.Append(range.HasLowerBound && range.IsMinInclusive ? '[' : '('); if (range.HasLowerBound) { sb.AppendFormat(_versionFormatter, ZeroN, range.MinVersion); } sb.Append(", "); if (range.HasUpperBound) { sb.AppendFormat(_versionFormatter, ZeroN, range.MaxVersion); } sb.Append(range.HasUpperBound && range.IsMaxInclusive ? ']' : ')'); return sb.ToString(); }
/// <summary> /// Creates a hash code based on all properties of the range. This follows the rules of the /// version comparer when comparing the version bounds. /// </summary> public int GetHashCode(VersionRangeBase obj) { if (Object.ReferenceEquals(obj, null)) { return 0; } HashCodeCombiner combiner = new HashCodeCombiner(); combiner.AddObject(obj.IncludePrerelease); combiner.AddObject(obj.IsMinInclusive); combiner.AddObject(obj.IsMaxInclusive); combiner.AddObject(_versionComparer.GetHashCode(obj.MinVersion)); combiner.AddObject(_versionComparer.GetHashCode(obj.MaxVersion)); return combiner.CombinedHash; }