private static XElement AddFirstElement(this XContainer parent, XElement element)
        {
            var indent = GetIndent(parent);

            parent.AddFirst(element);
            if (indent != null)
            {
                parent.AddFirst(new XText(indent));
            }
            return(element);
        }
        // Adds a property to the first property group without a condition
        private static void AddProperty(XContainer root, XNamespace xmlns, string name, string content)
        {
            var propertyGroup = root.Elements(xmlns + "PropertyGroup")
                                .FirstOrDefault(e => !e.Attributes(xmlns + "Condition").Any());

            if (propertyGroup == null)
            {
                propertyGroup = new XElement(xmlns + "PropertyGroup");
                root.AddFirst(propertyGroup);
            }

            propertyGroup.Add(new XElement(xmlns + name, content));
        }
        /// <summary>
        /// 组合目标。
        /// </summary>
        /// <param name="container">需要组合的容器。</param>
        private void CombineTargets(XContainer container)
        {
            var targetElements = _defaultLoggingConfigurationDocument.Descendants().Where(xElement => string.Equals(xElement.Name.LocalName, "target", StringComparison.OrdinalIgnoreCase));

            var targetsElement = new XElement("targets");

            foreach (var targetElement in targetElements)
            {
                targetElement.Name = XName.Get("target");
                targetsElement.Add(targetElement);
            }

            container.AddFirst(targetsElement);
        }
        private void UpdateNodeDocumentation(XContainer element, string documentation)
        {
            if (String.IsNullOrWhiteSpace(documentation))
            {
                return;
            }

            var fixedDocumentation = documentation.Trim();

            // Remove existing documentation.
            element.Edm().Descendants("Documentation").Remove();

            element.AddFirst(new XElement(XName.Get("Documentation", _namespace),
                                          new XElement(XName.Get("Summary", _namespace), fixedDocumentation)));
        }
Esempio n. 5
0
        private static bool ChangeOrSetProperty(XContainer root, XNamespace ns, string name, string val)
        {
            XElement node = root.Elements(ns + "PropertyGroup").Elements(ns + name).FirstOrDefault()
                            ?? new XElement(ns + name, "?");

            if (node.Value == val)
            {
                return(false);
            }
            node.Value = val;
            if (node.Parent == null)
            {
                var propertyGroup = new XElement(ns + "PropertyGroup");
                root.AddFirst(propertyGroup);
                propertyGroup.Add(node);
            }
            return(true);
        }
        public static XElement AquireElement(this XContainer container,
                                             string name, bool addFirst = false)
        {
            var element = container.Element(name);

            if (null != element)
            {
                return(element);
            }

            element = new XElement(name);

            if (addFirst)
            {
                container.AddFirst(element);
            }
            else
            {
                container.Add(element);
            }

            return(element);
        }