Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. XDocument machineConfig = XDocument.Load(string.Format(@"{0}\config\machine.config", dotnet));
  2.      Dictionary<string, string> sectionAttributes = new Dictionary<string, string>();
  3.      sectionAttributes["name"] = "system.webServer";
  4.      sectionAttributes["type"] = "System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken= PublicKeyToken=b77a5c561934e089";
  5.      if (!machineConfig.Descendants(XName.Get("section"))
  6.          .Any((XElement element) =>
  7.            {
  8.              return sectionAttributes.Keys.All((string key) =>
  9.                  element.Attribute(XName.Get(key)).Value == sectionAttributes[key]);
  10.              //List<string> keys = sectionAttributes.Keys.ToList<string>();
  11.              //return element.Attributes().Aggregate<XAttribute, int>(0, (int count, XAttribute attrib) =>
  12.              // {
  13.              //    if (keys.Contains(attrib.Name.NamespaceName) && attrib.Value == sectionAttributes[attrib.Name.NamespaceName])
  14.              //    {
  15.              //      ++count;
  16.              //      keys.Remove(attrib.Name.NamespaceName);
  17.              //    }
  18.              //    return count;
  19.              // }) == keys.Count;
  20.            }));
  21.      {
  22.        XElement configSections = machineConfig.Descendants(XName.Get("configSections")).First();
  23.        //<section name="system.webServer" type="System.Configuration.IgnoreSectionHandler,
  24.        //System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  25.        XElement section = new XElement(XName.Get("section"),
  26.                              new XAttribute(XName.Get("name"), sectionAttributes["name"]),
  27.                              new XAttribute(XName.Get("type"), sectionAttributes["type"]));
  28.        configSections.Add(section);
  29.      }
  30.  
  31.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement