/// <summary> /// Load specified ISavable object from a xml data /// </summary> /// <param name="savable">ISavable to load</param> /// <param name="xmlContent">String contains xml data</param> public static void LoadFromXmlContent(ISavable savable, string xmlContent) { if (savable == null) { throw new ArgumentNullException("Invalid ISavable object."); } if (string.IsNullOrEmpty(xmlContent)) { throw new Exception("Invalid Xml content"); } XmlDocument document = new XmlDocument(); document.LoadXml(xmlContent); XmlElement root = document[RootXmlElementName]; if (root != null) { XmlLoadStream stream = new XmlLoadStream(document); savable.Load(root, stream); } else { throw new Exception("Invalid Xml content"); } }
/// <summary> /// Load specified ISavable object from a stream /// </summary> /// <param name="savable">ISavable to load</param> /// <param name="stream">Stream to load</param> public static void LoadFromStream(ISavable savable, PCBinaryLoadStream stream) { if (savable == null) { throw new ArgumentNullException("Invalid ISavable object."); } savable.Load(stream); }
public void XmlSaveToFileTest() { Assert.AreEqual(nodeCount, sGraph.Node.Count); Assert.AreEqual(edgeCount, sGraph.Edge.Count); fileNameExtension = ".xml"; saveToFile = new XmlSaveToFile <int, int>(filePath); saveToFile.Save(sGraph); sGraph.Node.Clear(); sGraph.Edge.Clear(); sGraph = saveToFile.Load(); Assert.AreEqual(nodeCount, sGraph.Node.Count); Assert.AreEqual(edgeCount, sGraph.Edge.Count); }
void Example() { // ** Inicjalize graph graph.AddNode(51); graph.AddNode(12); graph.AddEdge(graph[0], graph[1]); // ** End inicjalize converter = new SerializableGraphConverter <int, int>(graph); serializableGraph = converter.GetSerializableGraph(); saver = new BinarySaveToFile <int, int>(filePath + ".bin"); // bin file or saver = new JsonSaveToFile <int, int>(filePath + ".json"); // json text file or saver = new XmlSaveToFile <int, int>(filePath + ".xml"); // xml file saver.Save(serializableGraph); // Save to file. serializableGraph = saver.Load(); // Load from file. }
public virtual T Value <T>() { if (m_value is List <JObject> || m_value is Dictionary <String, JObject> ) { T result = Activator.CreateInstance <T>(); if (result is ISavable) { ISavable savable = result as ISavable; savable.Load(this); return((T)result); } return(default(T)); } else { var typeTest = default(T); if (typeTest is float) { return((T)m_value); } return((T)m_value); } }