diff --git a/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs b/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs index b092a07f4a..0e9522acab 100644 --- a/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs @@ -45,12 +45,12 @@ namespace ControlCatalog.ViewModels public List Images { get; } = new List(); - private Bitmap? _SelectedImage; + private Bitmap _SelectedImage; /// /// Gets or Sets the selected image /// - public Bitmap? SelectedImage + public Bitmap SelectedImage { get { return _SelectedImage; } set { this.RaiseAndSetIfChanged(ref _SelectedImage, value); } @@ -293,7 +293,7 @@ namespace ControlCatalog.ViewModels /// /// Any one of the parameters may be null, but not both. /// - 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; diff --git a/src/Avalonia.Controls/Avalonia.Controls.csproj b/src/Avalonia.Controls/Avalonia.Controls.csproj index 4d239e69f4..3896dc2735 100644 --- a/src/Avalonia.Controls/Avalonia.Controls.csproj +++ b/src/Avalonia.Controls/Avalonia.Controls.csproj @@ -2,9 +2,6 @@ net6.0;netstandard2.0 - - - diff --git a/src/Avalonia.Themes.Default/SimpleTheme.cs b/src/Avalonia.Themes.Default/SimpleTheme.cs index 6929660757..664c95644f 100644 --- a/src/Avalonia.Themes.Default/SimpleTheme.cs +++ b/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 { diff --git a/src/Avalonia.Themes.Fluent/FluentTheme.cs b/src/Avalonia.Themes.Fluent/FluentTheme.cs index f6b47a5466..2a8e045c48 100644 --- a/src/Avalonia.Themes.Fluent/FluentTheme.cs +++ b/src/Avalonia.Themes.Fluent/FluentTheme.cs @@ -50,7 +50,9 @@ namespace Avalonia.Themes.Fluent /// The XAML service provider. 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.Children => _loaded?.Children ?? Array.Empty(); - public event EventHandler OwnerChanged + public event EventHandler? OwnerChanged { add { diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs index c21a2d4299..ef11b06369 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs +++ b/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)) { diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs index b6137aa89f..1091b3ec7e 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs +++ b/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; diff --git a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs index fa4a27fc50..46b5bc0c40 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs @@ -64,7 +64,7 @@ namespace Avalonia.Markup.Xaml.Styling IReadOnlyList IStyle.Children => _loaded ?? Array.Empty(); - public event EventHandler OwnerChanged + public event EventHandler? OwnerChanged { add { diff --git a/src/Windows/Avalonia.Win32/TrayIconImpl.cs b/src/Windows/Avalonia.Win32/TrayIconImpl.cs index 1c2dd92219..4d537a16a4 100644 --- a/src/Windows/Avalonia.Win32/TrayIconImpl.cs +++ b/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(); } diff --git a/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs index 48f5f8f871..e864f32138 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs +++ b/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)) { diff --git a/tests/Avalonia.Benchmarks/TestBindingObservable.cs b/tests/Avalonia.Benchmarks/TestBindingObservable.cs index 0721ca9855..653959ba18 100644 --- a/tests/Avalonia.Benchmarks/TestBindingObservable.cs +++ b/tests/Avalonia.Benchmarks/TestBindingObservable.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using Avalonia.Data; namespace Avalonia.Benchmarks diff --git a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs index 9d40898608..d395f68f96 100644 --- a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs +++ b/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) { diff --git a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs index a47638d2ec..6321e8a336 100644 --- a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs +++ b/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;