// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using JetBrains.Annotations; using osu.Framework.Bindables; namespace osu.Game.Rulesets.Objects { /// /// Represents a wrapper containing a lazily-initialised , backed by a temporary field used for storage until initialisation. /// public struct HitObjectProperty { [CanBeNull] private Bindable backingBindable; /// /// A temporary field to store the current value to, prior to 's initialisation. /// private T backingValue; /// /// The underlying , only initialised on first access. /// public Bindable Bindable => backingBindable ??= new Bindable(defaultValue) { Value = backingValue }; /// /// The current value, derived from and delegated to if initialised, or a temporary field otherwise. /// public T Value { get => backingBindable != null ? backingBindable.Value : backingValue; set { if (backingBindable != null) backingBindable.Value = value; else backingValue = value; } } private readonly T defaultValue; public HitObjectProperty(T value = default) { backingValue = defaultValue = value; backingBindable = null; } } }