Browse Source

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

fix: some nullable annotation warnings
pull/8273/head
Max Katz 4 years ago
committed by GitHub
parent
commit
5809b4b99a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs
  2. 2
      src/Android/Avalonia.Android/AvaloniaView.cs
  3. 2
      src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs
  4. 3
      src/Avalonia.Controls/Avalonia.Controls.csproj
  5. 6
      src/Avalonia.Controls/Carousel.cs
  6. 4
      src/Avalonia.Controls/Presenters/CarouselPresenter.cs
  7. 2
      src/Avalonia.Themes.Default/SimpleTheme.cs
  8. 6
      src/Avalonia.Themes.Fluent/FluentTheme.cs
  9. 2
      src/Avalonia.X11/X11Window.cs
  10. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs
  11. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
  12. 2
      src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
  13. 2
      src/Windows/Avalonia.Win32/Automation/RootAutomationNode.cs
  14. 1
      src/Windows/Avalonia.Win32/Interop/Automation/ISelectionItemProvider.cs
  15. 2
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  16. 2
      src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs
  17. 3
      tests/Avalonia.Benchmarks/TestBindingObservable.cs
  18. 4
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs
  19. 4
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

6
samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs

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

2
src/Android/Avalonia.Android/AvaloniaView.cs

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

2
src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs

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

3
src/Avalonia.Controls/Avalonia.Controls.csproj

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

6
src/Avalonia.Controls/Carousel.cs

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

4
src/Avalonia.Controls/Presenters/CarouselPresenter.cs

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

2
src/Avalonia.Themes.Default/SimpleTheme.cs

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

6
src/Avalonia.Themes.Fluent/FluentTheme.cs

@ -50,7 +50,9 @@ namespace Avalonia.Themes.Fluent
/// <param name="serviceProvider">The XAML service provider.</param> /// <param name="serviceProvider">The XAML service provider.</param>
public FluentTheme(IServiceProvider serviceProvider) 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); InitStyles(_baseUri);
} }
@ -146,7 +148,7 @@ namespace Avalonia.Themes.Fluent
IReadOnlyList<IStyle> IStyle.Children => _loaded?.Children ?? Array.Empty<IStyle>(); IReadOnlyList<IStyle> IStyle.Children => _loaded?.Children ?? Array.Empty<IStyle>();
public event EventHandler OwnerChanged public event EventHandler? OwnerChanged
{ {
add add
{ {

2
src/Avalonia.X11/X11Window.cs

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

4
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Text;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Data.Core; using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins; using Avalonia.Data.Core.Plugins;
@ -174,7 +172,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings
WeakEvents.CollectionChanged.Unsubscribe(incc, this); 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)) if (ShouldNotifyListeners(args))
{ {

4
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs

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

2
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>(); IReadOnlyList<IStyle> IStyle.Children => _loaded ?? Array.Empty<IStyle>();
public event EventHandler OwnerChanged public event EventHandler? OwnerChanged
{ {
add add
{ {

2
src/Windows/Avalonia.Win32/Automation/RootAutomationNode.cs

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

1
src/Windows/Avalonia.Win32/Interop/Automation/ISelectionItemProvider.cs

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

2
src/Windows/Avalonia.Win32/TrayIconImpl.cs

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

2
src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs

@ -109,7 +109,7 @@ namespace Avalonia.Win32
if (_owner is Window window) 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)) if (x is IInputElement ie && (!ie.IsHitTestVisible || !ie.IsVisible))
{ {

3
tests/Avalonia.Benchmarks/TestBindingObservable.cs

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

4
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs

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

4
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

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

Loading…
Cancel
Save