Changeset 17566
- Timestamp:
- 05/28/20 14:33:28 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ReferenceParameter.cs
r17532 r17566 45 45 public IValueParameter ReferencedParameter { get; } 46 46 47 [Storable(DefaultValue = true)] 48 private bool readOnly; 47 49 public bool ReadOnly { 48 get => ReferencedParameter.ReadOnly; 49 set => ReferencedParameter.ReadOnly = value; 50 } 50 get { return readOnly; } 51 set { 52 if (value != readOnly) { 53 readOnly = value; 54 OnReadOnlyChanged(); 55 } 56 } 57 } 58 51 59 52 60 [Storable(DefaultValue = true)] … … 80 88 protected ReferenceParameter(ReferenceParameter original, Cloner cloner) : base(original, cloner) { 81 89 ReferencedParameter = cloner.Clone(original.ReferencedParameter); 90 ReadOnly = original.ReadOnly; 91 GetsCollected = original.GetsCollected; 92 82 93 RegisterEvents(); 83 94 } … … 119 130 } 120 131 121 private EventHandler readOnlyChanged; 122 public event EventHandler ReadOnlyChanged { 123 add { // only subscribe when we have a subscriber ourselves 124 bool firstSubscription = readOnlyChanged == null; 125 readOnlyChanged += value; 126 if (firstSubscription && readOnlyChanged != null) //only subscribe once 127 ReferencedParameter.ReadOnlyChanged += OnReferencedParameterReadOnlyChanged; 128 } 129 remove { // unsubscribe if we have no more subscribers 130 readOnlyChanged -= value; 131 if (readOnlyChanged == null) ReferencedParameter.ReadOnlyChanged -= OnReferencedParameterReadOnlyChanged; 132 } 133 } 134 private void OnReferencedParameterReadOnlyChanged(object sender, EventArgs args) { 135 readOnlyChanged?.Invoke(this, args); // note "this", not "sender" as sender would be the referenced parameter 132 public event EventHandler ReadOnlyChanged; 133 private void OnReadOnlyChanged() { 134 ReadOnlyChanged?.Invoke(this, EventArgs.Empty); 136 135 } 137 136
Note: See TracChangeset
for help on using the changeset viewer.