diff --git a/src/Avalonia.Base/Data/BindingValue.cs b/src/Avalonia.Base/Data/BindingValue.cs index 93948e54ee..e8c84ffb21 100644 --- a/src/Avalonia.Base/Data/BindingValue.cs +++ b/src/Avalonia.Base/Data/BindingValue.cs @@ -247,7 +247,7 @@ namespace Avalonia.Data UnsetValueType _ => Unset, DoNothingType _ => DoNothing, BindingNotification n => n.ToBindingValue().Cast(), - _ => new BindingValue((T)value) + _ => new BindingValue((T?)value) }; } diff --git a/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs b/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs index 4a4644317d..251dbb458d 100644 --- a/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs +++ b/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs @@ -161,7 +161,7 @@ namespace Avalonia.Data.Converters .Compile(); } - private static Expression? ConvertTarget(object? target, MethodInfo method) => + private static Expression ConvertTarget(object target, MethodInfo method) => target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType); internal class WeakPropertyChangedProxy diff --git a/src/Avalonia.Controls/Application.cs b/src/Avalonia.Controls/Application.cs index 157bebe02b..df55d9e250 100644 --- a/src/Avalonia.Controls/Application.cs +++ b/src/Avalonia.Controls/Application.cs @@ -104,7 +104,7 @@ namespace Avalonia /// /// The application's focus manager. /// - public IFocusManager FocusManager + public IFocusManager? FocusManager { get; private set; @@ -116,7 +116,7 @@ namespace Avalonia /// /// The application's input manager. /// - public InputManager InputManager + public InputManager? InputManager { get; private set; @@ -175,7 +175,7 @@ namespace Avalonia /// - /// - /// - public IApplicationLifetime ApplicationLifetime { get; set; } + public IApplicationLifetime? ApplicationLifetime { get; set; } event Action> IGlobalStyles.GlobalStylesAdded { diff --git a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs index 4b903d056c..b874d149bf 100644 --- a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs +++ b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs @@ -562,8 +562,12 @@ namespace Avalonia.Controls.Primitives return eventArgs.Cancel; } - internal static void SetPresenterClasses(IControl presenter, Classes classes) + internal static void SetPresenterClasses(IControl? presenter, Classes classes) { + if(presenter is null) + { + return; + } //Remove any classes no longer in use, ignoring pseudo classes for (int i = presenter.Classes.Count - 1; i >= 0; i--) { diff --git a/src/Avalonia.Controls/Primitives/Popup.cs b/src/Avalonia.Controls/Primitives/Popup.cs index 4c9b95c22d..0f15f647dc 100644 --- a/src/Avalonia.Controls/Primitives/Popup.cs +++ b/src/Avalonia.Controls/Primitives/Popup.cs @@ -93,8 +93,8 @@ namespace Avalonia.Controls.Primitives public static readonly StyledProperty OverlayDismissEventPassThroughProperty = AvaloniaProperty.Register(nameof(OverlayDismissEventPassThrough)); - public static readonly DirectProperty OverlayInputPassThroughElementProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty OverlayInputPassThroughElementProperty = + AvaloniaProperty.RegisterDirect( nameof(OverlayInputPassThroughElement), o => o.OverlayInputPassThroughElement, (o, v) => o.OverlayInputPassThroughElement = v); @@ -138,7 +138,7 @@ namespace Avalonia.Controls.Primitives private bool _isOpen; private bool _ignoreIsOpenChanged; private PopupOpenState? _openState; - private IInputElement _overlayInputPassThroughElement; + private IInputElement? _overlayInputPassThroughElement; private Action? _popupHostChangedHandler; /// @@ -310,7 +310,7 @@ namespace Avalonia.Controls.Primitives /// Gets or sets an element that should receive pointer input events even when underneath /// the popup's overlay. /// - public IInputElement OverlayInputPassThroughElement + public IInputElement? OverlayInputPassThroughElement { get => _overlayInputPassThroughElement; set => SetAndRaise(OverlayInputPassThroughElementProperty, ref _overlayInputPassThroughElement, value); diff --git a/src/Avalonia.Controls/SplitView.cs b/src/Avalonia.Controls/SplitView.cs index 0e35c610b2..6a0d4e2023 100644 --- a/src/Avalonia.Controls/SplitView.cs +++ b/src/Avalonia.Controls/SplitView.cs @@ -129,14 +129,14 @@ namespace Avalonia.Controls /// /// Defines the property /// - public static readonly StyledProperty PaneProperty = - AvaloniaProperty.Register(nameof(Pane)); + public static readonly StyledProperty PaneProperty = + AvaloniaProperty.Register(nameof(Pane)); /// /// Defines the property. /// - public static readonly StyledProperty PaneTemplateProperty = - AvaloniaProperty.Register(nameof(PaneTemplate)); + public static readonly StyledProperty PaneTemplateProperty = + AvaloniaProperty.Register(nameof(PaneTemplate)); /// /// Defines the property @@ -267,7 +267,7 @@ namespace Avalonia.Controls /// /// Gets or sets the data template used to display the header content of the control. /// - public IDataTemplate? PaneTemplate + public IDataTemplate PaneTemplate { get => GetValue(PaneTemplateProperty); set => SetValue(PaneTemplateProperty, value); diff --git a/src/Avalonia.Controls/TrayIcon.cs b/src/Avalonia.Controls/TrayIcon.cs index 59edb6278a..9fbc2fc8b2 100644 --- a/src/Avalonia.Controls/TrayIcon.cs +++ b/src/Avalonia.Controls/TrayIcon.cs @@ -140,7 +140,7 @@ namespace Avalonia.Controls /// Gets or sets the parameter to pass to the property of a /// . /// - public object CommandParameter + public object? CommandParameter { get { return GetValue(CommandParameterProperty); } set { SetValue(CommandParameterProperty, value); } diff --git a/src/Avalonia.Input/ICommandSource.cs b/src/Avalonia.Input/ICommandSource.cs index eed71759d5..410b3a2e47 100644 --- a/src/Avalonia.Input/ICommandSource.cs +++ b/src/Avalonia.Input/ICommandSource.cs @@ -1,5 +1,5 @@ using System.Windows.Input; - +#nullable enable namespace Avalonia.Input { /// @@ -12,13 +12,13 @@ namespace Avalonia.Input /// Classes that implement this interface should enable or disable based on the command's CanExecute return value. /// The property may be implemented as read-write if desired. /// - ICommand Command { get; } + ICommand? Command { get; } /// /// The parameter that will be passed to the command when executing the command. /// The property may be implemented as read-write if desired. /// - object CommandParameter { get; } + object? CommandParameter { get; } /// diff --git a/src/Avalonia.Styling/Styling/PropertySetterInstance.cs b/src/Avalonia.Styling/Styling/PropertySetterInstance.cs index 1c3055fed6..bb0e342df6 100644 --- a/src/Avalonia.Styling/Styling/PropertySetterInstance.cs +++ b/src/Avalonia.Styling/Styling/PropertySetterInstance.cs @@ -16,14 +16,14 @@ namespace Avalonia.Styling private readonly IStyleable _target; private readonly StyledPropertyBase? _styledProperty; private readonly DirectPropertyBase? _directProperty; - private readonly T _value; + private readonly T? _value; private IDisposable? _subscription; private bool _isActive; public PropertySetterInstance( IStyleable target, StyledPropertyBase property, - T value) + T? value) { _target = target; _styledProperty = property; @@ -57,7 +57,7 @@ namespace Avalonia.Styling { if (_styledProperty is object) { - _subscription = _target.SetValue(_styledProperty, _value, BindingPriority.Style); + _subscription = _target.SetValue(_styledProperty!, _value, BindingPriority.Style); } else { diff --git a/src/Avalonia.Styling/Styling/Setter.cs b/src/Avalonia.Styling/Styling/Setter.cs index 1f3d6335a9..4c94ea02dd 100644 --- a/src/Avalonia.Styling/Styling/Setter.cs +++ b/src/Avalonia.Styling/Styling/Setter.cs @@ -101,7 +101,7 @@ namespace Avalonia.Styling data.result = new PropertySetterInstance( data.target, property, - (T)data.value); + (T?)data.value); } } @@ -128,7 +128,7 @@ namespace Avalonia.Styling data.result = new PropertySetterInstance( data.target, property, - (T)data.value); + (T)data.value!); } } diff --git a/src/tools/MicroComGenerator/CSharpGen.Utils.cs b/src/tools/MicroComGenerator/CSharpGen.Utils.cs index da845b0ecd..28baaa65f8 100644 --- a/src/tools/MicroComGenerator/CSharpGen.Utils.cs +++ b/src/tools/MicroComGenerator/CSharpGen.Utils.cs @@ -40,7 +40,7 @@ namespace MicroComGenerator SyntaxToken Semicolon() => Token(SyntaxKind.SemicolonToken); static VariableDeclarationSyntax DeclareVar(string type, string name, - ExpressionSyntax? initializer = null) + ExpressionSyntax initializer = null) => VariableDeclaration(ParseTypeName(type), SingletonSeparatedList(VariableDeclarator(name) .WithInitializer(initializer == null ? null : EqualsValueClause(initializer))));