diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs index fdd688cf9d..6a9cff6b71 100644 --- a/src/Avalonia.Base/AvaloniaObject.cs +++ b/src/Avalonia.Base/AvaloniaObject.cs @@ -7,6 +7,8 @@ using Avalonia.Logging; using Avalonia.PropertyStore; using Avalonia.Threading; +#nullable enable + namespace Avalonia { /// @@ -17,12 +19,12 @@ namespace Avalonia /// public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged, IValueSink { - private IAvaloniaObject _inheritanceParent; - private List _directBindings; - private PropertyChangedEventHandler _inpcChanged; - private EventHandler _propertyChanged; - private List _inheritanceChildren; - private ValueStore _values; + private IAvaloniaObject? _inheritanceParent; + private List? _directBindings; + private PropertyChangedEventHandler? _inpcChanged; + private EventHandler? _propertyChanged; + private List? _inheritanceChildren; + private ValueStore? _values; private bool _batchUpdate; /// @@ -36,7 +38,7 @@ namespace Avalonia /// /// Raised when a value changes on this object. /// - public event EventHandler PropertyChanged + public event EventHandler? PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } @@ -58,7 +60,7 @@ namespace Avalonia /// /// The inheritance parent. /// - protected IAvaloniaObject InheritanceParent + protected IAvaloniaObject? InheritanceParent { get { @@ -289,7 +291,8 @@ namespace Avalonia /// True if the property is animating, otherwise false. public bool IsAnimating(AvaloniaProperty property) { - Contract.Requires(property != null); + property = property ?? throw new ArgumentNullException(nameof(property)); + VerifyAccess(); return _values?.IsAnimating(property) ?? false; @@ -306,7 +309,8 @@ namespace Avalonia /// public bool IsSet(AvaloniaProperty property) { - Contract.Requires(property != null); + property = property ?? throw new ArgumentNullException(nameof(property)); + VerifyAccess(); return _values?.IsSet(property) ?? false; @@ -320,7 +324,7 @@ namespace Avalonia /// The priority of the value. public void SetValue( AvaloniaProperty property, - object value, + object? value, BindingPriority priority = BindingPriority.LocalValue) { property = property ?? throw new ArgumentNullException(nameof(property)); @@ -338,7 +342,7 @@ namespace Avalonia /// /// An if setting the property can be undone, otherwise null. /// - public IDisposable SetValue( + public IDisposable? SetValue( StyledPropertyBase property, T value, BindingPriority priority = BindingPriority.LocalValue) @@ -497,7 +501,7 @@ namespace Avalonia } /// - Delegate[] IAvaloniaObjectDebug.GetPropertyChangedSubscribers() + Delegate[]? IAvaloniaObjectDebug.GetPropertyChangedSubscribers() { return _propertyChanged?.GetInvocationList(); } @@ -723,7 +727,8 @@ namespace Avalonia { var values = o._values; - if (values?.TryGetValue(property, maxPriority, out value) == true) + if (values != null + && values.TryGetValue(property, maxPriority, out value) == true) { return value; } @@ -873,7 +878,7 @@ namespace Avalonia } else { - LogBindingError(property, value.Error); + LogBindingError(property, value.Error!); } } } @@ -907,14 +912,14 @@ namespace Avalonia { _owner = owner; _property = property; - _owner._directBindings.Add(this); + _owner._directBindings!.Add(this); _subscription = source.Subscribe(this); } public void Dispose() { _subscription.Dispose(); - _owner._directBindings.Remove(this); + _owner._directBindings!.Remove(this); } public void OnCompleted() => Dispose(); diff --git a/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs b/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs index 7f09425905..4b9f12ddf8 100644 --- a/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs +++ b/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Avalonia.Diagnostics { /// @@ -14,6 +16,6 @@ namespace Avalonia.Diagnostics /// /// The subscribers or null if no subscribers. /// - Delegate[] GetPropertyChangedSubscribers(); + Delegate[]? GetPropertyChangedSubscribers(); } } diff --git a/src/Avalonia.Base/IAvaloniaObject.cs b/src/Avalonia.Base/IAvaloniaObject.cs index 0452f77d4c..2e992f8616 100644 --- a/src/Avalonia.Base/IAvaloniaObject.cs +++ b/src/Avalonia.Base/IAvaloniaObject.cs @@ -1,6 +1,8 @@ using System; using Avalonia.Data; +#nullable enable + namespace Avalonia { /// @@ -11,7 +13,7 @@ namespace Avalonia /// /// Raised when a value changes on this object. /// - event EventHandler PropertyChanged; + event EventHandler? PropertyChanged; /// /// Clears an 's local value. @@ -75,7 +77,10 @@ namespace Avalonia /// The property. /// The value. /// The priority of the value. - IDisposable SetValue( + /// + /// An if setting the property can be undone, otherwise null. + /// + IDisposable? SetValue( StyledPropertyBase property, T value, BindingPriority priority = BindingPriority.LocalValue); diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 5f26f65512..ae14b12dae 100644 --- a/src/Avalonia.Styling/StyledElement.cs +++ b/src/Avalonia.Styling/StyledElement.cs @@ -300,7 +300,7 @@ namespace Avalonia bool IStyleHost.IsStylesInitialized => _styles != null; /// - IStyleHost? IStyleHost.StylingParent => (IStyleHost)InheritanceParent; + IStyleHost? IStyleHost.StylingParent => (IStyleHost?)InheritanceParent; /// public virtual void BeginInit() diff --git a/src/Avalonia.Styling/Styling/PropertySetterInstance.cs b/src/Avalonia.Styling/Styling/PropertySetterInstance.cs index b52ae6b146..1c3055fed6 100644 --- a/src/Avalonia.Styling/Styling/PropertySetterInstance.cs +++ b/src/Avalonia.Styling/Styling/PropertySetterInstance.cs @@ -50,7 +50,7 @@ namespace Avalonia.Styling } else { - _subscription = _target.Bind(_directProperty, this); + _subscription = _target.Bind(_directProperty!, this); } } else @@ -100,7 +100,7 @@ namespace Avalonia.Styling } else { - _target.ClearValue(_directProperty); + _target.ClearValue(_directProperty!); } } diff --git a/src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs b/src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs index 03d33faff9..92653d0064 100644 --- a/src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs +++ b/src/Avalonia.Styling/Styling/PropertySetterLazyInstance.cs @@ -53,7 +53,7 @@ namespace Avalonia.Styling } else { - _subscription = _target.Bind(_directProperty, this); + _subscription = _target.Bind(_directProperty!, this); } } @@ -91,7 +91,7 @@ namespace Avalonia.Styling } else { - _target.ClearValue(_directProperty); + _target.ClearValue(_directProperty!); } }