public static bool TryParse(string value, out StrictSemanticVersion version)
{
version = null;
if (value != null)
{
Version systemVersion = null;
var sections = ParseSections(value);
// null indicates the string did not meet the rules
if (sections != null
&& Version.TryParse(sections.Item1, out systemVersion))
{
// validate the version string
var parts = sections.Item1.Split('.');
if (parts.Length != 3)
{
// versions must be 3 parts
return false;
}
foreach (var part in parts)
{
if (!IsValidPart(part, false))
{
// leading zeros are not allowed
return false;
}
}
// labels
if (sections.Item2 != null
&& !sections.Item2.All(s => IsValidPart(s, false)))
{
return false;
}
// build metadata
if (sections.Item3 != null
&& !IsValid(sections.Item3, true))
{
return false;
}
var ver = NormalizeVersionValue(systemVersion);
version = new StrictSemanticVersion(version: ver,
releaseLabels: sections.Item2,
metadata: sections.Item3 ?? string.Empty);
return true;
}
}
return false;
}