Пример #1
0
        /// <summary>
        /// Gets the string version in the given format.
        /// Returns the <see cref="SVersion.ErrorMessage"/> if it is not null.
        /// </summary>
        /// <param name="f">Format to use.</param>
        /// <param name="buildInfo">Not null to generate a post-release version.</param>
        /// <returns>Formated string (or <see cref="SVersion.ErrorMessage"/> if any).</returns>
        public string ToString(CSVersionFormat f, CIBuildDescriptor?buildInfo = null)
        {
            if (ErrorMessage != null)
            {
                return(ErrorMessage);
            }
            Debug.Assert(NormalizedText != null);
            // Fast path and cache for format with no build info.
            if (buildInfo == null)
            {
                if (f == CSVersionFormat.Normalized)
                {
                    if (IsLongForm)
                    {
                        if (_cacheOtherForm == null)
                        {
                            _cacheOtherForm = ComputeShortFormVersion(Major, Minor, Patch, PrereleaseNameIdx, PrereleaseNumber, PrereleasePatch, BuildMetaData, null);
                        }
                        return(_cacheOtherForm);
                    }
                    return(NormalizedText);
                }
                if (f == CSVersionFormat.LongForm)
                {
                    if (IsLongForm)
                    {
                        return(NormalizedText);
                    }
                    if (_cacheOtherForm == null)
                    {
                        _cacheOtherForm = ComputeLongFormVersion(Major, Minor, Patch, PrereleaseNameIdx, PrereleaseNumber, PrereleasePatch, BuildMetaData, null);
                    }
                    return(_cacheOtherForm);
                }
            }
            if (f == CSVersionFormat.FileVersion)
            {
                return(ToStringFileVersion(buildInfo != null));
            }

            if (f == CSVersionFormat.LongForm)
            {
                return(ComputeLongFormVersion(Major, Minor, Patch, PrereleaseNameIdx, PrereleaseNumber, PrereleasePatch, BuildMetaData, buildInfo));
            }
            else
            {
                Debug.Assert(f == CSVersionFormat.Normalized);
                Debug.Assert(SVersion.Parse(ComputeShortFormVersion(Major, Minor, Patch, PrereleaseNameIdx, PrereleaseNumber, PrereleasePatch, BuildMetaData, buildInfo)).PackageQuality == PackageQuality.CI);
                return(ComputeShortFormVersion(Major, Minor, Patch, PrereleaseNameIdx, PrereleaseNumber, PrereleasePatch, BuildMetaData, buildInfo));
            }
        }
Пример #2
0
 /// <summary>
 /// Gets the standard Informational version string.
 /// If <see cref="SVersion.IsValid"/> is false this throws an <see cref="InvalidOperationException"/>:
 /// the constant <see cref="InformationalVersion.ZeroInformationalVersion"/> should be used when IsValid is false.
 /// </summary>
 /// <param name="commitSha">The SHA1 of the commit (must be 40 hex digits).</param>
 /// <param name="commitDateUtc">The commit date (must be in UTC).</param>
 /// <param name="buildInfo">Can be null: not null for post-release version.</param>
 /// <returns>The informational version.</returns>
 public string GetInformationalVersion(string commitSha, DateTime commitDateUtc, CIBuildDescriptor buildInfo)
 {
     return(IsValid && buildInfo != null
             ? SVersion.Parse(ToString( CSVersionFormat.Normalized, buildInfo )).GetInformationalVersion(commitSha, commitDateUtc)
             : GetInformationalVersion(commitSha, commitDateUtc));
 }