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.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index e964673845..a7ec7cc5d2 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -201,7 +201,7 @@ namespace Avalonia.Controls { base.OnLostFocus(e); - if (_focusAdorner != null) + if (_focusAdorner?.Parent != null) { var adornerLayer = (IPanel)_focusAdorner.Parent; adornerLayer.Children.Remove(_focusAdorner); diff --git a/src/Avalonia.Controls/IControl.cs b/src/Avalonia.Controls/IControl.cs index 6298531a16..598e6b6f4e 100644 --- a/src/Avalonia.Controls/IControl.cs +++ b/src/Avalonia.Controls/IControl.cs @@ -3,6 +3,8 @@ using Avalonia.Input; using Avalonia.Layout; using Avalonia.VisualTree; +#nullable enable + namespace Avalonia.Controls { /// @@ -15,6 +17,6 @@ namespace Avalonia.Controls INamed, IStyledElement { - new IControl Parent { get; } + new IControl? Parent { get; } } } diff --git a/src/Avalonia.Input/IInputElement.cs b/src/Avalonia.Input/IInputElement.cs index 7aa9c32bca..2245ff9986 100644 --- a/src/Avalonia.Input/IInputElement.cs +++ b/src/Avalonia.Input/IInputElement.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using Avalonia.Interactivity; using Avalonia.VisualTree; +#nullable enable + namespace Avalonia.Input { /// diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 8f99770b3b..65b9acae76 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -9,6 +9,8 @@ using Avalonia.Input.TextInput; using Avalonia.Interactivity; using Avalonia.VisualTree; +#nullable enable + namespace Avalonia.Input { /// diff --git a/src/Avalonia.Input/KeyboardDevice.cs b/src/Avalonia.Input/KeyboardDevice.cs index 5899824c29..79152e20d2 100644 --- a/src/Avalonia.Input/KeyboardDevice.cs +++ b/src/Avalonia.Input/KeyboardDevice.cs @@ -60,7 +60,7 @@ namespace Avalonia.Input ie.IsKeyboardFocusWithin = false; } - el = (IInputElement)el.VisualParent; + el = (IInputElement?)el.VisualParent; } } @@ -212,7 +212,7 @@ namespace Avalonia.Input Source = element, }; - IVisual currentHandler = element; + IVisual? currentHandler = element; while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown) { var bindings = (currentHandler as IInputElement)?.KeyBindings; diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index 6e937b7e13..cfa3690daf 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -377,7 +377,7 @@ namespace Avalonia.Input e.Source = element; e.Handled = false; element.RaiseEvent(e); - element = (IInputElement)element.VisualParent; + element = (IInputElement?)element.VisualParent; } root.PointerOverElement = null; @@ -444,7 +444,7 @@ namespace Avalonia.Input branch = el; break; } - el = (IInputElement)el.VisualParent; + el = (IInputElement?)el.VisualParent; } el = root.PointerOverElement; @@ -460,7 +460,7 @@ namespace Avalonia.Input e.Source = el; e.Handled = false; el.RaiseEvent(e); - el = (IInputElement)el.VisualParent; + el = (IInputElement?)el.VisualParent; } el = root.PointerOverElement = element; @@ -471,7 +471,7 @@ namespace Avalonia.Input e.Source = el; e.Handled = false; el.RaiseEvent(e); - el = (IInputElement)el.VisualParent; + el = (IInputElement?)el.VisualParent; } } diff --git a/src/Avalonia.Interactivity/IInteractive.cs b/src/Avalonia.Interactivity/IInteractive.cs index 5c01f870ab..afda29e329 100644 --- a/src/Avalonia.Interactivity/IInteractive.cs +++ b/src/Avalonia.Interactivity/IInteractive.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Avalonia.Interactivity { /// diff --git a/src/Avalonia.Interactivity/Interactive.cs b/src/Avalonia.Interactivity/Interactive.cs index 580704bb19..4cd810af20 100644 --- a/src/Avalonia.Interactivity/Interactive.cs +++ b/src/Avalonia.Interactivity/Interactive.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using Avalonia.Layout; using Avalonia.VisualTree; +#nullable enable + namespace Avalonia.Interactivity { /// diff --git a/src/Avalonia.Layout/Layoutable.cs b/src/Avalonia.Layout/Layoutable.cs index a1d00017ed..7568ea8e09 100644 --- a/src/Avalonia.Layout/Layoutable.cs +++ b/src/Avalonia.Layout/Layoutable.cs @@ -782,7 +782,7 @@ namespace Avalonia.Layout } /// - protected sealed override void OnVisualParentChanged(IVisual oldParent, IVisual newParent) + protected sealed override void OnVisualParentChanged(IVisual? oldParent, IVisual? newParent) { LayoutHelper.InvalidateSelfAndChildrenMeasure(this); diff --git a/src/Avalonia.Styling/Controls/ISetInheritanceParent.cs b/src/Avalonia.Styling/Controls/ISetInheritanceParent.cs index ef3c1d5b89..dbf8c68892 100644 --- a/src/Avalonia.Styling/Controls/ISetInheritanceParent.cs +++ b/src/Avalonia.Styling/Controls/ISetInheritanceParent.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace Avalonia.Controls { /// @@ -14,6 +16,6 @@ namespace Avalonia.Controls /// Sets the control's inheritance parent. /// /// The parent. - void SetParent(IAvaloniaObject parent); + void SetParent(IAvaloniaObject? parent); } -} \ No newline at end of file +} diff --git a/src/Avalonia.Styling/Controls/ISetLogicalParent.cs b/src/Avalonia.Styling/Controls/ISetLogicalParent.cs index 0c0cd1c1bb..85bda05961 100644 --- a/src/Avalonia.Styling/Controls/ISetLogicalParent.cs +++ b/src/Avalonia.Styling/Controls/ISetLogicalParent.cs @@ -1,5 +1,7 @@ using Avalonia.LogicalTree; +#nullable enable + namespace Avalonia.Controls { /// @@ -14,6 +16,6 @@ namespace Avalonia.Controls /// Sets the control's parent. /// /// The parent. - void SetParent(ILogical parent); + void SetParent(ILogical? parent); } -} \ No newline at end of file +} diff --git a/src/Avalonia.Styling/IDataContextProvider.cs b/src/Avalonia.Styling/IDataContextProvider.cs index 31639c5784..1172adcaa4 100644 --- a/src/Avalonia.Styling/IDataContextProvider.cs +++ b/src/Avalonia.Styling/IDataContextProvider.cs @@ -1,4 +1,6 @@ -namespace Avalonia +#nullable enable + +namespace Avalonia { /// /// Defines an element with a data context that can be used for binding. @@ -8,6 +10,6 @@ /// /// Gets or sets the element's data context. /// - object DataContext { get; set; } + object? DataContext { get; set; } } } diff --git a/src/Avalonia.Styling/IStyledElement.cs b/src/Avalonia.Styling/IStyledElement.cs index 046a6f9872..a068d4a5bf 100644 --- a/src/Avalonia.Styling/IStyledElement.cs +++ b/src/Avalonia.Styling/IStyledElement.cs @@ -4,6 +4,8 @@ using Avalonia.Controls; using Avalonia.LogicalTree; using Avalonia.Styling; +#nullable enable + namespace Avalonia { public interface IStyledElement : @@ -17,7 +19,7 @@ namespace Avalonia /// /// Occurs when the control has finished initialization. /// - event EventHandler Initialized; + event EventHandler? Initialized; /// /// Gets a value that indicates whether the element has finished initialization. @@ -32,6 +34,6 @@ namespace Avalonia /// /// Gets the control's logical parent. /// - IStyledElement Parent { get; } + IStyledElement? Parent { get; } } } diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 5f26f65512..2292f5c518 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() @@ -465,7 +465,7 @@ namespace Avalonia /// Sets the styled element's inheritance parent. /// /// The parent. - void ISetInheritanceParent.SetParent(IAvaloniaObject parent) + void ISetInheritanceParent.SetParent(IAvaloniaObject? parent) { InheritanceParent = parent; } diff --git a/src/Avalonia.Styling/Styling/ISetterValue.cs b/src/Avalonia.Styling/Styling/ISetterValue.cs index 63c544cf7d..0fd245a429 100644 --- a/src/Avalonia.Styling/Styling/ISetterValue.cs +++ b/src/Avalonia.Styling/Styling/ISetterValue.cs @@ -1,4 +1,6 @@ -namespace Avalonia.Styling +#nullable enable + +namespace Avalonia.Styling { /// /// Customizes the behavior of a class when added as a value to an . 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!); } } diff --git a/src/Avalonia.Visuals/Visual.cs b/src/Avalonia.Visuals/Visual.cs index 80d4195421..2c96d87bb6 100644 --- a/src/Avalonia.Visuals/Visual.cs +++ b/src/Avalonia.Visuals/Visual.cs @@ -11,6 +11,8 @@ using Avalonia.Rendering; using Avalonia.Utilities; using Avalonia.VisualTree; +#nullable enable + namespace Avalonia { /// @@ -45,8 +47,8 @@ namespace Avalonia /// /// Defines the property. /// - public static readonly StyledProperty ClipProperty = - AvaloniaProperty.Register(nameof(Clip)); + public static readonly StyledProperty ClipProperty = + AvaloniaProperty.Register(nameof(Clip)); /// /// Defines the property. @@ -63,14 +65,14 @@ namespace Avalonia /// /// Defines the property. /// - public static readonly StyledProperty OpacityMaskProperty = - AvaloniaProperty.Register(nameof(OpacityMask)); + public static readonly StyledProperty OpacityMaskProperty = + AvaloniaProperty.Register(nameof(OpacityMask)); /// /// Defines the property. /// - public static readonly StyledProperty RenderTransformProperty = - AvaloniaProperty.Register(nameof(RenderTransform)); + public static readonly StyledProperty RenderTransformProperty = + AvaloniaProperty.Register(nameof(RenderTransform)); /// /// Defines the property. @@ -81,8 +83,8 @@ namespace Avalonia /// /// Defines the property. /// - public static readonly DirectProperty VisualParentProperty = - AvaloniaProperty.RegisterDirect("VisualParent", o => o._visualParent); + public static readonly DirectProperty VisualParentProperty = + AvaloniaProperty.RegisterDirect(nameof(IVisual.VisualParent), o => o._visualParent); /// /// Defines the property. @@ -92,8 +94,8 @@ namespace Avalonia private Rect _bounds; private TransformedBounds? _transformedBounds; - private IRenderRoot _visualRoot; - private IVisual _visualParent; + private IRenderRoot? _visualRoot; + private IVisual? _visualParent; /// /// Initializes static members of the class. @@ -128,12 +130,12 @@ namespace Avalonia /// /// Raised when the control is attached to a rooted visual tree. /// - public event EventHandler AttachedToVisualTree; + public event EventHandler? AttachedToVisualTree; /// /// Raised when the control is detached from a rooted visual tree. /// - public event EventHandler DetachedFromVisualTree; + public event EventHandler? DetachedFromVisualTree; /// /// Gets the bounds of the control relative to its parent. @@ -161,7 +163,7 @@ namespace Avalonia /// /// Gets or sets the geometry clip for this visual. /// - public Geometry Clip + public Geometry? Clip { get { return GetValue(ClipProperty); } set { SetValue(ClipProperty, value); } @@ -174,7 +176,7 @@ namespace Avalonia { get { - IVisual node = this; + IVisual? node = this; while (node != null) { @@ -211,7 +213,7 @@ namespace Avalonia /// /// Gets or sets the opacity mask of the control. /// - public IBrush OpacityMask + public IBrush? OpacityMask { get { return GetValue(OpacityMaskProperty); } set { SetValue(OpacityMaskProperty, value); } @@ -220,7 +222,7 @@ namespace Avalonia /// /// Gets or sets the render transform of the control. /// - public ITransform RenderTransform + public ITransform? RenderTransform { get { return GetValue(RenderTransformProperty); } set { SetValue(RenderTransformProperty, value); } @@ -261,7 +263,7 @@ namespace Avalonia /// /// Gets the root of the visual tree, if the control is attached to a visual tree. /// - protected IRenderRoot VisualRoot => _visualRoot ?? (this as IRenderRoot); + protected IRenderRoot? VisualRoot => _visualRoot ?? (this as IRenderRoot); /// /// Gets a value indicating whether this control is attached to a visual root. @@ -276,12 +278,12 @@ namespace Avalonia /// /// Gets the control's parent visual. /// - IVisual IVisual.VisualParent => _visualParent; + IVisual? IVisual.VisualParent => _visualParent; /// /// Gets the root of the visual tree, if the control is attached to a visual tree. /// - IRenderRoot IVisual.VisualRoot => VisualRoot; + IRenderRoot? IVisual.VisualRoot => VisualRoot; TransformedBounds? IVisual.TransformedBounds { @@ -476,12 +478,12 @@ namespace Avalonia /// /// The old visual parent. /// The new visual parent. - protected virtual void OnVisualParentChanged(IVisual oldParent, IVisual newParent) + protected virtual void OnVisualParentChanged(IVisual? oldParent, IVisual? newParent) { RaisePropertyChanged( VisualParentProperty, - new Optional(oldParent), - new BindingValue(newParent), + new Optional(oldParent), + new BindingValue(newParent), BindingPriority.LocalValue); } @@ -582,7 +584,7 @@ namespace Avalonia /// Sets the visual parent of the Visual. /// /// The visual parent. - private void SetVisualParent(Visual value) + private void SetVisualParent(Visual? value) { if (_visualParent == value) { @@ -634,7 +636,7 @@ namespace Avalonia } } - private static void SetVisualParent(IList children, Visual parent) + private static void SetVisualParent(IList children, Visual? parent) { var count = children.Count; diff --git a/src/Avalonia.Visuals/VisualTree/IVisual.cs b/src/Avalonia.Visuals/VisualTree/IVisual.cs index 50787655d9..97c4554de6 100644 --- a/src/Avalonia.Visuals/VisualTree/IVisual.cs +++ b/src/Avalonia.Visuals/VisualTree/IVisual.cs @@ -3,6 +3,8 @@ using Avalonia.Collections; using Avalonia.Media; using Avalonia.Rendering; +#nullable enable + namespace Avalonia.VisualTree { /// @@ -21,12 +23,12 @@ namespace Avalonia.VisualTree /// /// Raised when the control is attached to a rooted visual tree. /// - event EventHandler AttachedToVisualTree; + event EventHandler? AttachedToVisualTree; /// /// Raised when the control is detached from a rooted visual tree. /// - event EventHandler DetachedFromVisualTree; + event EventHandler? DetachedFromVisualTree; /// /// Gets the bounds of the control relative to its parent. @@ -46,7 +48,7 @@ namespace Avalonia.VisualTree /// /// Gets or sets the geometry clip for this visual. /// - Geometry Clip { get; set; } + Geometry? Clip { get; set; } /// /// Gets a value indicating whether this control is attached to a visual root. @@ -71,12 +73,12 @@ namespace Avalonia.VisualTree /// /// Gets or sets the opacity mask for the control. /// - IBrush OpacityMask { get; set; } + IBrush? OpacityMask { get; set; } /// /// Gets or sets the render transform of the control. /// - ITransform RenderTransform { get; set; } + ITransform? RenderTransform { get; set; } /// /// Gets or sets the render transform origin of the control. @@ -91,12 +93,12 @@ namespace Avalonia.VisualTree /// /// Gets the control's parent visual. /// - IVisual VisualParent { get; } + IVisual? VisualParent { get; } /// /// Gets the root of the visual tree, if the control is attached to a visual tree. /// - IRenderRoot VisualRoot { get; } + IRenderRoot? VisualRoot { get; } /// /// Gets or sets the Z index of the node.