public void ReadSections(XElement root) { if (root == null) { throw new ArgumentNullException("root"); } var sectionsElement = root.Element("Sections"); if (sectionsElement == null) { return; } var sectionElements = from el in sectionsElement.Elements("Section") select el; // Loop through the sections foreach (var sectionElement in sectionElements) { CoalesceSection section; var currentSection = new CoalesceSection(); var sectionName = (string)sectionElement.Attribute("name"); // Make sure the section has a name if (sectionName.IsNullOrEmpty()) { continue; } var propertyElements = from el in sectionElement.Elements("Property") select el; // Loop through the current sections properties foreach (var propertyElement in propertyElements) { var currentProperty = ReadProperty(propertyElement); CoalesceProperty property; if (currentProperty == null) { continue; } if (!currentSection.TryGetValue(currentProperty.Name, out property)) { property = new CoalesceProperty(); currentSection.Add(currentProperty.Name, property); } property.AddRange(currentProperty); } if (!Sections.TryGetValue(sectionName, out section)) { section = new CoalesceSection(); Sections.Add(sectionName, section); } section.Combine(currentSection); } }
public void ReadSections(XElement root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } var sectionsElement = root.Element("Sections"); if (sectionsElement == null) { return; } var sectionElements = from el in sectionsElement.Elements("Section") select el; // Loop through the sections foreach (var sectionElement in sectionElements) { var currentSection = new CoalesceSection(); var sectionName = (string)sectionElement.Attribute("name"); // Make sure the section has a name if (string.IsNullOrEmpty(sectionName)) { continue; } var propertyElements = from el in sectionElement.Elements("Property") select el; // Loop through the current sections properties foreach (var propertyElement in propertyElements) { var currentProperty = ReadProperty(propertyElement); if (currentProperty == null) { continue; } if (!currentSection.TryGetValue(currentProperty.Name, out CoalesceProperty property)) { property = new CoalesceProperty(); currentSection.Add(currentProperty.Name, property); } property.AddRange(currentProperty); //currentSection[currentProperty.Name] = (CoalesceProperty) property.Concat(currentProperty); //properties.Add(property); // If the current section dictionary does not contain the property, add it // Else replace the property with this one /*if (!coalescedSection.ContainsKey(property.Name)) * { * coalescedSection.Add(property.Name, property); * } * else * { * //coalescedSection[property.Name] = property; * coalescedSection[property.Name].Combine(property); * }*/ } if (!Sections.TryGetValue(sectionName, out CoalesceSection section)) { section = new CoalesceSection(); Sections.Add(sectionName, section); } section.Combine(currentSection); // If the current asset dictionary does not contain the current section, add it // Else replace it with this one /*if (!Sections.ContainsKey(sectionName)) * { * Sections.Add(sectionName, currentSection); * } * else * { * Sections[sectionName].Combine(currentSection); * }*/ } }
public void ReadSections(XElement root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } var sectionsElement = root.Element("Sections"); if (sectionsElement == null) { return; } var sectionElements = from el in sectionsElement.Elements("Section") select el; // Loop through the sections foreach (var sectionElement in sectionElements) { CoalesceSection section; var currentSection = new CoalesceSection(); var sectionName = (string) sectionElement.Attribute("name"); // Make sure the section has a name if (sectionName.IsNullOrEmpty()) { continue; } var propertyElements = from el in sectionElement.Elements("Property") select el; // Loop through the current sections properties foreach (var propertyElement in propertyElements) { var currentProperty = ReadProperty(propertyElement); CoalesceProperty property; if (currentProperty == null) { continue; } if (!currentSection.TryGetValue(currentProperty.Name, out property)) { property = new CoalesceProperty(); currentSection.Add(currentProperty.Name, property); } property.AddRange(currentProperty); //currentSection[currentProperty.Name] = (CoalesceProperty) property.Concat(currentProperty); //properties.Add(property); // If the current section dictionary does not contain the property, add it // Else replace the property with this one /*if (!coalescedSection.ContainsKey(property.Name)) { coalescedSection.Add(property.Name, property); } else { //coalescedSection[property.Name] = property; coalescedSection[property.Name].Combine(property); }*/ } if (!Sections.TryGetValue(sectionName, out section)) { section = new CoalesceSection(); Sections.Add(sectionName, section); } section.Combine(currentSection); // If the current asset dictionary does not contain the current section, add it // Else replace it with this one /*if (!Sections.ContainsKey(sectionName)) { Sections.Add(sectionName, currentSection); } else { Sections[sectionName].Combine(currentSection); }*/ } }