Changeset 11064 for branches/DataPreprocessing/HeuristicLab.Scripting
- Timestamp:
- 07/01/14 10:53:46 (10 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing
- Property svn:mergeinfo changed
/trunk/sources merged: 11008,11012-11014,11019,11024-11027,11031,11034-11035,11048,11050-11052,11056-11058,11060
- Property svn:mergeinfo changed
-
branches/DataPreprocessing/HeuristicLab.Scripting/3.3/CSharpScript.cs
r11009 r11064 78 78 protected CSharpScript(CSharpScript original, Cloner cloner) 79 79 : base(original, cloner) { 80 variableStore = new VariableStore();80 variableStore = cloner.Clone(original.variableStore); 81 81 } 82 82 public CSharpScript() { -
branches/DataPreprocessing/HeuristicLab.Scripting/3.3/VariableStore.cs
r10506 r11064 20 20 #endregion 21 21 22 using System; 23 using System.IO; 22 24 using HeuristicLab.Collections; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; 27 using HeuristicLab.Persistence.Core; 25 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Persistence.Default.Xml; 26 30 27 31 namespace HeuristicLab.Scripting { 28 32 [Item("VariableStore", "Represents a variable store.")] 29 33 [StorableClass] 30 public class VariableStore : ObservableDictionary<string, object>, IContent {34 public class VariableStore : ObservableDictionary<string, object>, IContent, IDeepCloneable { 31 35 [StorableConstructor] 32 36 protected VariableStore(bool deserializing) : base(deserializing) { } 37 protected VariableStore(VariableStore original, Cloner cloner) { 38 cloner.RegisterClonedObject(original, this); 39 foreach (var kvp in original.dict) { 40 var clonedValue = kvp.Value as IDeepCloneable; 41 if (clonedValue != null) { 42 dict[kvp.Key] = cloner.Clone(clonedValue); 43 } else { 44 try { 45 dict[kvp.Key] = CloneByPersistence(kvp.Value); 46 } catch (PersistenceException pe) { 47 throw new NotSupportedException("VariableStore: Variable " + kvp.Key + " could not be cloned.", pe); 48 } 49 } 50 } 51 } 33 52 public VariableStore() : base() { } 53 54 public object Clone() { 55 return Clone(new Cloner()); 56 } 57 public IDeepCloneable Clone(Cloner cloner) { 58 return new VariableStore(this, cloner); 59 } 60 61 protected object CloneByPersistence(object value) { 62 using (var serializerStream = new MemoryStream()) { 63 XmlGenerator.Serialize(value, serializerStream); 64 var bytes = serializerStream.GetBuffer(); 65 using (var deserializerStream = new MemoryStream(bytes)) { 66 return XmlParser.Deserialize<VariableStore>(deserializerStream); 67 } 68 } 69 } 34 70 } 35 71 }
Note: See TracChangeset
for help on using the changeset viewer.