// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; namespace osu.Framework.Bindables { /// /// A bindable which holds a reference to a bound target, allowing switching between targets and handling unbind/rebind. /// /// The type of our stored . public class BindableWithCurrent : Bindable, IBindableWithCurrent { private Bindable currentBound; public Bindable Current { get => this; set { if (value == null) throw new ArgumentNullException(nameof(value)); if (currentBound != null) UnbindFrom(currentBound); BindTo(currentBound = value); } } public BindableWithCurrent(T defaultValue = default) : base(defaultValue) { } protected override Bindable CreateInstance() => new BindableWithCurrent(); } }