private PackageData CreatePackageData(XElement packageElement)
 {
     var data = new PackageData
     {
         Id = packageElement.Attribute("id")
             .Value,
         Version = packageElement.Attribute("version")
             .Value,
         TargetFramework = packageElement.Attribute("targetFramework")
             .Value
     };
     return data;
 }
        private static XElement TryFindExistingGroupElement(XElement dependencies,
            PackageData packageData)
        {
            foreach (var element in dependencies.Elements())
            {
                if (element.Name != "group")
                {
                    continue;
                }

                var groupTargetFramework = element.Attribute("targetFramework")
                    .Value;

                if (groupTargetFramework == packageData.TargetFramework)
                {
                    return element;
                }
            }

            return null;
        }
 private static bool IsWrongGroup(PackageData packageData,
     XElement groupElement)
 {
     return groupElement != null && groupElement.Attribute("targetFramework")
         .Value != packageData.TargetFramework;
 }
        private XElement TryFindCurrentGroupElement(XElement dependencies,
            PackageData packageData)
        {
            foreach (var group in dependencies.Elements())
            {
                if (group.Name != "group")
                {
                    continue;
                }

                foreach (var dependency in group.Elements())
                {
                    if (dependency.Attribute("id")
                        .Value == packageData.Id)
                    {
                        return group;
                    }
                }
            }

            return null;
        }
        private XElement FindAndRemoveDependencyIfRequired(XElement dependencies,
            PackageData packageData)
        {
            var currentGroupElement = TryFindCurrentGroupElement(dependencies,
                packageData);
            // todo testing
            if (IsWrongGroup(packageData,
                currentGroupElement))
            {
                RemoveFromGroup(currentGroupElement,
                    packageData);

                return null;
            }

            return currentGroupElement;
        }
        private static void UpdateDependencyId(XElement element,
            PackageData packageData)
        {
            var id = element.Attribute("id");

            if (id == null)
            {
                id = new XAttribute("id",
                    packageData.Id);

                element.Add(id);
            }
            else
            {
                id.Value = packageData.Id;
            }
        }
        private static void UpdateDependencyVersion(XElement element,
            PackageData packageData)
        {
            var version = element.Attribute("version");

            if (version == null)
            {
                version = new XAttribute("version",
                    packageData.Version);

                element.Add(version);
            }
            else
            {
                version.Value = packageData.Version;
            }
        }