From 548220ba0e05a328eeb734e299d0eb2aad722d3b Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 17 Oct 2018 14:56:55 -0400 Subject: [PATCH] feat: Shims for deserializing xml lists and dictionaries --- ICD.Common.Utils/Xml/XmlUtils.cs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ICD.Common.Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Xml/XmlUtils.cs index 0f559f4..d84a455 100644 --- a/ICD.Common.Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Xml/XmlUtils.cs @@ -857,6 +857,26 @@ namespace ICD.Common.Utils.Xml return ReadListFromXml(xml, rootElement, childElement, readChild); } + /// + /// Deserializes the xml to a dictionary. + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable> ReadDictFromXml( + string xml, string rootElement, string childElement, string keyElement, string valueElement) + { + Func readKey = IcdXmlConvert.DeserializeObject; + Func readValue = IcdXmlConvert.DeserializeObject; + + return ReadDictFromXml(xml, rootElement, childElement, keyElement, valueElement, readKey, readValue); + } + /// /// Calls childElementCallback for each item in the list. /// @@ -877,6 +897,20 @@ namespace ICD.Common.Utils.Xml yield return readChild(child); } + + /// + /// Deserializes the xml to a list. + /// + /// + /// + /// + public static IEnumerable ReadListFromXml(string xml, string rootElement, string childElement) + { + Func readChild = IcdXmlConvert.DeserializeObject; + + return ReadListFromXml(xml, rootElement, childElement, readChild); + } + #endregion #region Write Content