Browse Source

fix: some nullable annotation warnings

Giuseppe Lippolis 3 years ago
parent
commit
543fe599c6

+ 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;

+ 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" />

+ 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 - 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/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

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