<commit_before>// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using JetBrains.Annotations;

namespace osu.Framework.Configuration
{
    public class LeasedBindable<T> : Bindable<T>
    {
        private readonly Bindable<T> source;

        internal LeasedBindable([NotNull] Bindable<T> source)
        {
            BindTo(source);
            this.source = source ?? throw new ArgumentNullException(nameof(source));
        }

        public LeasedBindable(T value) : base(value)
        {
            // used for GetBoundCopy, where we don't want a source.
        }

        private bool hasBeenReturned;

        /// <summary>
        /// End the lease on the source <see cref="Bindable{T}"/>.
        /// </summary>
        public void Return()
        {
            if (source == null)
                throw new InvalidOperationException($"Must {nameof(Return)} from original leased source");

            if (hasBeenReturned)
                throw new InvalidOperationException($"This bindable has already been {nameof(Return)}ed.");

            UnbindAll();
        }

        public override T Value
        {
            get => source == null ? base.Value : source.Value;
            set
            {
                if (source == null)
                    SetValue(value, true);
                else
                {
                    checkValid();
                    source.SetValue(value, true, this);
                }
            }
        }

        public override bool Disabled
        {
            get => source?.Disabled ?? base.Disabled;
            set
            {
                if (source == null)
                    SetDisabled(value, true);
                else
                {
                    checkValid();
                    source.SetDisabled(value, true, this);
                }
            }
        }

        public override void UnbindAll()
        {
            if (!hasBeenReturned)
            {
                source.EndLease(this);
                hasBeenReturned = true;
            }

            base.UnbindAll();
        }

        private void checkValid()
        {
            if (source != null && hasBeenReturned)
                throw new InvalidOperationException($"Cannot perform operations on a {nameof(LeasedBindable<T>)} that has been {nameof(Return)}ed.");
        }
    }
}<commit_msg>Add check for source<commit_after>// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using JetBrains.Annotations;

namespace osu.Framework.Configuration
{
    public class LeasedBindable<T> : Bindable<T>
    {
        private readonly Bindable<T> source;

        internal LeasedBindable([NotNull] Bindable<T> source)
        {
            BindTo(source);
            this.source = source ?? throw new ArgumentNullException(nameof(source));
        }

        public LeasedBindable(T value) : base(value)
        {
            // used for GetBoundCopy, where we don't want a source.
        }

        private bool hasBeenReturned;

        /// <summary>
        /// End the lease on the source <see cref="Bindable{T}"/>.
        /// </summary>
        public void Return()
        {
            if (source == null)
                throw new InvalidOperationException($"Must {nameof(Return)} from original leased source");

            if (hasBeenReturned)
                throw new InvalidOperationException($"This bindable has already been {nameof(Return)}ed.");

            UnbindAll();
        }

        public override T Value
        {
            get => source == null ? base.Value : source.Value;
            set
            {
                if (source == null)
                    SetValue(value, true);
                else
                {
                    checkValid();
                    source.SetValue(value, true, this);
                }
            }
        }

        public override bool Disabled
        {
            get => source?.Disabled ?? base.Disabled;
            set
            {
                if (source == null)
                    SetDisabled(value, true);
                else
                {
                    checkValid();
                    source.SetDisabled(value, true, this);
                }
            }
        }

        public override void UnbindAll()
        {
            if (source != null && !hasBeenReturned)
            {
                source.EndLease(this);
                hasBeenReturned = true;
            }

            base.UnbindAll();
        }

        private void checkValid()
        {
            if (source != null && hasBeenReturned)
                throw new InvalidOperationException($"Cannot perform operations on a {nameof(LeasedBindable<T>)} that has been {nameof(Return)}ed.");
        }
    }
}
{'fraction_non_alphanumeric': 0.09777599679422962, 'fraction_numerical': 0.003205770386696053, 'mean_word_length': 1.3930968360498561, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6637700', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1223, 'n_words': 317}