Changeset 1669 for trunk/sources/HeuristicLab.Data/3.3/ItemDictionary_T.cs
- Timestamp:
- 04/27/09 14:45:44 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data/3.3/ItemDictionary_T.cs
r1529 r1669 5 5 using System.Xml; 6 6 using HeuristicLab.Core; 7 using HeuristicLab.Persistence.Default.Decomposers.Storable; 7 8 8 9 namespace HeuristicLab.Data { … … 14 15 public class ItemDictionary<K,V> : ItemBase, IDictionary<K,V> 15 16 where K : IItem 16 where V : IItem{ 17 where V : IItem { 18 19 [Storable] 17 20 private Dictionary<K, V> dict; 18 21 … … 57 60 } 58 61 return clone; 59 }60 61 /// <summary>62 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.63 /// </summary>64 /// <remarks>Every key-value pair is saved as new child node with the tag name "KeyValuePair".<br/>65 /// In the child node the key is saved as a new child node with the tag name "Key".<br/>66 /// The value is also saved as new child node with the tag name "Val".67 /// </remarks>68 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>69 /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>70 /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>71 /// <returns>The saved <see cref="XmlNode"/>.</returns>72 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {73 XmlNode node = base.GetXmlNode(name, document, persistedObjects);74 foreach (KeyValuePair<K, V> item in dict) {75 XmlNode keyNode = PersistenceManager.Persist("Key", item.Key, document, persistedObjects);76 XmlNode valueNode = PersistenceManager.Persist("Val", item.Value, document, persistedObjects);77 XmlNode pairNode = document.CreateNode(XmlNodeType.Element, "KeyValuePair", null);78 pairNode.AppendChild(keyNode);79 pairNode.AppendChild(valueNode);80 node.AppendChild(pairNode);81 }82 return node;83 }84 85 /// <summary>86 /// Loads the persisted matrix from the specified <paramref name="node"/>.87 /// </summary>88 /// <remarks>All key-value pairs must be saved as child nodes of the node. <br/>89 /// Every child node has to contain two child nodes itself, one for the key, having the tag name "Key",90 /// and one for the value, having the tag name "Val" (see <see cref="GetXmlNode"/>).</remarks>91 /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>92 /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>93 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {94 base.Populate(node, restoredObjects);95 for (int i = 0; i < node.ChildNodes.Count; i++) {96 K key = (K) PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Key"), restoredObjects);97 V val = (V) PersistenceManager.Restore(node.ChildNodes[i].SelectSingleNode("Val"), restoredObjects);98 dict[key] = val;99 }100 62 } 101 63
Note: See TracChangeset
for help on using the changeset viewer.