Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 14:13:06 (16 years ago)
Author:
gkronber
Message:

Refactored cloning in HL.Core, HL.Data and HL.Constraints

#285 (Cloning could be improved by creating objects at the bottom of the cloning chain with 'new' instead of the top with Activator.CreateInstance())

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Data/StringData.cs

    r763 r885  
    5555      Data = data;
    5656    }
     57
     58    /// <summary>
     59    /// Copy constructor to create clones (deep).
     60    /// </summary>
     61    /// <param name="original">The original instance to be cloned.</param>
     62    public StringData(StringData original) : this(original, new Dictionary<Guid, object>()) { }
     63   /// <summary>
     64    /// Copy constructor to create clones (deep) reusing already cloned object references.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     68    protected StringData(StringData original, IDictionary<Guid, object> clonedObjects)
     69      : base(original, clonedObjects) {
     70      this.Data = original.Data;
     71    }
    5772   
    5873    /// <summary>
     
    6580
    6681    /// <summary>
    67     /// Clones the current instance.
     82    /// Clones the current instance using the copy constructor.
    6883    /// </summary>
    6984    /// <remarks>The current instance is added to the dictionary <paramref name="clonedObjects"/>.</remarks>
    70     /// <param name="clonedObjects">A dictionary of all already cloned objects.</param>
     85    /// <param name="clonedObjects">A dictionary of all already cloned objects (for referential integrity).</param>
    7186    /// <returns>The coned instance as <see cref="StringData"/>.</returns>
    7287    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    73       StringData clone = new StringData();
    74       clonedObjects.Add(Guid, clone);
    75       clone.Data = Data;
    76       return clone;
     88      return new StringData(this, clonedObjects);
    7789    }
    7890
Note: See TracChangeset for help on using the changeset viewer.