- Timestamp:
- 04/15/08 14:17:26 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/XmlTextReaderBranch/HeuristicLab.Core/ConstrainedItemBase.cs
r121 r122 39 39 ConstrainedItemBase clone = (ConstrainedItemBase)base.Clone(clonedObjects); 40 40 clone.myConstraints.Clear(); 41 foreach 41 foreach(IConstraint constraint in Constraints) 42 42 clone.AddConstraint((IConstraint)Auxiliary.Clone(constraint, clonedObjects)); 43 43 return clone; … … 49 49 } 50 50 public virtual void RemoveConstraint(IConstraint constraint) { 51 if 51 if(myConstraints.Remove(constraint)) 52 52 OnConstraintRemoved(constraint); 53 53 } … … 55 55 public bool IsValid() { 56 56 bool result = true; 57 foreach 57 foreach(IConstraint constraint in Constraints) 58 58 result = result && constraint.Check(this); 59 59 return result; … … 62 62 bool result = true; 63 63 violatedConstraints = new List<IConstraint>(); 64 foreach 65 if 64 foreach(IConstraint constraint in Constraints) { 65 if(!constraint.Check(this)) { 66 66 result = false; 67 67 violatedConstraints.Add(constraint); … … 77 77 public event EventHandler<ConstraintEventArgs> ConstraintAdded; 78 78 protected virtual void OnConstraintAdded(IConstraint constraint) { 79 if 79 if(ConstraintAdded != null) 80 80 ConstraintAdded(this, new ConstraintEventArgs(constraint)); 81 81 } 82 82 public event EventHandler<ConstraintEventArgs> ConstraintRemoved; 83 83 protected virtual void OnConstraintRemoved(IConstraint constraint) { 84 if 84 if(ConstraintRemoved != null) 85 85 ConstraintRemoved(this, new ConstraintEventArgs(constraint)); 86 86 } 87 87 88 88 #region Persistence Methods 89 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {89 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 90 90 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 91 if 91 if(Constraints.Count > 0) { 92 92 XmlNode constraintsNode = document.CreateNode(XmlNodeType.Element, "Constraints", null); 93 foreach 93 foreach(IConstraint constraint in Constraints) 94 94 constraintsNode.AppendChild(PersistenceManager.Persist(constraint, document, persistedObjects)); 95 95 node.AppendChild(constraintsNode); … … 108 108 public override void Populate(XmlReader reader, IDictionary<Guid, IStorable> restoredObjects) { 109 109 base.Populate(reader, restoredObjects); 110 if(reader.IsStartElement()) {111 reader.ReadToDescendant("Constraints");110 reader.Read(); 111 if(reader.Name == "Constraints") { 112 112 myConstraints.Clear(); 113 113 while(reader.IsStartElement())
Note: See TracChangeset
for help on using the changeset viewer.