- Timestamp:
- 10/07/14 08:32:58 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
r11406 r11421 29 29 [Item("Port", "Abstract base class for ports of an optimization network node.")] 30 30 [StorableClass] 31 public abstract class Port <T> : NamedItem, IPort<T> where T : class, IItem{31 public abstract class Port : NamedItem, IPort { 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; } … … 35 35 36 36 [Storable] 37 protected T value; 38 public virtual T Value { 39 get { return value; } 40 protected set { 41 DeregisterValueEvents(); 42 this.value = value; 43 RegisterValueEvents(); 44 OnValueChanged(); 37 private INode node; 38 public INode Node { 39 get { return node; } 40 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; 45 46 } 46 }47 object IPort.Value {48 get { return Value; }49 47 } 50 48 51 49 [StorableConstructor] 52 50 protected Port(bool deserializing) : base(deserializing) { } 53 protected Port(Port <T>original, Cloner cloner)51 protected Port(Port original, Cloner cloner) 54 52 : base(original, cloner) { 55 value = cloner.Clone(original.value); 56 RegisterValueEvents(); 53 node = (INode)cloner.GetClone(original.node); // NOTE: original node is NOT automatically cloned 57 54 } 58 55 protected Port() : base("Port") { } 59 56 protected Port(string name) : base(name) { } 60 57 protected Port(string name, string description) : base(name, description) { } 61 62 [StorableHook(HookType.AfterDeserialization)]63 private void AfterDeserialization() {64 RegisterValueEvents();65 }66 67 public override string ToString() {68 return Name + ": " + (Value != null ? Value.ToString() : "null");69 }70 71 public event EventHandler ValueChanged;72 protected virtual void OnValueChanged() {73 var handler = ValueChanged;74 if (handler != null) handler(this, EventArgs.Empty);75 OnToStringChanged();76 }77 78 protected virtual void RegisterValueEvents() {79 if (value != null) {80 value.ToStringChanged += new EventHandler(Value_ToStringChanged);81 }82 }83 protected virtual void DeregisterValueEvents() {84 if (value != null) {85 value.ToStringChanged -= new EventHandler(Value_ToStringChanged);86 }87 }88 private void Value_ToStringChanged(object sender, EventArgs e) {89 OnToStringChanged();90 }91 58 } 92 59 }
Note: See TracChangeset
for help on using the changeset viewer.