/// <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([NotNull] string value) { if (string.IsNullOrEmpty(value)) { throw new FormatException(Resources.MustStartWithDottedList); } if (ModelUtils.ContainsTemplateVariables(value)) { _verbatimString = value; _additionalParts = new VersionPart[0]; return; } string[] 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 _additionalParts = new VersionPart[parts.Length - 1]; for (int i = 1; i < parts.Length; i++) { _additionalParts[i - 1] = new VersionPart(parts[i]); } }
/// <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]; }