diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f7952..18366b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] + +### Added + - Added Shim to read a list from xml with no root element + ### Changed - Fixed JSON DateTime parsing in .Net Standard - Fixed threading exception in TypeExtensions + ## [9.4.0] - 2019-05-10 ### Added - Added extension method for peeking queues diff --git a/ICD.Common.Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Xml/XmlUtils.cs index 9ad62a8..9cf03a8 100644 --- a/ICD.Common.Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Xml/XmlUtils.cs @@ -972,6 +972,22 @@ namespace ICD.Common.Utils.Xml return ReadDictFromXml(xml, rootElement, childElement, keyElement, valueElement, readKey, readValue); } + /// + /// Calls childElementCallback for each item in the list. + /// + /// + /// + /// + /// + public static IEnumerable ReadListFromXml(string xml, string childElement, Func readChild) + { + if (readChild == null) + throw new ArgumentNullException("readChild"); + + foreach (string child in GetChildElementsAsString(xml, childElement)) + yield return readChild(child); + } + /// /// Calls childElementCallback for each item in the list. /// @@ -988,10 +1004,22 @@ namespace ICD.Common.Utils.Xml if (!TryGetChildElementAsString(xml, rootElement, out xml)) yield break; - foreach (string child in GetChildElementsAsString(xml, childElement)) - yield return readChild(child); + foreach (T child in ReadListFromXml(xml, childElement, readChild)) + yield return child; } + /// + /// Deserializes the xml to a list. + /// + /// + /// + /// + public static IEnumerable ReadListFromXml(string xml, string childElement) + { + Func readChild = IcdXmlConvert.DeserializeObject; + + return ReadListFromXml(xml, childElement, readChild); + } /// /// Deserializes the xml to a list.