public static ConfigObject FromExpando(ExpandoObject e) { var edict = e as IDictionary <string, object>; var c = new ConfigObject(); var cdict = (IDictionary <string, object>)c; // this is not complete. It will, however work for JsonFX ExpandoObjects // which consits only of primitive types, ExpandoObject or ExpandoObject [] // but won't work for generic ExpandoObjects which might include collections etc. foreach (var kvp in edict) { // recursively convert and add ExpandoObjects if (kvp.Value is ExpandoObject) { cdict.Add(kvp.Key, FromExpando((ExpandoObject)kvp.Value)); } else if (kvp.Value is ExpandoObject[]) { var config_objects = new List <ConfigObject>(); foreach (var ex in ((ExpandoObject[])kvp.Value)) { config_objects.Add(FromExpando(ex)); } cdict.Add(kvp.Key, config_objects.ToArray()); } else { cdict.Add(kvp.Key, kvp.Value); } } return(c); }
private static void Serialise(ConfigObject data) { XmlSerializer xsSubmit = new XmlSerializer(typeof(ConfigObject)); var subReq = data; using (XmlWriter writer = XmlWriter.Create(SavePath)) { xsSubmit.Serialize(writer, subReq); } }
public void ReadXml(XmlReader reader) { var doc = XDocument.Load(reader.ReadSubtree()); foreach (var rootItems in doc.Root.Descendants()) { if (rootItems.HasElements) { members.Add(rootItems.Name.LocalName, new ConfigObject()); } else { ConfigObject internalObject = (ConfigObject)members[rootItems.Parent?.Name.LocalName ?? "Config"]; internalObject.Add(rootItems.Name.LocalName, StringConverter.ConvertString(rootItems.Attribute("type")?.Value ?? "", rootItems.Value)); } } }