mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
Write List/Dict xml methods provide writer to callback
This commit is contained in:
parent
880745ff1e
commit
c80fea4db9
1 changed files with 14 additions and 13 deletions
|
|
@ -881,8 +881,8 @@ namespace ICD.Common.Utils.Xml
|
||||||
if (dict == null)
|
if (dict == null)
|
||||||
throw new ArgumentNullException("dict");
|
throw new ArgumentNullException("dict");
|
||||||
|
|
||||||
Action<TKey> writeKey = key => writer.WriteElementString(keyElement, IcdXmlConvert.ToString(key));
|
Action<IcdXmlTextWriter, TKey> writeKey = (w, k) => w.WriteElementString(keyElement, IcdXmlConvert.ToString(k));
|
||||||
Action<TValue> writeValue = value => writer.WriteElementString(valueElement, IcdXmlConvert.ToString(value));
|
Action<IcdXmlTextWriter, TValue> writeValue = (w, v) => w.WriteElementString(valueElement, IcdXmlConvert.ToString(v));
|
||||||
|
|
||||||
WriteDictToXml(writer, dict, rootElement, childElement, writeKey, writeValue);
|
WriteDictToXml(writer, dict, rootElement, childElement, writeKey, writeValue);
|
||||||
}
|
}
|
||||||
|
|
@ -899,8 +899,9 @@ namespace ICD.Common.Utils.Xml
|
||||||
/// <param name="writeKey"></param>
|
/// <param name="writeKey"></param>
|
||||||
/// <param name="writeValue"></param>
|
/// <param name="writeValue"></param>
|
||||||
public static void WriteDictToXml<TKey, TValue>(IcdXmlTextWriter writer, IEnumerable<KeyValuePair<TKey, TValue>> dict,
|
public static void WriteDictToXml<TKey, TValue>(IcdXmlTextWriter writer, IEnumerable<KeyValuePair<TKey, TValue>> dict,
|
||||||
string rootElement, string childElement, Action<TKey> writeKey,
|
string rootElement, string childElement,
|
||||||
Action<TValue> writeValue)
|
Action<IcdXmlTextWriter, TKey> writeKey,
|
||||||
|
Action<IcdXmlTextWriter, TValue> writeValue)
|
||||||
{
|
{
|
||||||
if (writer == null)
|
if (writer == null)
|
||||||
throw new ArgumentNullException("writer");
|
throw new ArgumentNullException("writer");
|
||||||
|
|
@ -914,15 +915,15 @@ namespace ICD.Common.Utils.Xml
|
||||||
if (writeValue == null)
|
if (writeValue == null)
|
||||||
throw new ArgumentNullException("writeValue");
|
throw new ArgumentNullException("writeValue");
|
||||||
|
|
||||||
Action<KeyValuePair<TKey, TValue>> writeItem =
|
Action<IcdXmlTextWriter, KeyValuePair<TKey, TValue>> writeItem =
|
||||||
pair =>
|
(w, p) =>
|
||||||
{
|
{
|
||||||
writer.WriteStartElement(childElement);
|
w.WriteStartElement(childElement);
|
||||||
{
|
{
|
||||||
writeKey(pair.Key);
|
writeKey(w, p.Key);
|
||||||
writeValue(pair.Value);
|
writeValue(w, p.Value);
|
||||||
}
|
}
|
||||||
writer.WriteEndElement();
|
w.WriteEndElement();
|
||||||
};
|
};
|
||||||
|
|
||||||
WriteListToXml(writer, dict, rootElement, writeItem);
|
WriteListToXml(writer, dict, rootElement, writeItem);
|
||||||
|
|
@ -945,7 +946,7 @@ namespace ICD.Common.Utils.Xml
|
||||||
if (list == null)
|
if (list == null)
|
||||||
throw new ArgumentNullException("list");
|
throw new ArgumentNullException("list");
|
||||||
|
|
||||||
Action<T> writeItem = child => writer.WriteElementString(childElement, IcdXmlConvert.ToString(child));
|
Action<IcdXmlTextWriter, T> writeItem = (w, c) => w.WriteElementString(childElement, IcdXmlConvert.ToString(c));
|
||||||
WriteListToXml(writer, list, listElement, writeItem);
|
WriteListToXml(writer, list, listElement, writeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -958,7 +959,7 @@ namespace ICD.Common.Utils.Xml
|
||||||
/// <param name="listElement"></param>
|
/// <param name="listElement"></param>
|
||||||
/// <param name="writeItem"></param>
|
/// <param name="writeItem"></param>
|
||||||
public static void WriteListToXml<T>(IcdXmlTextWriter writer, IEnumerable<T> list, string listElement,
|
public static void WriteListToXml<T>(IcdXmlTextWriter writer, IEnumerable<T> list, string listElement,
|
||||||
Action<T> writeItem)
|
Action<IcdXmlTextWriter, T> writeItem)
|
||||||
{
|
{
|
||||||
if (writer == null)
|
if (writer == null)
|
||||||
throw new ArgumentNullException("writer");
|
throw new ArgumentNullException("writer");
|
||||||
|
|
@ -972,7 +973,7 @@ namespace ICD.Common.Utils.Xml
|
||||||
writer.WriteStartElement(listElement);
|
writer.WriteStartElement(listElement);
|
||||||
{
|
{
|
||||||
foreach (T child in list)
|
foreach (T child in list)
|
||||||
writeItem(child);
|
writeItem(writer, child);
|
||||||
}
|
}
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue