// ----------------------------------------------------------------------- // // Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { using System; /// /// A registered binding in a . /// internal class PriorityBindingEntry : IDisposable { /// /// The binding subscription. /// private IDisposable subscription; /// /// Initializes a new instance of the class. /// /// /// The binding index. Later bindings should have higher indexes. /// public PriorityBindingEntry(int index) { this.Index = index; } /// /// Gets the observable associated with the entry. /// public IObservable Observable { get; private set; } /// /// Gets a description of the binding. /// public string Description { get; private set; } /// /// Gets the binding entry index. Later bindings will have higher indexes. /// public int Index { get; } /// /// The current value of the binding. /// public object Value { get; private set; } /// /// Starts listening to the binding. /// /// The binding. /// Called when the binding changes. /// Called when the binding completes. public void Start( IObservable binding, Action changed, Action completed) { Contract.Requires(binding != null); Contract.Requires(changed != null); Contract.Requires(completed != null); if (this.subscription != null) { throw new Exception("PriorityValue.Entry.Start() called more than once."); } this.Observable = binding; this.Value = PerspexProperty.UnsetValue; if (binding is IDescription) { this.Description = ((IDescription)binding).Description; } this.subscription = binding.Subscribe( value => { this.Value = value; changed(this); }, () => completed(this)); } /// /// Ends the binding subscription. /// public void Dispose() { if (this.subscription != null) { this.subscription.Dispose(); } } } }