Browse Source

Merge pull request #8193 from workgroupengineering/fixes/Warnings/Null-Annotation

fix: some nullable annotation warnings
Max Katz 3 years ago
parent
commit
5809b4b99a

+ 3 - 3
samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs

@@ -45,12 +45,12 @@ namespace ControlCatalog.ViewModels
         public List<Bitmap> Images { get; } = new List<Bitmap>();
 
 
-        private Bitmap? _SelectedImage;
+        private Bitmap _SelectedImage;
 
         /// <summary>
         /// Gets or Sets the selected image
         /// </summary>
-        public Bitmap? SelectedImage
+        public Bitmap SelectedImage
         {
             get { return _SelectedImage; }
             set { this.RaiseAndSetIfChanged(ref _SelectedImage, value); }
@@ -293,7 +293,7 @@ namespace ControlCatalog.ViewModels
         /// <remarks>
         /// Any one of the parameters may be null, but not both.
         /// </remarks>
-        private static IVisual GetVisualParent(IVisual? from, IVisual? to)
+        private static IVisual GetVisualParent(IVisual from, IVisual to)
         {
             var p1 = (from ?? to)!.VisualParent;
             var p2 = (to ?? from)!.VisualParent;

+ 1 - 1
src/Android/Avalonia.Android/AvaloniaView.cs

@@ -15,7 +15,7 @@ namespace Avalonia.Android
         private EmbeddableControlRoot _root;
         private readonly ViewImpl _view;
 
-        private IDisposable? _timerSubscription;
+        private IDisposable _timerSubscription;
 
         public AvaloniaView(Context context) : base(context)
         {

+ 1 - 1
src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs

@@ -30,7 +30,7 @@ namespace Avalonia.Android.Platform.Specific.Helpers
             return DispatchKeyEventInternal(e, out callBase);
         }
 
-        string? UnicodeTextInput(KeyEvent keyEvent)
+        string UnicodeTextInput(KeyEvent keyEvent)
         {
             return keyEvent.Action == KeyEventActions.Multiple
                 && keyEvent.RepeatCount == 0

+ 0 - 3
src/Avalonia.Controls/Avalonia.Controls.csproj

@@ -2,9 +2,6 @@
   <PropertyGroup>
     <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
   </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\Avalonia.Base\Metadata\NullableAttributes.cs" Link="NullableAttributes.cs" />
-  </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
     <ProjectReference Include="..\Avalonia.Remote.Protocol\Avalonia.Remote.Protocol.csproj" />

+ 3 - 3
src/Avalonia.Controls/Carousel.cs

@@ -20,8 +20,8 @@ namespace Avalonia.Controls
         /// <summary>
         /// Defines the <see cref="PageTransition"/> property.
         /// </summary>
-        public static readonly StyledProperty<IPageTransition> PageTransitionProperty =
-            AvaloniaProperty.Register<Carousel, IPageTransition>(nameof(PageTransition));
+        public static readonly StyledProperty<IPageTransition?> PageTransitionProperty =
+            AvaloniaProperty.Register<Carousel, IPageTransition?>(nameof(PageTransition));
 
         /// <summary>
         /// The default value of <see cref="ItemsControl.ItemsPanelProperty"/> for 
@@ -54,7 +54,7 @@ namespace Avalonia.Controls
         /// <summary>
         /// Gets or sets the transition to use when moving between pages.
         /// </summary>
-        public IPageTransition PageTransition
+        public IPageTransition? PageTransition
         {
             get { return GetValue(PageTransitionProperty); }
             set { SetValue(PageTransitionProperty, value); }

+ 2 - 2
src/Avalonia.Controls/Presenters/CarouselPresenter.cs

@@ -31,7 +31,7 @@ namespace Avalonia.Controls.Presenters
         /// <summary>
         /// Defines the <see cref="PageTransition"/> property.
         /// </summary>
-        public static readonly StyledProperty<IPageTransition> PageTransitionProperty =
+        public static readonly StyledProperty<IPageTransition?> PageTransitionProperty =
             Carousel.PageTransitionProperty.AddOwner<CarouselPresenter>();
 
         private int _selectedIndex = -1;
@@ -85,7 +85,7 @@ namespace Avalonia.Controls.Presenters
         /// <summary>
         /// Gets or sets a transition to use when switching pages.
         /// </summary>
-        public IPageTransition PageTransition
+        public IPageTransition? PageTransition
         {
             get { return GetValue(PageTransitionProperty); }
             set { SetValue(PageTransitionProperty, value); }

+ 1 - 1
src/Avalonia.Themes.Default/SimpleTheme.cs

@@ -44,7 +44,7 @@ namespace Avalonia.Themes.Default
             InitStyles(_baseUri);
         }
 
-        public event EventHandler OwnerChanged
+        public event EventHandler? OwnerChanged
         {
             add
             {

+ 4 - 2
src/Avalonia.Themes.Fluent/FluentTheme.cs

@@ -50,7 +50,9 @@ namespace Avalonia.Themes.Fluent
         /// <param name="serviceProvider">The XAML service provider.</param>
         public FluentTheme(IServiceProvider serviceProvider)
         {
-            _baseUri = ((IUriContext)serviceProvider.GetService(typeof(IUriContext))).BaseUri;
+            var ctx  = serviceProvider.GetService(typeof(IUriContext)) as IUriContext
+                 ?? throw new NullReferenceException("Unable retrive UriContext");
+            _baseUri = ctx.BaseUri;
             InitStyles(_baseUri);
         }
 
@@ -146,7 +148,7 @@ namespace Avalonia.Themes.Fluent
 
         IReadOnlyList<IStyle> IStyle.Children => _loaded?.Children ?? Array.Empty<IStyle>();
 
-        public event EventHandler OwnerChanged
+        public event EventHandler? OwnerChanged
         {
             add
             {

+ 1 - 1
src/Avalonia.X11/X11Window.cs

@@ -1184,7 +1184,7 @@ namespace Avalonia.X11
             }
 
             public IntPtr Handle => _owner._renderHandle;
-            public string? HandleDescriptor => "XID";
+            public string HandleDescriptor => "XID";
         }
     }
 }

+ 1 - 3
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs

@@ -1,8 +1,6 @@
 using System;
-using System.Collections.Generic;
 using System.Collections.Specialized;
 using System.ComponentModel;
-using System.Text;
 using Avalonia.Data;
 using Avalonia.Data.Core;
 using Avalonia.Data.Core.Plugins;
@@ -174,7 +172,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings
                 WeakEvents.CollectionChanged.Unsubscribe(incc, this);
         }
         
-        public void OnEvent(object? sender, WeakEvent ev, NotifyCollectionChangedEventArgs args)
+        public void OnEvent(object sender, WeakEvent ev, NotifyCollectionChangedEventArgs args)
         {
             if (ShouldNotifyListeners(args))
             {

+ 2 - 2
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs

@@ -42,7 +42,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
 
         bool IResourceNode.HasResources => Loaded.HasResources;
 
-        public event EventHandler OwnerChanged
+        public event EventHandler? OwnerChanged
         {
             add => Loaded.OwnerChanged += value;
             remove => Loaded.OwnerChanged -= value;
@@ -52,7 +52,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
         {
             if (!_isLoading)
             {
-                return Loaded.TryGetResource(key, out value);                
+                return Loaded.TryGetResource(key, out value);
             }
 
             value = null;

+ 1 - 1
src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs

@@ -64,7 +64,7 @@ namespace Avalonia.Markup.Xaml.Styling
 
         IReadOnlyList<IStyle> IStyle.Children => _loaded ?? Array.Empty<IStyle>();
 
-        public event EventHandler OwnerChanged
+        public event EventHandler? OwnerChanged
         {
             add
             {

+ 1 - 1
src/Windows/Avalonia.Win32/Automation/RootAutomationNode.cs

@@ -42,7 +42,7 @@ namespace Avalonia.Win32.Automation
             return GetOrCreate(focus);
         }
 
-        public void FocusChanged(object sender, EventArgs e)
+        public void FocusChanged(object? sender, EventArgs e)
         {
             RaiseFocusChanged(GetOrCreate(Peer.GetFocus()));
         }

+ 1 - 0
src/Windows/Avalonia.Win32/Interop/Automation/ISelectionItemProvider.cs

@@ -1,3 +1,4 @@
+#nullable enable
 using System;
 using System.Runtime.InteropServices;
 

+ 1 - 1
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@@ -195,7 +195,7 @@ namespace Avalonia.Win32
                 ShowActivated = true;
             }
 
-            private void TrayPopupRoot_Deactivated(object sender, EventArgs e)
+            private void TrayPopupRoot_Deactivated(object? sender, EventArgs e)
             {
                 Close();
             }

+ 1 - 1
src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs

@@ -109,7 +109,7 @@ namespace Avalonia.Win32
 
                             if (_owner is Window window)
                             {
-                                var visual = window.Renderer.HitTestFirst(position, _owner as Window, x =>
+                                var visual = window.Renderer.HitTestFirst(position, _owner, x =>
                                 {
                                     if (x is IInputElement ie && (!ie.IsHitTestVisible || !ie.IsVisible))
                                     {

+ 2 - 1
tests/Avalonia.Benchmarks/TestBindingObservable.cs

@@ -1,4 +1,5 @@
-using System;
+#nullable enable
+using System;
 using Avalonia.Data;
 
 namespace Avalonia.Benchmarks

+ 2 - 2
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs

@@ -602,7 +602,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
 
         private class EndOfLineTextSource : ITextSource
         {
-            public TextRun? GetTextRun(int textSourceIndex)
+            public TextRun GetTextRun(int textSourceIndex)
             {
                 return new TextEndOfLine();
             }
@@ -617,7 +617,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
                 _text = text;
             }
             
-            public TextRun? GetTextRun(int textSourceIndex)
+            public TextRun GetTextRun(int textSourceIndex)
             {
                 if (textSourceIndex >= _text.Length + TextRun.DefaultTextSourceLength + _text.Length)
                 {

+ 2 - 2
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

@@ -639,7 +639,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
         {
             const string Text = "_A_A";
 
-            public TextRun? GetTextRun(int textSourceIndex)
+            public TextRun GetTextRun(int textSourceIndex)
             {
                 switch (textSourceIndex)
                 {
@@ -907,7 +907,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
                 _textRuns = textRuns;
             }
 
-            public TextRun? GetTextRun(int textSourceIndex)
+            public TextRun GetTextRun(int textSourceIndex)
             {
                 var currentPosition = 0;