/// <summary> /// Creates a legacy short string that is compatible with NuGet 2.8.3 /// </summary> private string GetLegacyShortString(VersionRangeBase range) { string s = null; if (range.HasLowerBound && range.IsMinInclusive && !range.HasUpperBound) { s = string.Format(VersionFormatter, ZeroN, range.MinVersion); } else if (range.HasLowerAndUpperBounds && range.IsMinInclusive && range.IsMaxInclusive && range.MinVersion.Equals(range.MaxVersion)) { s = string.Format(VersionFormatter, "[{0:N}]", range.MinVersion); } else { s = GetLegacyString(range); } return(s); }
/// <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 (ReferenceEquals(obj, null)) { return(0); } var combiner = new HashCodeCombiner(); combiner.AddObject(obj.IsMinInclusive); combiner.AddObject(obj.IsMaxInclusive); combiner.AddObject(_versionComparer.GetHashCode(obj.MinVersion)); combiner.AddObject(_versionComparer.GetHashCode(obj.MaxVersion)); return(combiner.CombinedHash); }
/// <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) { if (ReferenceEquals(x, y)) { return(true); } if (ReferenceEquals(y, null) || ReferenceEquals(x, null)) { return(false); } return(x.IsMinInclusive == y.IsMinInclusive && y.IsMaxInclusive == x.IsMaxInclusive && _versionComparer.Equals(y.MinVersion, x.MinVersion) && _versionComparer.Equals(y.MaxVersion, x.MaxVersion)); }
/// <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) { var 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()); }