Beispiel #1
0
 public SemanticVersion(int major = 0, int minor = 0, int patch = 0)
 {
     Major         = major;
     Minor         = minor;
     Patch         = patch;
     PreReleaseTag = new SemanticVersionPreReleaseTag();
     BuildMetaData = new SemanticVersionBuildMetaData();
 }
Beispiel #2
0
        public SemanticVersion(SemanticVersion semanticVersion)
        {
            Major = semanticVersion.Major;
            Minor = semanticVersion.Minor;
            Patch = semanticVersion.Patch;

            PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag);
            BuildMetaData = new SemanticVersionBuildMetaData(semanticVersion.BuildMetaData);
        }
Beispiel #3
0
        public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
        {
            var match = Regex.Match(version, string.Format("^({0})?(?<version>.*)$", tagPrefixRegex));

            if (!match.Success)
            {
                semanticVersion = null;
                return(false);
            }

            version = match.Groups["version"].Value;
            var parsed = ParseSemVer.Match(version);

            if (!parsed.Success)
            {
                semanticVersion = null;
                return(false);
            }

            var semanticVersionBuildMetaData = SemanticVersionBuildMetaData.Parse(parsed.Groups["BuildMetaData"].Value);
            var fourthPart = parsed.Groups["FourthPart"];

            if (fourthPart.Success && semanticVersionBuildMetaData.CommitsSinceTag == null)
            {
                semanticVersionBuildMetaData.CommitsSinceTag = int.Parse(fourthPart.Value);
            }

            semanticVersion = new SemanticVersion
            {
                Major         = int.Parse(parsed.Groups["Major"].Value),
                Minor         = parsed.Groups["Minor"].Success ? int.Parse(parsed.Groups["Minor"].Value) : 0,
                Patch         = parsed.Groups["Patch"].Success ? int.Parse(parsed.Groups["Patch"].Value) : 0,
                PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
                BuildMetaData = semanticVersionBuildMetaData
            };

            return(true);
        }