Core/CafeLib.Core/Support/SemVer.cs
/// <summary>
/// Parses the specified string to a semantic version.
/// </summary>
/// <param name="version">The version string.</param>
/// <param name="strict">If set to <c>true</c> minor and patch version are required, else they default to 0.</param>
/// <returns>The SemVersion object.</returns>
/// <exception cref="System.InvalidOperationException">When a invalid version string is passed.</exception>
Parses the specified string to a semantic version.
Parses the specified string to a semantic version .
public static SemVer Parse(string version, bool strict = false)
        {
            var match = ParseEx.Match(version);
            if (!match.Success)
                throw new ArgumentException("Invalid version.", nameof(version));
            var major = int.Parse(match.Groups["major"].Value);
            var minorMatch = match.Groups["minor"];
            var minor = 0;
            if (minorMatch.Success)
            {
                minor = int.Parse(minorMatch.Value);
            }
            else if (strict)
            {
                throw new InvalidOperationException("Invalid version (no minor version given in strict mode)");
            }
            var patchMatch = match.Groups["patch"];
            var patch = 0;
            if (patchMatch.Success)
            {
                patch = int.Parse(patchMatch.Value);
            }
            else if (strict)
            {
                throw new InvalidOperationException("Invalid version (no patch version given in strict mode)");
            }
            var prerelease = match.Groups["pre"].Value;
            var build = match.Groups["build"].Value;
            return new SemVer(major, minor, patch, prerelease, build);
        }
public static SemVer Parse ( string version , bool strict = false ) { var match = ParseEx . Match ( version ) ; if ( ! match . Success ) throw new ArgumentException ( " " , nameof ( version ) ) ; var major = int . Parse ( match . Groups [ " " ] . Value ) ; var minorMatch = match . Groups [ " " ] ; var minor = 0 ; if ( minorMatch . Success ) { minor = int . Parse ( minorMatch . Value ) ; } else if ( strict ) { throw new InvalidOperationException ( " " ) ; } var patchMatch = match . Groups [ " " ] ; var patch = 0 ; if ( patchMatch . Success ) { patch = int . Parse ( patchMatch . Value ) ; } else if ( strict ) { throw new InvalidOperationException ( " " ) ; } var prerelease = match . Groups [ " " ] . Value ; var build = match . Groups [ " " ] . Value ; return new SemVer ( major , minor , patch , prerelease , build ) ; }
Parses the specified string to a semantic version.
Parses the specified string to a semantic version .
The SemVersion object.
The SemVersion object .
When a invalid version string is passed.
When a invalid version string is passed .
version
string
The version string.
The version string .
strict
bool
If set to true
If set to true