public Int32 CompareTo(AppVersion other) { Int32 major = Major.CompareTo(other.Major); if (major != 0) { return(major); } Int32 minor = Minor.CompareTo(other.Minor); if (minor != 0) { return(minor); } Int32 patch = Patch.CompareTo(other.Patch); if (patch != 0) { return(patch); } return(BuildTime?.CompareTo(other.BuildTime) ?? -1); }
/// <summary> /// Compares two semantic versions by precedence as defined in the SemVer spec. Versions /// that differ only by build metadata have the same precedence. /// </summary> /// <param name="other">The semantic version.</param> /// <returns> /// A value that indicates the relative order of the objects being compared. /// The return value has these meanings: /// Less than zero: This instance precedes <paramref name="other" /> in the sort order. /// Zero: This instance occurs in the same position in the sort order as <paramref name="other" />. /// Greater than zero: This instance follows <paramref name="other" /> in the sort order. /// </returns> private int CompareByPrecedence(SemVersion other) { if (other is null) { return(1); } var r = Major.CompareTo(other.Major); if (r != 0) { return(r); } r = Minor.CompareTo(other.Minor); if (r != 0) { return(r); } r = Patch.CompareTo(other.Patch); if (r != 0) { return(r); } return(CompareComponent(Prerelease, other.Prerelease, true)); }
public int CompareTo(Semver other) { var difference = Major.CompareTo(other.Major); if (difference != 0) { return(difference); } difference = Minor.CompareTo(other.Minor); if (difference != 0) { return(difference); } difference = Patch.CompareTo(other.Patch); if (difference != 0) { return(difference); } difference = Prerelease.CompareTo(other.Prerelease); if (difference != 0) { return(difference); } return(Trailer.CompareTo(other.Trailer)); }
public int CompareTo(object obj) { if (obj == null) { return(1); } if (!(obj is ISemVer other)) { throw new ArgumentOutOfRangeException("object is not ISemVer"); } int majorResult = Major.CompareTo(other.Major); if (majorResult != 0) { return(majorResult); } int minorResult = Minor.CompareTo(other.Minor); if (minorResult != 0) { return(minorResult); } int patchResult = Patch.CompareTo(other.Patch); if (patchResult != 0) { return(patchResult); } return(ReleaseFlag.CompareTo(other.ReleaseFlag)); }
public int CompareTo(object obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var other = (SemanticVersion)obj; var result = Major.CompareTo(other.Major); if (result != 0) { return(result); } result = Minor.CompareTo(other.Minor); if (result != 0) { return(result); } result = Patch.CompareTo(other.Patch); if (result != 0) { return(result); } return(CompareComponent(Prerelease, other.Prerelease, true)); }
/// <summary> /// Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information. /// </summary> /// <param name="other">The semantic version.</param> /// <returns> /// A value that indicates the relative order of the objects being compared. /// The return value has these meanings: Value Meaning Less than zero /// This instance precedes <paramref name="other" /> in the version precedence. /// Zero This instance has the same precedence as <paramref name="other" />. i /// Greater than zero This instance has creater precedence as <paramref name="other" />. /// </returns> public int CompareByPrecedence(SemVersion other) { if (ReferenceEquals(other, null)) { return(1); } var r = Major.CompareTo(other.Major); if (r != 0) { return(r); } r = Minor.CompareTo(other.Minor); if (r != 0) { return(r); } r = Patch.CompareTo(other.Patch); if (r != 0) { return(r); } r = CompareComponent(Prerelease, other.Prerelease, true); return(r); }
public int CompareTo(object obj) { if (!(obj is SemanticVersion other)) { return(-1); } if (Major != other.Major) { return(Major.CompareTo(other.Major)); } if (Minor != other.Minor) { return(Minor.CompareTo(other.Minor)); } if (Patch != other.Patch) { return(Patch.CompareTo(other.Patch)); } if (PreReleaseTag != other.PreReleaseTag) { return(string.Compare(PreReleaseTag, other.PreReleaseTag, StringComparison.Ordinal)); } // IMPORTANT: According to the SemVer 2.0 standard, we do not compare based on the build metadata. return(0); }
/// <summary> /// Compares this instance to another <see cref="ReleaseVersion"/> and returns an indication of their relative precedence. /// Dot-separated prerelease labels are individually compared. Versions that only differ in build metadata have the same /// precedence. /// </summary> /// <param name="value">The <see cref="ReleaseVersion"/> to compare against this instance.</param> /// <returns>Returns a signed integer indicating whether this instance precedes, follows or appears in the same position in /// the sort order as the specified <paramref name="value"/>. /// </returns> public int ComparePrecedenceTo(ReleaseVersion value) { // Versions that only differ in build metadata have the same precedence. // Reference: https://semver.org/#spec-item-10 if (value is null) { return(1); } int result = Major.CompareTo(value.Major); if (result != 0) { return(result); } result = Minor.CompareTo(value.Minor); if (result != 0) { return(result); } result = Patch.CompareTo(value.Patch); if (result != 0) { return(result); } return(CompareIdentifiers(Prerelease, value.Prerelease)); }
public int CompareTo(Semver2Version other) { var majorMinorComparison = base.CompareTo(other); if (majorMinorComparison == 0) { var patchComparison = Patch.CompareTo(other.Patch); if (patchComparison == 0) { var preReleaseComparison = PreRelease.CompareTo(other.PreRelease); if (preReleaseComparison == 0) { return(Build.CompareTo(other.Build)); } else { return(preReleaseComparison); } } return(patchComparison); } return(majorMinorComparison); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <returns> A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref /// name="other" /> parameter.Zero This object is equal to <paramref name="other" /> . Greater than zero This object is greater than <paramref /// name="other" /> . </returns> /// <param name="other"> An object to compare with this object. </param> public virtual int CompareTo(SemanticVersion other) { if (other == null) { return(1); } if (Major != other.Major) { return(Major.CompareTo(other.Major)); } if (Minor != other.Minor) { return(Minor.CompareTo(other.Minor)); } if (Patch != other.Patch) { return(Patch.CompareTo(other.Patch)); } int i = CompareLabels(PreRelease, other.PreRelease, true); if (i != 0) { return(i); } return(CompareLabels(Build, other.Build, false)); }
public int CompareTo(SemVersion other) { var result = Major.CompareTo(other.Major); if (result != 0) { return(result); } result = Minor.CompareTo(other.Minor); if (result != 0) { return(result); } result = Patch.CompareTo(other.Patch); if (result != 0) { return(result); } result = CompareExtension(Prerelease, other.Prerelease, true); if (result != 0) { return(result); } return(0); }
public int CompareTo(SemanticVersion other) { var result = Major.CompareTo(other.Major); if (result != 0) { return(result); } result = Minor.CompareTo(other.Minor); if (result != 0) { return(result); } result = Patch.CompareTo(other.Patch); if (result != 0) { return(result); } result = PreRelease.CompareTo(other.PreRelease); if (result != 0) { return(result); } return(Build.CompareTo(other.Build)); }
/// <summary> /// Compares this object with another SemanticVersion according to Semver 2.0.0 precedence rules. /// </summary> /// <param name="other">another SemanticVersion</param> /// <returns>0 if equal, -1 if the current object has lower precedence, or 1 if the current object has higher precedence</returns> public int ComparePrecedence(SemanticVersion other) { if (Major != other.Major) { return(Major.CompareTo(other.Major)); } if (Minor != other.Minor) { return(Minor.CompareTo(other.Minor)); } if (Patch != other.Patch) { return(Patch.CompareTo(other.Patch)); } if (String.IsNullOrEmpty(Prerelease) && String.IsNullOrEmpty(other.Prerelease)) { return(0); // build component is ignored in precedence comparison } // *no* prerelease component always has higher precedence than *any* prerelease component if (String.IsNullOrEmpty(Prerelease)) { return(1); } if (String.IsNullOrEmpty(other.Prerelease)) { return(-1); } return(CompareIdentifiers(Prerelease.Split('.'), other.Prerelease.Split('.'))); }
private int CompareVersionInformation(SemanticVersion other) { int majorCompare = Major.CompareTo(other.Major); if (majorCompare != 0) { return(majorCompare); } int minorCompare = Minor.CompareTo(other.Minor); if (minorCompare != 0) { return(minorCompare); } int patchCompare = Patch.CompareTo(other.Patch); if (patchCompare != 0) { return(patchCompare); } return(0); }
public int CompareTo(SematicVersion sematicVersion) { if (sematicVersion != null) { int result = Major.CompareTo(sematicVersion.Major); if (result == 0) { result = Minor.CompareTo(sematicVersion.Minor); if (result == 0) { result = Patch.CompareTo(sematicVersion.Patch); if (result == 0) { if (HasPreRelease == false && sematicVersion.HasPreRelease == false) { result = 0; } else if (HasPreRelease && !sematicVersion.HasPreRelease) { result = -1; } else if (!HasPreRelease && sematicVersion.HasPreRelease) { result = 1; } else { string[] a = PreRelease.ToArray(); string[] b = sematicVersion.PreRelease.ToArray(); for (int i = 0; i < a.Length && i < b.Length; i++) { result = a[i].CompareTo(b[i]); if (result != 0) { break; } } if (result == 0) { if (a.Length > b.Length) { result = 1; } else if (a.Length < b.Length) { result = -1; } } } } } } return(result); } else { throw new ArgumentNullException(); } }
private IEnumerable <int> PartComparisons(Version other) { yield return(Major.CompareTo(other.Major)); yield return(Minor.CompareTo(other.Minor)); yield return(Patch.CompareTo(other.Patch)); }
public int CompareTo(BuildVersion other) { if ((Revision == 0) && (other.Revision == 0)) { if (!IsDevMark && other.IsDevMark) { return(-1); } else if (IsDevMark && !other.IsDevMark) { return(1); } } int majorCompare = Major.CompareTo(other.Major); if (majorCompare != 0) { return(majorCompare); } int minorCompare = Minor.CompareTo(other.Minor); if (minorCompare != 0) { return(minorCompare); } int patchCompare = Patch.CompareTo(other.Patch); if (patchCompare != 0) { return(patchCompare); } int revisionCompare = Revision.CompareTo(other.Revision); if (revisionCompare != 0) { return(revisionCompare); } string normTag = Tag ?? string.Empty; string normOtherTag = other.Tag ?? string.Empty; if (normTag != normOtherTag) { return(normTag.CompareTo(normOtherTag)); } return(0); }
public int CompareTo(VersionInfo other) { int majorCompare = Major.CompareTo(other?.Major); if (majorCompare != 0) { return(majorCompare); } int minorCompare = Minor.CompareTo(other?.Minor); if (minorCompare != 0) { return(minorCompare); } int patchCompare = Patch.CompareTo(other?.Patch); if (patchCompare != 0) { return(patchCompare); } int revisionCompare = BuildNumber.CompareTo(other?.BuildNumber); if (revisionCompare != 0) { return(revisionCompare); } if (BuildNumber == 0 && other?.BuildNumber == 0) { if (!IsBasedOnDevMark && other.IsBasedOnDevMark) { return(1); } else if (IsBasedOnDevMark && !other.IsBasedOnDevMark) { return(-1); } } string preReleaseTag = PreReleaseTag ?? string.Empty; string otherPreReleaseTag = other?.PreReleaseTag ?? string.Empty; if (preReleaseTag != otherPreReleaseTag) { return(preReleaseTag.CompareTo(otherPreReleaseTag)); } return(0); }
public int CompareTo(SdkVersionInfo other) { var majorComparison = Major.CompareTo(other.Major); if (majorComparison != 0) { return(majorComparison); } var minorComparison = Minor.CompareTo(other.Minor); if (minorComparison != 0) { return(minorComparison); } var featureComparison = Feature.CompareTo(other.Feature); if (featureComparison != 0) { return(featureComparison); } var patchComparison = Patch.CompareTo(other.Patch); if (patchComparison != 0) { return(patchComparison); } // 3.1.100-preview1-01445 is lesser than 3.1.100 if (IsPrerelease && !other.IsPrerelease) { return(-1); } if (!IsPrerelease && other.IsPrerelease) { return(1); } if (IsPrerelease && other.IsPrerelease) { // We are not parsing the preview part here and are only using string comparison // One more thing to complicate thing is that the preview part format has changed between // 3.* and 5.*, so this comparison is just fine. return(string.Compare(PrereleaseVersion, other.PrereleaseVersion, ignoreCase: true)); } return(0); }
public int CompareTo(SemanticVersion other) { if (other == null) { return(1); } int result = Major.CompareTo(other.Major); if (result != 0) { return(result); } result = Minor.CompareTo(other.Minor); if (result != 0) { return(result); } result = Patch.CompareTo(other.Patch); if (result != 0) { return(result); } //A version not marked with prerelease is later than one with a prerelease designation if (PrereleaseVersion == null && other.PrereleaseVersion != null) { return(1); } //A version not marked with prerelease is later than one with a prerelease designation if (PrereleaseVersion != null && other.PrereleaseVersion == null) { return(-1); } result = StringComparer.OrdinalIgnoreCase.Compare(PrereleaseVersion, other.PrereleaseVersion); if (result != 0) { return(result); } return(StringComparer.OrdinalIgnoreCase.Compare(OriginalText, other.OriginalText)); }
public int CompareTo(VersionInfo other) { var r = Major.CompareTo(other.Major); if (r != 0) { return(r); } r = Minor.CompareTo(other.Minor); if (r != 0) { return(r); } return(Patch.CompareTo(other.Patch)); }
public int CompareTo(StructuredVersion other) { var majorDiff = Major.CompareTo(other.Major); if (majorDiff != 0) { return(majorDiff); } var minorDiff = Minor.CompareTo(other.Minor); if (minorDiff != 0) { return(minorDiff); } var patchDiff = Patch.CompareTo(other.Patch); if (patchDiff != 0) { return(patchDiff); } if (Build != other.Build) { if (Build is null) { return(-1); } if (other.Build is null) { return(-1); } return(Build.Value.CompareTo(other.Build.Value)); } // Null comes *after* anything else when it comes to prereleases, // so we can't just use StringComparer. if (Prerelease is null && other.Prerelease is null) { return(0); } if (Prerelease is null) { return(1); } if (other.Prerelease is null) { return(-1); } return(string.CompareOrdinal(Prerelease, other.Prerelease)); }
public int compareIgnoreDate(ScriptVersion other) { int compare = Major.CompareTo(other.Major); if (compare != 0) { return(compare); } compare = Minor.CompareTo(other.Minor); if (compare != 0) { return(compare); } return(Patch.CompareTo(other.Patch)); }
public int CompareTo([CanBeNull] SemanticVersion other) { if (other == null) { return(1); } // Compare to the most significant part which is different if (!Major.Equals(other.Major)) { return(Major.CompareTo(other.Major)); } if (!Minor.Equals(other.Minor)) { return(Minor.CompareTo(other.Minor)); } if (!Patch.Equals(other.Patch)) { return(Patch.CompareTo(other.Patch)); } if (Tag != other.Tag) { // Versions with a prerelease tag are considered older than those without // i.e. `1.0.0-beta` < `1.0.0` if (Tag != null && other.Tag == null) { return(-1); } if (Tag == null && other.Tag != null) { return(1); } // They both have a tag, so just order them by tag return(string.Compare(Tag, other.Tag, StringComparison.Ordinal)); } return(0); }
/// <summary> /// This method determines the ordering of VersionNumber instances. /// </summary> /// <see cref="IComparable{T}.CompareTo"/> public int CompareTo(VersionNumber other) { var compare = Major.CompareTo(other.Major); if (compare != 0) { return(compare); } compare = Minor.CompareTo(other.Minor); if (compare != 0) { return(compare); } compare = Patch.CompareTo(other.Patch); if (compare != 0) { return(compare); } if (PreReleaseLabel == null && other.PreReleaseLabel == null) { return(0); } if (PreReleaseLabel != null && other.PreReleaseLabel == null) { return(-1); } if (PreReleaseLabel == null && other.PreReleaseLabel != null) { return(1); } if (PreReleaseLabel != null && other.PreReleaseLabel != null) { return(PreReleaseLabel.CompareTo(other.PreReleaseLabel)); } return(0); }
public int CompareTo(Version other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } var majorComparison = Major.CompareTo(other.Major); if (majorComparison != 0) { return(majorComparison); } var minorComparison = Minor.CompareTo(other.Minor); if (minorComparison != 0) { return(minorComparison); } var patchComparison = Patch.CompareTo(other.Patch); if (patchComparison != 0) { return(patchComparison); } if (!IsPrerelease && !other.IsPrerelease) { return(0); } if (!IsPrerelease) { return(1); } if (!other.IsPrerelease) { return(-1); } return(CompareNonEmptyIdents(Prerelease, other.Prerelease)); }
/// <summary> /// </summary> /// <param name="other"></param> /// <returns> /// greater than 0 newer /// </returns> public int CompareTo(SuffixVersion other) { var majorComparison = Major.CompareTo(other.Major); if (majorComparison != 0) { return(majorComparison); } var minorComparison = Minor.CompareTo(other.Minor); if (minorComparison != 0) { return(minorComparison); } var patchComparison = Patch.CompareTo(other.Patch); if (patchComparison != 0) { return(patchComparison); } if (PreRelease == string.Empty) { return(other.PreRelease == string.Empty ? 0 : 1); } if (other.PreRelease == string.Empty) { return(-1); } var suffixComparison = string.Compare(PreRelease, other.PreRelease, StringComparison.Ordinal); if (suffixComparison != 0) { return(suffixComparison); } return(Build.CompareTo(other.Build)); }
public int CompareTo([CanBeNull] SemanticVersion other) { if (other == null) { return(1); } //Compare to the most significant part which is different if (!Major.Equals(other.Major)) { return(Major.CompareTo(other.Major)); } if (!Minor.Equals(other.Minor)) { return(Minor.CompareTo(other.Minor)); } if (!Patch.Equals(other.Patch)) { return(Patch.CompareTo(other.Patch)); } if (Tag != other.Tag) { // versions with a prerelease tag are considered newer if (Tag != null && other.Tag == null) { return(1); } if (Tag == null && other.Tag != null) { return(-1); } } return(0); }
/// <summary> /// <seealso href="http://semver.org/#spec-item-11">SemVer spec</seealso> /// Precedence refers to how versions are compared to each other when ordered. /// Precedence MUST be calculated by separating the version into major, minor, patch and /// pre-release identifiers in that order (Build metadata does not figure into precedence). /// Precedence is determined by the first difference when comparing each of these /// identifiers from left to right as follows: Major, minor, and patch versions are always compared numerically. /// Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1. /// When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. /// Example: 1.0.0-alpha < 1.0.0. /// Precedence for two pre-release versions with the same major, minor, and patch version /// MUST be determined by comparing each dot separated identifier from left to right until /// a difference is found as follows: /// identifiers consisting of only digits are compared numerically and identifiers with /// letters or hyphens are compared lexically in ASCII sort order. /// Numeric identifiers always have lower precedence than non-numeric identifiers. /// A larger set of pre-release fields has a higher precedence than a smaller set, /// if all of the preceding identifiers are equal. /// Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < /// 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(SemVer other) { if (ReferenceEquals(other, null)) { return(1); } var compare = Major.CompareTo(other.Major); if (compare != 0) { return(compare); } compare = Minor.CompareTo(other.Minor); if (compare != 0) { return(compare); } compare = Patch.CompareTo(other.Patch); if (compare != 0) { return(compare); } // a pre-release version has lower precedence than a normal version if (!IsPreRelease && other.IsPreRelease) { return(1); } if (IsPreRelease && !other.IsPreRelease) { return(-1); } return(CompareIdentifiers(PreReleaseIdentifiers, other.PreReleaseIdentifiers)); }
/// <summary> /// Compare semantic verions using precedence rules from https://semver.org/#spec-item-11 /// </summary> /// <param name="other">Semantic version to compare to</param> /// <returns>-1, if this precedes other, +1 if other precedes this, or 0 if no precedence could be determined</returns> public int CompareTo(SemanticVersion other) { Contract.Requires(null != other); var major = Major.CompareTo(other.Major); if (0 != major) { return(major); } var minor = Minor.CompareTo(other.Minor); if (0 != minor) { return(minor); } var patch = Patch.CompareTo(other.Patch); if (0 != patch) { return(patch); } // pre-release is tricky, null to be considered greater than any value var thisPrereleaseEmpty = string.IsNullOrEmpty(Prerelease); var otherPrereleaseEmpty = string.IsNullOrEmpty(other.Prerelease); if (thisPrereleaseEmpty || otherPrereleaseEmpty) { return(!thisPrereleaseEmpty ? -1 : otherPrereleaseEmpty ? 0 : +1); } var prerelease = string.Compare(Prerelease, other.Prerelease, StringComparison.CurrentCulture); if (0 != prerelease) { return(prerelease); } // we do not compare metadata, per standard return(0); }