/// <summary>
        /// Creates a new implementation version from a a string.
        /// </summary>
        /// <param name="value">The string containing the version information.</param>
        /// <exception cref="FormatException"><paramref name="value"/> is not a valid version string.</exception>
        public ImplementationVersion(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new FormatException(Resources.MustStartWithDottedList);
            }

            if (ModelUtils.ContainsTemplateVariables(value))
            {
                _verbatimString = value;
                AdditionalParts = new VersionPart[0];
                return;
            }

            var parts = value.Split('-');

            // Ensure the first part is a dotted list
            if (!VersionDottedList.IsValid(parts[0]))
            {
                throw new FormatException(Resources.MustStartWithDottedList);
            }
            FirstPart = new VersionDottedList(parts[0]);

            // Iterate through all additional parts
            var additionalParts = new VersionPart[parts.Length - 1];

            for (int i = 1; i < parts.Length; i++)
            {
                additionalParts[i - 1] = new VersionPart(parts[i]);
            }
            AdditionalParts = additionalParts;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new dotted-list from a a string.
        /// </summary>
        /// <param name="value">The string containing the dotted-list.</param>
        public VersionPart(string value)
            : this()
        {
            // Detect and trim version modifiers
            if (value.StartsWith("pre"))
            {
                value    = value.Substring("pre".Length);
                Modifier = VersionModifier.Pre;
            }
            else if (value.StartsWith("rc"))
            {
                value    = value.Substring("rc".Length);
                Modifier = VersionModifier.RC;
            }
            else if (value.StartsWith("post"))
            {
                value    = value.Substring("post".Length);
                Modifier = VersionModifier.Post;
            }
            else
            {
                Modifier = VersionModifier.None;
            }

            // Parse any rest as dotted list
            if (!string.IsNullOrEmpty(value))
            {
                DottedList = new VersionDottedList(value);
            }
        }
        /// <summary>
        /// Creates a new implementation version from a .NET <see cref="Version"/>.
        /// </summary>
        /// <param name="version">The .NET <see cref="Version"/> to convert.</param>
        public ImplementationVersion(Version version)
        {
            #region Sanity checks
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }
            #endregion

            FirstPart       = new VersionDottedList(version.ToString());
            AdditionalParts = new VersionPart[0];
        }