Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Parameters/3.3/ParameterActualNameBinding.cs @ 4757

Last change on this file since 4757 was 4757, checked in by abeham, 13 years ago

#1258

  • worked on parameter binding (wip)
File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6using HeuristicLab.Core;
7using HeuristicLab.Common;
8
9namespace HeuristicLab.Parameters {
10  [StorableClass]
11  public class ParameterActualNameBinding : IParameterBinding {
12    [Storable]
13    private ILookupParameter source;
14    public ILookupParameter Source {
15      get { return source; }
16    }
17    [Storable]
18    private ILookupParameter destination;
19    public ILookupParameter Destination {
20      get { return destination; }
21    }
22
23    [StorableConstructor]
24    protected ParameterActualNameBinding(bool deserializing) { }
25    protected ParameterActualNameBinding(ParameterActualNameBinding original, Cloner cloner) {
26      this.source = cloner.Clone(source);
27      this.destination = cloner.Clone(destination);
28      RegisterEventHandlers();
29    }
30    public ParameterActualNameBinding(ILookupParameter source, ILookupParameter destination) {
31      if (source == null) throw new ArgumentNullException("source");
32      if (destination == null) throw new ArgumentNullException("destination");
33      this.source = source;
34      this.destination = destination;
35      RegisterEventHandlers();
36    }
37
38    public override IDeepCloneable Clone(Cloner cloner) {
39      return new ParameterActualNameBinding(this, cloner);
40    }
41
42    public void Bind() {
43      RegisterEventHandlers();
44    }
45
46    public void Unbind() {
47      DeregisterEventHandlers();
48    }
49
50    [StorableHook(HookType.AfterDeserialization)]
51    private void AfterDeserialization() {
52      RegisterEventHandlers();
53    }
54
55    private void RegisterEventHandlers() {
56      source.ActualNameChanged += new EventHandler(source_ActualNameChanged);
57    }
58
59    private void DeregisterEventHandlers() {
60      source.ActualNameChanged -= new EventHandler(source_ActualNameChanged);
61    }
62   
63
64    private void source_ActualNameChanged(object sender, EventArgs e) {
65      if (destination.ActualName != source.ActualName)
66        destination.ActualName = source.ActualName;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.