Changeset 1667 for trunk/sources/HeuristicLab.Core/3.3/Variable.cs
- Timestamp:
- 04/27/09 14:18:39 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Variable.cs
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class Variable : ItemBase, IVariable { 33 34 [Storable] 32 35 private string myName; 33 36 /// <inheritdoc/> … … 47 50 } 48 51 } 52 53 [Storable] 49 54 private IItem myValue; 50 55 /// <inheritdoc/> … … 59 64 } 60 65 } 61 66 62 67 /// <summary> 63 68 /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c> … … 145 150 OnChanged(); 146 151 } 147 148 #region Persistence Methods149 /// <summary>150 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.151 /// </summary>152 /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>153 /// The name of the current instance is saved as an <see cref="XmlAttribute"/> with the154 /// tag name <c>Name</c>, the value is saved as child node with the tag name <c>Value</c>.</remarks>155 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>156 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>157 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>158 /// <returns>The saved <see cref="XmlNode"/>.</returns>159 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {160 XmlNode node = base.GetXmlNode(name, document, persistedObjects);161 XmlAttribute nameAttribute = document.CreateAttribute("Name");162 nameAttribute.Value = Name;163 node.Attributes.Append(nameAttribute);164 if (Value != null)165 node.AppendChild(PersistenceManager.Persist("Value", Value, document, persistedObjects));166 return node;167 }168 /// <summary>169 /// Loads the persisted variable from the specified <paramref name="node"/>.170 /// </summary>171 /// <remarks>See <see cref="GetXmlNode"/> to get information on how the variable must be saved.<br/>172 /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>173 /// <param name="node">The <see cref="XmlNode"/> where the variable is saved.</param>174 /// <param name="restoredObjects">The dictionary of all already restored objects.175 /// (Needed to avoid cycles.)</param>176 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {177 base.Populate(node, restoredObjects);178 myName = node.Attributes["Name"].Value;179 XmlNode valueNode = node.SelectSingleNode("Value");180 if (valueNode != null)181 myValue = (IItem)PersistenceManager.Restore(valueNode, restoredObjects);182 }183 #endregion184 152 } 185 153 }
Note: See TracChangeset
for help on using the changeset viewer.