Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17566


Ignore:
Timestamp:
05/28/20 14:33:28 (4 years ago)
Author:
mkommend
Message:

#2521: Decoupled readonly state of ReferenceParameter from the referenced parameter and corrected cloning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ReferenceParameter.cs

    r17532 r17566  
    4545    public IValueParameter ReferencedParameter { get; }
    4646
     47    [Storable(DefaultValue = true)]
     48    private bool readOnly;
    4749    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
    5159
    5260    [Storable(DefaultValue = true)]
     
    8088    protected ReferenceParameter(ReferenceParameter original, Cloner cloner) : base(original, cloner) {
    8189      ReferencedParameter = cloner.Clone(original.ReferencedParameter);
     90      ReadOnly = original.ReadOnly;
     91      GetsCollected = original.GetsCollected;
     92
    8293      RegisterEvents();
    8394    }
     
    119130    }
    120131
    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);
    136135    }
    137136
Note: See TracChangeset for help on using the changeset viewer.