From 7792b016294ec482364ea93f954dac79b8a19b28 Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Fri, 31 May 2019 15:52:47 -0400 Subject: [PATCH 1/2] feat: Added Shim to read a list from xml with no root element --- ICD.Common.Utils/Xml/XmlUtils.cs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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. From 4312ad1a61ccd564a53ce404d22a9174300098a3 Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Fri, 31 May 2019 15:58:06 -0400 Subject: [PATCH 2/2] chore: updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a3418..8fe6867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ 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 + ## [9.4.0] - 2019-05-10 ### Added - Added extension method for peeking queues