Exemplo n.º 1
0
        /// <summary>
        ///     Compares the current instance with another object of the same type and returns an integer that indicates
        ///     whether the current instance precedes, follows, or occurs in the same position in the sort order as the
        ///     <paramref name="comparison" /> object.
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         Semantic Versions have a very specific and somewhat counterintuitive order of precedence. Comparison
        ///         begins with the major version and proceeds to the minor version, patch, prerelease tag and build
        ///         metadata tag. The order of precedence is always returned as soon as it can be determined.
        ///     </para>
        ///     <para>
        ///         If order cannot be determined from the major, minor and patch versions, then comparison proceeds to
        ///         the prerelease tag and then the build metadata tag. These fields can contain multiple segments
        ///         separated by the '.' character. each dot-separated segment is considered separately and where
        ///         possible is converted to an integer, so that <c>beta.9</c> sorts before <c>beta.10</c>.
        ///     </para>
        ///     <para>
        ///         Note that any version with a prerelease tag sorts lower than the same version without a prerelease
        ///         tag. Put another way: a release version is greater than a prerelease version.
        ///     </para>
        ///     <para>
        ///         The specification states that build metadata should be ignored when determining precedence. That
        ///         doesn't seem like a very sensible approach to us, since builds have to appear in some sort of order
        ///         and 'random' didn't strike us as an amazingly useful outcome. Therefore we have chosen to deviate
        ///         from the specification and include it as the last item in the list of comparisons when determining
        ///         the collation sequence. We treat the build metadata in a similar way to the prerelease tag, giving
        ///         it the lowest precedence but nonetheless yielding a more deterministic result when comparing and
        ///         sorting semantic versions.
        ///     </para>
        /// </remarks>
        /// <param name="comparison">An object to compare with this instance.</param>
        /// <returns>
        ///     A value that indicates the relative order of the objects being compared.
        /// </returns>
        public int CompareTo(SemanticVersion comparison)
        {
            if (comparison == null)
            {
                throw new ArgumentNullException(nameof(comparison));
            }
            if (ReferenceEquals(this, comparison))
            {
                return(0);
            }
            int result = MajorVersion.CompareTo(comparison.MajorVersion);

            if (result != 0)
            {
                return(result);
            }
            result = MinorVersion.CompareTo(comparison.MinorVersion);
            if (result != 0)
            {
                return(result);
            }
            result = PatchVersion.CompareTo(comparison.PatchVersion);
            if (result != 0)
            {
                return(result);
            }
            result = ComparePrereleaseVersions(PrereleaseVersion, comparison.PrereleaseVersion);
            if (result != 0)
            {
                return(result);
            }
            return(CompareBuildVersions(BuildVersion, comparison.BuildVersion));
        }
Exemplo n.º 2
0
        public int CompareTo(ModuleVersion other)
        {
            var comparison = MajorVersion.CompareTo(other.MajorVersion);

            if (comparison != 0)
            {
                return(comparison);
            }

            comparison = MinorVersion.CompareTo(other.MinorVersion);

            if (comparison != 0)
            {
                return(comparison);
            }

            comparison = Revision.CompareTo(other.Revision);

            if (comparison != 0)
            {
                return(comparison);
            }

            if (IsPreRelease && !other.IsPreRelease)
            {
                return(-1);
            }

            if (other.IsPreRelease && !IsPreRelease)
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compares two tags based on their version details.
        /// </summary>
        /// <param name="other">The tag instance to compare against.</param>
        /// <returns>TODO:</returns>
        public int CompareTo(Id3Tag other)
        {
            if (other == null)
            {
                return(1);
            }
            int majorComparison = MajorVersion.CompareTo(other.MajorVersion);
            int minorComparison = MinorVersion.CompareTo(other.MinorVersion);

            if (majorComparison == 0 && minorComparison == 0)
            {
                return(0);
            }
            return(majorComparison != 0 ? majorComparison : minorComparison);
        }
Exemplo n.º 4
0
        public int CompareTo(EventReader other)
        {
            if (other is null)
            {
                return(1);
            }

            if (Equals(other))
            {
                return(0);
            }

            if (MajorVersion == other.MajorVersion)
            {
                return(MinorVersion.CompareTo(other.MinorVersion));
            }

            return(MajorVersion.CompareTo(other.MajorVersion));
        }