- Timestamp:
- 04/14/08 21:51:15 (16 years ago)
- Location:
- branches/XmlTextReaderBranch
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/XmlTextReaderBranch/HeuristicLab.Core/PersistenceManager.cs
r40 r121 49 49 } 50 50 } 51 public static IStorable Restore(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 52 Guid guid = new Guid(node.Attributes["GUID"].Value); 53 if (restoredObjects.ContainsKey(guid)) { 51 52 public static IStorable Restore(XmlReader reader, string elementName, IDictionary<Guid, IStorable> restoredObjects) { 53 reader.ReadToDescendant(elementName); 54 return RestoreElement(reader, restoredObjects); 55 } 56 57 public static IStorable Restore(XmlReader reader, IDictionary<Guid, IStorable> restoredObjects) { 58 reader.Read(); 59 return RestoreElement(reader, restoredObjects); 60 } 61 private static IStorable RestoreElement(XmlReader reader, IDictionary<Guid, IStorable> restoredObjects) { 62 Guid guid = new Guid(reader["GUID"]); 63 if(restoredObjects.ContainsKey(guid)) { 64 reader.ReadEndElement(); 54 65 return restoredObjects[guid]; 55 66 } else { 56 Type type = Type.GetType( node.Attributes["Type"].Value, true);67 Type type = Type.GetType(reader["Type"], true); 57 68 IStorable instance = (IStorable)Activator.CreateInstance(type); 58 69 restoredObjects.Add(guid, instance); 59 instance.Populate(node, restoredObjects); 70 instance.Populate(reader, restoredObjects); 71 reader.ReadEndElement(); 60 72 return instance; 61 73 } … … 79 91 public static IStorable Load(Stream stream) { 80 92 XmlDocument doc = new XmlDocument(); 81 doc.Load(stream); 82 return PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>()); 93 XmlTextReader reader = new XmlTextReader(stream); 94 reader.WhitespaceHandling = WhitespaceHandling.None; 95 reader.MoveToContent(); // read "<?xml version="1.0"?/> 96 return PersistenceManager.RestoreElement(reader, new Dictionary<Guid, IStorable>()); 83 97 } 84 98
Note: See TracChangeset
for help on using the changeset viewer.