/// <summary> /// Finds descendant nodes named <i>section</i> where the <i>name</i> attribute matches <paramref name="sectionName"/>. /// </summary> /// <param name="root">Specifies the node whose descendants should be searched.</param> /// <param name="sectionName">Specifies the value of the name attribute of the section.</param> /// <param name="regexMatch">Specifies whether <paramref name="sectionName"/> should be used a regular expression matching string.</param> /// <returns></returns> public static IEnumerable <XElement> FindSections(this XElement root, RfwsDeserializableSectionAttribute attr) { (string sectionName, float minimumVersion, bool regexMatch) = attr; if (regexMatch) { return(from element in root.Descendants("section") let name = (string)element.Attribute("name") where Regex.IsMatch(name, sectionName) where element.GetSectionVersion() >= minimumVersion select element); } else { return(from element in root.Descendants("section") let name = (string)element.Attribute("name") where name == sectionName where element.GetSectionVersion() >= minimumVersion select element); } }
/// <summary> /// Finds descendant nodes named <i>section</i> where the <i>name</i> attribute matches the <see cref="RfwsDeserializableSectionAttribute.sectionName"/> /// value for the <see cref="RfwsSection"/> type defined by <paramref name="sectionType"/>. /// </summary> /// <param name="root">Specifies the node whose descendants should be searched.</param> /// <param name="sectionType">Specifies the type of <see cref="RfwsSection"/> to find in the XML data.</param> public static IEnumerable <XElement> FindSections <T>(this XElement root) { RfwsDeserializableSectionAttribute attr = typeof(T).GetCustomAttribute <RfwsDeserializableSectionAttribute>(); return(root.FindSections(attr)); }