private XmlElement SerializeValue(object value, XmlDocument doc)
{
if (value == null)
return null;
var sValue = value as string;
if (sValue != null)
{
var el = doc.CreateElement("item", SerializedLibrary.Namespace_v4);
el.InnerXml = (string)value;
return el;
}
var dict = value as IDictionary;
if (dict != null)
{
var el = doc.CreateElement("dict", SerializedLibrary.Namespace_v4);
foreach (DictionaryEntry de in dict)
{
var sub = SerializeValue(de.Value, doc);
sub.SetAttribute("key", de.Key.ToString());
el.AppendChild(sub);
}
return el;
}
var ienum = value as IEnumerable;
if (ienum != null)
{
var el = doc.CreateElement("list", SerializedLibrary.Namespace_v4);
foreach (var oValue in ienum)
{
el.AppendChild(SerializeValue(oValue, doc));
}
return el;
}
throw new NotSupportedException(value.GetType().Name);
}