Merge branch 'feat/XmlUtilsRoku' of Common/Utils into ConnectPro_v1.3

This commit is contained in:
Chris Cameron
2019-05-31 20:16:55 +00:00
committed by Gogs
2 changed files with 35 additions and 2 deletions

View File

@@ -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

View File

@@ -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.