Created
December 9, 2017 04:24
-
-
Save jakesays-old/955c7a647d51506df3e78781ca47f8cf to your computer and use it in GitHub Desktop.
Backing store example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using Money.Common.Contracts.Configuration; | |
using Std.BasicTypes; | |
//ReSharper disable ImpureMethodCallOnReadonlyValueField | |
namespace Money.Tools.ModelEditors.Models | |
{ | |
public class SignalRangeModel : INotifyPropertyChanged | |
{ | |
private readonly UndoableTrackedBackingStore<SignalRangeType> _type; | |
private readonly UndoableTrackedBackingStore<int> _start; | |
private readonly UndoableTrackedBackingStore<int> _end; | |
private readonly UndoableTrackedBackingStore<int> _singleValue; | |
private readonly PropertyTrackingManager _tracker; | |
public event PropertyChangedEventHandler PropertyChanged | |
{ | |
add => _tracker.PropertyChanged += value; | |
remove => _tracker.PropertyChanged -= value; | |
} | |
public SignalRangeModel() | |
{ | |
_tracker = new PropertyTrackingManager(_propertyNames, this); | |
_type = new UndoableTrackedBackingStore<SignalRangeType>(_tracker, 0, (lhs, rhs) => lhs == rhs); | |
_start = new UndoableTrackedBackingStore<int>(_tracker, 1, (lhs, rhs) => lhs == rhs); | |
_end = new UndoableTrackedBackingStore<int>(_tracker, 2, (lhs, rhs) => lhs == rhs); | |
_singleValue = new UndoableTrackedBackingStore<int>(_tracker, 3, (lhs, rhs) => lhs == rhs); | |
} | |
public SignalRangeModel(SignalRange source) | |
: this() | |
{ | |
if (source == null) | |
{ | |
return; | |
} | |
_type.InitializeValue(source.Type); | |
_start.InitializeValue(source.Start); | |
_end.InitializeValue(source.End); | |
_singleValue.InitializeValue(source.SingleValue); | |
} | |
public SignalRange Complete() | |
{ | |
var result = new SignalRange( | |
_type.Get(), | |
_start.Get(), | |
_end.Get(), | |
_singleValue.Get()); | |
return result; | |
} | |
public void BeginUpdate() | |
{ | |
_tracker.BeginUpdate(); | |
} | |
public void EndUpdate(bool notifyAll = false) | |
{ | |
_tracker.EndUpdate(notifyAll); | |
} | |
public SignalRangeType Type | |
{ | |
get => _type.Get(); | |
set => _type.Set(value); | |
} | |
public int Start | |
{ | |
get => _start.Get(); | |
set => _start.Set(value); | |
} | |
public int End | |
{ | |
get => _end.Get(); | |
set => _end.Set(value); | |
} | |
public int SingleValue | |
{ | |
get => _singleValue.Get(); | |
set => _singleValue.Set(value); | |
} | |
private static readonly string[] _propertyNames = | |
{ | |
nameof(Type), | |
nameof(Start), | |
nameof(End), | |
nameof(SingleValue) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment