Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11056 for trunk/sources


Ignore:
Timestamp:
06/30/14 11:20:08 (10 years ago)
Author:
jkarder
Message:

#2203: used the persistence to clone the VariableStore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting/3.3/CSharpScript.cs

    r10857 r11056  
    2121
    2222using System;
     23using System.IO;
    2324using System.Linq;
    2425using System.Reflection;
     
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
     29using HeuristicLab.Persistence.Core;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Persistence.Default.Xml;
    2932
    3033namespace HeuristicLab.Scripting {
     
    7881    protected CSharpScript(CSharpScript original, Cloner cloner)
    7982      : base(original, cloner) {
    80       variableStore = new VariableStore();
     83      try {
     84        using (var serializerStream = new MemoryStream()) {
     85          XmlGenerator.Serialize(original.variableStore, serializerStream);
     86          var bytes = serializerStream.GetBuffer();
     87          using (var deserializerStream = new MemoryStream(bytes)) {
     88            variableStore = XmlParser.Deserialize<VariableStore>(deserializerStream);
     89          }
     90        }
     91      } catch (PersistenceException pe) {
     92        throw new NotSupportedException("Could not clone the script because some of its variables could not be cloned.", pe);
     93      }
    8194    }
    8295    public CSharpScript() {
Note: See TracChangeset for help on using the changeset viewer.