- Timestamp:
- 10/08/14 03:27:24 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
r11421 r11423 34 34 } 35 35 36 [Storable] 37 private INode node; 38 public INode Node { 39 get { return node; } 36 private INode parent; 37 public INode Parent { 38 get { return parent; } 40 39 set { 41 if ((value != null) && !value.Ports.Contains(this)) 42 throw new InvalidOperationException("Port is not contained in port collection of node."); 43 if ((value == null) && node.Ports.Contains(this)) 44 throw new InvalidOperationException("Port is still contained in port collection of node."); 45 node = value; 40 if (value != parent) { 41 // NOTE: never call setter directly as the Parent property is set by the node which contains the port 42 if ((value != null) && !value.Ports.Contains(this)) 43 throw new InvalidOperationException("Port is not contained in port collection of node."); 44 if ((value == null) && parent.Ports.Contains(this)) 45 throw new InvalidOperationException("Port is still contained in port collection of node."); 46 DeregisterParentEvents(); 47 parent = value; 48 RegisterParentEvents(); 49 OnToStringChanged(); 50 } 46 51 } 47 52 } … … 49 54 [StorableConstructor] 50 55 protected Port(bool deserializing) : base(deserializing) { } 51 protected Port(Port original, Cloner cloner) 52 : base(original, cloner) { 53 node = (INode)cloner.GetClone(original.node); // NOTE: original node is NOT automatically cloned 54 } 56 protected Port(Port original, Cloner cloner) : base(original, cloner) { } 55 57 protected Port() : base("Port") { } 56 58 protected Port(string name) : base(name) { } 57 59 protected Port(string name, string description) : base(name, description) { } 60 61 public override string ToString() { 62 if (parent != null) { 63 return string.Concat(parent.ToString(), " -> ", base.ToString()); 64 } 65 return base.ToString(); 66 } 67 68 #region Parent Events 69 protected virtual void RegisterParentEvents() { 70 if (parent != null) { 71 parent.ToStringChanged += Parent_ToStringChanged; 72 } 73 } 74 protected virtual void DeregisterParentEvents() { 75 if (parent != null) { 76 parent.ToStringChanged -= Parent_ToStringChanged; 77 } 78 } 79 void Parent_ToStringChanged(object sender, EventArgs e) { 80 OnToStringChanged(); 81 } 82 #endregion 58 83 } 59 84 }
Note: See TracChangeset
for help on using the changeset viewer.