TryParseVersionSpec() 공개 정적인 메소드

public static TryParseVersionSpec ( string value, IVersionSpec &result ) : bool
value string
result IVersionSpec
리턴 bool
예제 #1
0
        /// <summary>
        /// Parses a dependency from the feed in the format:
        /// id or id:versionSpec, or id:versionSpec:targetFramework
        /// </summary>
        private static Tuple <string, IVersionSpec, FrameworkName> ParseDependency(string value)
        {
            if (String.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            // IMPORTANT: Do not pass StringSplitOptions.RemoveEmptyEntries to this method, because it will break
            // if the version spec is null, for in that case, the Dependencies string sent down is "<id>::<target framework>".
            // We do want to preserve the second empty element after the split.
            string[] tokens = value.Trim().Split(new[] { ':' });

            if (tokens.Length == 0)
            {
                return(null);
            }

            // Trim the id
            string id = tokens[0].Trim();

            IVersionSpec versionSpec = null;

            if (tokens.Length > 1)
            {
                // Attempt to parse the version
                VersionUtility.TryParseVersionSpec(tokens[1], out versionSpec);
            }

            var targetFramework = (tokens.Length > 2 && !String.IsNullOrEmpty(tokens[2]))
                                    ? VersionUtility.ParseFrameworkName(tokens[2])
                                    : null;

            return(Tuple.Create(id, versionSpec, targetFramework));
        }
예제 #2
0
        public IEnumerable <PackageReference> GetPackageReferences(bool requireVersion)
        {
            XDocument document = GetDocument();

            if (document == null)
            {
                yield break;
            }

            foreach (var e in document.Root.Elements("package"))
            {
                string          id                      = e.GetOptionalAttributeValue("id");
                string          versionString           = e.GetOptionalAttributeValue("version");
                string          versionConstraintString = e.GetOptionalAttributeValue("allowedVersions");
                string          targetFrameworkString   = e.GetOptionalAttributeValue("targetFramework");
                SemanticVersion version                 = null;

                if (String.IsNullOrEmpty(id))
                {
                    // If the id is empty, ignore the record unless unspecified versions are allowed
                    continue;
                }

                if (String.IsNullOrEmpty(versionString))
                {
                    // If the version is empty, ignore the record unless unspecified versions are allowed
                    if (requireVersion)
                    {
                        continue;
                    }
                }
                else if (!SemanticVersion.TryParse(versionString, out version))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionString, _path));
                }

                IVersionSpec versionConstaint = null;
                if (!String.IsNullOrEmpty(versionConstraintString))
                {
                    if (!VersionUtility.TryParseVersionSpec(versionConstraintString, out versionConstaint))
                    {
                        throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionConstraintString, _path));
                    }

                    _constraints[id] = versionConstraintString;
                }

                FrameworkName targetFramework = null;
                if (!String.IsNullOrEmpty(targetFrameworkString))
                {
                    targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkString);
                    if (targetFramework == VersionUtility.UnsupportedFrameworkName)
                    {
                        targetFramework = null;
                    }
                }

                yield return(new PackageReference(id, version, versionConstaint, targetFramework));
            }
        }
예제 #3
0
        /// <summary>
        /// Parses a dependency from the feed in the format:
        /// id:versionSpec or id
        /// </summary>
        private static PackageDependency ParseDependency(string value)
        {
            if (String.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            string[] tokens = value.Trim().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length == 0)
            {
                return(null);
            }

            // Trim the id
            string       id          = tokens[0].Trim();
            IVersionSpec versionSpec = null;

            if (tokens.Length > 1)
            {
                // Attempt to parse the version
                VersionUtility.TryParseVersionSpec(tokens[1], out versionSpec);
            }

            return(new PackageDependency(id, versionSpec));
        }
예제 #4
0
        private static Tuple <string, IVersionSpec, FrameworkName> ParseDependency(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }
            char[]   separator = new char[] { ':' };
            string[] strArray  = value.Trim().Split(separator);
            if (strArray.Length == 0)
            {
                return(null);
            }
            IVersionSpec result = null;

            if (strArray.Length > 1)
            {
                VersionUtility.TryParseVersionSpec(strArray[1], out result);
            }
            return(Tuple.Create <string, IVersionSpec, FrameworkName>(strArray[0].Trim(), result, ((strArray.Length <= 2) || string.IsNullOrEmpty(strArray[2])) ? null : VersionUtility.ParseFrameworkName(strArray[2])));
        }
예제 #5
0
        public IEnumerable <PackageReference> GetPackageReferences(bool requireVersion)
        {
            XDocument document = GetDocument();

            if (document == null)
            {
                yield break;
            }

            foreach (var e in document.Root.Elements("package"))
            {
                string          id                          = e.GetOptionalAttributeValue("id");
                string          versionString               = e.GetOptionalAttributeValue("version");
                string          versionConstraintString     = e.GetOptionalAttributeValue("allowedVersions");
                string          targetFrameworkString       = e.GetOptionalAttributeValue("targetFramework");
                string          developmentFlagString       = e.GetOptionalAttributeValue("developmentDependency");
                string          requireReinstallationString = e.GetOptionalAttributeValue("requireReinstallation");
                SemanticVersion version                     = null;

                if (String.IsNullOrEmpty(id))
                {
                    // If the id is empty, ignore the record
                    continue;
                }

                // If the version is invalid, raise an error unless it's both empty and not required
                if ((requireVersion || !String.IsNullOrEmpty(versionString)) && !SemanticVersion.TryParse(versionString, out version))
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionString, _path));
                }

                IVersionSpec versionConstaint = null;
                if (!String.IsNullOrEmpty(versionConstraintString))
                {
                    if (!VersionUtility.TryParseVersionSpec(versionConstraintString, out versionConstaint))
                    {
                        throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionConstraintString, _path));
                    }

                    _constraints[id] = versionConstraintString;
                }

                FrameworkName targetFramework = null;
                if (!String.IsNullOrEmpty(targetFrameworkString))
                {
                    targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkString);
                    if (targetFramework == VersionUtility.UnsupportedFrameworkName)
                    {
                        targetFramework = null;
                    }
                }

                var developmentFlag = false;
                if (!String.IsNullOrEmpty(developmentFlagString))
                {
                    if (!Boolean.TryParse(developmentFlagString, out developmentFlag))
                    {
                        throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidDevelopmentFlag, developmentFlagString, _path));
                    }

                    _developmentFlags[id] = developmentFlagString;
                }

                var requireReinstallation = false;
                if (!String.IsNullOrEmpty(requireReinstallationString))
                {
                    if (!Boolean.TryParse(requireReinstallationString, out requireReinstallation))
                    {
                        throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidRequireReinstallationFlag, requireReinstallationString, _path));
                    }
                }

                yield return(new PackageReference(id, version, versionConstaint, targetFramework, developmentFlag, requireReinstallation));
            }
        }