TryParse() public static méthode

Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an optional special version.
public static TryParse ( string value, SemanticVersion &version, bool preserveMissingComponents = false ) : bool
value string
version SemanticVersion
preserveMissingComponents bool
Résultat bool
Exemple #1
0
        public void Add(string stepNameOrPackageIdAndVersion)
        {
            var split = stepNameOrPackageIdAndVersion.Split(Delimiters);

            if (split.Length < 2)
            {
                throw new CommandException("The package argument '" + stepNameOrPackageIdAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            var stepNameOrPackageId  = split[0];
            var packageReferenceName = split.Length > 2 ? split[1] : WildCard;
            var version = split.Length > 2 ? split[2] : split[1];

            if (string.IsNullOrWhiteSpace(stepNameOrPackageId) || string.IsNullOrWhiteSpace(version))
            {
                throw new CommandException("The package argument '" + stepNameOrPackageIdAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            if (!SemanticVersion.TryParse(version, out var parsedVersion))
            {
                throw new CommandException("The version portion of the package constraint '" + stepNameOrPackageIdAndVersion + "' is not a valid semantic version number.");
            }

            Add(stepNameOrPackageId, packageReferenceName, version);
        }