mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-10 02:05:20 +00:00
feat: Added Shim to read a list from xml with no root element
This commit is contained in:
@@ -972,6 +972,22 @@ namespace ICD.Common.Utils.Xml
|
||||
return ReadDictFromXml(xml, rootElement, childElement, keyElement, valueElement, readKey, readValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls childElementCallback for each item in the list.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="rootElement"></param>
|
||||
/// <param name="childElement"></param>
|
||||
/// <param name="readChild"></param>
|
||||
public static IEnumerable<T> ReadListFromXml<T>(string xml, string childElement, Func<string, T> readChild)
|
||||
{
|
||||
if (readChild == null)
|
||||
throw new ArgumentNullException("readChild");
|
||||
|
||||
foreach (string child in GetChildElementsAsString(xml, childElement))
|
||||
yield return readChild(child);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls childElementCallback for each item in the list.
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the xml to a list.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="rootElement"></param>
|
||||
/// <param name="childElement"></param>
|
||||
public static IEnumerable<T> ReadListFromXml<T>(string xml, string childElement)
|
||||
{
|
||||
Func<string, T> readChild = IcdXmlConvert.DeserializeObject<T>;
|
||||
|
||||
return ReadListFromXml(xml, childElement, readChild);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the xml to a list.
|
||||
|
||||
Reference in New Issue
Block a user