feat: Shims for deserializing xml lists and dictionaries

This commit is contained in:
Chris Cameron
2018-10-17 14:56:55 -04:00
parent 692da3253f
commit 548220ba0e

View File

@@ -857,6 +857,26 @@ namespace ICD.Common.Utils.Xml
return ReadListFromXml(xml, rootElement, childElement, readChild);
}
/// <summary>
/// Deserializes the xml to a dictionary.
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="xml"></param>
/// <param name="rootElement"></param>
/// <param name="childElement"></param>
/// <param name="keyElement"></param>
/// <param name="valueElement"></param>
/// <returns></returns>
public static IEnumerable<KeyValuePair<TKey, TValue>> ReadDictFromXml<TKey, TValue>(
string xml, string rootElement, string childElement, string keyElement, string valueElement)
{
Func<string, TKey> readKey = IcdXmlConvert.DeserializeObject<TKey>;
Func<string, TValue> readValue = IcdXmlConvert.DeserializeObject<TValue>;
return ReadDictFromXml(xml, rootElement, childElement, keyElement, valueElement, readKey, readValue);
}
/// <summary>
/// Calls childElementCallback for each item in the list.
/// </summary>
@@ -877,6 +897,20 @@ namespace ICD.Common.Utils.Xml
yield return readChild(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 rootElement, string childElement)
{
Func<string, T> readChild = IcdXmlConvert.DeserializeObject<T>;
return ReadListFromXml(xml, rootElement, childElement, readChild);
}
#endregion
#region Write Content