Exemplo n.º 1
0
        /// <summary>
        /// Return a cleaned, normalised version string.
        /// </summary>
        /// <returns>The cleaned version string.</returns>
        public string Clean()
        {
            var preReleaseString = PreRelease == null ? ""
                : String.Format("-{0}", PreReleaseVersion.Clean(PreRelease));
            var buildString = Build == null ? ""
                : String.Format("+{0}", Build);

            return(String.Format("{0}.{1}.{2}{3}{4}",
                                 Major, Minor, Patch, preReleaseString, buildString));
        }
Exemplo n.º 2
0
        // Implement IComparable<Version>
        public int CompareTo(Version other)
        {
            if (ReferenceEquals(other, null))
            {
                return(1);
            }

            foreach (var c in PartComparisons(other))
            {
                if (c != 0)
                {
                    return(c);
                }
            }

            return(PreReleaseVersion.Compare(this.PreRelease, other.PreRelease));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a new semantic version from a version string.
        /// </summary>
        /// <param name="input">The version string.</param>
        /// <param name="loose">When true, be more forgiving of some invalid version specifications.</param>
        /// <exception cref="System.ArgumentException">Thrown when the version string is invalid.</exception>
        public Version(string input, bool loose = false)
        {
            _inputString = input;

            var regex = loose ? looseRegex : strictRegex;

            var match = regex.Match(input);

            if (!match.Success)
            {
                throw new ArgumentException(String.Format("Invalid version string: {0}", input));
            }

            _major = Int32.Parse(match.Groups[1].Value);

            _minor = Int32.Parse(match.Groups[2].Value);

            _patch = Int32.Parse(match.Groups[3].Value);

            if (match.Groups[4].Success)
            {
                var inputPreRelease   = match.Groups[5].Value;
                var cleanedPreRelease = PreReleaseVersion.Clean(inputPreRelease);
                if (!loose && inputPreRelease != cleanedPreRelease)
                {
                    throw new ArgumentException(String.Format(
                                                    "Invalid pre-release version: {0}", inputPreRelease));
                }
                _preRelease = cleanedPreRelease;
            }

            if (match.Groups[6].Success)
            {
                _build = match.Groups[7].Value;
            }
        }