Browse Source

fix: some nullable annotation warnings

pull/8193/head
Giuseppe Lippolis 4 years ago
parent
commit
543fe599c6
  1. 6
      samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs
  2. 3
      src/Avalonia.Controls/Avalonia.Controls.csproj
  3. 2
      src/Avalonia.Themes.Default/SimpleTheme.cs
  4. 6
      src/Avalonia.Themes.Fluent/FluentTheme.cs
  5. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs
  6. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
  7. 2
      src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
  8. 2
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  9. 2
      src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs
  10. 3
      tests/Avalonia.Benchmarks/TestBindingObservable.cs
  11. 4
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs
  12. 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;

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

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
{ {

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

@ -547,7 +547,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)
{ {
@ -755,7 +755,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