コード例 #1
0
ファイル: SemanticVersion.cs プロジェクト: hgtools/VCSVersion
 /// <summary>
 /// Create an instance of <see cref="SemanticVersion"/>
 /// </summary>
 /// <param name="major">Major version part</param>
 /// <param name="minor">Minor version part</param>
 /// <param name="patch">Patch version part</param>
 /// <param name="preReleaseTag">Pre-release version tag</param>
 /// <param name="buildMetadata">Build metadata</param>
 public SemanticVersion(int major, int minor, int patch, PreReleaseTag preReleaseTag = null, BuildMetadata buildMetadata = null)
 {
     Major         = major;
     Minor         = minor;
     Patch         = patch;
     PreReleaseTag = preReleaseTag ?? new PreReleaseTag();
     BuildMetadata = buildMetadata ?? new BuildMetadata();
 }
コード例 #2
0
ファイル: SemanticVersion.cs プロジェクト: hgtools/VCSVersion
 /// <summary>
 /// Create an instance of <see cref="SemanticVersion"/>
 /// </summary>
 /// <param name="major">Major version part</param>
 /// <param name="minor">Minor version part</param>
 /// <param name="patch">Patch version part</param>
 public SemanticVersion(int major = 0, int minor = 0, int patch = 0)
 {
     Major         = major;
     Minor         = minor;
     Patch         = patch;
     PreReleaseTag = new PreReleaseTag();
     BuildMetadata = new BuildMetadata();
 }
コード例 #3
0
ファイル: SemanticVersion.cs プロジェクト: hgtools/VCSVersion
        /// <summary>
        /// Create a copy of <see cref="SemanticVersion"/>
        /// </summary>
        /// <param name="semanticVersion">Original version</param>
        public SemanticVersion(SemanticVersion semanticVersion)
        {
            Major = semanticVersion.Major;
            Minor = semanticVersion.Minor;
            Patch = semanticVersion.Patch;

            PreReleaseTag = new PreReleaseTag(semanticVersion.PreReleaseTag);
            BuildMetadata = new BuildMetadata(semanticVersion.BuildMetadata);
        }
コード例 #4
0
ファイル: SemanticVersion.cs プロジェクト: hgtools/VCSVersion
        public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
        {
            if (string.IsNullOrEmpty(version))
            {
                semanticVersion = null;
                return(false);
            }

            var match = Regex.Match(version, $"^({tagPrefixRegex})?(?<version>.*)$");

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

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

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

            var buildMetaData = BuildMetadata.Parse(parsed.Groups["BuildMetadata"].Value);
            var fourthPart    = parsed.Groups["FourthPart"];

            if (fourthPart.Success && buildMetaData.CommitsSinceTag == null)
            {
                buildMetaData = new BuildMetadata(
                    commitsSinceTag: int.Parse(fourthPart.Value),
                    branch: buildMetaData.Branch,
                    commitDate: buildMetaData.CommitDate,
                    commitHash: buildMetaData.Hash,
                    otherMetadata: buildMetaData.OtherMetadata);
            }

            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: PreReleaseTag.Parse(parsed.Groups["Tag"].Value),
                buildMetadata: buildMetaData
                );

            return(true);
        }
コード例 #5
0
 /// <summary>
 /// Create a copy of <see cref="SemanticVersion"/> with defined changes
 /// </summary>
 /// <param name="version">Semantic version</param>
 /// <param name="major">Major version part to change</param>
 /// <param name="minor">Minor version part to change</param>
 /// <param name="patch">Patch version part to change</param>
 /// <param name="preReleaseTag">Pre-release version tag to change</param>
 /// <param name="buildMetadata">Build metadata to change</param>
 public static SemanticVersion Copy(this SemanticVersion version, int?major = null, int?minor = null, int?patch = null, PreReleaseTag preReleaseTag = null, BuildMetadata buildMetadata = null)
 {
     return(new SemanticVersion(
                major: major ?? version.Major,
                minor: minor ?? version.Minor,
                patch: patch ?? version.Patch,
                preReleaseTag: preReleaseTag ?? version.PreReleaseTag,
                buildMetadata: buildMetadata ?? version.BuildMetadata));
 }