mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-14 04:58:33 +00:00
feat: Added Shim to read a list from xml with no root element
This commit is contained in:
parent
6f67064d34
commit
7792b01629
1 changed files with 30 additions and 2 deletions
|
|
@ -972,6 +972,22 @@ namespace ICD.Common.Utils.Xml
|
||||||
return ReadDictFromXml(xml, rootElement, childElement, keyElement, valueElement, readKey, readValue);
|
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>
|
/// <summary>
|
||||||
/// Calls childElementCallback for each item in the list.
|
/// Calls childElementCallback for each item in the list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -988,10 +1004,22 @@ namespace ICD.Common.Utils.Xml
|
||||||
if (!TryGetChildElementAsString(xml, rootElement, out xml))
|
if (!TryGetChildElementAsString(xml, rootElement, out xml))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
foreach (string child in GetChildElementsAsString(xml, childElement))
|
foreach (T child in ReadListFromXml(xml, childElement, readChild))
|
||||||
yield return readChild(child);
|
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>
|
/// <summary>
|
||||||
/// Deserializes the xml to a list.
|
/// Deserializes the xml to a list.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue