From 719179982124f6d56ccfdf2594b468689ec90227 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 13 Apr 2022 17:56:20 +0800 Subject: [PATCH 01/19] Enable NRT for Bindable --- osu.Framework/Bindables/Bindable.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 8afa5e469e..1e372efe60 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -11,6 +11,8 @@ using osu.Framework.IO.Serialization; using osu.Framework.Lists; +#nullable enable + namespace osu.Framework.Bindables { /// @@ -22,17 +24,17 @@ public class Bindable : IBindable, IBindable, IParseable, ISerializableBin /// /// An event which is raised when has changed (or manually via ). /// - public event Action> ValueChanged; + public event Action>? ValueChanged; /// /// An event which is raised when has changed (or manually via ). /// - public event Action DisabledChanged; + public event Action? DisabledChanged; /// /// An event which is raised when has changed (or manually via ). /// - public event Action> DefaultChanged; + public event Action>? DefaultChanged; private T value; @@ -57,7 +59,7 @@ public virtual bool Disabled } } - internal void SetDisabled(bool value, bool bypassChecks = false, Bindable source = null) + internal void SetDisabled(bool value, bool bypassChecks = false, Bindable? source = null) { if (!bypassChecks) throwIfLeased(); @@ -88,7 +90,7 @@ public virtual T Value // if the leased bindable decides to disable exclusive access (by setting Disabled = false) then anything will be able to write to Value. if (Disabled) - throw new InvalidOperationException($"Can not set value to \"{value.ToString()}\" as bindable is disabled."); + throw new InvalidOperationException($"Can not set value to \"{value}\" as bindable is disabled."); if (EqualityComparer.Default.Equals(this.value, value)) return; @@ -96,7 +98,7 @@ public virtual T Value } } - internal void SetValue(T previousValue, T value, bool bypassChecks = false, Bindable source = null) + internal void SetValue(T previousValue, T value, bool bypassChecks = false, Bindable? source = null) { this.value = value; TriggerValueChange(previousValue, source ?? this, true, bypassChecks); @@ -114,7 +116,7 @@ public virtual T Default // if the leased bindable decides to disable exclusive access (by setting Disabled = false) then anything will be able to write to Default. if (Disabled) - throw new InvalidOperationException($"Can not set default value to \"{value.ToString()}\" as bindable is disabled."); + throw new InvalidOperationException($"Can not set default value to \"{value}\" as bindable is disabled."); if (EqualityComparer.Default.Equals(defaultValue, value)) return; @@ -122,7 +124,7 @@ public virtual T Default } } - internal void SetDefaultValue(T previousValue, T value, bool bypassChecks = false, Bindable source = null) + internal void SetDefaultValue(T previousValue, T value, bool bypassChecks = false, Bindable? source = null) { defaultValue = value; TriggerDefaultChange(previousValue, source ?? this, true, bypassChecks); @@ -359,8 +361,7 @@ public void UnbindBindings() internal virtual void UnbindAllInternal() { - if (isLeased) - leasedBindable.Return(); + leasedBindable?.Return(); UnbindEvents(); UnbindBindings(); @@ -411,7 +412,7 @@ void ISerializableBindable.DeserializeFrom(JsonReader reader, JsonSerializer ser Value = serializer.Deserialize(reader); } - private LeasedBindable leasedBindable; + private LeasedBindable? leasedBindable; private bool isLeased => leasedBindable != null; From 3c3f9d7ae867aa28a7a0a2ac07766fb478fc28a0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 13 Apr 2022 18:06:40 +0800 Subject: [PATCH 02/19] Resolve and add comments for constructor and deserialization. --- osu.Framework/Bindables/Bindable.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 1e372efe60..aac4a24fb5 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -130,7 +130,7 @@ internal void SetDefaultValue(T previousValue, T value, bool bypassChecks = fals TriggerDefaultChange(previousValue, source ?? this, true, bypassChecks); } - private WeakReference> weakReferenceInstance; + private WeakReference>? weakReferenceInstance; private WeakReference> weakReference => weakReferenceInstance ??= new WeakReference>(this); @@ -139,7 +139,7 @@ internal void SetDefaultValue(T previousValue, T value, bool bypassChecks = fals /// [UsedImplicitly] private Bindable() - : this(default) + : this(default!) { } @@ -147,12 +147,15 @@ private Bindable() /// Creates a new bindable instance initialised with a default value. /// /// The initial and default value for this bindable. - public Bindable(T defaultValue = default) + /// Consider to pass a default value for non-nullable T. + public Bindable(T defaultValue = default!) { - value = Default = defaultValue; + // It lacks a way to represent "warn if called with non-nullable T". + // Not verifying to avoid breaking tons of existing usages. + value = this.defaultValue = defaultValue; } - protected LockedWeakList> Bindings { get; private set; } + protected LockedWeakList>? Bindings { get; private set; } void IBindable.BindTo(IBindable them) { @@ -254,7 +257,7 @@ public virtual void Parse(object input) default: if (underlyingType.IsEnum) - Value = (T)Enum.Parse(underlyingType, input.ToString()); + Value = (T)Enum.Parse(underlyingType, input.ToString()!); else Value = (T)Convert.ChangeType(input, underlyingType, CultureInfo.InvariantCulture); @@ -376,7 +379,7 @@ public virtual void UnbindFrom(IUnbindable them) tThem.removeWeakReference(weakReference); } - public string Description { get; set; } + public string? Description { get; set; } public override string ToString() => value?.ToString() ?? string.Empty; @@ -409,7 +412,8 @@ void ISerializableBindable.SerializeTo(JsonWriter writer, JsonSerializer seriali void ISerializableBindable.DeserializeFrom(JsonReader reader, JsonSerializer serializer) { - Value = serializer.Deserialize(reader); + // Deserialize returns null for json literal "null". + Value = serializer.Deserialize(reader)!; } private LeasedBindable? leasedBindable; From 1028d75aba79e97d99f5b5d1157682f691388239 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 13 Apr 2022 18:14:37 +0800 Subject: [PATCH 03/19] Nullable for bindable list --- osu.Framework/Bindables/BindableList.cs | 48 +++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 1399b64ca4..f11f9c816d 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -9,6 +9,8 @@ using osu.Framework.Caching; using osu.Framework.Lists; +#nullable enable + namespace osu.Framework.Bindables { public class BindableList : IBindableList, IBindable, IParseable, IList, IList @@ -16,12 +18,12 @@ public class BindableList : IBindableList, IBindable, IParseable, IList /// /// An event which is raised when this changes. /// - public event NotifyCollectionChangedEventHandler CollectionChanged; + public event NotifyCollectionChangedEventHandler? CollectionChanged; /// /// An event which is raised when 's state has changed (or manually via ). /// - public event Action DisabledChanged; + public event Action? DisabledChanged; private readonly List collection = new List(); @@ -29,13 +31,13 @@ public class BindableList : IBindableList, IBindable, IParseable, IList private WeakReference> weakReference => weakReferenceCache.IsValid ? weakReferenceCache.Value : weakReferenceCache.Value = new WeakReference>(this); - private LockedWeakList> bindings; + private LockedWeakList>? bindings; /// /// Creates a new , optionally adding the items of the given collection. /// /// The items that are going to be contained in the newly created . - public BindableList(IEnumerable items = null) + public BindableList(IEnumerable? items = null) { if (items != null) collection.AddRange(items); @@ -54,7 +56,7 @@ public T this[int index] set => setIndex(index, value, null); } - private void setIndex(int index, T item, BindableList caller) + private void setIndex(int index, T item, BindableList? caller) { ensureMutationAllowed(); @@ -84,7 +86,7 @@ private void setIndex(int index, T item, BindableList caller) public void Add(T item) => add(item, null); - private void add(T item, BindableList caller) + private void add(T item, BindableList? caller) { ensureMutationAllowed(); @@ -120,7 +122,7 @@ private void add(T item, BindableList caller) public void Insert(int index, T item) => insert(index, item, null); - private void insert(int index, T item, BindableList caller) + private void insert(int index, T item, BindableList? caller) { ensureMutationAllowed(); @@ -147,7 +149,7 @@ private void insert(int index, T item, BindableList caller) public void Clear() => clear(null); - private void clear(BindableList caller) + private void clear(BindableList? caller) { ensureMutationAllowed(); @@ -190,7 +192,7 @@ public bool Contains(T item) public bool Remove(T item) => remove(item, null); - private bool remove(T item, BindableList caller) + private bool remove(T item, BindableList? caller) { ensureMutationAllowed(); @@ -231,7 +233,7 @@ public void RemoveRange(int index, int count) removeRange(index, count, null); } - private void removeRange(int index, int count, BindableList caller) + private void removeRange(int index, int count, BindableList? caller) { ensureMutationAllowed(); @@ -264,7 +266,7 @@ private void removeRange(int index, int count, BindableList caller) public void RemoveAt(int index) => removeAt(index, null); - private void removeAt(int index, BindableList caller) + private void removeAt(int index, BindableList? caller) { ensureMutationAllowed(); @@ -293,7 +295,7 @@ private void removeAt(int index, BindableList caller) public int RemoveAll(Predicate match) => removeAll(match, null); - private int removeAll(Predicate match, BindableList caller) + private int removeAll(Predicate match, BindableList? caller) { ensureMutationAllowed(); @@ -347,25 +349,25 @@ public void CopyTo(Array array, int index) #region IList - object IList.this[int index] + object? IList.this[int index] { get => this[index]; - set => this[index] = (T)value; + set => this[index] = (T)value!; } - int IList.Add(object value) + int IList.Add(object? value) { - Add((T)value); + Add((T)value!); return Count - 1; } - bool IList.Contains(object value) => Contains((T)value); + bool IList.Contains(object? value) => Contains((T)value!); - int IList.IndexOf(object value) => IndexOf((T)value); + int IList.IndexOf(object? value) => IndexOf((T)value!); - void IList.Insert(int index, object value) => Insert(index, (T)value); + void IList.Insert(int index, object? value) => Insert(index, (T)value!); - void IList.Remove(object value) => Remove((T)value); + void IList.Remove(object? value) => Remove((T)value!); bool IList.IsFixedSize => false; @@ -488,7 +490,7 @@ public virtual void UnbindFrom(IUnbindable them) #region IHasDescription - public string Description { get; set; } + public string? Description { get; set; } #endregion IHasDescription @@ -502,7 +504,7 @@ public virtual void UnbindFrom(IUnbindable them) public void AddRange(IEnumerable items) => addRange(items as IList ?? items.ToArray(), null); - private void addRange(IList items, BindableList caller) + private void addRange(IList items, BindableList? caller) { ensureMutationAllowed(); @@ -530,7 +532,7 @@ private void addRange(IList items, BindableList caller) public void Move(int oldIndex, int newIndex) => move(oldIndex, newIndex, null); - private void move(int oldIndex, int newIndex, BindableList caller) + private void move(int oldIndex, int newIndex, BindableList? caller) { ensureMutationAllowed(); From 53abe186fb790b0116fd8f2397e0e5eee4840ee5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 13 Apr 2022 18:25:38 +0800 Subject: [PATCH 04/19] Enable nullable for other bindables --- osu.Framework/Bindables/AggregateBindable.cs | 8 +++++--- osu.Framework/Bindables/BindableNumber.cs | 6 ++++-- osu.Framework/Bindables/BindableNumberWithCurrent.cs | 4 +++- osu.Framework/Bindables/BindableSize.cs | 2 ++ osu.Framework/Bindables/BindableWithCurrent.cs | 7 +++++-- osu.Framework/Bindables/IBindable.cs | 2 ++ osu.Framework/Bindables/IBindableList.cs | 2 ++ osu.Framework/Bindables/IBindableNumber.cs | 2 ++ osu.Framework/Bindables/IBindableWithCurrent.cs | 4 +++- osu.Framework/Bindables/ICanBeDisabled.cs | 2 ++ osu.Framework/Bindables/IHasDescription.cs | 4 +++- osu.Framework/Bindables/IParseable.cs | 2 ++ osu.Framework/Bindables/IUnbindable.cs | 2 ++ osu.Framework/Bindables/LeasedBindable.cs | 11 ++++++----- osu.Framework/Bindables/NonNullableBindable.cs | 2 ++ osu.Framework/Bindables/RangeConstrainedBindable.cs | 12 +++++++----- osu.Framework/Bindables/ValueChangedEvent.cs | 2 ++ 17 files changed, 54 insertions(+), 20 deletions(-) diff --git a/osu.Framework/Bindables/AggregateBindable.cs b/osu.Framework/Bindables/AggregateBindable.cs index 1432bad461..443bd03de0 100644 --- a/osu.Framework/Bindables/AggregateBindable.cs +++ b/osu.Framework/Bindables/AggregateBindable.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Linq; +#nullable enable + namespace osu.Framework.Bindables { /// @@ -29,7 +31,7 @@ public class AggregateBindable /// /// The function to be used for aggregation, taking two input values and returning one output. /// An optional newly constructed bindable to use for . The initial value of this bindable is used as the initial value for the aggregate. - public AggregateBindable(Func aggregateFunction, Bindable resultBindable = null) + public AggregateBindable(Func aggregateFunction, Bindable? resultBindable = null) { this.aggregateFunction = aggregateFunction; result = resultBindable ?? new Bindable(); @@ -75,10 +77,10 @@ public void RemoveSource(IBindable bindable) } } - private WeakRefPair findExistingPair(IBindable bindable) => + private WeakRefPair? findExistingPair(IBindable bindable) => sourceMapping.FirstOrDefault(p => p.WeakReference.TryGetTarget(out var target) && target == bindable); - private void recalculateAggregate(ValueChangedEvent obj = null) + private void recalculateAggregate(ValueChangedEvent? obj = null) { T calculated = initialValue; diff --git a/osu.Framework/Bindables/BindableNumber.cs b/osu.Framework/Bindables/BindableNumber.cs index babedfd3af..c7f2fb2081 100644 --- a/osu.Framework/Bindables/BindableNumber.cs +++ b/osu.Framework/Bindables/BindableNumber.cs @@ -6,12 +6,14 @@ using System.Globalization; using osu.Framework.Utils; +#nullable enable + namespace osu.Framework.Bindables { public class BindableNumber : RangeConstrainedBindable, IBindableNumber where T : struct, IComparable, IConvertible, IEquatable { - public event Action PrecisionChanged; + public event Action? PrecisionChanged; public BindableNumber(T defaultValue = default) : base(defaultValue) @@ -177,7 +179,7 @@ public override void TriggerChange() TriggerPrecisionChange(this, false); } - protected void TriggerPrecisionChange(BindableNumber source = null, bool propagateToBindings = true) + protected void TriggerPrecisionChange(BindableNumber? source = null, bool propagateToBindings = true) { // check a bound bindable hasn't changed the value again (it will fire its own event) T beforePropagation = precision; diff --git a/osu.Framework/Bindables/BindableNumberWithCurrent.cs b/osu.Framework/Bindables/BindableNumberWithCurrent.cs index 2082ec4a40..890e782f24 100644 --- a/osu.Framework/Bindables/BindableNumberWithCurrent.cs +++ b/osu.Framework/Bindables/BindableNumberWithCurrent.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Framework.Bindables { /// @@ -12,7 +14,7 @@ namespace osu.Framework.Bindables public class BindableNumberWithCurrent : BindableNumber, IBindableWithCurrent where T : struct, IComparable, IConvertible, IEquatable { - private BindableNumber currentBound; + private BindableNumber? currentBound; public Bindable Current { diff --git a/osu.Framework/Bindables/BindableSize.cs b/osu.Framework/Bindables/BindableSize.cs index f2f3157fee..815345cc58 100644 --- a/osu.Framework/Bindables/BindableSize.cs +++ b/osu.Framework/Bindables/BindableSize.cs @@ -4,6 +4,8 @@ using System; using System.Drawing; +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/BindableWithCurrent.cs b/osu.Framework/Bindables/BindableWithCurrent.cs index 1f7e05ec0d..f1cb051c45 100644 --- a/osu.Framework/Bindables/BindableWithCurrent.cs +++ b/osu.Framework/Bindables/BindableWithCurrent.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Framework.Bindables { /// @@ -11,7 +13,7 @@ namespace osu.Framework.Bindables /// The type of our stored . public class BindableWithCurrent : Bindable, IBindableWithCurrent { - private Bindable currentBound; + private Bindable? currentBound; public Bindable Current { @@ -26,9 +28,10 @@ public Bindable Current } } - public BindableWithCurrent(T defaultValue = default) + public BindableWithCurrent(T defaultValue = default!) : base(defaultValue) { + // Not verifying, as base Bindable constructor } protected override Bindable CreateInstance() => new BindableWithCurrent(); diff --git a/osu.Framework/Bindables/IBindable.cs b/osu.Framework/Bindables/IBindable.cs index 80bd1ee0cb..3973db4cdf 100644 --- a/osu.Framework/Bindables/IBindable.cs +++ b/osu.Framework/Bindables/IBindable.cs @@ -5,6 +5,8 @@ using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Utils; +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IBindableList.cs b/osu.Framework/Bindables/IBindableList.cs index 92d9518340..819dae0580 100644 --- a/osu.Framework/Bindables/IBindableList.cs +++ b/osu.Framework/Bindables/IBindableList.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Collections.Specialized; +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IBindableNumber.cs b/osu.Framework/Bindables/IBindableNumber.cs index da4ecd735b..0836154821 100644 --- a/osu.Framework/Bindables/IBindableNumber.cs +++ b/osu.Framework/Bindables/IBindableNumber.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Framework.Bindables { public interface IBindableNumber : IBindable diff --git a/osu.Framework/Bindables/IBindableWithCurrent.cs b/osu.Framework/Bindables/IBindableWithCurrent.cs index 498324cb50..e623ba7cce 100644 --- a/osu.Framework/Bindables/IBindableWithCurrent.cs +++ b/osu.Framework/Bindables/IBindableWithCurrent.cs @@ -5,6 +5,8 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; +#nullable enable + namespace osu.Framework.Bindables { public interface IBindableWithCurrent : IBindable, IHasCurrentValue @@ -17,7 +19,7 @@ public interface IBindableWithCurrent : IBindable, IHasCurrentValue public static IBindableWithCurrent Create() { if (Validation.IsSupportedBindableNumberType()) - return (IBindableWithCurrent)Activator.CreateInstance(typeof(BindableNumberWithCurrent<>).MakeGenericType(typeof(T)), default(T)); + return (IBindableWithCurrent)Activator.CreateInstance(typeof(BindableNumberWithCurrent<>).MakeGenericType(typeof(T)), default(T))!; return new BindableWithCurrent(); } diff --git a/osu.Framework/Bindables/ICanBeDisabled.cs b/osu.Framework/Bindables/ICanBeDisabled.cs index d6a8e55ffd..60bd0876da 100644 --- a/osu.Framework/Bindables/ICanBeDisabled.cs +++ b/osu.Framework/Bindables/ICanBeDisabled.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IHasDescription.cs b/osu.Framework/Bindables/IHasDescription.cs index a5660e15b9..737ecd13f8 100644 --- a/osu.Framework/Bindables/IHasDescription.cs +++ b/osu.Framework/Bindables/IHasDescription.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + namespace osu.Framework.Bindables { /// @@ -11,6 +13,6 @@ public interface IHasDescription /// /// The description for this object. /// - string Description { get; } + string? Description { get; } } } diff --git a/osu.Framework/Bindables/IParseable.cs b/osu.Framework/Bindables/IParseable.cs index c45202bb0e..a81d3199b5 100644 --- a/osu.Framework/Bindables/IParseable.cs +++ b/osu.Framework/Bindables/IParseable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IUnbindable.cs b/osu.Framework/Bindables/IUnbindable.cs index 963b1333bb..2fc78aef5f 100644 --- a/osu.Framework/Bindables/IUnbindable.cs +++ b/osu.Framework/Bindables/IUnbindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/LeasedBindable.cs b/osu.Framework/Bindables/LeasedBindable.cs index 97ca32c643..e2f9fb3e21 100644 --- a/osu.Framework/Bindables/LeasedBindable.cs +++ b/osu.Framework/Bindables/LeasedBindable.cs @@ -3,7 +3,8 @@ using System; using System.Collections.Generic; -using JetBrains.Annotations; + +#nullable enable namespace osu.Framework.Bindables { @@ -14,13 +15,13 @@ namespace osu.Framework.Bindables /// public class LeasedBindable : Bindable, ILeasedBindable { - private readonly Bindable source; + private readonly Bindable? source; - private readonly T valueBeforeLease; + private readonly T valueBeforeLease = default!; private readonly bool disabledBeforeLease; private readonly bool revertValueOnReturn; - internal LeasedBindable([NotNull] Bindable source, bool revertValueOnReturn) + internal LeasedBindable(Bindable source, bool revertValueOnReturn) { BindTo(source); @@ -37,7 +38,7 @@ internal LeasedBindable([NotNull] Bindable source, bool revertValueOnReturn) Disabled = true; } - private LeasedBindable(T defaultValue = default) + private LeasedBindable(T defaultValue = default!) : base(defaultValue) { // used for GetBoundCopy, where we don't want a source. diff --git a/osu.Framework/Bindables/NonNullableBindable.cs b/osu.Framework/Bindables/NonNullableBindable.cs index 4d376b6fae..aa753b6a29 100644 --- a/osu.Framework/Bindables/NonNullableBindable.cs +++ b/osu.Framework/Bindables/NonNullableBindable.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Framework.Bindables { public class NonNullableBindable : Bindable diff --git a/osu.Framework/Bindables/RangeConstrainedBindable.cs b/osu.Framework/Bindables/RangeConstrainedBindable.cs index 2ae5f5b770..0f7fa3d091 100644 --- a/osu.Framework/Bindables/RangeConstrainedBindable.cs +++ b/osu.Framework/Bindables/RangeConstrainedBindable.cs @@ -4,13 +4,15 @@ using System; using System.Collections.Generic; +#nullable enable + namespace osu.Framework.Bindables { public abstract class RangeConstrainedBindable : Bindable { - public event Action MinValueChanged; + public event Action? MinValueChanged; - public event Action MaxValueChanged; + public event Action? MaxValueChanged; private T minValue; @@ -62,7 +64,7 @@ public override T Value public bool HasDefinedRange => !EqualityComparer.Default.Equals(MinValue, DefaultMinValue) || !EqualityComparer.Default.Equals(MaxValue, DefaultMaxValue); - protected RangeConstrainedBindable(T defaultValue = default) + protected RangeConstrainedBindable(T defaultValue = default!) : base(defaultValue) { minValue = DefaultMinValue; @@ -116,7 +118,7 @@ public override void TriggerChange() TriggerMaxValueChange(this, false); } - protected void TriggerMinValueChange(RangeConstrainedBindable source = null, bool propagateToBindings = true) + protected void TriggerMinValueChange(RangeConstrainedBindable? source = null, bool propagateToBindings = true) { // check a bound bindable hasn't changed the value again (it will fire its own event) T beforePropagation = minValue; @@ -136,7 +138,7 @@ protected void TriggerMinValueChange(RangeConstrainedBindable source = null, MinValueChanged?.Invoke(minValue); } - protected void TriggerMaxValueChange(RangeConstrainedBindable source = null, bool propagateToBindings = true) + protected void TriggerMaxValueChange(RangeConstrainedBindable? source = null, bool propagateToBindings = true) { // check a bound bindable hasn't changed the value again (it will fire its own event) T beforePropagation = maxValue; diff --git a/osu.Framework/Bindables/ValueChangedEvent.cs b/osu.Framework/Bindables/ValueChangedEvent.cs index 9809faf052..6a958271b1 100644 --- a/osu.Framework/Bindables/ValueChangedEvent.cs +++ b/osu.Framework/Bindables/ValueChangedEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + namespace osu.Framework.Bindables { /// From 6650687ad042202c03da00628d6e5cd5e0da4efd Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 13 Apr 2022 18:42:22 +0800 Subject: [PATCH 05/19] Enable nullable for LocalisableBindableString --- osu.Framework/Localisation/ILocalisedBindableString.cs | 2 ++ .../LocalisationManager_LocalisedBindableString.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Localisation/ILocalisedBindableString.cs b/osu.Framework/Localisation/ILocalisedBindableString.cs index f0756ffcb3..265e628897 100644 --- a/osu.Framework/Localisation/ILocalisedBindableString.cs +++ b/osu.Framework/Localisation/ILocalisedBindableString.cs @@ -3,6 +3,8 @@ using osu.Framework.Bindables; +#nullable enable + namespace osu.Framework.Localisation { /// diff --git a/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs b/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs index c9a6011c7d..28046fcfc3 100644 --- a/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs +++ b/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#pragma warning disable 8632 // TODO: can be #nullable enable when Bindables are updated to also be. +#nullable enable using osu.Framework.Bindables; @@ -11,7 +11,7 @@ public partial class LocalisationManager { private class LocalisedBindableString : Bindable, ILocalisedBindableString { - private IBindable parameters; + private IBindable? parameters; private LocalisableString text; From 3e88848ade03ebd6d7d4d19d4ab0f8e78b16068a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 14 Apr 2022 13:37:49 +0800 Subject: [PATCH 06/19] Disable aggressive warning about nullable --- osu-framework.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/osu-framework.sln.DotSettings b/osu-framework.sln.DotSettings index af8804c371..6b6240a5dc 100644 --- a/osu-framework.sln.DotSettings +++ b/osu-framework.sln.DotSettings @@ -58,6 +58,7 @@ HINT HINT HINT + HINT HINT DO_NOT_SHOW WARNING From fe5b8b63ce999785725ddb7d3ef2068c54eeba10 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 17 Apr 2022 14:43:37 +0800 Subject: [PATCH 07/19] Apply suggestion from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Framework/Bindables/Bindable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index aac4a24fb5..e901605d94 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -147,7 +147,7 @@ private Bindable() /// Creates a new bindable instance initialised with a default value. /// /// The initial and default value for this bindable. - /// Consider to pass a default value for non-nullable T. + /// Consider to pass a default value for non-nullable . public Bindable(T defaultValue = default!) { // It lacks a way to represent "warn if called with non-nullable T". From 6ada9f54aac4e96be3c59e6fb912e248b0ed321f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 29 Jun 2022 23:12:35 +0800 Subject: [PATCH 08/19] Remove unnecessary #nullable for bindables --- osu.Framework/Bindables/AggregateBindable.cs | 4 ---- osu.Framework/Bindables/Bindable.cs | 4 ---- osu.Framework/Bindables/BindableBool.cs | 2 -- osu.Framework/Bindables/BindableDouble.cs | 2 -- osu.Framework/Bindables/BindableFloat.cs | 2 -- osu.Framework/Bindables/BindableInt.cs | 2 -- osu.Framework/Bindables/BindableList.cs | 4 ---- osu.Framework/Bindables/BindableLong.cs | 2 -- osu.Framework/Bindables/BindableMarginPadding.cs | 2 -- osu.Framework/Bindables/BindableNumber.cs | 4 ---- osu.Framework/Bindables/BindableNumberWithCurrent.cs | 4 ---- osu.Framework/Bindables/BindableSafeArea.cs | 2 -- osu.Framework/Bindables/BindableSize.cs | 4 ---- osu.Framework/Bindables/BindableWithCurrent.cs | 4 ---- osu.Framework/Bindables/IBindable.cs | 4 ---- osu.Framework/Bindables/IBindableList.cs | 4 ---- osu.Framework/Bindables/IBindableNumber.cs | 4 ---- osu.Framework/Bindables/IBindableWithCurrent.cs | 4 ---- osu.Framework/Bindables/ICanBeDisabled.cs | 4 ---- osu.Framework/Bindables/IHasDefaultValue.cs | 2 -- osu.Framework/Bindables/ILeasedBindable.cs | 2 -- osu.Framework/Bindables/LeasedBindable.cs | 4 ---- osu.Framework/Bindables/NonNullableBindable.cs | 4 ---- osu.Framework/Bindables/RangeConstrainedBindable.cs | 4 ---- 24 files changed, 78 deletions(-) diff --git a/osu.Framework/Bindables/AggregateBindable.cs b/osu.Framework/Bindables/AggregateBindable.cs index 21108b485a..4237f7a65d 100644 --- a/osu.Framework/Bindables/AggregateBindable.cs +++ b/osu.Framework/Bindables/AggregateBindable.cs @@ -1,14 +1,10 @@ // 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 System; using System.Collections.Generic; using System.Linq; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index dbd3c8b639..dda31c2a4f 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -1,8 +1,6 @@ // 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 System; using System.Collections.Generic; using System.Globalization; @@ -13,8 +11,6 @@ using osu.Framework.IO.Serialization; using osu.Framework.Lists; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/BindableBool.cs b/osu.Framework/Bindables/BindableBool.cs index add13c38d4..90e19345f5 100644 --- a/osu.Framework/Bindables/BindableBool.cs +++ b/osu.Framework/Bindables/BindableBool.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Framework.Bindables { public class BindableBool : Bindable diff --git a/osu.Framework/Bindables/BindableDouble.cs b/osu.Framework/Bindables/BindableDouble.cs index 0c84ce1a97..bbac0f8b3b 100644 --- a/osu.Framework/Bindables/BindableDouble.cs +++ b/osu.Framework/Bindables/BindableDouble.cs @@ -1,8 +1,6 @@ // 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 System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableFloat.cs b/osu.Framework/Bindables/BindableFloat.cs index 70f77b3020..8e960f8a54 100644 --- a/osu.Framework/Bindables/BindableFloat.cs +++ b/osu.Framework/Bindables/BindableFloat.cs @@ -1,8 +1,6 @@ // 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 System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableInt.cs b/osu.Framework/Bindables/BindableInt.cs index 096045f613..67d2056f5c 100644 --- a/osu.Framework/Bindables/BindableInt.cs +++ b/osu.Framework/Bindables/BindableInt.cs @@ -1,8 +1,6 @@ // 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 System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 8dc77166fc..dd562a6959 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -1,8 +1,6 @@ // 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 System; using System.Collections; using System.Collections.Generic; @@ -11,8 +9,6 @@ using osu.Framework.Caching; using osu.Framework.Lists; -#nullable enable - namespace osu.Framework.Bindables { public class BindableList : IBindableList, IBindable, IParseable, IList, IList diff --git a/osu.Framework/Bindables/BindableLong.cs b/osu.Framework/Bindables/BindableLong.cs index e7236f9376..63f2b5416b 100644 --- a/osu.Framework/Bindables/BindableLong.cs +++ b/osu.Framework/Bindables/BindableLong.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Framework.Bindables { public class BindableLong : BindableNumber diff --git a/osu.Framework/Bindables/BindableMarginPadding.cs b/osu.Framework/Bindables/BindableMarginPadding.cs index 91169db696..2378e2826b 100644 --- a/osu.Framework/Bindables/BindableMarginPadding.cs +++ b/osu.Framework/Bindables/BindableMarginPadding.cs @@ -1,8 +1,6 @@ // 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 System; using System.Globalization; using osu.Framework.Graphics; diff --git a/osu.Framework/Bindables/BindableNumber.cs b/osu.Framework/Bindables/BindableNumber.cs index e3c0f7ffc0..747e40a9d6 100644 --- a/osu.Framework/Bindables/BindableNumber.cs +++ b/osu.Framework/Bindables/BindableNumber.cs @@ -1,15 +1,11 @@ // 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 System; using System.Diagnostics; using System.Globalization; using osu.Framework.Utils; -#nullable enable - namespace osu.Framework.Bindables { public class BindableNumber : RangeConstrainedBindable, IBindableNumber diff --git a/osu.Framework/Bindables/BindableNumberWithCurrent.cs b/osu.Framework/Bindables/BindableNumberWithCurrent.cs index a2a342ed69..5dfc596537 100644 --- a/osu.Framework/Bindables/BindableNumberWithCurrent.cs +++ b/osu.Framework/Bindables/BindableNumberWithCurrent.cs @@ -1,12 +1,8 @@ // 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 System; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/BindableSafeArea.cs b/osu.Framework/Bindables/BindableSafeArea.cs index e69a9d009a..9489e5ff95 100644 --- a/osu.Framework/Bindables/BindableSafeArea.cs +++ b/osu.Framework/Bindables/BindableSafeArea.cs @@ -1,8 +1,6 @@ // 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 osu.Framework.Graphics; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableSize.cs b/osu.Framework/Bindables/BindableSize.cs index 8a2c203b60..f2f3157fee 100644 --- a/osu.Framework/Bindables/BindableSize.cs +++ b/osu.Framework/Bindables/BindableSize.cs @@ -1,13 +1,9 @@ // 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 System; using System.Drawing; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/BindableWithCurrent.cs b/osu.Framework/Bindables/BindableWithCurrent.cs index 88aac01f7a..8acc34daef 100644 --- a/osu.Framework/Bindables/BindableWithCurrent.cs +++ b/osu.Framework/Bindables/BindableWithCurrent.cs @@ -1,12 +1,8 @@ // 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 System; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IBindable.cs b/osu.Framework/Bindables/IBindable.cs index 6f79fb737c..80bd1ee0cb 100644 --- a/osu.Framework/Bindables/IBindable.cs +++ b/osu.Framework/Bindables/IBindable.cs @@ -1,14 +1,10 @@ // 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 System; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Utils; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IBindableList.cs b/osu.Framework/Bindables/IBindableList.cs index 31f6932dc9..92d9518340 100644 --- a/osu.Framework/Bindables/IBindableList.cs +++ b/osu.Framework/Bindables/IBindableList.cs @@ -1,13 +1,9 @@ // 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 System.Collections.Generic; using System.Collections.Specialized; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IBindableNumber.cs b/osu.Framework/Bindables/IBindableNumber.cs index a7f273e10a..da4ecd735b 100644 --- a/osu.Framework/Bindables/IBindableNumber.cs +++ b/osu.Framework/Bindables/IBindableNumber.cs @@ -1,12 +1,8 @@ // 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 System; -#nullable enable - namespace osu.Framework.Bindables { public interface IBindableNumber : IBindable diff --git a/osu.Framework/Bindables/IBindableWithCurrent.cs b/osu.Framework/Bindables/IBindableWithCurrent.cs index 7116f45587..911c7fd04b 100644 --- a/osu.Framework/Bindables/IBindableWithCurrent.cs +++ b/osu.Framework/Bindables/IBindableWithCurrent.cs @@ -1,14 +1,10 @@ // 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 System; using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; -#nullable enable - namespace osu.Framework.Bindables { public interface IBindableWithCurrent : IBindable, IHasCurrentValue diff --git a/osu.Framework/Bindables/ICanBeDisabled.cs b/osu.Framework/Bindables/ICanBeDisabled.cs index ee3d749695..d6a8e55ffd 100644 --- a/osu.Framework/Bindables/ICanBeDisabled.cs +++ b/osu.Framework/Bindables/ICanBeDisabled.cs @@ -1,12 +1,8 @@ // 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 System; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IHasDefaultValue.cs b/osu.Framework/Bindables/IHasDefaultValue.cs index b9387d567e..e3eee44a2f 100644 --- a/osu.Framework/Bindables/IHasDefaultValue.cs +++ b/osu.Framework/Bindables/IHasDefaultValue.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/ILeasedBindable.cs b/osu.Framework/Bindables/ILeasedBindable.cs index 2b21cb4541..b5f04f94f1 100644 --- a/osu.Framework/Bindables/ILeasedBindable.cs +++ b/osu.Framework/Bindables/ILeasedBindable.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/LeasedBindable.cs b/osu.Framework/Bindables/LeasedBindable.cs index 55dcddac66..32d7f0d051 100644 --- a/osu.Framework/Bindables/LeasedBindable.cs +++ b/osu.Framework/Bindables/LeasedBindable.cs @@ -1,13 +1,9 @@ // 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 System; using System.Collections.Generic; -#nullable enable - namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/NonNullableBindable.cs b/osu.Framework/Bindables/NonNullableBindable.cs index e7cde41e63..4d376b6fae 100644 --- a/osu.Framework/Bindables/NonNullableBindable.cs +++ b/osu.Framework/Bindables/NonNullableBindable.cs @@ -1,12 +1,8 @@ // 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 System; -#nullable enable - namespace osu.Framework.Bindables { public class NonNullableBindable : Bindable diff --git a/osu.Framework/Bindables/RangeConstrainedBindable.cs b/osu.Framework/Bindables/RangeConstrainedBindable.cs index f63215e585..9932040517 100644 --- a/osu.Framework/Bindables/RangeConstrainedBindable.cs +++ b/osu.Framework/Bindables/RangeConstrainedBindable.cs @@ -1,13 +1,9 @@ // 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 System; using System.Collections.Generic; -#nullable enable - namespace osu.Framework.Bindables { public abstract class RangeConstrainedBindable : Bindable From abd2caaccd272c9ce3cc25efbe3c482b423c2129 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 29 Jun 2022 23:35:55 +0800 Subject: [PATCH 09/19] Revert "Disable aggressive warning about nullable" This reverts commit 3e88848ade03ebd6d7d4d19d4ab0f8e78b16068a. --- osu-framework.sln.DotSettings | 1 - 1 file changed, 1 deletion(-) diff --git a/osu-framework.sln.DotSettings b/osu-framework.sln.DotSettings index 29656ed3bd..6c41a91352 100644 --- a/osu-framework.sln.DotSettings +++ b/osu-framework.sln.DotSettings @@ -62,7 +62,6 @@ HINT HINT HINT - HINT HINT DO_NOT_SHOW WARNING From 706cfe78b9b0c5d609cdac860e1e5ad159d4e421 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 30 Jun 2022 00:04:48 +0800 Subject: [PATCH 10/19] Mark OnMixerChanged as nullable based on usage analysis --- osu.Framework/Graphics/Audio/DrawableSample.cs | 2 +- osu.Framework/Graphics/Audio/DrawableTrack.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Graphics/Audio/DrawableSample.cs b/osu.Framework/Graphics/Audio/DrawableSample.cs index c6e0e9666a..2b9d29481a 100644 --- a/osu.Framework/Graphics/Audio/DrawableSample.cs +++ b/osu.Framework/Graphics/Audio/DrawableSample.cs @@ -53,7 +53,7 @@ public SampleChannel GetChannel() private IAudioMixer? mixer; - protected override void OnMixerChanged(ValueChangedEvent mixer) + protected override void OnMixerChanged(ValueChangedEvent mixer) { base.OnMixerChanged(mixer); diff --git a/osu.Framework/Graphics/Audio/DrawableTrack.cs b/osu.Framework/Graphics/Audio/DrawableTrack.cs index aaaece9e17..37fc052e3c 100644 --- a/osu.Framework/Graphics/Audio/DrawableTrack.cs +++ b/osu.Framework/Graphics/Audio/DrawableTrack.cs @@ -106,7 +106,7 @@ public void ResetSpeedAdjustments() /// public bool TrackLoaded => track.IsLoaded; - protected override void OnMixerChanged(ValueChangedEvent mixer) + protected override void OnMixerChanged(ValueChangedEvent mixer) { base.OnMixerChanged(mixer); From 8f7fb1b741b9313b053b62e7e2a41f6732827cb5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 30 Jun 2022 00:15:19 +0800 Subject: [PATCH 11/19] Update comments from suggestion --- osu.Framework/Bindables/Bindable.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index dda31c2a4f..de132e5a10 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -7,6 +7,7 @@ using System.Linq; using JetBrains.Annotations; using Newtonsoft.Json; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.IO.Serialization; using osu.Framework.Lists; @@ -145,11 +146,10 @@ private Bindable() /// Creates a new bindable instance initialised with a default value. /// /// The initial and default value for this bindable. - /// Consider to pass a default value for non-nullable . + /// Consider passing a default value for non-nullable . public Bindable(T defaultValue = default!) { - // It lacks a way to represent "warn if called with non-nullable T". - // Not verifying to avoid breaking tons of existing usages. + // TODO: add a custom analyser warning about no default value provided for non-nullable T value = this.defaultValue = defaultValue; } @@ -362,7 +362,9 @@ public void UnbindBindings() internal virtual void UnbindAllInternal() { - leasedBindable?.Return(); + // TODO: annotate isLeased with [MemberNotNull(nameof(leasedBindable))] on .NET 5+ to satisfy the nullability check + if (isLeased) + leasedBindable.AsNonNull().Return(); UnbindEvents(); UnbindBindings(); From 7b1594ffa8ed1ce524d204099d12739f71227f1f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 2 Jul 2022 12:25:25 +0800 Subject: [PATCH 12/19] Update more comments based on code review --- osu.Framework/Bindables/Bindable.cs | 2 +- osu.Framework/Bindables/BindableWithCurrent.cs | 1 - osu.Framework/Localisation/ILocalisedBindableString.cs | 4 ---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index de132e5a10..c4bd11d645 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -146,10 +146,10 @@ private Bindable() /// Creates a new bindable instance initialised with a default value. /// /// The initial and default value for this bindable. - /// Consider passing a default value for non-nullable . public Bindable(T defaultValue = default!) { // TODO: add a custom analyser warning about no default value provided for non-nullable T + // remember to also check for derived class constructors value = this.defaultValue = defaultValue; } diff --git a/osu.Framework/Bindables/BindableWithCurrent.cs b/osu.Framework/Bindables/BindableWithCurrent.cs index 8acc34daef..500301dd16 100644 --- a/osu.Framework/Bindables/BindableWithCurrent.cs +++ b/osu.Framework/Bindables/BindableWithCurrent.cs @@ -29,7 +29,6 @@ public Bindable Current public BindableWithCurrent(T defaultValue = default!) : base(defaultValue) { - // Not verifying, as base Bindable constructor } protected override Bindable CreateInstance() => new BindableWithCurrent(); diff --git a/osu.Framework/Localisation/ILocalisedBindableString.cs b/osu.Framework/Localisation/ILocalisedBindableString.cs index a123d48ef6..f0756ffcb3 100644 --- a/osu.Framework/Localisation/ILocalisedBindableString.cs +++ b/osu.Framework/Localisation/ILocalisedBindableString.cs @@ -1,12 +1,8 @@ // 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 osu.Framework.Bindables; -#nullable enable - namespace osu.Framework.Localisation { /// From 5a4090618b99a1e132d45b37312b95dabe5eaaac Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 2 Jul 2022 11:23:19 +0300 Subject: [PATCH 13/19] Replace null-forgiving operator with `AsNonNull` --- osu.Framework/Bindables/Bindable.cs | 7 +++++-- osu.Framework/Bindables/BindableList.cs | 13 +++++++------ osu.Framework/Bindables/IBindableWithCurrent.cs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index c4bd11d645..eba347f622 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Linq; using JetBrains.Annotations; @@ -255,7 +256,7 @@ public virtual void Parse(object input) default: if (underlyingType.IsEnum) - Value = (T)Enum.Parse(underlyingType, input.ToString()!); + Value = (T)Enum.Parse(underlyingType, input.ToString().AsNonNull()); else Value = (T)Convert.ChangeType(input, underlyingType, CultureInfo.InvariantCulture); @@ -413,7 +414,9 @@ void ISerializableBindable.SerializeTo(JsonWriter writer, JsonSerializer seriali void ISerializableBindable.DeserializeFrom(JsonReader reader, JsonSerializer serializer) { // Deserialize returns null for json literal "null". - Value = serializer.Deserialize(reader)!; + var result = serializer.Deserialize(reader); + Debug.Assert(result != null); + Value = result; } private LeasedBindable? leasedBindable; diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index dd562a6959..863b5eff4a 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -7,6 +7,7 @@ using System.Collections.Specialized; using System.Linq; using osu.Framework.Caching; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Lists; namespace osu.Framework.Bindables @@ -350,22 +351,22 @@ public void CopyTo(Array array, int index) object? IList.this[int index] { get => this[index]; - set => this[index] = (T)value!; + set => this[index] = (T)value.AsNonNull(); } int IList.Add(object? value) { - Add((T)value!); + Add((T)value.AsNonNull()); return Count - 1; } - bool IList.Contains(object? value) => Contains((T)value!); + bool IList.Contains(object? value) => Contains((T)value.AsNonNull()); - int IList.IndexOf(object? value) => IndexOf((T)value!); + int IList.IndexOf(object? value) => IndexOf((T)value.AsNonNull()); - void IList.Insert(int index, object? value) => Insert(index, (T)value!); + void IList.Insert(int index, object? value) => Insert(index, (T)value.AsNonNull()); - void IList.Remove(object? value) => Remove((T)value!); + void IList.Remove(object? value) => Remove((T)value.AsNonNull()); bool IList.IsFixedSize => false; diff --git a/osu.Framework/Bindables/IBindableWithCurrent.cs b/osu.Framework/Bindables/IBindableWithCurrent.cs index 911c7fd04b..e8af747113 100644 --- a/osu.Framework/Bindables/IBindableWithCurrent.cs +++ b/osu.Framework/Bindables/IBindableWithCurrent.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; @@ -17,7 +18,7 @@ public interface IBindableWithCurrent : IBindable, IHasCurrentValue public static IBindableWithCurrent Create() { if (Validation.IsSupportedBindableNumberType()) - return (IBindableWithCurrent)Activator.CreateInstance(typeof(BindableNumberWithCurrent<>).MakeGenericType(typeof(T)), default(T))!; + return (IBindableWithCurrent)Activator.CreateInstance(typeof(BindableNumberWithCurrent<>).MakeGenericType(typeof(T)), default(T)).AsNonNull(); return new BindableWithCurrent(); } From 36a0f6e09f315ed90caab18711a4325d9ce75ae7 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 3 Jul 2022 10:15:16 +0800 Subject: [PATCH 14/19] Make description to be non-nullable --- osu.Framework/Bindables/Bindable.cs | 2 +- osu.Framework/Bindables/BindableDictionary.cs | 2 +- osu.Framework/Bindables/BindableList.cs | 2 +- osu.Framework/Bindables/IHasDescription.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index eba347f622..a18b1b8df8 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -380,7 +380,7 @@ public virtual void UnbindFrom(IUnbindable them) tThem.removeWeakReference(weakReference); } - public string? Description { get; set; } + public string Description { get; set; } = string.Empty; public override string ToString() => value?.ToString() ?? string.Empty; diff --git a/osu.Framework/Bindables/BindableDictionary.cs b/osu.Framework/Bindables/BindableDictionary.cs index 4d392987dd..c67b6080b6 100644 --- a/osu.Framework/Bindables/BindableDictionary.cs +++ b/osu.Framework/Bindables/BindableDictionary.cs @@ -418,7 +418,7 @@ private void unbind(BindableDictionary binding) #region IHasDescription - public string? Description { get; set; } + public string Description { get; set; } = string.Empty; #endregion IHasDescription diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 863b5eff4a..1f0726bdb6 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -489,7 +489,7 @@ public virtual void UnbindFrom(IUnbindable them) #region IHasDescription - public string? Description { get; set; } + public string Description { get; set; } = string.Empty; #endregion IHasDescription diff --git a/osu.Framework/Bindables/IHasDescription.cs b/osu.Framework/Bindables/IHasDescription.cs index 89c7b811b9..a5660e15b9 100644 --- a/osu.Framework/Bindables/IHasDescription.cs +++ b/osu.Framework/Bindables/IHasDescription.cs @@ -11,6 +11,6 @@ public interface IHasDescription /// /// The description for this object. /// - string? Description { get; } + string Description { get; } } } From 56de9b4d7481477899731e1dfb616196f31556da Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 7 Jul 2022 15:33:59 +0800 Subject: [PATCH 15/19] Use AsNonNull and add comment for explaination --- osu.Framework/Bindables/Bindable.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index a18b1b8df8..8f348753ba 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.Linq; using JetBrains.Annotations; @@ -414,9 +413,8 @@ void ISerializableBindable.SerializeTo(JsonWriter writer, JsonSerializer seriali void ISerializableBindable.DeserializeFrom(JsonReader reader, JsonSerializer serializer) { // Deserialize returns null for json literal "null". - var result = serializer.Deserialize(reader); - Debug.Assert(result != null); - Value = result; + // The nullability of type parameter T is unavailable here, so we can't do any validation. + Value = serializer.Deserialize(reader).AsNonNull(); } private LeasedBindable? leasedBindable; From 00453658a972da2205f9dd290ff072b5e274aa76 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 27 May 2023 21:41:19 +0800 Subject: [PATCH 16/19] Update nullable annotation for new members --- osu.Framework/Bindables/Bindable.cs | 2 +- osu.Framework/Bindables/BindableColour4.cs | 2 +- osu.Framework/Bindables/BindableDouble.cs | 2 +- osu.Framework/Bindables/BindableFloat.cs | 2 +- osu.Framework/Bindables/BindableList.cs | 4 ++-- osu.Framework/Bindables/BindableSize.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 72781bad7e..2692b2d3fd 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -392,7 +392,7 @@ public virtual void UnbindFrom(IUnbindable them) public sealed override string ToString() => ToString(null, CultureInfo.CurrentCulture); - public virtual string ToString(string format, IFormatProvider formatProvider) => string.Format(formatProvider, $"{{0:{format}}}", Value); + public virtual string ToString(string? format, IFormatProvider? formatProvider) => string.Format(formatProvider, $"{{0:{format}}}", Value); /// /// Create an unbound clone of this bindable. diff --git a/osu.Framework/Bindables/BindableColour4.cs b/osu.Framework/Bindables/BindableColour4.cs index d8d1b152c7..b5b3518f90 100644 --- a/osu.Framework/Bindables/BindableColour4.cs +++ b/osu.Framework/Bindables/BindableColour4.cs @@ -14,7 +14,7 @@ public BindableColour4(Colour4 value = default) } // 8-bit precision should probably be enough for serialization. - public override string ToString(string format, IFormatProvider formatProvider) => Value.ToHex(); + public override string ToString(string? format, IFormatProvider? formatProvider) => Value.ToHex(); public override void Parse(object input) { diff --git a/osu.Framework/Bindables/BindableDouble.cs b/osu.Framework/Bindables/BindableDouble.cs index aa9801a14e..74df855522 100644 --- a/osu.Framework/Bindables/BindableDouble.cs +++ b/osu.Framework/Bindables/BindableDouble.cs @@ -12,7 +12,7 @@ public BindableDouble(double defaultValue = 0) { } - public override string ToString(string format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider); + public override string ToString(string? format, IFormatProvider? formatProvider) => base.ToString(format ?? "0.0###", formatProvider); protected override Bindable CreateInstance() => new BindableDouble(); } diff --git a/osu.Framework/Bindables/BindableFloat.cs b/osu.Framework/Bindables/BindableFloat.cs index 9a09d545e4..b1fe05c3fd 100644 --- a/osu.Framework/Bindables/BindableFloat.cs +++ b/osu.Framework/Bindables/BindableFloat.cs @@ -12,7 +12,7 @@ public BindableFloat(float defaultValue = 0) { } - public override string ToString(string format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider); + public override string ToString(string? format, IFormatProvider? formatProvider) => base.ToString(format ?? "0.0###", formatProvider); protected override Bindable CreateInstance() => new BindableFloat(); } diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 28454aa310..3c55d910df 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -331,7 +331,7 @@ private int removeAll(Predicate match, BindableList? caller) public void ReplaceRange(int index, int count, IEnumerable newItems) => replaceRange(index, count, newItems as IList ?? newItems.ToArray(), null); - private void replaceRange(int index, int count, IList newItems, BindableList caller) + private void replaceRange(int index, int count, IList newItems, BindableList? caller) { ensureMutationAllowed(); @@ -691,6 +691,6 @@ private void ensureMutationAllowed() public bool IsDefault => Count == 0; - string IFormattable.ToString(string format, IFormatProvider formatProvider) => ((FormattableString)$"{GetType().ReadableName()}({nameof(Count)}={Count})").ToString(formatProvider); + string IFormattable.ToString(string? format, IFormatProvider? formatProvider) => ((FormattableString)$"{GetType().ReadableName()}({nameof(Count)}={Count})").ToString(formatProvider); } } diff --git a/osu.Framework/Bindables/BindableSize.cs b/osu.Framework/Bindables/BindableSize.cs index f65a0c4e99..aef240af93 100644 --- a/osu.Framework/Bindables/BindableSize.cs +++ b/osu.Framework/Bindables/BindableSize.cs @@ -19,7 +19,7 @@ public BindableSize(Size defaultValue = default) { } - public override string ToString(string format, IFormatProvider formatProvider) => ((FormattableString)$"{Value.Width}x{Value.Height}").ToString(formatProvider); + public override string ToString(string? format, IFormatProvider? formatProvider) => ((FormattableString)$"{Value.Width}x{Value.Height}").ToString(formatProvider); public override void Parse(object input) { From db7c54a63bebdda86a9d758b7a4e5eab6e0edf76 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 27 May 2023 21:53:46 +0800 Subject: [PATCH 17/19] Use MemberNotNullWhen to remove workaround for isLeased --- osu.Framework/Bindables/Bindable.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 2692b2d3fd..316cda7e63 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using JetBrains.Annotations; @@ -371,9 +372,8 @@ public void UnbindBindings() internal virtual void UnbindAllInternal() { - // TODO: annotate isLeased with [MemberNotNull(nameof(leasedBindable))] on .NET 5+ to satisfy the nullability check if (isLeased) - leasedBindable.AsNonNull().Return(); + leasedBindable.Return(); UnbindEvents(); UnbindBindings(); @@ -430,6 +430,7 @@ void ISerializableBindable.DeserializeFrom(JsonReader reader, JsonSerializer ser private LeasedBindable? leasedBindable; + [MemberNotNullWhen(true, nameof(leasedBindable))] private bool isLeased => leasedBindable != null; /// From 9c9b8ad9f090b093d9927fab60ef785ba52da3dc Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 27 Nov 2024 20:46:55 +0800 Subject: [PATCH 18/19] Update annotations with latest usages --- osu.Framework/Bindables/AggregateBindable.cs | 2 +- osu.Framework/Bindables/Bindable.cs | 6 +++--- osu.Framework/Bindables/BindableList.cs | 2 +- .../Bindables/RangeConstrainedBindable.cs | 20 +++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/osu.Framework/Bindables/AggregateBindable.cs b/osu.Framework/Bindables/AggregateBindable.cs index b1782def65..41442f3504 100644 --- a/osu.Framework/Bindables/AggregateBindable.cs +++ b/osu.Framework/Bindables/AggregateBindable.cs @@ -83,7 +83,7 @@ public void RemoveSource(IBindable bindable) return null; } - private void recalculateAggregate(ValueChangedEvent obj = null) + private void recalculateAggregate(ValueChangedEvent? obj = null) { T calculated = initialValue; diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 2802a074ac..fd2918d29c 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -247,7 +247,7 @@ private void addWeakReference(WeakReference> weakReference) /// /// The input which is to be parsed. /// An object that provides culture-specific formatting information about . - public virtual void Parse(object input, IFormatProvider provider) + public virtual void Parse(object? input, IFormatProvider provider) { switch (input) { @@ -261,7 +261,7 @@ public virtual void Parse(object input, IFormatProvider provider) // Nullable value types and reference types (annotated or not) are allowed to be initialised with `null`. if (typeof(T).IsNullable() || typeof(T).IsClass) { - Value = default; + Value = default!; break; } @@ -281,7 +281,7 @@ public virtual void Parse(object input, IFormatProvider provider) // Nullable value types and reference types are initialised to `null` on empty strings. if (typeof(T).IsNullable() || typeof(T).IsClass) { - Value = default; + Value = default!; break; } diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 2975e701c8..33e0c4d016 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -418,7 +418,7 @@ int IList.Add(object? value) /// The input which is to be parsed. /// Not valid for . /// Thrown if this is . - public void Parse(object input, IFormatProvider provider) + public void Parse(object? input, IFormatProvider provider) { ensureMutationAllowed(); diff --git a/osu.Framework/Bindables/RangeConstrainedBindable.cs b/osu.Framework/Bindables/RangeConstrainedBindable.cs index f89e27ccc2..f5d89a4e28 100644 --- a/osu.Framework/Bindables/RangeConstrainedBindable.cs +++ b/osu.Framework/Bindables/RangeConstrainedBindable.cs @@ -90,25 +90,25 @@ public float NormalizedValue private static float convertToSingle(T val) { if (typeof(T) == typeof(sbyte)) - return Convert.ToSingle((sbyte)(object)val); + return Convert.ToSingle((sbyte)(object)val!); if (typeof(T) == typeof(byte)) - return Convert.ToSingle((byte)(object)val); + return Convert.ToSingle((byte)(object)val!); if (typeof(T) == typeof(short)) - return Convert.ToSingle((short)(object)val); + return Convert.ToSingle((short)(object)val!); if (typeof(T) == typeof(ushort)) - return Convert.ToSingle((ushort)(object)val); + return Convert.ToSingle((ushort)(object)val!); if (typeof(T) == typeof(int)) - return Convert.ToSingle((int)(object)val); + return Convert.ToSingle((int)(object)val!); if (typeof(T) == typeof(uint)) - return Convert.ToSingle((uint)(object)val); + return Convert.ToSingle((uint)(object)val!); if (typeof(T) == typeof(long)) - return Convert.ToSingle((long)(object)val); + return Convert.ToSingle((long)(object)val!); if (typeof(T) == typeof(ulong)) - return Convert.ToSingle((ulong)(object)val); + return Convert.ToSingle((ulong)(object)val!); if (typeof(T) == typeof(double)) - return Convert.ToSingle((double)(object)val); + return Convert.ToSingle((double)(object)val!); if (typeof(T) == typeof(float)) - return (float)(object)val; + return (float)(object)val!; throw new InvalidOperationException(); } From 62deab70e521934a9e8fe8f645b4d6d219c13f7d Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 27 Nov 2024 21:39:16 +0800 Subject: [PATCH 19/19] Update InspectCode warnings --- osu.Framework.Tests/Bindables/BindableDoubleTest.cs | 2 +- osu.Framework.Tests/Bindables/BindableFloatTest.cs | 2 +- osu.Framework.Tests/Bindables/BindableLeasingTest.cs | 2 +- .../Visual/Platform/FrameworkConfigVisualiser.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Framework.Tests/Bindables/BindableDoubleTest.cs b/osu.Framework.Tests/Bindables/BindableDoubleTest.cs index d076511803..8840a73402 100644 --- a/osu.Framework.Tests/Bindables/BindableDoubleTest.cs +++ b/osu.Framework.Tests/Bindables/BindableDoubleTest.cs @@ -125,7 +125,7 @@ public void TestParsingNumberLocale(double value, string locale, string expected CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(locale); var bindable = new BindableDouble(value); - string? asString = bindable.ToString(); + string asString = bindable.ToString(); Assert.AreEqual(expected, asString); Assert.DoesNotThrow(() => bindable.Parse(asString, CultureInfo.CurrentCulture)); Assert.AreEqual(value, bindable.Value, Precision.DOUBLE_EPSILON); diff --git a/osu.Framework.Tests/Bindables/BindableFloatTest.cs b/osu.Framework.Tests/Bindables/BindableFloatTest.cs index 200988ee85..78792c2a97 100644 --- a/osu.Framework.Tests/Bindables/BindableFloatTest.cs +++ b/osu.Framework.Tests/Bindables/BindableFloatTest.cs @@ -112,7 +112,7 @@ public void TestParsingNumberLocale(float value, string locale, string expected) CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(locale); var bindable = new BindableFloat(value); - string? asString = bindable.ToString(); + string asString = bindable.ToString(); Assert.AreEqual(expected, asString); Assert.DoesNotThrow(() => bindable.Parse(asString, CultureInfo.CurrentCulture)); Assert.AreEqual(value, bindable.Value, Precision.FLOAT_EPSILON); diff --git a/osu.Framework.Tests/Bindables/BindableLeasingTest.cs b/osu.Framework.Tests/Bindables/BindableLeasingTest.cs index fc2323e67b..4bb5419625 100644 --- a/osu.Framework.Tests/Bindables/BindableLeasingTest.cs +++ b/osu.Framework.Tests/Bindables/BindableLeasingTest.cs @@ -95,7 +95,7 @@ public void TestDoubleLeaseFails() public void TestIncorrectEndLease() { // end a lease when no lease exists. - Assert.Throws(() => original.EndLease(null)); + Assert.Throws(() => original.EndLease(null!)); // end a lease with an incorrect bindable original.BeginLease(true); diff --git a/osu.Framework.Tests/Visual/Platform/FrameworkConfigVisualiser.cs b/osu.Framework.Tests/Visual/Platform/FrameworkConfigVisualiser.cs index 56701f67e5..3f263cd991 100644 --- a/osu.Framework.Tests/Visual/Platform/FrameworkConfigVisualiser.cs +++ b/osu.Framework.Tests/Visual/Platform/FrameworkConfigVisualiser.cs @@ -59,6 +59,6 @@ protected override void LoadComplete() })); } - private void updateText() => valueText.Text = bindable.ToString() ?? ""; + private void updateText() => valueText.Text = bindable?.ToString() ?? ""; } }