Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 14:13:06 (15 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.Constraints/AndConstraint.cs

    r764 r885  
    4444    }
    4545
     46    /// <summary>
     47    /// Default constructor for an empty AndConstraint.
     48    /// </summary>
    4649    public AndConstraint() {
    4750      clauses = new ItemList<IConstraint>();
     51    }
     52
     53    /// <summary>
     54    /// Copy constructor to create clones (deep).
     55    /// </summary>
     56    /// <param name="original">The original instance to be cloned.</param>
     57    public AndConstraint(AndConstraint original) : this(original, new Dictionary<Guid, object>()) { }
     58   /// <summary>
     59    /// Copy constructor to create clones (deep) reusing already cloned object references.
     60    /// </summary>
     61    /// <param name="original">The instance to be cloned.</param>
     62    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     63    protected AndConstraint(AndConstraint original, IDictionary<Guid, object> clonedObjects)
     64      : base(original, clonedObjects) {
     65      this.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(original.Clauses, clonedObjects);
    4866    }
    4967
     
    6078      return new AndConstraintView(this);
    6179    }
    62 
     80    /// <summary>
     81    /// Uses copy constructor to create a deep clone reusing already cloned object references.
     82    /// </summary>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     84    /// <returns></returns>
    6385    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       AndConstraint clone = new AndConstraint();
    65       clonedObjects.Add(Guid, clone);
    66       clone.Clauses = (ItemList<IConstraint>)Auxiliary.Clone(Clauses, clonedObjects);
    67       return clone;
     86      return new AndConstraint(this, clonedObjects);
    6887    }
    6988
Note: See TracChangeset for help on using the changeset viewer.