Пример #1
0
        /// <summary>
        /// Tries to parse the specified input into a dependency.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="dependency">The dependency.</param>
        /// <returns><see langword="true"/> if successful; otherwise <see langword="false"/>.</returns>
        /// <remarks></remarks>
        public static bool TryParse(string input, out NuSpecDependency dependency)
        {
            dependency = default(NuSpecDependency);
            if (String.IsNullOrWhiteSpace(input))
            {
                return(false);
            }

            string[] split = input.Split(new[] { ',' }, 2);
            dependency = split.Length != 2 ? new NuSpecDependency(split[0]) : new NuSpecDependency(split[0], split[1]);
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Ensures the dependency is added if not present.
        /// </summary>
        /// <param name="dependency">The dependency.</param>
        /// <remarks></remarks>
        public void EnsureDependency(NuSpecDependency dependency)
        {
            XElement dependencyElement = DependenciesElement.Elements()
                                         .FirstOrDefault(
                e =>
                e != null &&
                e.Name == DependencyXName &&
                e.Attributes("id").FirstOrDefault(
                    a => a.Value.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase)) != null);


            if (dependencyElement == null)
            {
                // Add the dependency element
                dependencyElement = new XElement(
                    DependencyXName,
                    new XAttribute("id", dependency.Id),
                    String.IsNullOrWhiteSpace(dependency.Version)
                        ? null
                        : new XAttribute("version", dependency.Version));
                DependenciesElement.Add(dependencyElement);
                HasChanges = true;
                return;
            }

            // We already have a matching dependency, check the version if necessary.
            if (dependency.Version == null)
            {
                return;
            }

            XAttribute versionAttribute = dependencyElement.Attributes("version").SingleOrDefault();

            if (versionAttribute == null)
            {
                versionAttribute = new XAttribute("version", dependency.Version);
                dependencyElement.Add(versionAttribute);
            }
            else
            {
                if (versionAttribute.Value.Equals(dependency.Version, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                versionAttribute.SetValue(dependency.Version);
            }
            HasChanges = true;
        }
Пример #3
0
        /// <summary>
        /// Ensures the dependency is added if not present.
        /// </summary>
        /// <param name="dependency">The dependency.</param>
        /// <remarks></remarks>
        public void EnsureDependency(NuSpecDependency dependency)
        {
            XElement dependencyElement = DependenciesElement.Elements()
                .FirstOrDefault(
                    e =>
                        e != null &&
                        e.Name == DependencyXName &&
                        e.Attributes("id").FirstOrDefault(
                            a => a.Value.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase)) != null);


            if (dependencyElement == null)
            {
                // Add the dependency element
                dependencyElement = new XElement(
                    DependencyXName,
                    new XAttribute("id", dependency.Id),
                    String.IsNullOrWhiteSpace(dependency.Version)
                        ? null
                        : new XAttribute("version", dependency.Version));
                DependenciesElement.Add(dependencyElement);
                HasChanges = true;
                return;
            }

            // We already have a matching dependency, check the version if necessary.
            if (dependency.Version == null) return;

            XAttribute versionAttribute = dependencyElement.Attributes("version").SingleOrDefault();
            if (versionAttribute == null)
            {
                versionAttribute = new XAttribute("version", dependency.Version);
                dependencyElement.Add(versionAttribute);
            }
            else
            {
                if (versionAttribute.Value.Equals(dependency.Version, StringComparison.OrdinalIgnoreCase))
                    return;
                versionAttribute.SetValue(dependency.Version);
            }
            HasChanges = true;
        }
Пример #4
0
        /// <summary>
        /// Tries to parse the specified input into a dependency.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="dependency">The dependency.</param>
        /// <returns><see langword="true"/> if successful; otherwise <see langword="false"/>.</returns>
        /// <remarks></remarks>
        public static bool TryParse(string input, out NuSpecDependency dependency)
        {
            dependency = default(NuSpecDependency);
            if (String.IsNullOrWhiteSpace(input))
                return false;

            string[] split = input.Split(new[] {','}, 2);
            dependency = split.Length != 2 ? new NuSpecDependency(split[0]) : new NuSpecDependency(split[0], split[1]);
            return true;
        }