public void FlattenTest() { var o = new TestClass(); var flattener = new CommonXmlObjectFlattener(); XmlNode flat = flattener.Flatten(o, o.GetType()); Assert.IsTrue(o.EqualsXml(flat)); }
public void LoadFromXmlTest() { var o = new TestClass(); var flattener = new CommonXmlObjectFlattener(); XmlNode xml = flattener.Flatten(o, typeof(TestClass)); PropertyLoader loader = new PropertyLoader(); var test = loader.LoadFromXml <TestClass>(xml); Assert.IsTrue(o.Equals(test)); }
public void AddWindowManager <DataType>(DataType data, string name) where DataType : class { XmlNode dataAsXml = new CommonXmlObjectFlattener().Flatten(data, typeof(DataType)); XmlNode storedData = xmlDocument.SelectSingleNode(".//" + name); if (storedData != null) { root.RemoveChild(storedData); } XmlNode dataRoot = xmlDocument.CreateElement(name); foreach (XmlNode node in dataAsXml) { XmlNode importedNode = xmlDocument.ImportNode(node, true); dataRoot.AppendChild(importedNode); } root.AppendChild(dataRoot); }
/// <summary> /// ToString but for properties of an object. Only flatten if the property is a primitive type or a string. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <returns></returns> public static Dictionary <string, string> Flatten <T>(T data) where T : class { try { XmlNode xml = new CommonXmlObjectFlattener().Flatten(data, typeof(T)); } catch (StackOverflowException e) { Console.Error.WriteLine(e.ToString()); Console.WriteLine("Data could not be flatten into a xml format"); } try { return(new BasicObjectFlattener().Flatten(data, typeof(T))); } catch (StackOverflowException e) { Console.WriteLine(e.ToString()); } return(null); }
public void SetProperties <T>(T o) where T : class { CommonXmlObjectFlattener flattener = new CommonXmlObjectFlattener(); flattener.Flatten(o, typeof(T)); }