diff --git a/.ncrunch/Avalonia.Android.v3.ncrunchproject b/.ncrunch/Avalonia.Android.v3.ncrunchproject index a4953e14f9..319cd523ce 100644 --- a/.ncrunch/Avalonia.Android.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Android.v3.ncrunchproject @@ -1,6 +1,5 @@  True - True \ No newline at end of file diff --git a/.ncrunch/Avalonia.Animation.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Animation.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Animation.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Animation.v3.ncrunchproject b/.ncrunch/Avalonia.Animation.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Animation.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Base.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Base.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Base.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Base.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Base.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Base.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Base.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Base.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Base.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Base.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Base.UnitTests.v3.ncrunchproject deleted file mode 100644 index 13f78c1d4c..0000000000 --- a/.ncrunch/Avalonia.Base.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - LongTestTimesWithoutParallelExecution - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Base.v3.ncrunchproject b/.ncrunch/Avalonia.Base.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Base.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Benchmarks.v3.ncrunchproject b/.ncrunch/Avalonia.Benchmarks.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Benchmarks.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject b/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/Avalonia.Build.Tasks.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Cairo.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.Cairo.RenderTests.v3.ncrunchproject deleted file mode 100644 index 101c806e63..0000000000 --- a/.ncrunch/Avalonia.Cairo.RenderTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - AbnormalReferenceResolution - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Cairo.v3.ncrunchproject b/.ncrunch/Avalonia.Cairo.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Cairo.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.DataGrid.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.DataGrid.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Controls.DataGrid.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Controls.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index f30a20df78..0000000000 --- a/.ncrunch/Avalonia.Controls.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - Avalonia.Controls.UnitTests.TimePickerTests - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Controls.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.UnitTests.v3.ncrunchproject deleted file mode 100644 index 13f78c1d4c..0000000000 --- a/.ncrunch/Avalonia.Controls.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - LongTestTimesWithoutParallelExecution - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Controls.v3.ncrunchproject b/.ncrunch/Avalonia.Controls.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Controls.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Designer.HostApp.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Designer.HostApp.net461.v3.ncrunchproject index e9d39b0c74..319cd523ce 100644 --- a/.ncrunch/Avalonia.Designer.HostApp.net461.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Designer.HostApp.net461.v3.ncrunchproject @@ -1,7 +1,5 @@  - - MissingOrIgnoredProjectReference - + True \ No newline at end of file diff --git a/.ncrunch/Avalonia.Designer.HostApp.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Designer.HostApp.netcoreapp2.0.v3.ncrunchproject index e9d39b0c74..319cd523ce 100644 --- a/.ncrunch/Avalonia.Designer.HostApp.netcoreapp2.0.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Designer.HostApp.netcoreapp2.0.v3.ncrunchproject @@ -1,7 +1,5 @@  - - MissingOrIgnoredProjectReference - + True \ No newline at end of file diff --git a/.ncrunch/Avalonia.Designer.v3.ncrunchproject b/.ncrunch/Avalonia.Designer.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Designer.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.DesignerSupport.TestApp.v3.ncrunchproject b/.ncrunch/Avalonia.DesignerSupport.TestApp.v3.ncrunchproject index a4953e14f9..319cd523ce 100644 --- a/.ncrunch/Avalonia.DesignerSupport.TestApp.v3.ncrunchproject +++ b/.ncrunch/Avalonia.DesignerSupport.TestApp.v3.ncrunchproject @@ -1,6 +1,5 @@  True - True \ No newline at end of file diff --git a/.ncrunch/Avalonia.DesignerSupport.Tests.v3.ncrunchproject b/.ncrunch/Avalonia.DesignerSupport.Tests.v3.ncrunchproject index a4953e14f9..319cd523ce 100644 --- a/.ncrunch/Avalonia.DesignerSupport.Tests.v3.ncrunchproject +++ b/.ncrunch/Avalonia.DesignerSupport.Tests.v3.ncrunchproject @@ -1,6 +1,5 @@  True - True \ No newline at end of file diff --git a/.ncrunch/Avalonia.DesignerSupport.v3.ncrunchproject b/.ncrunch/Avalonia.DesignerSupport.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.DesignerSupport.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Designer.HostApp.NetFX.v3.ncrunchproject b/.ncrunch/Avalonia.Desktop.net6.0.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.Designer.HostApp.NetFX.v3.ncrunchproject rename to .ncrunch/Avalonia.Desktop.net6.0.v3.ncrunchproject diff --git a/.ncrunch/Avalonia.Designer.HostApp.v3.ncrunchproject b/.ncrunch/Avalonia.Desktop.netstandard2.0.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.Designer.HostApp.v3.ncrunchproject rename to .ncrunch/Avalonia.Desktop.netstandard2.0.v3.ncrunchproject diff --git a/.ncrunch/Avalonia.DesktopRuntime.net461.v3.ncrunchproject b/.ncrunch/Avalonia.DesktopRuntime.net461.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.DesktopRuntime.net461.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.DesktopRuntime.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.DesktopRuntime.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.DesktopRuntime.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.DesktopRuntime.v3.ncrunchproject b/.ncrunch/Avalonia.DesktopRuntime.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/Avalonia.DesktopRuntime.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Diagnostics.v3.ncrunchproject b/.ncrunch/Avalonia.Diagnostics.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Diagnostics.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject deleted file mode 100644 index 0846098ce5..0000000000 --- a/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject +++ /dev/null @@ -1,12 +0,0 @@ - - - - ..\TestFiles\Direct2D1\**.* - - 3000 - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Direct2D1.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Direct2D1.UnitTests.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Direct2D1.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Direct2D1.v3.ncrunchproject b/.ncrunch/Avalonia.Direct2D1.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Direct2D1.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Gtk3.v3.ncrunchproject b/.ncrunch/Avalonia.Gtk3.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Gtk3.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Input.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Input.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Input.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Input.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Input.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Input.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Input.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Input.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Input.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Input.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Input.UnitTests.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Input.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Input.v3.ncrunchproject b/.ncrunch/Avalonia.Input.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Input.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Interactivity.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Interactivity.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Interactivity.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Interactivity.UnitTests.netcoreapp1.1.v3.ncrunchproject b/.ncrunch/Avalonia.Interactivity.UnitTests.netcoreapp1.1.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Interactivity.UnitTests.netcoreapp1.1.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Interactivity.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Interactivity.UnitTests.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Interactivity.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Interactivity.v3.ncrunchproject b/.ncrunch/Avalonia.Interactivity.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Interactivity.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Layout.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Layout.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Layout.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Layout.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Layout.UnitTests.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Layout.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Layout.v3.ncrunchproject b/.ncrunch/Avalonia.Layout.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Layout.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.LeakTests.v3.ncrunchproject b/.ncrunch/Avalonia.LeakTests.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.LeakTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.LinuxFramebuffer.v3.ncrunchproject b/.ncrunch/Avalonia.LinuxFramebuffer.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.LinuxFramebuffer.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Logging.Serilog.v3.ncrunchproject b/.ncrunch/Avalonia.Logging.Serilog.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Logging.Serilog.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Markup.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Markup.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp1.1.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp1.1.v3.ncrunchproject deleted file mode 100644 index 15d9efad87..0000000000 --- a/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp1.1.v3.ncrunchproject +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Avalonia.Markup.UnitTests.Data.Plugins.DataAnnotationsValidationPluginTests.Produces_Aggregate_BindingNotificationsx - - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Markup.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.UnitTests.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Markup.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.Xaml.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.Xaml.UnitTests.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Markup.Xaml.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.Xaml.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.Xaml.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Markup.Xaml.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Markup.v3.ncrunchproject b/.ncrunch/Avalonia.Markup.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Markup.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject b/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/Avalonia.MicroCom.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Native.net6.0.v3.ncrunchproject b/.ncrunch/Avalonia.Native.net6.0.v3.ncrunchproject new file mode 100644 index 0000000000..e8de009693 --- /dev/null +++ b/.ncrunch/Avalonia.Native.net6.0.v3.ncrunchproject @@ -0,0 +1,6 @@ + + + True + + + \ No newline at end of file diff --git a/.ncrunch/Avalonia.Desktop.v3.ncrunchproject b/.ncrunch/Avalonia.Native.netstandard2.0.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.Desktop.v3.ncrunchproject rename to .ncrunch/Avalonia.Native.netstandard2.0.v3.ncrunchproject diff --git a/.ncrunch/Avalonia.OpenGL.v3.ncrunchproject b/.ncrunch/Avalonia.OpenGL.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.OpenGL.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.ReactiveUI.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.ReactiveUI.UnitTests.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.ReactiveUI.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.ReactiveUI.v3.ncrunchproject b/.ncrunch/Avalonia.ReactiveUI.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.ReactiveUI.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.RenderTests.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/Avalonia.RenderTests.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.Android.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.Android.v3.ncrunchproject deleted file mode 100644 index a4953e14f9..0000000000 --- a/.ncrunch/Avalonia.Skia.Android.v3.ncrunchproject +++ /dev/null @@ -1,6 +0,0 @@ - - - True - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.Desktop.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.Desktop.v3.ncrunchproject deleted file mode 100644 index ae3801f32b..0000000000 --- a/.ncrunch/Avalonia.Skia.Desktop.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - True - False - True - x86 - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject deleted file mode 100644 index 2966be8f73..0000000000 --- a/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject +++ /dev/null @@ -1,12 +0,0 @@ - - - - ..\TestFiles\Skia\**.* - - 3000 - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.UnitTests.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Skia.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.iOS.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.iOS.v3.ncrunchproject deleted file mode 100644 index a4953e14f9..0000000000 --- a/.ncrunch/Avalonia.Skia.iOS.v3.ncrunchproject +++ /dev/null @@ -1,6 +0,0 @@ - - - True - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Skia.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Styling.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Styling.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Styling.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Styling.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Styling.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Styling.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Styling.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Styling.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Styling.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Styling.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Styling.UnitTests.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Styling.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Styling.v3.ncrunchproject b/.ncrunch/Avalonia.Styling.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Styling.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Themes.Default.v3.ncrunchproject b/.ncrunch/Avalonia.Themes.Default.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Themes.Default.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.UnitTests.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Visuals.UnitTests.net461.v3.ncrunchproject b/.ncrunch/Avalonia.Visuals.UnitTests.net461.v3.ncrunchproject deleted file mode 100644 index 6800b4a3fe..0000000000 --- a/.ncrunch/Avalonia.Visuals.UnitTests.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Visuals.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.Visuals.UnitTests.net47.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Visuals.UnitTests.net47.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Visuals.UnitTests.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Visuals.UnitTests.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.Visuals.UnitTests.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Visuals.UnitTests.v3.ncrunchproject b/.ncrunch/Avalonia.Visuals.UnitTests.v3.ncrunchproject deleted file mode 100644 index ee655751a0..0000000000 --- a/.ncrunch/Avalonia.Visuals.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,9 +0,0 @@ - - - - AbnormalReferenceResolution - LongTestTimesWithoutParallelExecution - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Visuals.v3.ncrunchproject b/.ncrunch/Avalonia.Visuals.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Visuals.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Win32.Interop.v3.ncrunchproject b/.ncrunch/Avalonia.Win32.Interop.v3.ncrunchproject deleted file mode 100644 index e12537d535..0000000000 --- a/.ncrunch/Avalonia.Win32.Interop.v3.ncrunchproject +++ /dev/null @@ -1,8 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Win32.v3.ncrunchproject b/.ncrunch/Avalonia.Win32.net6.0.v3.ncrunchproject similarity index 50% rename from .ncrunch/Avalonia.Win32.v3.ncrunchproject rename to .ncrunch/Avalonia.Win32.net6.0.v3.ncrunchproject index bc2ee91007..28b692bb51 100644 --- a/.ncrunch/Avalonia.Win32.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Win32.net6.0.v3.ncrunchproject @@ -3,9 +3,5 @@ ..\..\tools\MicroComGenerator\bin\Debug\net6.0\**.* - - MissingOrIgnoredProjectReference - - True \ No newline at end of file diff --git a/.ncrunch/Avalonia.Win32.netstandard2.0.v3.ncrunchproject b/.ncrunch/Avalonia.Win32.netstandard2.0.v3.ncrunchproject new file mode 100644 index 0000000000..28b692bb51 --- /dev/null +++ b/.ncrunch/Avalonia.Win32.netstandard2.0.v3.ncrunchproject @@ -0,0 +1,7 @@ + + + + ..\..\tools\MicroComGenerator\bin\Debug\net6.0\**.* + + + \ No newline at end of file diff --git a/.ncrunch/Avalonia.X11.v3.ncrunchproject b/.ncrunch/Avalonia.X11.v3.ncrunchproject deleted file mode 100644 index e9d39b0c74..0000000000 --- a/.ncrunch/Avalonia.X11.v3.ncrunchproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - MissingOrIgnoredProjectReference - - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.net461.v3.ncrunchproject b/.ncrunch/Avalonia.net461.v3.ncrunchproject index 319cd523ce..4fdcd169ae 100644 --- a/.ncrunch/Avalonia.net461.v3.ncrunchproject +++ b/.ncrunch/Avalonia.net461.v3.ncrunchproject @@ -1,5 +1,7 @@  - True + + DerivedFilesIncludedInWorkspace + \ No newline at end of file diff --git a/.ncrunch/Avalonia.Animation.UnitTests.net47.v3.ncrunchproject b/.ncrunch/Avalonia.net6.0.v3.ncrunchproject similarity index 59% rename from .ncrunch/Avalonia.Animation.UnitTests.net47.v3.ncrunchproject rename to .ncrunch/Avalonia.net6.0.v3.ncrunchproject index e9d39b0c74..4fdcd169ae 100644 --- a/.ncrunch/Avalonia.Animation.UnitTests.net47.v3.ncrunchproject +++ b/.ncrunch/Avalonia.net6.0.v3.ncrunchproject @@ -1,7 +1,7 @@  - MissingOrIgnoredProjectReference + DerivedFilesIncludedInWorkspace \ No newline at end of file diff --git a/.ncrunch/Avalonia.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/Avalonia.netcoreapp2.0.v3.ncrunchproject index 3f3c53a7fd..4fdcd169ae 100644 --- a/.ncrunch/Avalonia.netcoreapp2.0.v3.ncrunchproject +++ b/.ncrunch/Avalonia.netcoreapp2.0.v3.ncrunchproject @@ -2,7 +2,6 @@ DerivedFilesIncludedInWorkspace - MissingOrIgnoredProjectReference \ No newline at end of file diff --git a/.ncrunch/Avalonia.netstandard2.0.v3.ncrunchproject b/.ncrunch/Avalonia.netstandard2.0.v3.ncrunchproject index 3f3c53a7fd..4fdcd169ae 100644 --- a/.ncrunch/Avalonia.netstandard2.0.v3.ncrunchproject +++ b/.ncrunch/Avalonia.netstandard2.0.v3.ncrunchproject @@ -2,7 +2,6 @@ DerivedFilesIncludedInWorkspace - MissingOrIgnoredProjectReference \ No newline at end of file diff --git a/.ncrunch/BindingDemo.net461.v3.ncrunchproject b/.ncrunch/BindingDemo.net461.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/BindingDemo.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/BindingDemo.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/BindingDemo.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/BindingDemo.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.Native.v3.ncrunchproject b/.ncrunch/ControlCatalog.Web.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.Native.v3.ncrunchproject rename to .ncrunch/ControlCatalog.Web.v3.ncrunchproject diff --git a/.ncrunch/ControlCatalog.v3.ncrunchproject b/.ncrunch/ControlCatalog.v3.ncrunchproject index a4953e14f9..319cd523ce 100644 --- a/.ncrunch/ControlCatalog.v3.ncrunchproject +++ b/.ncrunch/ControlCatalog.v3.ncrunchproject @@ -1,6 +1,5 @@  True - True \ No newline at end of file diff --git a/.ncrunch/Avalonia.Skia.Desktop.NetStandard.v3.ncrunchproject b/.ncrunch/ControlSamples.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.Skia.Desktop.NetStandard.v3.ncrunchproject rename to .ncrunch/ControlSamples.v3.ncrunchproject diff --git a/.ncrunch/Direct3DInteropSample.v3.ncrunchproject b/.ncrunch/Direct3DInteropSample.v3.ncrunchproject index 21fcdee3a6..319cd523ce 100644 --- a/.ncrunch/Direct3DInteropSample.v3.ncrunchproject +++ b/.ncrunch/Direct3DInteropSample.v3.ncrunchproject @@ -1,9 +1,5 @@  - - MissingOrIgnoredProjectReference - True - True \ No newline at end of file diff --git a/.ncrunch/GtkInteropDemo.v3.ncrunchproject b/.ncrunch/GtkInteropDemo.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/GtkInteropDemo.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/Avalonia.iOSTestApplication.v3.ncrunchproject b/.ncrunch/MiniMvvm.v3.ncrunchproject similarity index 100% rename from .ncrunch/Avalonia.iOSTestApplication.v3.ncrunchproject rename to .ncrunch/MiniMvvm.v3.ncrunchproject diff --git a/.ncrunch/PlatformSanityChecks.v3.ncrunchproject b/.ncrunch/PlatformSanityChecks.v3.ncrunchproject index e9d39b0c74..319cd523ce 100644 --- a/.ncrunch/PlatformSanityChecks.v3.ncrunchproject +++ b/.ncrunch/PlatformSanityChecks.v3.ncrunchproject @@ -1,7 +1,5 @@  - - MissingOrIgnoredProjectReference - + True \ No newline at end of file diff --git a/.ncrunch/PlatformSupport.v3.ncrunchproject b/.ncrunch/PlatformSupport.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/PlatformSupport.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/RenderDemo.net461.v3.ncrunchproject b/.ncrunch/RenderDemo.net461.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/RenderDemo.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/RenderDemo.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/RenderDemo.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/RenderDemo.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/RenderHelpers.v3.ncrunchproject b/.ncrunch/RenderHelpers.v3.ncrunchproject deleted file mode 100644 index 95a483b433..0000000000 --- a/.ncrunch/RenderHelpers.v3.ncrunchproject +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.ncrunch/VirtualizationDemo.net461.v3.ncrunchproject b/.ncrunch/VirtualizationDemo.net461.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/VirtualizationDemo.net461.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/.ncrunch/VirtualizationDemo.netcoreapp2.0.v3.ncrunchproject b/.ncrunch/VirtualizationDemo.netcoreapp2.0.v3.ncrunchproject deleted file mode 100644 index 319cd523ce..0000000000 --- a/.ncrunch/VirtualizationDemo.netcoreapp2.0.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/Avalonia.sln b/Avalonia.sln index a288bacbde..3c2fc7437b 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -60,7 +60,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A689DEF5-D50F-4975-8B72-124C9EB54066}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - src\Shared\SharedAssemblyInfo.cs = src\Shared\SharedAssemblyInfo.cs EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.ReactiveUI", "src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj", "{6417B24E-49C2-4985-8DB2-3AB9D898EC91}" diff --git a/NuGet.Config b/NuGet.Config index e430390d39..7a1f28bea7 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -5,6 +5,5 @@ - diff --git a/build/ApiDiff.props b/build/ApiDiff.props index a7454b4a4f..b0b1942f60 100644 --- a/build/ApiDiff.props +++ b/build/ApiDiff.props @@ -3,6 +3,7 @@ 0.10.0 $(PackageId) Avalonia + false diff --git a/build/HarfBuzzSharp.props b/build/HarfBuzzSharp.props index 1346a1dafc..1d84d5289a 100644 --- a/build/HarfBuzzSharp.props +++ b/build/HarfBuzzSharp.props @@ -1,7 +1,7 @@  - - - + + + diff --git a/build/JetBrains.dotMemoryUnit.props b/build/JetBrains.dotMemoryUnit.props index 1713dead68..eb4e2b6f15 100644 --- a/build/JetBrains.dotMemoryUnit.props +++ b/build/JetBrains.dotMemoryUnit.props @@ -1,5 +1,5 @@ - + diff --git a/build/MicroCom.targets b/build/MicroCom.targets index 1ed388f689..029d7f95f5 100644 --- a/build/MicroCom.targets +++ b/build/MicroCom.targets @@ -6,6 +6,7 @@ false all true + TargetFramework=net6.0 diff --git a/build/NullableEnable.props b/build/NullableEnable.props new file mode 100644 index 0000000000..cf5f9069d4 --- /dev/null +++ b/build/NullableEnable.props @@ -0,0 +1,11 @@ + + + + enable + $(WarningsAsErrors);nullable + $(NoWarn);nullable + + diff --git a/build/SkiaSharp.props b/build/SkiaSharp.props index 4a75a18290..bb370256f9 100644 --- a/build/SkiaSharp.props +++ b/build/SkiaSharp.props @@ -1,7 +1,7 @@  - - - + + + diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/window.mm index 16f49b8e26..0b88908252 100644 --- a/native/Avalonia.Native/src/OSX/window.mm +++ b/native/Avalonia.Native/src/OSX/window.mm @@ -43,6 +43,7 @@ public: StandardContainer = [[AutoFitContentView new] initWithContent:View]; Window = [[AvnWindow alloc] initWithParent:this]; + [Window setContentView: StandardContainer]; lastPositionSet.X = 100; lastPositionSet.Y = 100; @@ -124,8 +125,6 @@ public: SetPosition(lastPositionSet); UpdateStyle(); - [Window setContentView: StandardContainer]; - [Window setTitle:_lastTitle]; if(ShouldTakeFocusOnShow() && activate) @@ -328,8 +327,8 @@ public: BaseEvents->Resized(AvnSize{x,y}, reason); } - [StandardContainer setFrameSize:NSSize{x,y}]; - [Window setContentSize:NSSize{x, y}]; + [Window setContentSize:NSSize{x,y}]; + [Window invalidateShadow]; } @finally { diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index 6f4afd9191..f0b894b596 100644 --- a/nukebuild/Build.cs +++ b/nukebuild/Build.cs @@ -253,10 +253,14 @@ partial class Build : NukeBuild .DependsOn(Compile) .Executes(() => { - var testAssembly = "tests\\Avalonia.LeakTests\\bin\\Release\\net461\\Avalonia.LeakTests.dll"; - DotMemoryUnit( - $"{XunitPath.DoubleQuoteIfNeeded()} --propagate-exit-code -- {testAssembly}", - timeout: 120_000); + void DoMemoryTest() + { + var testAssembly = "tests\\Avalonia.LeakTests\\bin\\Release\\net461\\Avalonia.LeakTests.dll"; + DotMemoryUnit( + $"{XunitPath.DoubleQuoteIfNeeded()} --propagate-exit-code -- {testAssembly}", + timeout: 120_000); + } + ControlFlow.ExecuteWithRetry(DoMemoryTest, waitInSeconds: 3); }); Target ZipFiles => _ => _ diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 44e2290a0d..4b28527465 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net461;netcoreapp2.0 + net6.0;netstandard2.0;net461;netcoreapp2.0 Avalonia diff --git a/readme.md b/readme.md index a8a6399f2f..b38552a010 100644 --- a/readme.md +++ b/readme.md @@ -75,6 +75,12 @@ For more information see the [.NET Foundation Code of Conduct](https://dotnetfou Avalonia is licenced under the [MIT licence](licence.md). +## Support Avalonia + +**BTC**: bc1q05wx78qemgy9x6ytl5ljk2xrt00yqargyjm8gx + +This will be shared with the community and awarded for significant contributions. + ### Backers Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/Avalonia#backer)] diff --git a/samples/ControlCatalog.Android/ControlCatalog.Android.csproj b/samples/ControlCatalog.Android/ControlCatalog.Android.csproj index 1a68c4d732..617b6b6ab0 100644 --- a/samples/ControlCatalog.Android/ControlCatalog.Android.csproj +++ b/samples/ControlCatalog.Android/ControlCatalog.Android.csproj @@ -32,7 +32,7 @@ True False False - armeabi-v7a;x86 + armeabi-v7a;x86;x86_64 Xamarin False False @@ -51,7 +51,7 @@ True False False - armeabi-v7a,x86 + armeabi-v7a,x86;x86_64 Xamarin False False @@ -125,6 +125,10 @@ {42472427-4774-4c81-8aff-9f27b8e31721} Avalonia.Layout + + {c42d2fc1-a531-4ed4-84b9-89aec7c962fc} + Avalonia.Themes.Fluent + {eb582467-6abb-43a1-b052-e981ba910e3a} Avalonia.Visuals diff --git a/samples/ControlCatalog.Android/Resources/Resource.Designer.cs b/samples/ControlCatalog.Android/Resources/Resource.Designer.cs index b1ca548e2c..dccc3f7159 100644 --- a/samples/ControlCatalog.Android/Resources/Resource.Designer.cs +++ b/samples/ControlCatalog.Android/Resources/Resource.Designer.cs @@ -14,7 +14,7 @@ namespace ControlCatalog.Android { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.1.99.62")] public partial class Resource { diff --git a/samples/ControlCatalog/App.xaml.cs b/samples/ControlCatalog/App.xaml.cs index 36b6fc2dcd..816356bee9 100644 --- a/samples/ControlCatalog/App.xaml.cs +++ b/samples/ControlCatalog/App.xaml.cs @@ -5,6 +5,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml.Styling; using Avalonia.Styling; +using Avalonia.Themes.Fluent; using ControlCatalog.ViewModels; namespace ControlCatalog @@ -16,33 +17,17 @@ namespace ControlCatalog DataContext = new ApplicationViewModel(); } - private static readonly StyleInclude DataGridFluent = new StyleInclude(new Uri("avares://ControlCatalog/Styles")) + public static readonly StyleInclude DataGridFluent = new StyleInclude(new Uri("avares://ControlCatalog/Styles")) { Source = new Uri("avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml") }; - private static readonly StyleInclude DataGridDefault = new StyleInclude(new Uri("avares://ControlCatalog/Styles")) + public static readonly StyleInclude DataGridDefault = new StyleInclude(new Uri("avares://ControlCatalog/Styles")) { Source = new Uri("avares://Avalonia.Controls.DataGrid/Themes/Default.xaml") }; - public static Styles FluentDark = new Styles - { - new StyleInclude(new Uri("avares://ControlCatalog/Styles")) - { - Source = new Uri("avares://Avalonia.Themes.Fluent/FluentDark.xaml") - }, - DataGridFluent - }; - - public static Styles FluentLight = new Styles - { - new StyleInclude(new Uri("avares://ControlCatalog/Styles")) - { - Source = new Uri("avares://Avalonia.Themes.Fluent/FluentLight.xaml") - }, - DataGridFluent - }; + public static FluentTheme Fluent = new FluentTheme(new Uri("avares://ControlCatalog/Styles")); public static Styles DefaultLight = new Styles { @@ -65,8 +50,7 @@ namespace ControlCatalog new StyleInclude(new Uri("resm:Styles?assembly=ControlCatalog")) { Source = new Uri("avares://Avalonia.Themes.Default/DefaultTheme.xaml") - }, - DataGridDefault + } }; public static Styles DefaultDark = new Styles @@ -90,14 +74,13 @@ namespace ControlCatalog new StyleInclude(new Uri("resm:Styles?assembly=ControlCatalog")) { Source = new Uri("avares://Avalonia.Themes.Default/DefaultTheme.xaml") - }, - DataGridDefault + } }; public override void Initialize() { - Styles.Insert(0, FluentLight); - + Styles.Insert(0, Fluent); + Styles.Insert(1, DataGridFluent); AvaloniaXamlLoader.Load(this); } @@ -111,6 +94,11 @@ namespace ControlCatalog singleViewLifetime.MainView = new MainView(); base.OnFrameworkInitializationCompleted(); + + this.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions() + { + StartupScreenIndex = 1, + }); } } } diff --git a/samples/ControlCatalog/DecoratedWindow.xaml.cs b/samples/ControlCatalog/DecoratedWindow.xaml.cs index bdf5b8fbee..a1383b9107 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml.cs +++ b/samples/ControlCatalog/DecoratedWindow.xaml.cs @@ -11,7 +11,6 @@ namespace ControlCatalog public DecoratedWindow() { this.InitializeComponent(); - this.AttachDevTools(); } void SetupSide(string name, StandardCursorType cursor, WindowEdge edge) diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs index abedda3c85..0579355831 100644 --- a/samples/ControlCatalog/MainView.xaml.cs +++ b/samples/ControlCatalog/MainView.xaml.cs @@ -3,14 +3,12 @@ using System.Collections; using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -using Avalonia.Markup.Xaml.MarkupExtensions; -using Avalonia.Markup.Xaml.Styling; -using Avalonia.Markup.Xaml.XamlIl; using Avalonia.Media; using Avalonia.Media.Immutable; using Avalonia.Platform; -using ControlCatalog.Pages; +using Avalonia.Themes.Fluent; using ControlCatalog.Models; +using ControlCatalog.Pages; namespace ControlCatalog { @@ -43,14 +41,36 @@ namespace ControlCatalog { if (themes.SelectedItem is CatalogTheme theme) { - Application.Current.Styles[0] = theme switch + var themeStyle = Application.Current.Styles[0]; + if (theme == CatalogTheme.FluentLight) + { + if (App.Fluent.Mode != FluentThemeMode.Light) + { + App.Fluent.Mode = FluentThemeMode.Light; + } + Application.Current.Styles[0] = App.Fluent; + Application.Current.Styles[1] = App.DataGridFluent; + } + else if (theme == CatalogTheme.FluentDark) + { + + if (App.Fluent.Mode != FluentThemeMode.Dark) + { + App.Fluent.Mode = FluentThemeMode.Dark; + } + Application.Current.Styles[0] = App.Fluent; + Application.Current.Styles[1] = App.DataGridFluent; + } + else if (theme == CatalogTheme.DefaultLight) + { + Application.Current.Styles[0] = App.DefaultLight; + Application.Current.Styles[1] = App.DataGridDefault; + } + else if (theme == CatalogTheme.DefaultDark) { - CatalogTheme.FluentLight => App.FluentLight, - CatalogTheme.FluentDark => App.FluentDark, - CatalogTheme.DefaultLight => App.DefaultLight, - CatalogTheme.DefaultDark => App.DefaultDark, - _ => Application.Current.Styles[0] - }; + Application.Current.Styles[0] = App.DefaultDark; + Application.Current.Styles[1] = App.DataGridDefault; + } } }; diff --git a/samples/ControlCatalog/MainWindow.xaml.cs b/samples/ControlCatalog/MainWindow.xaml.cs index dd62698cc7..20591103b7 100644 --- a/samples/ControlCatalog/MainWindow.xaml.cs +++ b/samples/ControlCatalog/MainWindow.xaml.cs @@ -17,10 +17,7 @@ namespace ControlCatalog public MainWindow() { this.InitializeComponent(); - this.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions() - { - StartupScreenIndex = 1, - }); + //Renderer.DrawFps = true; //Renderer.DrawDirtyRects = Renderer.DrawFps = true; diff --git a/samples/ControlCatalog/Pages/PointersPage.cs b/samples/ControlCatalog/Pages/PointersPage.cs index 60e946dfbe..fddc503a90 100644 --- a/samples/ControlCatalog/Pages/PointersPage.cs +++ b/samples/ControlCatalog/Pages/PointersPage.cs @@ -99,10 +99,9 @@ namespace ControlCatalog.Pages foreach (var pt in _pointers.Values) { var brush = new ImmutableSolidColorBrush(pt.Color); - context.DrawGeometry(brush, null, new EllipseGeometry(new Rect(pt.Point.X - 75, pt.Point.Y - 75, - 150, 150))); + + context.DrawEllipse(brush, null, pt.Point, 75, 75); } - } } } diff --git a/src/Android/Avalonia.Android/AndroidPlatform.cs b/src/Android/Avalonia.Android/AndroidPlatform.cs index 5e11d8eab2..57f22e7a05 100644 --- a/src/Android/Avalonia.Android/AndroidPlatform.cs +++ b/src/Android/Avalonia.Android/AndroidPlatform.cs @@ -43,11 +43,12 @@ namespace Avalonia.Android AvaloniaLocator.CurrentMutable .Bind().ToTransient() .Bind().ToTransient() + .Bind().ToConstant(new WindowingPlatformStub()) .Bind().ToSingleton() .Bind().ToConstant(Instance) .Bind().ToConstant(new AndroidThreadingInterface()) .Bind().ToTransient() - .Bind().ToSingleton() + .Bind().ToSingleton() .Bind().ToConstant(new ChoreographerTimer()) .Bind().ToConstant(new RenderLoop()) .Bind().ToSingleton() diff --git a/src/Android/Avalonia.Android/Stubs.cs b/src/Android/Avalonia.Android/Stubs.cs new file mode 100644 index 0000000000..f36c01dbc8 --- /dev/null +++ b/src/Android/Avalonia.Android/Stubs.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using Avalonia.Platform; + +namespace Avalonia.Android +{ + class WindowingPlatformStub : IWindowingPlatform + { + public IWindowImpl CreateWindow() => throw new NotSupportedException(); + + public IWindowImpl CreateEmbeddableWindow() => throw new NotSupportedException(); + + public ITrayIconImpl CreateTrayIcon() => null; + } + + class PlatformIconLoaderStub : IPlatformIconLoader + { + public IWindowIconImpl LoadIcon(IBitmapImpl bitmap) + { + using (var stream = new MemoryStream()) + { + bitmap.Save(stream); + return LoadIcon(stream); + } + } + + public IWindowIconImpl LoadIcon(Stream stream) + { + var ms = new MemoryStream(); + stream.CopyTo(ms); + return new IconStub(ms); + } + + public IWindowIconImpl LoadIcon(string fileName) + { + using (var file = File.Open(fileName, FileMode.Open)) + return LoadIcon(file); + } + } + + public class IconStub : IWindowIconImpl + { + private readonly MemoryStream _ms; + + public IconStub(MemoryStream stream) + { + _ms = stream; + } + + public void Save(Stream outputStream) + { + _ms.Position = 0; + _ms.CopyTo(outputStream); + } + } +} diff --git a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs index 83db67fcee..87fd47df25 100644 --- a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs +++ b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs @@ -14,7 +14,7 @@ namespace Avalonia.AndroidTestApplication { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.1.99.62")] public partial class Resource { diff --git a/src/Avalonia.Animation/Avalonia.Animation.csproj b/src/Avalonia.Animation/Avalonia.Animation.csproj index ee91acf45e..465b922b72 100644 --- a/src/Avalonia.Animation/Avalonia.Animation.csproj +++ b/src/Avalonia.Animation/Avalonia.Animation.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Base/AttachedProperty.cs b/src/Avalonia.Base/AttachedProperty.cs index 352104897a..12c569c452 100644 --- a/src/Avalonia.Base/AttachedProperty.cs +++ b/src/Avalonia.Base/AttachedProperty.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/Avalonia.Base.csproj b/src/Avalonia.Base/Avalonia.Base.csproj index 0470dbfe89..376075df2a 100644 --- a/src/Avalonia.Base/Avalonia.Base.csproj +++ b/src/Avalonia.Base/Avalonia.Base.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 Avalonia.Base Avalonia True @@ -11,4 +11,5 @@ + diff --git a/src/Avalonia.Base/AvaloniaInternalException.cs b/src/Avalonia.Base/AvaloniaInternalException.cs index 60e3040e01..a536073174 100644 --- a/src/Avalonia.Base/AvaloniaInternalException.cs +++ b/src/Avalonia.Base/AvaloniaInternalException.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaLocator.cs b/src/Avalonia.Base/AvaloniaLocator.cs index 3163d15c1b..8ec245507b 100644 --- a/src/Avalonia.Base/AvaloniaLocator.cs +++ b/src/Avalonia.Base/AvaloniaLocator.cs @@ -7,10 +7,10 @@ namespace Avalonia { public class AvaloniaLocator : IAvaloniaDependencyResolver { - private readonly IAvaloniaDependencyResolver _parentScope; + private readonly IAvaloniaDependencyResolver? _parentScope; public static IAvaloniaDependencyResolver Current { get; set; } public static AvaloniaLocator CurrentMutable { get; set; } - private readonly Dictionary> _registry = new Dictionary>(); + private readonly Dictionary> _registry = new Dictionary>(); static AvaloniaLocator() { @@ -27,10 +27,9 @@ namespace Avalonia _parentScope = parentScope; } - public object GetService(Type t) + public object? GetService(Type t) { - Func rv; - return _registry.TryGetValue(t, out rv) ? rv() : _parentScope?.GetService(t); + return _registry.TryGetValue(t, out var rv) ? rv() : _parentScope?.GetService(t); } public class RegistrationHelper @@ -57,7 +56,7 @@ namespace Avalonia public AvaloniaLocator ToLazy(Func func) where TImlp : TService { var constructed = false; - TImlp instance = default; + TImlp? instance = default; _locator._registry[typeof (TService)] = () => { if (!constructed) @@ -73,7 +72,7 @@ namespace Avalonia public AvaloniaLocator ToSingleton() where TImpl : class, TService, new() { - TImpl instance = null; + TImpl? instance = null; return ToFunc(() => instance ?? (instance = new TImpl())); } @@ -117,14 +116,24 @@ namespace Avalonia public interface IAvaloniaDependencyResolver { - object GetService(Type t); + object? GetService(Type t); } public static class LocatorExtensions { - public static T GetService(this IAvaloniaDependencyResolver resolver) + public static T? GetService(this IAvaloniaDependencyResolver resolver) { - return (T) resolver.GetService(typeof (T)); + return (T?) resolver.GetService(typeof (T)); + } + + public static object GetRequiredService(this IAvaloniaDependencyResolver resolver, Type t) + { + return resolver.GetService(t) ?? throw new InvalidOperationException($"Unable to locate '{t}'."); + } + + public static T GetRequiredService(this IAvaloniaDependencyResolver resolver) + { + return (T?)resolver.GetService(typeof(T)) ?? throw new InvalidOperationException($"Unable to locate '{typeof(T)}'."); } } } diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs index 9a1101e637..437339d3b2 100644 --- a/src/Avalonia.Base/AvaloniaObject.cs +++ b/src/Avalonia.Base/AvaloniaObject.cs @@ -7,8 +7,6 @@ using Avalonia.Logging; using Avalonia.PropertyStore; using Avalonia.Threading; -#nullable enable - namespace Avalonia { /// @@ -47,7 +45,7 @@ namespace Avalonia /// /// Raised when a value changes on this object. /// - event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged + event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged { add { _inpcChanged += value; } remove { _inpcChanged -= value; } @@ -857,7 +855,7 @@ namespace Avalonia private string GetDescription(object o) { var description = o as IDescription; - return description?.Description ?? o.ToString(); + return description?.Description ?? o.ToString() ?? o.GetType().Name; } /// diff --git a/src/Avalonia.Base/AvaloniaObjectExtensions.cs b/src/Avalonia.Base/AvaloniaObjectExtensions.cs index 16f0ca38a7..51237409bf 100644 --- a/src/Avalonia.Base/AvaloniaObjectExtensions.cs +++ b/src/Avalonia.Base/AvaloniaObjectExtensions.cs @@ -6,8 +6,6 @@ using System.Reactive.Subjects; using Avalonia.Data; using Avalonia.Reactive; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaProperty.cs b/src/Avalonia.Base/AvaloniaProperty.cs index 3e5cfb24a2..3d1e898f50 100644 --- a/src/Avalonia.Base/AvaloniaProperty.cs +++ b/src/Avalonia.Base/AvaloniaProperty.cs @@ -4,8 +4,6 @@ using Avalonia.Data; using Avalonia.Data.Core; using Avalonia.Utilities; -#nullable enable - namespace Avalonia { /// @@ -544,12 +542,12 @@ namespace Avalonia throw new ArgumentNullException(nameof(type)); } - if (_metadataCache.TryGetValue(type, out AvaloniaPropertyMetadata result)) + if (_metadataCache.TryGetValue(type, out var result)) { return result; } - Type currentType = type; + Type? currentType = type; while (currentType != null) { diff --git a/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs b/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs index 896d86e29d..445f35aad2 100644 --- a/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs +++ b/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs @@ -1,8 +1,6 @@ using System; using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs b/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs index 054bf93b3a..734e38596c 100644 --- a/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs +++ b/src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs @@ -1,7 +1,5 @@ using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaPropertyMetadata.cs b/src/Avalonia.Base/AvaloniaPropertyMetadata.cs index 4090aab558..2963567b14 100644 --- a/src/Avalonia.Base/AvaloniaPropertyMetadata.cs +++ b/src/Avalonia.Base/AvaloniaPropertyMetadata.cs @@ -1,7 +1,5 @@ using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs index 91db8c16c2..d86e723b38 100644 --- a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs +++ b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/AvaloniaProperty`1.cs b/src/Avalonia.Base/AvaloniaProperty`1.cs index 3485f195c5..3937ee5658 100644 --- a/src/Avalonia.Base/AvaloniaProperty`1.cs +++ b/src/Avalonia.Base/AvaloniaProperty`1.cs @@ -3,8 +3,6 @@ using System.Reactive.Subjects; using Avalonia.Data; using Avalonia.Utilities; -#nullable enable - namespace Avalonia { /// @@ -84,15 +82,15 @@ namespace Avalonia protected override IObservable GetChanged() => Changed; - protected BindingValue TryConvert(object? value) + protected BindingValue TryConvert(object? value) { if (value == UnsetValue) { - return BindingValue.Unset; + return BindingValue.Unset; } else if (value == BindingOperations.DoNothing) { - return BindingValue.DoNothing; + return BindingValue.DoNothing; } if (!TypeUtilities.TryConvertImplicit(PropertyType, value, out var converted)) @@ -102,7 +100,7 @@ namespace Avalonia Name, value, value?.GetType().FullName ?? "(null)")); - return BindingValue.BindingError(error); + return BindingValue.BindingError(error); } return converted; diff --git a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs index e5ee1e1eef..0e027712e0 100644 --- a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs +++ b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs @@ -3,11 +3,10 @@ using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Avalonia.Data.Core; -#nullable enable - namespace Avalonia.Collections { /// @@ -19,6 +18,7 @@ namespace Avalonia.Collections IDictionary, INotifyCollectionChanged, INotifyPropertyChanged + where TKey : notnull { private Dictionary _inner; @@ -76,8 +76,7 @@ namespace Avalonia.Collections set { - TValue old; - bool replace = _inner.TryGetValue(key, out old); + bool replace = _inner.TryGetValue(key, out var old); _inner[key] = value; if (replace) @@ -89,7 +88,7 @@ namespace Avalonia.Collections var e = new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Replace, new KeyValuePair(key, value), - new KeyValuePair(key, old)); + new KeyValuePair(key, old!)); CollectionChanged(this, e); } } @@ -100,7 +99,7 @@ namespace Avalonia.Collections } } - object IDictionary.this[object key] { get => ((IDictionary)_inner)[key]; set => ((IDictionary)_inner)[key] = value; } + object? IDictionary.this[object key] { get => ((IDictionary)_inner)[key]; set => ((IDictionary)_inner)[key] = value; } /// public void Add(TKey key, TValue value) @@ -145,7 +144,7 @@ namespace Avalonia.Collections /// public bool Remove(TKey key) { - if (_inner.TryGetValue(key, out TValue value)) + if (_inner.TryGetValue(key, out var value)) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]")); @@ -168,8 +167,7 @@ namespace Avalonia.Collections } /// - public bool TryGetValue(TKey key, out TValue value) => _inner.TryGetValue(key, out value); - + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => _inner.TryGetValue(key, out value); /// IEnumerator IEnumerable.GetEnumerator() => _inner.GetEnumerator(); @@ -195,7 +193,7 @@ namespace Avalonia.Collections } /// - void IDictionary.Add(object key, object value) => Add((TKey)key, (TValue)value); + void IDictionary.Add(object key, object? value) => Add((TKey)key, (TValue)value!); /// bool IDictionary.Contains(object key) => ((IDictionary) _inner).Contains(key); diff --git a/src/Avalonia.Base/Collections/AvaloniaList.cs b/src/Avalonia.Base/Collections/AvaloniaList.cs index 5b8ba108c7..6414328e90 100644 --- a/src/Avalonia.Base/Collections/AvaloniaList.cs +++ b/src/Avalonia.Base/Collections/AvaloniaList.cs @@ -6,8 +6,6 @@ using System.ComponentModel; using System.Linq; using Avalonia.Diagnostics; -#nullable enable - namespace Avalonia.Collections { /// @@ -95,7 +93,7 @@ namespace Avalonia.Collections /// /// Raised when a change is made to the collection's items. /// - public event NotifyCollectionChangedEventHandler CollectionChanged + public event NotifyCollectionChangedEventHandler? CollectionChanged { add => _collectionChanged += value; remove => _collectionChanged -= value; @@ -135,7 +133,7 @@ namespace Avalonia.Collections bool ICollection.IsSynchronized => false; /// - object? ICollection.SyncRoot => null; + object ICollection.SyncRoot => this; /// bool ICollection.IsReadOnly => false; diff --git a/src/Avalonia.Base/Collections/AvaloniaListConverter.cs b/src/Avalonia.Base/Collections/AvaloniaListConverter.cs index 444cdec144..b3fc0b01b6 100644 --- a/src/Avalonia.Base/Collections/AvaloniaListConverter.cs +++ b/src/Avalonia.Base/Collections/AvaloniaListConverter.cs @@ -3,8 +3,6 @@ using System.ComponentModel; using System.Globalization; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Collections { /// @@ -12,23 +10,26 @@ namespace Avalonia.Collections /// public class AvaloniaListConverter : TypeConverter { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) { return sourceType == typeof(string); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value) { + if (value is not string stringValue) + return null; + var result = new AvaloniaList(); // TODO: Use StringTokenizer here. - var values = ((string)value).Split(','); + var values = stringValue.Split(','); foreach (var s in values) { if (TypeUtilities.TryConvert(typeof(T), s, culture, out var v)) { - result.Add((T)v); + result.Add((T)v!); } else { diff --git a/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs b/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs index 5f3c3964f7..fb70729cf8 100644 --- a/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs +++ b/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs @@ -5,8 +5,6 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Reactive.Disposables; -#nullable enable - namespace Avalonia.Collections { /// @@ -88,7 +86,7 @@ namespace Avalonia.Collections { for (var i = items.Count - 1; i >= 0; --i) { - removed(index + i, (T)items[i]); + removed(index + i, (T)items[i]!); } } @@ -97,22 +95,22 @@ namespace Avalonia.Collections switch (e.Action) { case NotifyCollectionChangedAction.Add: - Add(e.NewStartingIndex, e.NewItems); + Add(e.NewStartingIndex, e.NewItems!); break; case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Replace: - Remove(e.OldStartingIndex, e.OldItems); + Remove(e.OldStartingIndex, e.OldItems!); int newIndex = e.NewStartingIndex; if(newIndex > e.OldStartingIndex) { - newIndex -= e.OldItems.Count; + newIndex -= e.OldItems!.Count; } - Add(newIndex, e.NewItems); + Add(newIndex, e.NewItems!); break; case NotifyCollectionChangedAction.Remove: - Remove(e.OldStartingIndex, e.OldItems); + Remove(e.OldStartingIndex, e.OldItems!); break; case NotifyCollectionChangedAction.Reset: @@ -166,7 +164,7 @@ namespace Avalonia.Collections /// A disposable used to terminate the subscription. public static IDisposable TrackItemPropertyChanged( this IAvaloniaReadOnlyList collection, - Action> callback) + Action> callback) { List tracked = new List(); diff --git a/src/Avalonia.Base/Collections/IAvaloniaList.cs b/src/Avalonia.Base/Collections/IAvaloniaList.cs index c28fb835e0..250d4faeb9 100644 --- a/src/Avalonia.Base/Collections/IAvaloniaList.cs +++ b/src/Avalonia.Base/Collections/IAvaloniaList.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -#nullable enable - namespace Avalonia.Collections { /// diff --git a/src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs b/src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs index 09622dceba..a6a5953827 100644 --- a/src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs +++ b/src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; -#nullable enable - namespace Avalonia.Collections { /// diff --git a/src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs b/src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs index 7a8c2325e6..dcd32ddd76 100644 --- a/src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs +++ b/src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs @@ -4,8 +4,6 @@ using System.Reactive.Linq; using Avalonia.Reactive; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Collections { public static class NotifyCollectionChangedExtensions @@ -70,14 +68,14 @@ namespace Avalonia.Collections _sourceReference = source; } - public void OnEvent(object sender, NotifyCollectionChangedEventArgs e) + public void OnEvent(object? sender, NotifyCollectionChangedEventArgs e) { PublishNext(e); } protected override void Initialize() { - if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance)) + if (_sourceReference.TryGetTarget(out var instance)) { WeakSubscriptionManager.Subscribe( instance, @@ -88,7 +86,7 @@ namespace Avalonia.Collections protected override void Deinitialize() { - if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance)) + if (_sourceReference.TryGetTarget(out var instance)) { WeakSubscriptionManager.Unsubscribe( instance, diff --git a/src/Avalonia.Base/Collections/Pooled/ClearMode.cs b/src/Avalonia.Base/Collections/Pooled/ClearMode.cs index f13538dce3..d78ac8feab 100644 --- a/src/Avalonia.Base/Collections/Pooled/ClearMode.cs +++ b/src/Avalonia.Base/Collections/Pooled/ClearMode.cs @@ -1,8 +1,6 @@ // This source file is adapted from the Collections.Pooled. // (https://github.com/jtmueller/Collections.Pooled/tree/master/Collections.Pooled/) -#nullable enable - namespace Avalonia.Collections.Pooled { /// diff --git a/src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs b/src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs index 6f89cb7728..2b15388a13 100644 --- a/src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs +++ b/src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs @@ -6,8 +6,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -#nullable enable - namespace Avalonia.Collections.Pooled { internal sealed class ICollectionDebugView diff --git a/src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs b/src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs index 7ac22d2baf..7a233a62ab 100644 --- a/src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs +++ b/src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; -#nullable enable - namespace Avalonia.Collections.Pooled { /// diff --git a/src/Avalonia.Base/Collections/Pooled/PooledList.cs b/src/Avalonia.Base/Collections/Pooled/PooledList.cs index 73cd602948..200a52fb0d 100644 --- a/src/Avalonia.Base/Collections/Pooled/PooledList.cs +++ b/src/Avalonia.Base/Collections/Pooled/PooledList.cs @@ -13,8 +13,6 @@ using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Threading; -#nullable enable - namespace Avalonia.Collections.Pooled { /// @@ -656,14 +654,15 @@ namespace Avalonia.Collections.Pooled // compatible array type. void ICollection.CopyTo(Array array, int arrayIndex) { - if ((array != null) && (array.Rank != 1)) + _ = array ?? throw new ArgumentNullException(nameof(array)); + + if (array.Rank != 1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); } try { - // Array.Copy will check for NULL. Array.Copy(_items, 0, array, arrayIndex, _size); } catch (ArrayTypeMismatchException) @@ -1336,7 +1335,7 @@ namespace Avalonia.Collections.Pooled _version++; } - public void Sort(Func comparison) + public void Sort(Func comparison) { if (comparison == null) { @@ -1442,7 +1441,7 @@ namespace Avalonia.Collections.Pooled _version++; } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { // We can't serialize array pools, so deserialized PooledLists will // have to use the shared pool, even if they were using a custom pool @@ -1522,14 +1521,14 @@ namespace Avalonia.Collections.Pooled private readonly struct Comparer : IComparer { - private readonly Func _comparison; + private readonly Func _comparison; - public Comparer(Func comparison) + public Comparer(Func comparison) { _comparison = comparison; } - public int Compare(T x, T y) => _comparison(x, y); + public int Compare(T? x, T? y) => _comparison(x, y); } } } diff --git a/src/Avalonia.Base/Collections/Pooled/PooledStack.cs b/src/Avalonia.Base/Collections/Pooled/PooledStack.cs index 8a03c6f5e4..f721cb1b62 100644 --- a/src/Avalonia.Base/Collections/Pooled/PooledStack.cs +++ b/src/Avalonia.Base/Collections/Pooled/PooledStack.cs @@ -20,8 +20,6 @@ using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Threading; -#nullable enable - namespace Avalonia.Collections.Pooled { /// @@ -613,7 +611,7 @@ namespace Avalonia.Collections.Pooled _version++; } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { // We can't serialize array pools, so deserialized PooledStacks will // have to use the shared pool, even if they were using a custom pool diff --git a/src/Avalonia.Base/Collections/Pooled/StackDebugView.cs b/src/Avalonia.Base/Collections/Pooled/StackDebugView.cs index b55ac110c6..b042388079 100644 --- a/src/Avalonia.Base/Collections/Pooled/StackDebugView.cs +++ b/src/Avalonia.Base/Collections/Pooled/StackDebugView.cs @@ -5,8 +5,6 @@ using System; using System.Diagnostics; -#nullable enable - namespace Avalonia.Collections.Pooled { internal sealed class StackDebugView diff --git a/src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs b/src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs index 3237286107..c0a60b695a 100644 --- a/src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs +++ b/src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs @@ -42,8 +42,6 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.Serialization; -#nullable enable - namespace Avalonia.Collections.Pooled { internal static class ThrowHelper diff --git a/src/Avalonia.Base/Data/AssignBindingAttribute.cs b/src/Avalonia.Base/Data/AssignBindingAttribute.cs index f88055a1e1..15bd32c7c2 100644 --- a/src/Avalonia.Base/Data/AssignBindingAttribute.cs +++ b/src/Avalonia.Base/Data/AssignBindingAttribute.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/BindingChainException.cs b/src/Avalonia.Base/Data/BindingChainException.cs index 09acf459cc..2890680f9a 100644 --- a/src/Avalonia.Base/Data/BindingChainException.cs +++ b/src/Avalonia.Base/Data/BindingChainException.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/BindingMode.cs b/src/Avalonia.Base/Data/BindingMode.cs index a57487fa7a..0d04c2eb10 100644 --- a/src/Avalonia.Base/Data/BindingMode.cs +++ b/src/Avalonia.Base/Data/BindingMode.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/BindingNotification.cs b/src/Avalonia.Base/Data/BindingNotification.cs index 867a7f637a..4b97b1a02c 100644 --- a/src/Avalonia.Base/Data/BindingNotification.cs +++ b/src/Avalonia.Base/Data/BindingNotification.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data { /// @@ -214,8 +212,10 @@ namespace Avalonia.Data /// The error type. public void AddError(Exception e, BindingErrorType type) { - Contract.Requires(e != null); - Contract.Requires(type != BindingErrorType.None); + _ = e ?? throw new ArgumentNullException(nameof(e)); + + if (type == BindingErrorType.None) + throw new ArgumentException("BindingErrorType may not be None", nameof(type)); Error = Error != null ? new AggregateException(Error, e) : e; diff --git a/src/Avalonia.Base/Data/BindingOperations.cs b/src/Avalonia.Base/Data/BindingOperations.cs index 05900de01d..5353e8175d 100644 --- a/src/Avalonia.Base/Data/BindingOperations.cs +++ b/src/Avalonia.Base/Data/BindingOperations.cs @@ -2,8 +2,6 @@ using System; using System.Reactive.Disposables; using System.Reactive.Linq; -#nullable enable - namespace Avalonia.Data { public static class BindingOperations diff --git a/src/Avalonia.Base/Data/BindingPriority.cs b/src/Avalonia.Base/Data/BindingPriority.cs index e4fb11cf06..ece64375f2 100644 --- a/src/Avalonia.Base/Data/BindingPriority.cs +++ b/src/Avalonia.Base/Data/BindingPriority.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/BindingValue.cs b/src/Avalonia.Base/Data/BindingValue.cs index 8e90bed8bc..55be611083 100644 --- a/src/Avalonia.Base/Data/BindingValue.cs +++ b/src/Avalonia.Base/Data/BindingValue.cs @@ -2,8 +2,6 @@ using System.Diagnostics; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data { /// @@ -418,15 +416,15 @@ namespace Avalonia.Data { BindingValueType.DoNothing => BindingValue.DoNothing, BindingValueType.UnsetValue => BindingValue.Unset, - BindingValueType.Value => new BindingValue(TypeUtilities.ConvertImplicit(value.Value)), + BindingValueType.Value => new BindingValue(TypeUtilities.ConvertImplicit(value.Value!)), BindingValueType.BindingError => BindingValue.BindingError(value.Error!), BindingValueType.BindingErrorWithFallback => BindingValue.BindingError( value.Error!, - TypeUtilities.ConvertImplicit(value.Value)), + TypeUtilities.ConvertImplicit(value.Value!)), BindingValueType.DataValidationError => BindingValue.DataValidationError(value.Error!), BindingValueType.DataValidationErrorWithFallback => BindingValue.DataValidationError( value.Error!, - TypeUtilities.ConvertImplicit(value.Value)), + TypeUtilities.ConvertImplicit(value.Value!)), _ => throw new NotSupportedException("Invalid BindingValue type."), }; } diff --git a/src/Avalonia.Base/Data/Converters/BoolConverters.cs b/src/Avalonia.Base/Data/Converters/BoolConverters.cs index 6a45ab8593..3985c5e32f 100644 --- a/src/Avalonia.Base/Data/Converters/BoolConverters.cs +++ b/src/Avalonia.Base/Data/Converters/BoolConverters.cs @@ -1,7 +1,5 @@ using System.Linq; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs b/src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs index f99ac1f81d..11d50afe93 100644 --- a/src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs @@ -3,8 +3,6 @@ using System.Globalization; using System.Windows.Input; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Converters { /// @@ -38,7 +36,7 @@ namespace Avalonia.Data.Converters return new MethodToCommandConverter(d); } - if (TypeUtilities.TryConvert(targetType, value, culture, out object result)) + if (TypeUtilities.TryConvert(targetType, value, culture, out var result)) { return result; } diff --git a/src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs b/src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs index 85dc6fc4f4..2577cac743 100644 --- a/src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs b/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs index fe71f1da1c..8a1f032593 100644 --- a/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs @@ -2,8 +2,6 @@ using System; using System.Globalization; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs b/src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs index e21746f571..d6e1c9f804 100644 --- a/src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Globalization; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/IValueConverter.cs b/src/Avalonia.Base/Data/Converters/IValueConverter.cs index c591dbda32..26c0e9582a 100644 --- a/src/Avalonia.Base/Data/Converters/IValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/IValueConverter.cs @@ -1,8 +1,6 @@ using System; using System.Globalization; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs b/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs index ee83776220..0672185a55 100644 --- a/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs +++ b/src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs @@ -7,19 +7,17 @@ using System.Reflection; using System.Windows.Input; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Converters { class MethodToCommandConverter : ICommand { - readonly static Func AlwaysEnabled = (_) => true; + readonly static Func AlwaysEnabled = (_) => true; readonly static MethodInfo tryConvert = typeof(TypeUtilities) - .GetMethod(nameof(TypeUtilities.TryConvert), BindingFlags.Public | BindingFlags.Static); + .GetMethod(nameof(TypeUtilities.TryConvert), BindingFlags.Public | BindingFlags.Static)!; readonly static PropertyInfo currentCulture = typeof(CultureInfo) - .GetProperty(nameof(CultureInfo.CurrentCulture), BindingFlags.Public | BindingFlags.Static); - readonly Func canExecute; - readonly Action execute; + .GetProperty(nameof(CultureInfo.CurrentCulture), BindingFlags.Public | BindingFlags.Static)!; + readonly Func canExecute; + readonly Action execute; readonly WeakPropertyChangedProxy? weakPropertyChanged; readonly PropertyChangedEventHandler? propertyChangedEventHandler; readonly string[]? dependencyProperties; @@ -40,7 +38,7 @@ namespace Avalonia.Data.Converters execute = CreateExecute(target, action.Method, parameterInfo); } - var canExecuteMethod = action.Method.DeclaringType.GetRuntimeMethods() + var canExecuteMethod = action.Method.DeclaringType?.GetRuntimeMethods() .FirstOrDefault(m => m.Name == canExecuteMethodName && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(object)); @@ -65,7 +63,7 @@ namespace Avalonia.Data.Converters } } - void OnPropertyChanged(object sender, PropertyChangedEventArgs args) + void OnPropertyChanged(object? sender, PropertyChangedEventArgs args) { if (string.IsNullOrWhiteSpace(args.PropertyName) || dependencyProperties?.Contains(args.PropertyName) == true) @@ -79,12 +77,12 @@ namespace Avalonia.Data.Converters public event EventHandler? CanExecuteChanged; #pragma warning restore 0067 - public bool CanExecute(object parameter) => canExecute(parameter); + public bool CanExecute(object? parameter) => canExecute(parameter); - public void Execute(object parameter) => execute(parameter); + public void Execute(object? parameter) => execute(parameter); - static Action CreateExecute(object target + static Action CreateExecute(object? target , System.Reflection.MethodInfo method) { @@ -100,11 +98,11 @@ namespace Avalonia.Data.Converters return Expression - .Lambda>(call, parameter) + .Lambda>(call, parameter) .Compile(); } - static Action CreateExecute(object target + static Action CreateExecute(object? target , System.Reflection.MethodInfo method , Type parameterType) { @@ -143,11 +141,11 @@ namespace Avalonia.Data.Converters } return Expression - .Lambda>(body, parameter) + .Lambda>(body, parameter) .Compile(); } - static Func CreateCanExecute(object target + static Func CreateCanExecute(object? target , System.Reflection.MethodInfo method) { var parameter = Expression.Parameter(typeof(object), "parameter"); @@ -159,12 +157,12 @@ namespace Avalonia.Data.Converters parameter ); return Expression - .Lambda>(call, parameter) + .Lambda>(call, parameter) .Compile(); } - private static Expression? ConvertTarget(object target, MethodInfo method) => - target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType); + private static Expression? ConvertTarget(object? target, MethodInfo method) => + target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType!); internal class WeakPropertyChangedProxy { @@ -199,7 +197,7 @@ namespace Avalonia.Data.Converters _listener.SetTarget(null); } - void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (_listener.TryGetTarget(out var handler) && handler != null) handler(sender, e); diff --git a/src/Avalonia.Base/Data/Converters/ObjectConverters.cs b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs index 3794d0ca3b..6796a1793e 100644 --- a/src/Avalonia.Base/Data/Converters/ObjectConverters.cs +++ b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/StringConverters.cs b/src/Avalonia.Base/Data/Converters/StringConverters.cs index a13cef349d..182eaf2e65 100644 --- a/src/Avalonia.Base/Data/Converters/StringConverters.cs +++ b/src/Avalonia.Base/Data/Converters/StringConverters.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs b/src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs index d66a2d2cdf..606ac9e6fa 100644 --- a/src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs b/src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs index 1b3451370a..5307ea4b9a 100644 --- a/src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs +++ b/src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs @@ -1,8 +1,6 @@ using System; using System.Globalization; -#nullable enable - namespace Avalonia.Data.Converters { /// diff --git a/src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs b/src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs index ce60e12ae1..92ecdafa0c 100644 --- a/src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs +++ b/src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs @@ -2,8 +2,6 @@ using System.Reactive.Linq; using Avalonia.Reactive; -#nullable enable - namespace Avalonia.Data.Core { public class AvaloniaPropertyAccessorNode : SettableNode diff --git a/src/Avalonia.Base/Data/Core/BindingExpression.cs b/src/Avalonia.Base/Data/Core/BindingExpression.cs index 3f7a9722b7..ea903c1042 100644 --- a/src/Avalonia.Base/Data/Core/BindingExpression.cs +++ b/src/Avalonia.Base/Data/Core/BindingExpression.cs @@ -7,8 +7,6 @@ using Avalonia.Logging; using Avalonia.Reactive; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Core { /// @@ -263,7 +261,7 @@ namespace Avalonia.Data.Core private BindingNotification ConvertFallback() { - object converted; + object? converted; if (_fallbackValue == AvaloniaProperty.UnsetValue) { diff --git a/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs b/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs index f52940bc80..24149c17e0 100644 --- a/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs +++ b/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs @@ -2,8 +2,6 @@ using System; using System.Linq.Expressions; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core { public class ClrPropertyInfo : IPropertyInfo @@ -49,7 +47,7 @@ namespace Avalonia.Data.Core var target = Expression.Parameter(typeof(object), "target"); var value = Expression.Parameter(typeof(object), "value"); return Expression.Lambda>( - Expression.Call(Expression.Convert(target, info.DeclaringType), info.SetMethod, + Expression.Call(Expression.Convert(target, info.DeclaringType!), info.SetMethod, Expression.Convert(value, info.SetMethod.GetParameters()[0].ParameterType)), target, value) .Compile(); @@ -61,7 +59,7 @@ namespace Avalonia.Data.Core return null; var target = Expression.Parameter(typeof(object), "target"); return Expression.Lambda>( - Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType), info.GetMethod), + Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType!), info.GetMethod), typeof(object))) .Compile(); } diff --git a/src/Avalonia.Base/Data/Core/CommonPropertyNames.cs b/src/Avalonia.Base/Data/Core/CommonPropertyNames.cs index 908beeca33..da6f407d81 100644 --- a/src/Avalonia.Base/Data/Core/CommonPropertyNames.cs +++ b/src/Avalonia.Base/Data/Core/CommonPropertyNames.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data.Core { public static class CommonPropertyNames diff --git a/src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs b/src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs index 115f617270..4e142fbee9 100644 --- a/src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs +++ b/src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Avalonia.Data.Core +namespace Avalonia.Data.Core { public class EmptyExpressionNode : ExpressionNode { diff --git a/src/Avalonia.Base/Data/Core/ExpressionNode.cs b/src/Avalonia.Base/Data/Core/ExpressionNode.cs index 25b0102891..54785f18e8 100644 --- a/src/Avalonia.Base/Data/Core/ExpressionNode.cs +++ b/src/Avalonia.Base/Data/Core/ExpressionNode.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core { public abstract class ExpressionNode diff --git a/src/Avalonia.Base/Data/Core/ExpressionObserver.cs b/src/Avalonia.Base/Data/Core/ExpressionObserver.cs index 9e38c8bfba..e4affd97de 100644 --- a/src/Avalonia.Base/Data/Core/ExpressionObserver.cs +++ b/src/Avalonia.Base/Data/Core/ExpressionObserver.cs @@ -7,8 +7,6 @@ using Avalonia.Data.Core.Parsers; using Avalonia.Data.Core.Plugins; using Avalonia.Reactive; -#nullable enable - namespace Avalonia.Data.Core { /// diff --git a/src/Avalonia.Base/Data/Core/ExpressionParseException.cs b/src/Avalonia.Base/Data/Core/ExpressionParseException.cs index 8fd7066a7b..a50e79f9cd 100644 --- a/src/Avalonia.Base/Data/Core/ExpressionParseException.cs +++ b/src/Avalonia.Base/Data/Core/ExpressionParseException.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core { /// diff --git a/src/Avalonia.Base/Data/Core/IPropertyInfo.cs b/src/Avalonia.Base/Data/Core/IPropertyInfo.cs index 9544565fcb..4d80feb4ba 100644 --- a/src/Avalonia.Base/Data/Core/IPropertyInfo.cs +++ b/src/Avalonia.Base/Data/Core/IPropertyInfo.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core { public interface IPropertyInfo diff --git a/src/Avalonia.Base/Data/Core/ITransformNode.cs b/src/Avalonia.Base/Data/Core/ITransformNode.cs index 49c1dea7b9..645d637e44 100644 --- a/src/Avalonia.Base/Data/Core/ITransformNode.cs +++ b/src/Avalonia.Base/Data/Core/ITransformNode.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Avalonia.Data.Core +namespace Avalonia.Data.Core { interface ITransformNode { diff --git a/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs b/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs index 22a58a245b..7a24f9cb77 100644 --- a/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs +++ b/src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs @@ -4,8 +4,6 @@ using System.ComponentModel; using System.Linq.Expressions; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core { class IndexerExpressionNode : IndexerNodeBase @@ -18,7 +16,7 @@ namespace Avalonia.Data.Core public IndexerExpressionNode(IndexExpression expression) { - _parameter = Expression.Parameter(expression.Object.Type); + _parameter = Expression.Parameter(expression.Object!.Type); _expression = expression.Update(_parameter, expression.Arguments); _getDelegate = Expression.Lambda(_expression, _parameter).Compile(); diff --git a/src/Avalonia.Base/Data/Core/IndexerNodeBase.cs b/src/Avalonia.Base/Data/Core/IndexerNodeBase.cs index ef4375a02c..e197e29103 100644 --- a/src/Avalonia.Base/Data/Core/IndexerNodeBase.cs +++ b/src/Avalonia.Base/Data/Core/IndexerNodeBase.cs @@ -7,8 +7,6 @@ using System.Linq; using System.Reactive.Linq; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Core { public abstract class IndexerNodeBase : SettableNode @@ -72,12 +70,12 @@ namespace Avalonia.Data.Core return index >= e.OldStartingIndex; case NotifyCollectionChangedAction.Replace: return index >= e.NewStartingIndex && - index < e.NewStartingIndex + e.NewItems.Count; + index < e.NewStartingIndex + e.NewItems!.Count; case NotifyCollectionChangedAction.Move: return (index >= e.NewStartingIndex && - index < e.NewStartingIndex + e.NewItems.Count) || + index < e.NewStartingIndex + e.NewItems!.Count) || (index >= e.OldStartingIndex && - index < e.OldStartingIndex + e.OldItems.Count); + index < e.OldStartingIndex + e.OldItems!.Count); case NotifyCollectionChangedAction.Reset: return true; } diff --git a/src/Avalonia.Base/Data/Core/LogicalNotNode.cs b/src/Avalonia.Base/Data/Core/LogicalNotNode.cs index 7ccec51e1a..45837db73d 100644 --- a/src/Avalonia.Base/Data/Core/LogicalNotNode.cs +++ b/src/Avalonia.Base/Data/Core/LogicalNotNode.cs @@ -1,8 +1,6 @@ using System; using System.Globalization; -#nullable enable - namespace Avalonia.Data.Core { public class LogicalNotNode : ExpressionNode, ITransformNode diff --git a/src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs b/src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs index 2dbeae41ae..5d23cecbef 100644 --- a/src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs +++ b/src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; -#nullable enable - namespace Avalonia.Data.Core { internal class MarkupBindingChainException : BindingChainException diff --git a/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs b/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs index 34409a3e36..d2035a592f 100644 --- a/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs +++ b/src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs @@ -1,8 +1,6 @@ using System.Linq; using System.Linq.Expressions; -#nullable enable - namespace Avalonia.Data.Core.Parsers { static class ExpressionTreeParser diff --git a/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs b/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs index caba0c2e78..1e82214d76 100644 --- a/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs +++ b/src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core.Parsers { class ExpressionVisitorNodeBuilder : ExpressionVisitor @@ -18,8 +16,8 @@ namespace Avalonia.Data.Core.Parsers static ExpressionVisitorNodeBuilder() { - AvaloniaObjectIndexer = typeof(AvaloniaObject).GetProperty("Item", new[] { typeof(AvaloniaProperty) }); - CreateDelegateMethod = typeof(MethodInfo).GetMethod("CreateDelegate", new[] { typeof(Type), typeof(object) }); + AvaloniaObjectIndexer = typeof(AvaloniaObject).GetProperty("Item", new[] { typeof(AvaloniaProperty) })!; + CreateDelegateMethod = typeof(MethodInfo).GetMethod("CreateDelegate", new[] { typeof(Type), typeof(object) })!; } public List Nodes { get; } @@ -164,7 +162,7 @@ namespace Avalonia.Data.Core.Parsers if (node.Method == CreateDelegateMethod) { var visited = Visit(node.Arguments[1]); - Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue(node.Object).Name, _enableDataValidation)); + Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue(node.Object!).Name, _enableDataValidation)); return node; } else if (node.Method.Name == StreamBindingExtensions.StreamBindingName || node.Method.Name.StartsWith(StreamBindingExtensions.StreamBindingName + '`')) @@ -185,20 +183,20 @@ namespace Avalonia.Data.Core.Parsers if (property != null) { - return Visit(Expression.MakeIndex(node.Object, property, node.Arguments)); + return Visit(Expression.MakeIndex(node.Object!, property, node.Arguments)); } - else if (node.Object.Type.IsArray && node.Method.Name == MultiDimensionalArrayGetterMethodName) + else if (node.Object!.Type.IsArray && node.Method.Name == MultiDimensionalArrayGetterMethodName) { return Visit(Expression.MakeIndex(node.Object, null, node.Arguments)); } - throw new ExpressionParseException(0, $"Invalid method call in binding expression: '{node.Method.DeclaringType.AssemblyQualifiedName}.{node.Method.Name}'."); + throw new ExpressionParseException(0, $"Invalid method call in binding expression: '{node.Method.DeclaringType!.AssemblyQualifiedName}.{node.Method.Name}'."); } - private PropertyInfo TryGetPropertyFromMethod(MethodInfo method) + private PropertyInfo? TryGetPropertyFromMethod(MethodInfo method) { var type = method.DeclaringType; - return type.GetRuntimeProperties().FirstOrDefault(prop => prop.GetMethod == method); + return type?.GetRuntimeProperties().FirstOrDefault(prop => prop.GetMethod == method); } protected override Expression VisitSwitch(SwitchExpression node) diff --git a/src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs index b72989ce00..3c4120ad0b 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs @@ -1,8 +1,6 @@ using System; using System.Runtime.ExceptionServices; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -74,12 +72,11 @@ namespace Avalonia.Data.Core.Plugins _property = property ?? throw new ArgumentNullException(nameof(property)); } - public AvaloniaObject Instance + public AvaloniaObject? Instance { get { - AvaloniaObject result; - _reference.TryGetTarget(out result); + _reference.TryGetTarget(out var result); return result; } } @@ -91,7 +88,7 @@ namespace Avalonia.Data.Core.Plugins { if (!_property.IsReadOnly) { - Instance.SetValue(_property, value, priority); + Instance?.SetValue(_property, value, priority); return true; } diff --git a/src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs index 4d973d4aaa..361d68dc81 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs @@ -4,8 +4,6 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -33,19 +31,23 @@ namespace Avalonia.Data.Core.Plugins private sealed class Accessor : DataValidationBase { - private readonly ValidationContext _context; + private readonly ValidationContext? _context; public Accessor(WeakReference reference, string name, IPropertyAccessor inner) : base(inner) { - reference.TryGetTarget(out var target); - - _context = new ValidationContext(target); - _context.MemberName = name; + if (reference.TryGetTarget(out var target)) + { + _context = new ValidationContext(target); + _context.MemberName = name; + } } protected override void InnerValueChanged(object? value) { + if (_context is null) + return; + var errors = new List(); if (Validator.TryValidateProperty(value, _context, errors)) diff --git a/src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs b/src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs index 3e98d26fa1..6bef9f69f6 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs index 95855b09f4..bf4a0a88bd 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs @@ -1,8 +1,6 @@ using System; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -32,7 +30,7 @@ namespace Avalonia.Data.Core.Plugins { return base.SetValue(value, priority); } - catch (TargetInvocationException ex) + catch (TargetInvocationException ex) when (ex.InnerException is not null) { PublishValue(new BindingNotification(ex.InnerException, BindingErrorType.DataValidationError)); } diff --git a/src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs index 549327bc0f..88e38a8d08 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs b/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs index 59017b5aae..8941e86598 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs index 4a391e8489..f000427de3 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs index 543bcba601..b741cfaca2 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs index 7b37b5d4e7..9f827daf94 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs @@ -4,8 +4,6 @@ using System.ComponentModel; using System.Linq; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -39,7 +37,7 @@ namespace Avalonia.Data.Core.Plugins _name = name; } - void IWeakSubscriber.OnEvent(object sender, DataErrorsChangedEventArgs e) + void IWeakSubscriber.OnEvent(object? sender, DataErrorsChangedEventArgs e) { if (e.PropertyName == _name || string.IsNullOrEmpty(e.PropertyName)) { diff --git a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs index d5bf8da029..fd532f3014 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs @@ -4,8 +4,6 @@ using System.ComponentModel; using System.Reflection; using Avalonia.Utilities; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -131,7 +129,7 @@ namespace Avalonia.Data.Core.Plugins return false; } - void IWeakSubscriber.OnEvent(object sender, PropertyChangedEventArgs e) + void IWeakSubscriber.OnEvent(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == _property.Name || string.IsNullOrEmpty(e.PropertyName)) { diff --git a/src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs index e0d686586c..160c7301f5 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core.Plugins { public class MethodAccessorPlugin : IPropertyAccessorPlugin diff --git a/src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs index 7d77adfb00..0288dbce91 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs @@ -3,8 +3,6 @@ using System.Linq; using System.Reactive.Linq; using System.Reflection; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -57,14 +55,14 @@ namespace Avalonia.Data.Core.Plugins // Make a Box<> delegate of the correct type. var funcType = typeof(Func<,>).MakeGenericType(sourceType, typeof(object)); - var box = GetType().GetMethod(nameof(Box), BindingFlags.Static | BindingFlags.NonPublic) + var box = GetType().GetMethod(nameof(Box), BindingFlags.Static | BindingFlags.NonPublic)! .MakeGenericMethod(sourceType) .CreateDelegate(funcType); // Call Observable.Select(target, box); - return (IObservable)select.Invoke( + return (IObservable)select.Invoke( null, - new object[] { target, box }); + new object[] { target, box })!; } private static MethodInfo GetObservableSelect(Type source) diff --git a/src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs b/src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs index ba3fca1ab5..df36347e93 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs b/src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs index c2a3214c0d..62629e13bd 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// diff --git a/src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs index d1a3568a55..377ea9f275 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs @@ -4,8 +4,6 @@ using System.Reactive.Subjects; using System.Reflection; using System.Threading.Tasks; -#nullable enable - namespace Avalonia.Data.Core.Plugins { /// @@ -72,7 +70,7 @@ namespace Avalonia.Data.Core.Plugins case TaskStatus.RanToCompletion: return Observable.Return(resultProperty.GetValue(task)); case TaskStatus.Faulted: - return Observable.Return(new BindingNotification(task.Exception, BindingErrorType.Error)); + return Observable.Return(new BindingNotification(task.Exception!, BindingErrorType.Error)); default: throw new AvaloniaInternalException("HandleCompleted called for non-completed Task."); } diff --git a/src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs b/src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs index 92c3b65307..c13c6fcbc8 100644 --- a/src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs +++ b/src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs @@ -2,8 +2,6 @@ using System; using System.Diagnostics; using Avalonia.Data.Core.Plugins; -#nullable enable - namespace Avalonia.Data.Core { public class PropertyAccessorNode : SettableNode diff --git a/src/Avalonia.Base/Data/Core/PropertyPath.cs b/src/Avalonia.Base/Data/Core/PropertyPath.cs index 4ec402d7e1..665953c4a1 100644 --- a/src/Avalonia.Base/Data/Core/PropertyPath.cs +++ b/src/Avalonia.Base/Data/Core/PropertyPath.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -#nullable enable - namespace Avalonia.Data.Core { public class PropertyPath diff --git a/src/Avalonia.Base/Data/Core/SettableNode.cs b/src/Avalonia.Base/Data/Core/SettableNode.cs index 3467a16123..9ad9ace814 100644 --- a/src/Avalonia.Base/Data/Core/SettableNode.cs +++ b/src/Avalonia.Base/Data/Core/SettableNode.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data.Core { public abstract class SettableNode : ExpressionNode diff --git a/src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs b/src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs index 75fe37f958..fa2929c6ef 100644 --- a/src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs +++ b/src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs @@ -1,8 +1,6 @@ using System; using System.Threading.Tasks; -#nullable enable - namespace Avalonia { public static class StreamBindingExtensions diff --git a/src/Avalonia.Base/Data/Core/StreamNode.cs b/src/Avalonia.Base/Data/Core/StreamNode.cs index 086fbb7ee2..133e6a75f1 100644 --- a/src/Avalonia.Base/Data/Core/StreamNode.cs +++ b/src/Avalonia.Base/Data/Core/StreamNode.cs @@ -2,8 +2,6 @@ using System; using System.Reactive.Linq; using Avalonia.Data.Core.Plugins; -#nullable enable - namespace Avalonia.Data.Core { public class StreamNode : ExpressionNode diff --git a/src/Avalonia.Base/Data/Core/TypeCastNode.cs b/src/Avalonia.Base/Data/Core/TypeCastNode.cs index 2404c90fe2..3a2ca955fa 100644 --- a/src/Avalonia.Base/Data/Core/TypeCastNode.cs +++ b/src/Avalonia.Base/Data/Core/TypeCastNode.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Text; -#nullable enable - namespace Avalonia.Data.Core { public class TypeCastNode : ExpressionNode diff --git a/src/Avalonia.Base/Data/DataValidationException.cs b/src/Avalonia.Base/Data/DataValidationException.cs index cafe74cd2c..74f39a1b6f 100644 --- a/src/Avalonia.Base/Data/DataValidationException.cs +++ b/src/Avalonia.Base/Data/DataValidationException.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/IBinding.cs b/src/Avalonia.Base/Data/IBinding.cs index 3b4add0269..9535cf608e 100644 --- a/src/Avalonia.Base/Data/IBinding.cs +++ b/src/Avalonia.Base/Data/IBinding.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/IndexerBinding.cs b/src/Avalonia.Base/Data/IndexerBinding.cs index bc8fe85a70..6a33d0c4fc 100644 --- a/src/Avalonia.Base/Data/IndexerBinding.cs +++ b/src/Avalonia.Base/Data/IndexerBinding.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Avalonia.Data +namespace Avalonia.Data { public class IndexerBinding : IBinding { diff --git a/src/Avalonia.Base/Data/IndexerDescriptor.cs b/src/Avalonia.Base/Data/IndexerDescriptor.cs index 3c02509063..c823630d3c 100644 --- a/src/Avalonia.Base/Data/IndexerDescriptor.cs +++ b/src/Avalonia.Base/Data/IndexerDescriptor.cs @@ -1,8 +1,6 @@ using System; using System.Reactive; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/InstancedBinding.cs b/src/Avalonia.Base/Data/InstancedBinding.cs index dd7fcb3007..9ff319eddb 100644 --- a/src/Avalonia.Base/Data/InstancedBinding.cs +++ b/src/Avalonia.Base/Data/InstancedBinding.cs @@ -1,8 +1,6 @@ using System; using System.Reactive.Subjects; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Data/Optional.cs b/src/Avalonia.Base/Data/Optional.cs index d2283bf66b..513222d427 100644 --- a/src/Avalonia.Base/Data/Optional.cs +++ b/src/Avalonia.Base/Data/Optional.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -#nullable enable - namespace Avalonia.Data { /// diff --git a/src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs b/src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs index c881c389c1..4189fd5234 100644 --- a/src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs +++ b/src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs @@ -17,9 +17,9 @@ namespace Avalonia.Diagnostics /// A diagnostic string. public AvaloniaPropertyValue( AvaloniaProperty property, - object value, + object? value, BindingPriority priority, - string diagnostic) + string? diagnostic) { Property = property; Value = value; @@ -35,7 +35,7 @@ namespace Avalonia.Diagnostics /// /// Gets the current property value. /// - public object Value { get; } + public object? Value { get; } /// /// Gets the priority of the current value. @@ -45,6 +45,6 @@ namespace Avalonia.Diagnostics /// /// Gets a diagnostic string. /// - public string Diagnostic { get; } + public string? Diagnostic { get; } } } diff --git a/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs b/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs index 4b9f12ddf8..2d88203f67 100644 --- a/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs +++ b/src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia.Diagnostics { /// diff --git a/src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs b/src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs index 36152e6430..00f2949b08 100644 --- a/src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs +++ b/src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs @@ -17,6 +17,6 @@ namespace Avalonia.Diagnostics /// /// The subscribers or null if no subscribers. /// - Delegate[] GetCollectionChangedSubscribers(); + Delegate[]? GetCollectionChangedSubscribers(); } } diff --git a/src/Avalonia.Base/DirectProperty.cs b/src/Avalonia.Base/DirectProperty.cs index eb04cfdce0..a5905a6081 100644 --- a/src/Avalonia.Base/DirectProperty.cs +++ b/src/Avalonia.Base/DirectProperty.cs @@ -2,8 +2,6 @@ using System; using System.Diagnostics.CodeAnalysis; using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/DirectPropertyBase.cs b/src/Avalonia.Base/DirectPropertyBase.cs index 4b54ee75ab..9c4896b96c 100644 --- a/src/Avalonia.Base/DirectPropertyBase.cs +++ b/src/Avalonia.Base/DirectPropertyBase.cs @@ -3,8 +3,6 @@ using Avalonia.Data; using Avalonia.Reactive; using Avalonia.Utilities; -#nullable enable - namespace Avalonia { /// @@ -155,7 +153,7 @@ namespace Avalonia if (v.HasValue) { - o.SetValue(this, (TValue)v.Value); + o.SetValue(this, (TValue)v.Value!); } else if (v.Type == BindingValueType.UnsetValue) { diff --git a/src/Avalonia.Base/DirectPropertyMetadata`1.cs b/src/Avalonia.Base/DirectPropertyMetadata`1.cs index a265032139..fe1cdd0e65 100644 --- a/src/Avalonia.Base/DirectPropertyMetadata`1.cs +++ b/src/Avalonia.Base/DirectPropertyMetadata`1.cs @@ -1,7 +1,5 @@ using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/EnumExtensions.cs b/src/Avalonia.Base/EnumExtensions.cs index 1f7c532cce..19eb42a700 100644 --- a/src/Avalonia.Base/EnumExtensions.cs +++ b/src/Avalonia.Base/EnumExtensions.cs @@ -1,8 +1,6 @@ using System; using System.Runtime.CompilerServices; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IAvaloniaObject.cs b/src/Avalonia.Base/IAvaloniaObject.cs index 2e992f8616..654528658f 100644 --- a/src/Avalonia.Base/IAvaloniaObject.cs +++ b/src/Avalonia.Base/IAvaloniaObject.cs @@ -1,8 +1,6 @@ using System; using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IDescription.cs b/src/Avalonia.Base/IDescription.cs index 17a7f98776..e1ff52476d 100644 --- a/src/Avalonia.Base/IDescription.cs +++ b/src/Avalonia.Base/IDescription.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IDirectPropertyAccessor.cs b/src/Avalonia.Base/IDirectPropertyAccessor.cs index e75ca238ad..e34483fa7b 100644 --- a/src/Avalonia.Base/IDirectPropertyAccessor.cs +++ b/src/Avalonia.Base/IDirectPropertyAccessor.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IDirectPropertyMetadata.cs b/src/Avalonia.Base/IDirectPropertyMetadata.cs index 7b132d192e..4fd4a3a6b7 100644 --- a/src/Avalonia.Base/IDirectPropertyMetadata.cs +++ b/src/Avalonia.Base/IDirectPropertyMetadata.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IStyledPropertyAccessor.cs b/src/Avalonia.Base/IStyledPropertyAccessor.cs index 6ef6391010..c4a0005f55 100644 --- a/src/Avalonia.Base/IStyledPropertyAccessor.cs +++ b/src/Avalonia.Base/IStyledPropertyAccessor.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/IStyledPropertyMetadata.cs b/src/Avalonia.Base/IStyledPropertyMetadata.cs index 2a0d09d6a7..6b29b5f977 100644 --- a/src/Avalonia.Base/IStyledPropertyMetadata.cs +++ b/src/Avalonia.Base/IStyledPropertyMetadata.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/Logging/ILogSink.cs b/src/Avalonia.Base/Logging/ILogSink.cs index 71268d5965..27558ba0ee 100644 --- a/src/Avalonia.Base/Logging/ILogSink.cs +++ b/src/Avalonia.Base/Logging/ILogSink.cs @@ -23,7 +23,7 @@ namespace Avalonia.Logging void Log( LogEventLevel level, string area, - object source, + object? source, string messageTemplate); /// @@ -37,7 +37,7 @@ namespace Avalonia.Logging void Log( LogEventLevel level, string area, - object source, + object? source, string messageTemplate, T0 propertyValue0); @@ -53,7 +53,7 @@ namespace Avalonia.Logging void Log( LogEventLevel level, string area, - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1); @@ -71,7 +71,7 @@ namespace Avalonia.Logging void Log( LogEventLevel level, string area, - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, @@ -88,8 +88,8 @@ namespace Avalonia.Logging void Log( LogEventLevel level, string area, - object source, + object? source, string messageTemplate, - params object[] propertyValues); + params object?[] propertyValues); } } diff --git a/src/Avalonia.Base/Logging/Logger.cs b/src/Avalonia.Base/Logging/Logger.cs index ed3fad93fc..c3fffb62de 100644 --- a/src/Avalonia.Base/Logging/Logger.cs +++ b/src/Avalonia.Base/Logging/Logger.cs @@ -8,7 +8,7 @@ namespace Avalonia.Logging /// /// Gets or sets the application-defined sink that receives the messages. /// - public static ILogSink Sink { get; set; } + public static ILogSink? Sink { get; set; } /// /// Checks if given log level is enabled. @@ -34,7 +34,7 @@ namespace Avalonia.Logging return null; } - return new ParametrizedLogger(Sink, level, area); + return new ParametrizedLogger(Sink!, level, area); } /// diff --git a/src/Avalonia.Base/Logging/ParametrizedLogger.cs b/src/Avalonia.Base/Logging/ParametrizedLogger.cs index adadb0f990..6b7331b504 100644 --- a/src/Avalonia.Base/Logging/ParametrizedLogger.cs +++ b/src/Avalonia.Base/Logging/ParametrizedLogger.cs @@ -30,7 +30,7 @@ namespace Avalonia.Logging /// The message template. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate) { _sink.Log(_level, _area, source, messageTemplate); @@ -44,7 +44,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0) { @@ -60,7 +60,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1) @@ -78,7 +78,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, @@ -98,7 +98,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, @@ -120,7 +120,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, @@ -144,7 +144,7 @@ namespace Avalonia.Logging /// Message property value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log( - object source, + object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, diff --git a/src/Avalonia.Base/Logging/TraceLogSink.cs b/src/Avalonia.Base/Logging/TraceLogSink.cs index f597844378..02ed191d2c 100644 --- a/src/Avalonia.Base/Logging/TraceLogSink.cs +++ b/src/Avalonia.Base/Logging/TraceLogSink.cs @@ -9,11 +9,11 @@ namespace Avalonia.Logging public class TraceLogSink : ILogSink { private readonly LogEventLevel _level; - private readonly IList _areas; + private readonly IList? _areas; public TraceLogSink( LogEventLevel minimumLevel, - IList areas = null) + IList? areas = null) { _level = minimumLevel; _areas = areas?.Count > 0 ? areas : null; @@ -24,7 +24,7 @@ namespace Avalonia.Logging return level >= _level && (_areas?.Contains(area) ?? true); } - public void Log(LogEventLevel level, string area, object source, string messageTemplate) + public void Log(LogEventLevel level, string area, object? source, string messageTemplate) { if (IsEnabled(level, area)) { @@ -32,7 +32,7 @@ namespace Avalonia.Logging } } - public void Log(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0) + public void Log(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0) { if (IsEnabled(level, area)) { @@ -40,7 +40,7 @@ namespace Avalonia.Logging } } - public void Log(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1) + public void Log(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1) { if (IsEnabled(level, area)) { @@ -48,7 +48,7 @@ namespace Avalonia.Logging } } - public void Log(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) + public void Log(LogEventLevel level, string area, object? source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) { if (IsEnabled(level, area)) { @@ -56,7 +56,7 @@ namespace Avalonia.Logging } } - public void Log(LogEventLevel level, string area, object source, string messageTemplate, params object[] propertyValues) + public void Log(LogEventLevel level, string area, object? source, string messageTemplate, params object?[] propertyValues) { if (IsEnabled(level, area)) { @@ -67,10 +67,10 @@ namespace Avalonia.Logging private static string Format( string area, string template, - object source, - T0 v0 = default, - T1 v1 = default, - T2 v2 = default) + object? source, + T0? v0 = default, + T1? v1 = default, + T2? v2 = default) { var result = new StringBuilder(template.Length); var r = new CharacterReader(template.AsSpan()); @@ -127,8 +127,8 @@ namespace Avalonia.Logging private static string Format( string area, string template, - object source, - object[] v) + object? source, + object?[] v) { var result = new StringBuilder(template.Length); var r = new CharacterReader(template.AsSpan()); diff --git a/src/Avalonia.Base/Metadata/TemplateContent.cs b/src/Avalonia.Base/Metadata/TemplateContent.cs index 7f9e878419..258154aba4 100644 --- a/src/Avalonia.Base/Metadata/TemplateContent.cs +++ b/src/Avalonia.Base/Metadata/TemplateContent.cs @@ -8,6 +8,6 @@ namespace Avalonia.Metadata [AttributeUsage(AttributeTargets.Property)] public class TemplateContentAttribute : Attribute { - public Type TemplateResultType { get; set; } + public Type? TemplateResultType { get; set; } } } diff --git a/src/Avalonia.Base/Platform/IAssetLoader.cs b/src/Avalonia.Base/Platform/IAssetLoader.cs index c2e422cabb..e3899784ad 100644 --- a/src/Avalonia.Base/Platform/IAssetLoader.cs +++ b/src/Avalonia.Base/Platform/IAssetLoader.cs @@ -27,7 +27,7 @@ namespace Avalonia.Platform /// A base URI to use if is relative. /// /// True if the asset could be found; otherwise false. - bool Exists(Uri uri, Uri baseUri = null); + bool Exists(Uri uri, Uri? baseUri = null); /// /// Opens the asset with the requested URI. @@ -40,7 +40,7 @@ namespace Avalonia.Platform /// /// The asset could not be found. /// - Stream Open(Uri uri, Uri baseUri = null); + Stream Open(Uri uri, Uri? baseUri = null); /// /// Opens the asset with the requested URI and returns the asset stream and the @@ -56,7 +56,7 @@ namespace Avalonia.Platform /// /// The asset could not be found. /// - (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri baseUri = null); + (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null); /// /// Extracts assembly information from URI @@ -66,7 +66,7 @@ namespace Avalonia.Platform /// A base URI to use if is relative. /// /// Assembly associated with the Uri - Assembly GetAssembly(Uri uri, Uri baseUri = null); + Assembly? GetAssembly(Uri uri, Uri? baseUri = null); /// /// Gets all assets of a folder and subfolders that match specified uri. @@ -74,6 +74,6 @@ namespace Avalonia.Platform /// The URI. /// The base URI. /// All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset - IEnumerable GetAssets(Uri uri, Uri baseUri); + IEnumerable GetAssets(Uri uri, Uri? baseUri); } } diff --git a/src/Avalonia.Base/Platform/IPlatformHandle.cs b/src/Avalonia.Base/Platform/IPlatformHandle.cs index a3b9d8f07c..e1e9888045 100644 --- a/src/Avalonia.Base/Platform/IPlatformHandle.cs +++ b/src/Avalonia.Base/Platform/IPlatformHandle.cs @@ -15,6 +15,6 @@ namespace Avalonia.Platform /// /// Gets an optional string that describes what represents. /// - string HandleDescriptor { get; } + string? HandleDescriptor { get; } } } diff --git a/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs b/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs index 7117576b3b..7a0b5b34cd 100644 --- a/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs +++ b/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs @@ -8,9 +8,9 @@ namespace Avalonia.Platform.Interop public class Utf8Buffer : SafeHandle { private GCHandle _gcHandle; - private byte[] _data; + private byte[]? _data; - public Utf8Buffer(string s) : base(IntPtr.Zero, true) + public Utf8Buffer(string? s) : base(IntPtr.Zero, true) { if (s == null) return; @@ -19,7 +19,7 @@ namespace Avalonia.Platform.Interop handle = _gcHandle.AddrOfPinnedObject(); } - public int ByteLen => _data.Length; + public int ByteLen => _data?.Length ?? 0; protected override bool ReleaseHandle() { @@ -34,7 +34,7 @@ namespace Avalonia.Platform.Interop public override bool IsInvalid => handle == IntPtr.Zero; - public static unsafe string StringFromPtr(IntPtr s) + public static unsafe string? StringFromPtr(IntPtr s) { var pstr = (byte*)s; if (pstr == null) diff --git a/src/Avalonia.Base/Platform/PlatformHandle.cs b/src/Avalonia.Base/Platform/PlatformHandle.cs index bed25a3b5b..9cc2741a12 100644 --- a/src/Avalonia.Base/Platform/PlatformHandle.cs +++ b/src/Avalonia.Base/Platform/PlatformHandle.cs @@ -14,7 +14,7 @@ namespace Avalonia.Platform /// /// An optional string that describes what represents. /// - public PlatformHandle(IntPtr handle, string descriptor) + public PlatformHandle(IntPtr handle, string? descriptor) { Handle = handle; HandleDescriptor = descriptor; @@ -28,6 +28,6 @@ namespace Avalonia.Platform /// /// Gets an optional string that describes what represents. /// - public string HandleDescriptor { get; } + public string? HandleDescriptor { get; } } } diff --git a/src/Avalonia.Base/PropertyStore/BindingEntry.cs b/src/Avalonia.Base/PropertyStore/BindingEntry.cs index 315e28f84a..cffbaed6b0 100644 --- a/src/Avalonia.Base/PropertyStore/BindingEntry.cs +++ b/src/Avalonia.Base/PropertyStore/BindingEntry.cs @@ -2,8 +2,6 @@ using Avalonia.Data; using Avalonia.Threading; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs b/src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs index 7e904f57df..c7fbf56abc 100644 --- a/src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs +++ b/src/Avalonia.Base/PropertyStore/ConstantValueEntry.cs @@ -2,8 +2,6 @@ using System.Diagnostics.CodeAnalysis; using Avalonia.Data; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/PropertyStore/IPriorityValueEntry.cs b/src/Avalonia.Base/PropertyStore/IPriorityValueEntry.cs index 4d82381323..26665ab683 100644 --- a/src/Avalonia.Base/PropertyStore/IPriorityValueEntry.cs +++ b/src/Avalonia.Base/PropertyStore/IPriorityValueEntry.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Avalonia.PropertyStore +namespace Avalonia.PropertyStore { /// /// Represents an untyped interface to . diff --git a/src/Avalonia.Base/PropertyStore/IValue.cs b/src/Avalonia.Base/PropertyStore/IValue.cs index bbf4739e6a..a4ec06e64e 100644 --- a/src/Avalonia.Base/PropertyStore/IValue.cs +++ b/src/Avalonia.Base/PropertyStore/IValue.cs @@ -1,7 +1,5 @@ using Avalonia.Data; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/PropertyStore/IValueSink.cs b/src/Avalonia.Base/PropertyStore/IValueSink.cs index 3a1e9731d8..738fdef267 100644 --- a/src/Avalonia.Base/PropertyStore/IValueSink.cs +++ b/src/Avalonia.Base/PropertyStore/IValueSink.cs @@ -1,7 +1,5 @@ using Avalonia.Data; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/PropertyStore/LocalValueEntry.cs b/src/Avalonia.Base/PropertyStore/LocalValueEntry.cs index 4afc90e71d..cb5f3556d1 100644 --- a/src/Avalonia.Base/PropertyStore/LocalValueEntry.cs +++ b/src/Avalonia.Base/PropertyStore/LocalValueEntry.cs @@ -1,8 +1,6 @@ using System.Diagnostics.CodeAnalysis; using Avalonia.Data; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/PropertyStore/PriorityValue.cs b/src/Avalonia.Base/PropertyStore/PriorityValue.cs index f5723cb3a7..f670160e75 100644 --- a/src/Avalonia.Base/PropertyStore/PriorityValue.cs +++ b/src/Avalonia.Base/PropertyStore/PriorityValue.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using Avalonia.Data; -#nullable enable - namespace Avalonia.PropertyStore { /// diff --git a/src/Avalonia.Base/Reactive/AvaloniaPropertyBindingObservable.cs b/src/Avalonia.Base/Reactive/AvaloniaPropertyBindingObservable.cs index 9a0dc61ba3..238bb16e3e 100644 --- a/src/Avalonia.Base/Reactive/AvaloniaPropertyBindingObservable.cs +++ b/src/Avalonia.Base/Reactive/AvaloniaPropertyBindingObservable.cs @@ -2,17 +2,14 @@ using System.Collections.Generic; using Avalonia.Data; -#nullable enable - namespace Avalonia.Reactive { internal class AvaloniaPropertyBindingObservable : LightweightObservableBase>, IDescription { private readonly WeakReference _target; private readonly AvaloniaProperty _property; - private T _value; + private BindingValue _value = BindingValue.Unset; -#nullable disable public AvaloniaPropertyBindingObservable( IAvaloniaObject target, AvaloniaProperty property) @@ -20,7 +17,6 @@ namespace Avalonia.Reactive _target = new WeakReference(target); _property = property; } -#nullable enable public string Description => $"{_target.GetType().Name}.{_property.Name}"; @@ -43,10 +39,13 @@ namespace Avalonia.Reactive protected override void Subscribed(IObserver> observer, bool first) { - observer.OnNext(new BindingValue(_value)); + if (_value.Type != BindingValueType.UnsetValue) + { + observer.OnNext(_value); + } } - private void PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e) + private void PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) { if (e.Property == _property) { @@ -54,7 +53,7 @@ namespace Avalonia.Reactive { var newValue = e.Sender.GetValue(typedArgs.Property); - if (!typedArgs.OldValue.HasValue || !EqualityComparer.Default.Equals(newValue, _value)) + if (!_value.HasValue || !EqualityComparer.Default.Equals(newValue, _value.Value)) { _value = newValue; PublishNext(_value); diff --git a/src/Avalonia.Base/Reactive/AvaloniaPropertyChangedObservable.cs b/src/Avalonia.Base/Reactive/AvaloniaPropertyChangedObservable.cs index 5ef0d25133..dc29ddbdff 100644 --- a/src/Avalonia.Base/Reactive/AvaloniaPropertyChangedObservable.cs +++ b/src/Avalonia.Base/Reactive/AvaloniaPropertyChangedObservable.cs @@ -35,7 +35,7 @@ namespace Avalonia.Reactive } } - private void PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e) + private void PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) { if (e.Property == _property) { diff --git a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs index 6a3f9b0b30..fbc126bb05 100644 --- a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs +++ b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Avalonia.Data; namespace Avalonia.Reactive { @@ -7,7 +8,7 @@ namespace Avalonia.Reactive { private readonly WeakReference _target; private readonly AvaloniaProperty _property; - private T _value; + private Optional _value; public AvaloniaPropertyObservable( IAvaloniaObject target, @@ -23,7 +24,7 @@ namespace Avalonia.Reactive { if (_target.TryGetTarget(out var target)) { - _value = (T)target.GetValue(_property); + _value = (T)target.GetValue(_property)!; target.PropertyChanged += PropertyChanged; } } @@ -34,14 +35,17 @@ namespace Avalonia.Reactive { target.PropertyChanged -= PropertyChanged; } + + _value = default; } protected override void Subscribed(IObserver observer, bool first) { - observer.OnNext(_value); + if (_value.HasValue) + observer.OnNext(_value.Value); } - private void PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e) + private void PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) { if (e.Property == _property) { @@ -53,13 +57,14 @@ namespace Avalonia.Reactive } else { - newValue = (T)e.Sender.GetValue(e.Property); + newValue = (T)e.Sender.GetValue(e.Property)!; } - if (!EqualityComparer.Default.Equals(newValue, _value)) + if (!_value.HasValue || + !EqualityComparer.Default.Equals(newValue, _value.Value)) { _value = newValue; - PublishNext(_value); + PublishNext(_value.Value!); } } } diff --git a/src/Avalonia.Base/Reactive/BindingValueAdapter.cs b/src/Avalonia.Base/Reactive/BindingValueAdapter.cs index 8c80e9f48c..8eaf21dcdc 100644 --- a/src/Avalonia.Base/Reactive/BindingValueAdapter.cs +++ b/src/Avalonia.Base/Reactive/BindingValueAdapter.cs @@ -2,8 +2,6 @@ using System.Reactive.Subjects; using Avalonia.Data; -#nullable enable - namespace Avalonia.Reactive { internal class BindingValueAdapter : SingleSubscriberObservableBase>, diff --git a/src/Avalonia.Base/Reactive/BindingValueExtensions.cs b/src/Avalonia.Base/Reactive/BindingValueExtensions.cs index 6f0d29dd0f..770da2cab4 100644 --- a/src/Avalonia.Base/Reactive/BindingValueExtensions.cs +++ b/src/Avalonia.Base/Reactive/BindingValueExtensions.cs @@ -2,8 +2,6 @@ using System.Reactive.Subjects; using Avalonia.Data; -#nullable enable - namespace Avalonia.Reactive { public static class BindingValueExtensions diff --git a/src/Avalonia.Base/Reactive/LightweightObservableBase.cs b/src/Avalonia.Base/Reactive/LightweightObservableBase.cs index f5052e5858..9a3ab89b62 100644 --- a/src/Avalonia.Base/Reactive/LightweightObservableBase.cs +++ b/src/Avalonia.Base/Reactive/LightweightObservableBase.cs @@ -18,12 +18,13 @@ namespace Avalonia.Reactive /// public abstract class LightweightObservableBase : IObservable { - private Exception _error; - private List> _observers = new List>(); + private Exception? _error; + private List>? _observers = new List>(); public IDisposable Subscribe(IObserver observer) { - Contract.Requires(observer != null); + _ = observer ?? throw new ArgumentNullException(nameof(observer)); + Dispatcher.UIThread.VerifyAccess(); var first = false; @@ -91,9 +92,9 @@ namespace Avalonia.Reactive sealed class RemoveObserver : IDisposable { - LightweightObservableBase _parent; + LightweightObservableBase? _parent; - IObserver _observer; + IObserver? _observer; public RemoveObserver(LightweightObservableBase parent, IObserver observer) { @@ -104,7 +105,7 @@ namespace Avalonia.Reactive public void Dispose() { var observer = _observer; - Interlocked.Exchange(ref _parent, null)?.Remove(observer); + Interlocked.Exchange(ref _parent, null)?.Remove(observer!); _observer = null; } } @@ -116,8 +117,8 @@ namespace Avalonia.Reactive { if (Volatile.Read(ref _observers) != null) { - IObserver[] observers = null; - IObserver singleObserver = null; + IObserver[]? observers = null; + IObserver? singleObserver = null; lock (this) { if (_observers == null) @@ -139,7 +140,7 @@ namespace Avalonia.Reactive } else { - foreach (var observer in observers) + foreach (var observer in observers!) { observer.OnNext(value); } diff --git a/src/Avalonia.Base/Reactive/ObservableEx.cs b/src/Avalonia.Base/Reactive/ObservableEx.cs index 8e963fb9d5..1cea568c88 100644 --- a/src/Avalonia.Base/Reactive/ObservableEx.cs +++ b/src/Avalonia.Base/Reactive/ObservableEx.cs @@ -34,4 +34,4 @@ namespace Avalonia.Reactive } } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs b/src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs index d3ac3dac8a..5e3a6bf79a 100644 --- a/src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs +++ b/src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs @@ -5,13 +5,13 @@ namespace Avalonia.Reactive { public abstract class SingleSubscriberObservableBase : IObservable, IDisposable { - private Exception _error; - private IObserver _observer; + private Exception? _error; + private IObserver? _observer; private bool _completed; public IDisposable Subscribe(IObserver observer) { - Contract.Requires(observer != null); + _ = observer ?? throw new ArgumentNullException(nameof(observer)); Dispatcher.UIThread.VerifyAccess(); if (_observer != null) diff --git a/src/Avalonia.Base/Reactive/TypedBindingAdapter.cs b/src/Avalonia.Base/Reactive/TypedBindingAdapter.cs index 44803bc7d6..f60ef247d5 100644 --- a/src/Avalonia.Base/Reactive/TypedBindingAdapter.cs +++ b/src/Avalonia.Base/Reactive/TypedBindingAdapter.cs @@ -2,8 +2,6 @@ using Avalonia.Data; using Avalonia.Logging; -#nullable enable - namespace Avalonia.Reactive { internal class TypedBindingAdapter : SingleSubscriberObservableBase>, diff --git a/src/Avalonia.Base/Reactive/UntypedBindingAdapter.cs b/src/Avalonia.Base/Reactive/UntypedBindingAdapter.cs index 03c1afcea9..58fbee7b8f 100644 --- a/src/Avalonia.Base/Reactive/UntypedBindingAdapter.cs +++ b/src/Avalonia.Base/Reactive/UntypedBindingAdapter.cs @@ -2,8 +2,6 @@ using System.Reactive.Subjects; using Avalonia.Data; -#nullable enable - namespace Avalonia.Reactive { internal class UntypedBindingAdapter : SingleSubscriberObservableBase, diff --git a/src/Avalonia.Base/StyledProperty.cs b/src/Avalonia.Base/StyledProperty.cs index 4bd24d4a42..d00a675d0f 100644 --- a/src/Avalonia.Base/StyledProperty.cs +++ b/src/Avalonia.Base/StyledProperty.cs @@ -1,7 +1,5 @@ using System; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/StyledPropertyBase.cs b/src/Avalonia.Base/StyledPropertyBase.cs index 526b1175b4..16ba571a5a 100644 --- a/src/Avalonia.Base/StyledPropertyBase.cs +++ b/src/Avalonia.Base/StyledPropertyBase.cs @@ -4,8 +4,6 @@ using Avalonia.Data; using Avalonia.Reactive; using Avalonia.Utilities; -#nullable enable - namespace Avalonia { /// @@ -207,7 +205,7 @@ namespace Avalonia if (v.HasValue) { - return o.SetValue(this, (TValue)v.Value, priority); + return o.SetValue(this, (TValue)v.Value!, priority); } else if (v.Type == BindingValueType.UnsetValue) { diff --git a/src/Avalonia.Base/StyledPropertyMetadata`1.cs b/src/Avalonia.Base/StyledPropertyMetadata`1.cs index a9f7eb38de..0a38960228 100644 --- a/src/Avalonia.Base/StyledPropertyMetadata`1.cs +++ b/src/Avalonia.Base/StyledPropertyMetadata`1.cs @@ -1,8 +1,6 @@ using System; using Avalonia.Data; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs index 326d1a3f53..b991f9eb40 100644 --- a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs +++ b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs @@ -28,13 +28,13 @@ namespace Avalonia.Threading } /// - public override void Post(SendOrPostCallback d, object state) + public override void Post(SendOrPostCallback d, object? state) { Dispatcher.UIThread.Post(() => d(state), DispatcherPriority.Send); } /// - public override void Send(SendOrPostCallback d, object state) + public override void Send(SendOrPostCallback d, object? state) { if (Dispatcher.UIThread.CheckAccess()) d(state); diff --git a/src/Avalonia.Base/Threading/Dispatcher.cs b/src/Avalonia.Base/Threading/Dispatcher.cs index fe2cec11f0..ffc013268d 100644 --- a/src/Avalonia.Base/Threading/Dispatcher.cs +++ b/src/Avalonia.Base/Threading/Dispatcher.cs @@ -15,12 +15,12 @@ namespace Avalonia.Threading public class Dispatcher : IDispatcher { private readonly JobRunner _jobRunner; - private IPlatformThreadingInterface _platform; + private IPlatformThreadingInterface? _platform; public static Dispatcher UIThread { get; } = new Dispatcher(AvaloniaLocator.Current.GetService()); - public Dispatcher(IPlatformThreadingInterface platform) + public Dispatcher(IPlatformThreadingInterface? platform) { _platform = platform; _jobRunner = new JobRunner(platform); @@ -56,7 +56,7 @@ namespace Avalonia.Threading /// public void MainLoop(CancellationToken cancellationToken) { - var platform = AvaloniaLocator.Current.GetService(); + var platform = AvaloniaLocator.Current.GetRequiredService(); cancellationToken.Register(() => platform.Signal(DispatcherPriority.Send)); platform.RunLoop(cancellationToken); } @@ -78,35 +78,35 @@ namespace Avalonia.Threading /// public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { - Contract.Requires(action != null); + _ = action ?? throw new ArgumentNullException(nameof(action)); return _jobRunner.InvokeAsync(action, priority); } /// public Task InvokeAsync(Func function, DispatcherPriority priority = DispatcherPriority.Normal) { - Contract.Requires(function != null); + _ = function ?? throw new ArgumentNullException(nameof(function)); return _jobRunner.InvokeAsync(function, priority); } /// public Task InvokeAsync(Func function, DispatcherPriority priority = DispatcherPriority.Normal) { - Contract.Requires(function != null); + _ = function ?? throw new ArgumentNullException(nameof(function)); return _jobRunner.InvokeAsync(function, priority).Unwrap(); } /// public Task InvokeAsync(Func> function, DispatcherPriority priority = DispatcherPriority.Normal) { - Contract.Requires(function != null); + _ = function ?? throw new ArgumentNullException(nameof(function)); return _jobRunner.InvokeAsync(function, priority).Unwrap(); } /// public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { - Contract.Requires(action != null); + _ = action ?? throw new ArgumentNullException(nameof(action)); _jobRunner.Post(action, priority); } @@ -142,4 +142,4 @@ namespace Avalonia.Threading } } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Threading/DispatcherTimer.cs b/src/Avalonia.Base/Threading/DispatcherTimer.cs index 56cde9738e..93023b90a5 100644 --- a/src/Avalonia.Base/Threading/DispatcherTimer.cs +++ b/src/Avalonia.Base/Threading/DispatcherTimer.cs @@ -9,7 +9,7 @@ namespace Avalonia.Threading /// public class DispatcherTimer { - private IDisposable _timer; + private IDisposable? _timer; private readonly DispatcherPriority _priority; @@ -58,7 +58,7 @@ namespace Avalonia.Threading /// /// Raised when the timer ticks. /// - public event EventHandler Tick; + public event EventHandler? Tick; /// /// Gets or sets the interval at which the timer ticks. @@ -108,7 +108,7 @@ namespace Avalonia.Threading /// /// Gets or sets user-defined data associated with the timer. /// - public object Tag + public object? Tag { get; set; @@ -176,7 +176,7 @@ namespace Avalonia.Threading { if (!IsEnabled) { - IPlatformThreadingInterface threading = AvaloniaLocator.Current.GetService(); + var threading = AvaloniaLocator.Current.GetService(); if (threading == null) { @@ -194,7 +194,7 @@ namespace Avalonia.Threading { if (IsEnabled) { - _timer.Dispose(); + _timer!.Dispose(); _timer = null; } } @@ -210,4 +210,4 @@ namespace Avalonia.Threading Tick?.Invoke(this, EventArgs.Empty); } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Threading/JobRunner.cs b/src/Avalonia.Base/Threading/JobRunner.cs index 58f623fb3f..eb7c5e1af3 100644 --- a/src/Avalonia.Base/Threading/JobRunner.cs +++ b/src/Avalonia.Base/Threading/JobRunner.cs @@ -11,12 +11,12 @@ namespace Avalonia.Threading /// internal class JobRunner { - private IPlatformThreadingInterface _platform; + private IPlatformThreadingInterface? _platform; private readonly Queue[] _queues = Enumerable.Range(0, (int) DispatcherPriority.MaxValue + 1) .Select(_ => new Queue()).ToArray(); - public JobRunner(IPlatformThreadingInterface platform) + public JobRunner(IPlatformThreadingInterface? platform) { _platform = platform; } @@ -48,7 +48,7 @@ namespace Avalonia.Threading { var job = new Job(action, priority, false); AddJob(job); - return job.Task; + return job.Task!; } /// @@ -96,7 +96,7 @@ namespace Avalonia.Threading _platform?.Signal(job.Priority); } - private IJob GetNextJob(DispatcherPriority minimumPriority) + private IJob? GetNextJob(DispatcherPriority minimumPriority) { for (int c = (int) DispatcherPriority.MaxValue; c >= (int) minimumPriority; c--) { @@ -135,7 +135,7 @@ namespace Avalonia.Threading /// /// The task completion source. /// - private readonly TaskCompletionSource _taskCompletionSource; + private readonly TaskCompletionSource? _taskCompletionSource; /// /// Initializes a new instance of the class. @@ -147,7 +147,7 @@ namespace Avalonia.Threading { _action = action; Priority = priority; - _taskCompletionSource = throwOnUiThread ? null : new TaskCompletionSource(); + _taskCompletionSource = throwOnUiThread ? null : new TaskCompletionSource(); } /// @@ -156,7 +156,7 @@ namespace Avalonia.Threading /// /// The task. /// - public Task Task => _taskCompletionSource?.Task; + public Task? Task => _taskCompletionSource?.Task; /// void IJob.Run() diff --git a/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs b/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs index c513f75962..cbe3771577 100644 --- a/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs +++ b/src/Avalonia.Base/Utilities/AvaloniaPropertyValueStore.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -#nullable enable - namespace Avalonia.Utilities { /// diff --git a/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs b/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs index ed5bc697b0..09e408cb42 100644 --- a/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs +++ b/src/Avalonia.Base/Utilities/AvaloniaResourcesIndex.cs @@ -7,8 +7,6 @@ using System.Runtime.Serialization.Json; using System.Xml.Linq; using System.Linq; -// ReSharper disable AssignNullToNotNullAttribute - namespace Avalonia.Utilities { #if !BUILDTASK @@ -24,14 +22,14 @@ namespace Avalonia.Utilities throw new Exception("Resources index format version is not known"); var assetDoc = XDocument.Load(stream); - XNamespace assetNs = assetDoc.Root.Attribute("xmlns").Value; + XNamespace assetNs = assetDoc.Root!.Attribute("xmlns")!.Value; List entries= - (from entry in assetDoc.Root.Element(assetNs + "Entries").Elements(assetNs + "AvaloniaResourcesIndexEntry") + (from entry in assetDoc.Root.Element(assetNs + "Entries")!.Elements(assetNs + "AvaloniaResourcesIndexEntry") select new AvaloniaResourcesIndexEntry { - Path = entry.Element(assetNs + "Path").Value, - Offset = int.Parse(entry.Element(assetNs + "Offset").Value), - Size = int.Parse(entry.Element(assetNs + "Size").Value) + Path = entry.Element(assetNs + "Path")!.Value, + Offset = int.Parse(entry.Element(assetNs + "Offset")!.Value), + Size = int.Parse(entry.Element(assetNs + "Size")!.Value) }).ToList(); return entries; @@ -95,7 +93,7 @@ namespace Avalonia.Utilities class AvaloniaResourcesIndexEntry { [DataMember] - public string Path { get; set; } + public string? Path { get; set; } [DataMember] public int Offset { get; set; } diff --git a/src/Avalonia.Base/Utilities/DisposableLock.cs b/src/Avalonia.Base/Utilities/DisposableLock.cs index b06e97da00..c6f01b24fa 100644 --- a/src/Avalonia.Base/Utilities/DisposableLock.cs +++ b/src/Avalonia.Base/Utilities/DisposableLock.cs @@ -11,7 +11,7 @@ namespace Avalonia.Utilities /// Tries to take a lock /// /// IDisposable if succeeded to obtain the lock - public IDisposable TryLock() + public IDisposable? TryLock() { if (Monitor.TryEnter(_lock)) return new UnlockDisposable(_lock); @@ -29,7 +29,7 @@ namespace Avalonia.Utilities private sealed class UnlockDisposable : IDisposable { - private object _lock; + private object? _lock; public UnlockDisposable(object @lock) { @@ -38,7 +38,7 @@ namespace Avalonia.Utilities public void Dispose() { - object @lock = Interlocked.Exchange(ref _lock, null); + object? @lock = Interlocked.Exchange(ref _lock, null); if (@lock != null) { diff --git a/src/Avalonia.Base/Utilities/IAvaloniaPropertyVisitor.cs b/src/Avalonia.Base/Utilities/IAvaloniaPropertyVisitor.cs index 4b889eb129..6a8df91b81 100644 --- a/src/Avalonia.Base/Utilities/IAvaloniaPropertyVisitor.cs +++ b/src/Avalonia.Base/Utilities/IAvaloniaPropertyVisitor.cs @@ -1,6 +1,4 @@ -#nullable enable - -namespace Avalonia.Utilities +namespace Avalonia.Utilities { /// /// A visitor to resolve an untyped to a typed property. diff --git a/src/Avalonia.Base/Utilities/IWeakSubscriber.cs b/src/Avalonia.Base/Utilities/IWeakSubscriber.cs index a2907eea2e..613c931165 100644 --- a/src/Avalonia.Base/Utilities/IWeakSubscriber.cs +++ b/src/Avalonia.Base/Utilities/IWeakSubscriber.cs @@ -13,6 +13,6 @@ namespace Avalonia.Utilities /// /// The event sender. /// The event arguments. - void OnEvent(object sender, T e); + void OnEvent(object? sender, T e); } } diff --git a/src/Avalonia.Base/Utilities/ImmutableReadOnlyListStructEnumerator.cs b/src/Avalonia.Base/Utilities/ImmutableReadOnlyListStructEnumerator.cs index a1246c57b5..90d1c52ff5 100644 --- a/src/Avalonia.Base/Utilities/ImmutableReadOnlyListStructEnumerator.cs +++ b/src/Avalonia.Base/Utilities/ImmutableReadOnlyListStructEnumerator.cs @@ -7,21 +7,18 @@ namespace Avalonia.Utilities { private readonly IReadOnlyList _readOnlyList; private int _pos; + private T? _current; public ImmutableReadOnlyListStructEnumerator(IReadOnlyList readOnlyList) { _readOnlyList = readOnlyList; _pos = -1; - Current = default; + _current = default; } - public T Current - { - get; - private set; - } + public T Current => _current!; - object IEnumerator.Current => Current; + object? IEnumerator.Current => Current; public void Dispose() { } @@ -32,7 +29,7 @@ namespace Avalonia.Utilities return false; } - Current = _readOnlyList[++_pos]; + _current = _readOnlyList[++_pos]; return true; @@ -42,7 +39,7 @@ namespace Avalonia.Utilities { _pos = -1; - Current = default; + _current = default; } } } diff --git a/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs b/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs index fd4e5d2ace..4cc1ba5190 100644 --- a/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs +++ b/src/Avalonia.Base/Utilities/NonPumpingLockHelper.cs @@ -6,9 +6,9 @@ namespace Avalonia.Utilities { public interface IHelperImpl { - IDisposable Use(); + IDisposable? Use(); } - public static IDisposable Use() => AvaloniaLocator.Current.GetService()?.Use(); + public static IDisposable? Use() => AvaloniaLocator.Current.GetService()?.Use(); } } diff --git a/src/Avalonia.Base/Utilities/Ref.cs b/src/Avalonia.Base/Utilities/Ref.cs index c9ebeefebc..7209f02720 100644 --- a/src/Avalonia.Base/Utilities/Ref.cs +++ b/src/Avalonia.Base/Utilities/Ref.cs @@ -82,7 +82,7 @@ namespace Avalonia.Utilities class RefCounter { - private IDisposable _item; + private IDisposable? _item; private volatile int _refs; public RefCounter(IDisposable item) @@ -120,7 +120,7 @@ namespace Avalonia.Utilities { if (old == 1) { - _item.Dispose(); + _item?.Dispose(); _item = null; } break; @@ -134,7 +134,7 @@ namespace Avalonia.Utilities class Ref : CriticalFinalizerObject, IRef where T : class { - private T _item; + private T? _item; private RefCounter _counter; private object _lock = new object(); @@ -168,7 +168,7 @@ namespace Avalonia.Utilities { lock (_lock) { - return _item; + return _item!; } } } @@ -206,4 +206,4 @@ namespace Avalonia.Utilities } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Utilities/SingleOrDictionary.cs b/src/Avalonia.Base/Utilities/SingleOrDictionary.cs index 140da6750d..00cc5864f5 100644 --- a/src/Avalonia.Base/Utilities/SingleOrDictionary.cs +++ b/src/Avalonia.Base/Utilities/SingleOrDictionary.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Avalonia.Utilities @@ -11,9 +12,10 @@ namespace Avalonia.Utilities /// The type of the key. /// The type of the value. public class SingleOrDictionary : IEnumerable> + where TKey : notnull { private KeyValuePair? _singleValue; - private Dictionary dictionary; + private Dictionary? dictionary; public void Add(TKey key, TValue value) { @@ -34,7 +36,7 @@ namespace Avalonia.Utilities } } - public bool TryGetValue(TKey key, out TValue value) + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) { if (dictionary == null) { @@ -120,7 +122,7 @@ namespace Avalonia.Utilities } } - object IEnumerator.Current => Current; + object? IEnumerator.Current => Current; public void Dispose() { diff --git a/src/Avalonia.Base/Utilities/SingleOrQueue.cs b/src/Avalonia.Base/Utilities/SingleOrQueue.cs index 643b0ba04d..99a92f6788 100644 --- a/src/Avalonia.Base/Utilities/SingleOrQueue.cs +++ b/src/Avalonia.Base/Utilities/SingleOrQueue.cs @@ -9,8 +9,8 @@ namespace Avalonia.Utilities /// The type of items held in the queue. public class SingleOrQueue { - private T _head; - private Queue _tail; + private T? _head; + private Queue? _tail; private Queue Tail => _tail ?? (_tail = new Queue()); @@ -51,7 +51,7 @@ namespace Avalonia.Utilities Empty = true; } - return result; + return result!; } } } diff --git a/src/Avalonia.Base/Utilities/StringTokenizer.cs b/src/Avalonia.Base/Utilities/StringTokenizer.cs index 24e99febb9..748eb09209 100644 --- a/src/Avalonia.Base/Utilities/StringTokenizer.cs +++ b/src/Avalonia.Base/Utilities/StringTokenizer.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using static System.Char; @@ -14,19 +15,19 @@ namespace Avalonia.Utilities private readonly string _s; private readonly int _length; private readonly char _separator; - private readonly string _exceptionMessage; + private readonly string? _exceptionMessage; private readonly IFormatProvider _formatProvider; private int _index; private int _tokenIndex; private int _tokenLength; - public StringTokenizer(string s, IFormatProvider formatProvider, string exceptionMessage = null) + public StringTokenizer(string s, IFormatProvider formatProvider, string? exceptionMessage = null) : this(s, GetSeparatorFromFormatProvider(formatProvider), exceptionMessage) { _formatProvider = formatProvider; } - public StringTokenizer(string s, char separator = DefaultSeparatorChar, string exceptionMessage = null) + public StringTokenizer(string s, char separator = DefaultSeparatorChar, string? exceptionMessage = null) { _s = s ?? throw new ArgumentNullException(nameof(s)); _length = s?.Length ?? 0; @@ -43,7 +44,7 @@ namespace Avalonia.Utilities } } - public string CurrentToken => _tokenIndex < 0 ? null : _s.Substring(_tokenIndex, _tokenLength); + public string? CurrentToken => _tokenIndex < 0 ? null : _s.Substring(_tokenIndex, _tokenLength); public void Dispose() { @@ -101,7 +102,7 @@ namespace Avalonia.Utilities return result; } - public bool TryReadString(out string result, char? separator = null) + public bool TryReadString([MaybeNullWhen(false)] out string result, char? separator = null) { var success = TryReadToken(separator ?? _separator); result = CurrentToken; @@ -219,4 +220,4 @@ namespace Avalonia.Utilities return c; } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Utilities/SynchronousCompletionAsyncResult.cs b/src/Avalonia.Base/Utilities/SynchronousCompletionAsyncResult.cs index f321b2b2f1..fb8d3ed224 100644 --- a/src/Avalonia.Base/Utilities/SynchronousCompletionAsyncResult.cs +++ b/src/Avalonia.Base/Utilities/SynchronousCompletionAsyncResult.cs @@ -10,8 +10,8 @@ namespace Avalonia.Utilities /// public struct SynchronousCompletionAsyncResult : INotifyCompletion { - private readonly SynchronousCompletionAsyncResultSource _source; - private readonly T _result; + private readonly SynchronousCompletionAsyncResultSource? _source; + private readonly T? _result; private readonly bool _isValid; internal SynchronousCompletionAsyncResult(SynchronousCompletionAsyncResultSource source) { @@ -44,7 +44,7 @@ namespace Avalonia.Utilities { if (!_isValid) ThrowNotInitialized(); - return _source == null ? _result : _source.Result; + return _source == null ? _result! : _source.Result; } @@ -67,15 +67,15 @@ namespace Avalonia.Utilities /// public class SynchronousCompletionAsyncResultSource { - private T _result; + private T? _result; internal bool IsCompleted { get; private set; } public SynchronousCompletionAsyncResult AsyncResult => new SynchronousCompletionAsyncResult(this); internal T Result => IsCompleted ? - _result : + _result! : throw new InvalidOperationException("Asynchronous operation is not yet completed"); - private List _continuations; + private List? _continuations; internal void OnCompleted(Action continuation) { diff --git a/src/Avalonia.Base/Utilities/TypeUtilities.cs b/src/Avalonia.Base/Utilities/TypeUtilities.cs index 0978308ef6..d29335d3d0 100644 --- a/src/Avalonia.Base/Utilities/TypeUtilities.cs +++ b/src/Avalonia.Base/Utilities/TypeUtilities.cs @@ -112,7 +112,7 @@ namespace Avalonia.Utilities /// The type to cast to /// The value to check if cast possible /// True if the cast is possible, otherwise false. - public static bool CanCast(object value) + public static bool CanCast(object? value) { return value is T || (value is null && AcceptsNull()); } @@ -125,7 +125,7 @@ namespace Avalonia.Utilities /// The culture to use. /// If successful, contains the convert value. /// True if the cast was successful, otherwise false. - public static bool TryConvert(Type to, object value, CultureInfo culture, out object result) + public static bool TryConvert(Type to, object? value, CultureInfo? culture, out object? result) { if (value == null) { @@ -167,9 +167,9 @@ namespace Avalonia.Utilities { result = null; - if (TryConvert(Enum.GetUnderlyingType(toUnderl), value, culture, out object enumValue)) + if (TryConvert(Enum.GetUnderlyingType(toUnderl), value, culture, out var enumValue)) { - result = Enum.ToObject(toUnderl, enumValue); + result = Enum.ToObject(toUnderl, enumValue!); return true; } } @@ -244,7 +244,7 @@ namespace Avalonia.Utilities /// The value to convert. /// If successful, contains the converted value. /// True if the convert was successful, otherwise false. - public static bool TryConvertImplicit(Type to, object value, out object result) + public static bool TryConvertImplicit(Type to, object? value, out object? result) { if (value == null) { @@ -306,9 +306,9 @@ namespace Avalonia.Utilities /// The type to convert to.. /// The culture to use. /// A value of . - public static object ConvertOrDefault(object value, Type type, CultureInfo culture) + public static object? ConvertOrDefault(object? value, Type type, CultureInfo culture) { - return TryConvert(type, value, culture, out object result) ? result : Default(type); + return TryConvert(type, value, culture, out var result) ? result : Default(type); } /// @@ -318,16 +318,16 @@ namespace Avalonia.Utilities /// The value to convert. /// The type to convert to. /// A value of . - public static object ConvertImplicitOrDefault(object value, Type type) + public static object? ConvertImplicitOrDefault(object? value, Type type) { - return TryConvertImplicit(type, value, out object result) ? result : Default(type); + return TryConvertImplicit(type, value, out var result) ? result : Default(type); } public static T ConvertImplicit(object value) { if (TryConvertImplicit(typeof(T), value, out var result)) { - return (T)result; + return (T)result!; } throw new InvalidCastException( @@ -339,7 +339,7 @@ namespace Avalonia.Utilities /// /// The type. /// The default value. - public static object Default(Type type) + public static object? Default(Type type) { if (type.IsValueType) { @@ -367,7 +367,7 @@ namespace Avalonia.Utilities return false; } - Type underlyingType = Nullable.GetUnderlyingType(type); + var underlyingType = Nullable.GetUnderlyingType(type); if (underlyingType != null) { @@ -391,7 +391,7 @@ namespace Avalonia.Utilities return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } - private static MethodInfo FindTypeConversionOperatorMethod(Type fromType, Type toType, OperatorType operatorType) + private static MethodInfo? FindTypeConversionOperatorMethod(Type fromType, Type toType, OperatorType operatorType) { const string implicitName = "op_Implicit"; const string explicitName = "op_Explicit"; diff --git a/src/Avalonia.Base/Utilities/ValueSingleOrList.cs b/src/Avalonia.Base/Utilities/ValueSingleOrList.cs index dc32cedb76..c1e5d912a8 100644 --- a/src/Avalonia.Base/Utilities/ValueSingleOrList.cs +++ b/src/Avalonia.Base/Utilities/ValueSingleOrList.cs @@ -58,7 +58,7 @@ namespace Avalonia.Utilities List.Add(Single); List.Add(value); - Single = default; + Single = default!; } } } @@ -81,7 +81,7 @@ namespace Avalonia.Utilities if (EqualityComparer.Default.Equals(Single, value)) { - Single = default; + Single = default!; _isSingleSet = false; diff --git a/src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs b/src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs index 28c9dcc262..4605aba800 100644 --- a/src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs +++ b/src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs @@ -23,10 +23,11 @@ namespace Avalonia.Utilities public static void Subscribe(TTarget target, string eventName, EventHandler subscriber) where TEventArgs : EventArgs where TSubscriber : class { + _ = target ?? throw new ArgumentNullException(nameof(target)); + var dic = SubscriptionTypeStorage.Subscribers.GetOrCreateValue(target); - Subscription sub; - if (!dic.TryGetValue(eventName, out sub)) + if (!dic.TryGetValue(eventName, out var sub)) { dic[eventName] = sub = new Subscription(dic, typeof(TTarget), target, eventName); } @@ -45,13 +46,9 @@ namespace Avalonia.Utilities public static void Unsubscribe(object target, string eventName, EventHandler subscriber) where TEventArgs : EventArgs where TSubscriber : class { - SubscriptionDic dic; - - if (SubscriptionTypeStorage.Subscribers.TryGetValue(target, out dic)) + if (SubscriptionTypeStorage.Subscribers.TryGetValue(target, out var dic)) { - Subscription sub; - - if (dic.TryGetValue(eventName, out sub)) + if (dic.TryGetValue(eventName, out var sub)) { sub.Remove(subscriber); } @@ -100,11 +97,14 @@ namespace Avalonia.Utilities _sdic = sdic; _target = target; _eventName = eventName; - Dictionary evDic; - if (!Accessors.TryGetValue(targetType, out evDic)) + if (!Accessors.TryGetValue(targetType, out var evDic)) Accessors[targetType] = evDic = new Dictionary(); - if (!evDic.TryGetValue(eventName, out _info)) + if (evDic.TryGetValue(eventName, out var info)) + { + _info = info; + } + else { var ev = targetType.GetRuntimeEvents().FirstOrDefault(x => x.Name == eventName); @@ -118,13 +118,13 @@ namespace Avalonia.Utilities } var del = new Action(OnEvent); - _delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType, del.Target); - _info.AddMethod.Invoke(target, new[] { _delegate }); + _delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType!, del.Target); + _info.AddMethod!.Invoke(target, new[] { _delegate }); } void Destroy() { - _info.RemoveMethod.Invoke(_target, new[] { _delegate }); + _info.RemoveMethod!.Invoke(_target, new[] { _delegate }); _sdic.Remove(_eventName); } @@ -141,7 +141,7 @@ namespace Avalonia.Utilities MethodInfo method = s.Method; - var subscriber = (TSubscriber)s.Target; + var subscriber = (TSubscriber)s.Target!; if (!s_Callers.TryGetValue(method, out var caller)) s_Callers[method] = caller = (CallerDelegate)Delegate.CreateDelegate(typeof(CallerDelegate), null, method); @@ -161,7 +161,7 @@ namespace Avalonia.Utilities { var reference = _data[c].Subscriber; - if (reference != null && reference.TryGetTarget(out TSubscriber instance) && Equals(instance, s.Target)) + if (reference != null && reference.TryGetTarget(out var instance) && Equals(instance, s.Target)) { _data[c] = default; removed = true; @@ -181,7 +181,7 @@ namespace Avalonia.Utilities { var r = _data[c]; - TSubscriber target = null; + TSubscriber? target = null; r.Subscriber?.TryGetTarget(out target); @@ -208,8 +208,7 @@ namespace Avalonia.Utilities for(var c=0; c<_count; c++) { var r = _data[c].Subscriber; - TSubscriber sub; - if (r.TryGetTarget(out sub)) + if (r.TryGetTarget(out var sub)) { _data[c].Caller(sub, sender, eventArgs); } diff --git a/src/Avalonia.Base/Utilities/WeakObservable.cs b/src/Avalonia.Base/Utilities/WeakObservable.cs index 20e01c751f..52edc7ad1a 100644 --- a/src/Avalonia.Base/Utilities/WeakObservable.cs +++ b/src/Avalonia.Base/Utilities/WeakObservable.cs @@ -23,8 +23,8 @@ namespace Avalonia.Utilities string eventName) where TEventArgs : EventArgs { - Contract.Requires(target != null); - Contract.Requires(eventName != null); + _ = target ?? throw new ArgumentNullException(nameof(target)); + _ = eventName ?? throw new ArgumentNullException(nameof(eventName)); return Observable.Create>(observer => { @@ -43,7 +43,7 @@ namespace Avalonia.Utilities _observer = observer; } - public void OnEvent(object sender, TEventArgs e) + public void OnEvent(object? sender, TEventArgs e) { _observer.OnNext(new EventPattern(sender, e)); } diff --git a/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs b/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs index 65128e7932..88b1e3c807 100644 --- a/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs +++ b/src/Avalonia.Base/Utilities/WeakSubscriptionManager.cs @@ -22,10 +22,11 @@ namespace Avalonia.Utilities public static void Subscribe(TTarget target, string eventName, IWeakSubscriber subscriber) where TEventArgs : EventArgs { + _ = target ?? throw new ArgumentNullException(nameof(target)); + var dic = SubscriptionTypeStorage.Subscribers.GetOrCreateValue(target); - Subscription sub; - if (!dic.TryGetValue(eventName, out sub)) + if (!dic.TryGetValue(eventName, out var sub)) { dic[eventName] = sub = new Subscription(dic, typeof(TTarget), target, eventName); } @@ -43,13 +44,9 @@ namespace Avalonia.Utilities public static void Unsubscribe(object target, string eventName, IWeakSubscriber subscriber) where T : EventArgs { - SubscriptionDic dic; - - if (SubscriptionTypeStorage.Subscribers.TryGetValue(target, out dic)) + if (SubscriptionTypeStorage.Subscribers.TryGetValue(target, out var dic)) { - Subscription sub; - - if (dic.TryGetValue(eventName, out sub)) + if (dic.TryGetValue(eventName, out var sub)) { sub.Remove(subscriber); } @@ -79,7 +76,7 @@ namespace Avalonia.Utilities private readonly string _eventName; private readonly Delegate _delegate; - private WeakReference>[] _data = new WeakReference>[16]; + private WeakReference>?[] _data = new WeakReference>?[16]; private int _count = 0; public Subscription(SubscriptionDic sdic, Type targetType, object target, string eventName) @@ -87,11 +84,14 @@ namespace Avalonia.Utilities _sdic = sdic; _target = target; _eventName = eventName; - Dictionary evDic; - if (!Accessors.TryGetValue(targetType, out evDic)) + if (!Accessors.TryGetValue(targetType, out var evDic)) Accessors[targetType] = evDic = new Dictionary(); - if (!evDic.TryGetValue(eventName, out _info)) + if (evDic.TryGetValue(eventName, out var info)) + { + _info = info; + } + else { var ev = targetType.GetRuntimeEvents().FirstOrDefault(x => x.Name == eventName); @@ -105,13 +105,13 @@ namespace Avalonia.Utilities } var del = new Action(OnEvent); - _delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType, del.Target); - _info.AddMethod.Invoke(target, new[] { _delegate }); + _delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType!, del.Target); + _info.AddMethod!.Invoke(target, new[] { _delegate }); } void Destroy() { - _info.RemoveMethod.Invoke(_target, new[] { _delegate }); + _info.RemoveMethod!.Invoke(_target, new[] { _delegate }); _sdic.Remove(_eventName); } @@ -120,11 +120,11 @@ namespace Avalonia.Utilities if (_count == _data.Length) { //Extend capacity - var ndata = new WeakReference>[_data.Length*2]; + var ndata = new WeakReference>?[_data.Length*2]; Array.Copy(_data, ndata, _data.Length); _data = ndata; } - _data[_count] = s; + _data[_count] = s!; _count++; } @@ -135,7 +135,7 @@ namespace Avalonia.Utilities for (int c = 0; c < _count; ++c) { var reference = _data[c]; - IWeakSubscriber instance; + IWeakSubscriber? instance; if (reference != null && reference.TryGetTarget(out instance) && instance == s) { @@ -179,9 +179,8 @@ namespace Avalonia.Utilities for(var c=0; c<_count; c++) { var r = _data[c]; - IWeakSubscriber sub; - if (r.TryGetTarget(out sub)) - sub.OnEvent(sender, eventArgs); + if (r?.TryGetTarget(out var sub) == true) + sub!.OnEvent(sender, eventArgs); else needCompact = true; } diff --git a/src/Avalonia.Base/Utilities/WeakTimer.cs b/src/Avalonia.Base/Utilities/WeakTimer.cs index a4d18ca13b..ab784fca4d 100644 --- a/src/Avalonia.Base/Utilities/WeakTimer.cs +++ b/src/Avalonia.Base/Utilities/WeakTimer.cs @@ -23,8 +23,7 @@ namespace Avalonia.Utilities private void OnTick() { - IWeakTimerSubscriber subscriber; - if (!_subscriber.TryGetTarget(out subscriber) || !subscriber.Tick()) + if (!_subscriber.TryGetTarget(out var subscriber) || !subscriber.Tick()) Stop(); } diff --git a/src/Avalonia.Base/ValueStore.cs b/src/Avalonia.Base/ValueStore.cs index 9f036fbd34..6b7b598086 100644 --- a/src/Avalonia.Base/ValueStore.cs +++ b/src/Avalonia.Base/ValueStore.cs @@ -5,8 +5,6 @@ using Avalonia.Data; using Avalonia.PropertyStore; using Avalonia.Utilities; -#nullable enable - namespace Avalonia { /// diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj index 90f6abc873..e864ea2007 100644 --- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj +++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj @@ -1,13 +1,12 @@  netstandard2.0 - netstandard2.0;netcoreapp3.1 exe false tools $(DefineConstants);BUILDTASK;XAMLX_CECIL_INTERNAL;XAMLX_INTERNAL true - NU1605 + NU1605;CS8632 @@ -90,6 +89,7 @@ Markup/%(RecursiveDir)%(FileName)%(Extension) + diff --git a/src/Avalonia.Build.Tasks/SpanCompat.cs b/src/Avalonia.Build.Tasks/SpanCompat.cs index f8960f56ec..25f8d0175a 100644 --- a/src/Avalonia.Build.Tasks/SpanCompat.cs +++ b/src/Avalonia.Build.Tasks/SpanCompat.cs @@ -1,4 +1,4 @@ -#if !NETCOREAPP3_1 +#if !NETCOREAPP3_1_OR_GREATER namespace System { // This is a hack to enable our span code to work inside MSBuild task without referencing System.Memory diff --git a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj index 6975642db2..c89157dc0f 100644 --- a/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj +++ b/src/Avalonia.Controls.DataGrid/Avalonia.Controls.DataGrid.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 Avalonia.Controls.DataGrid @@ -16,7 +16,7 @@ - + diff --git a/src/Avalonia.Controls/Application.cs b/src/Avalonia.Controls/Application.cs index df55d9e250..584c3db23b 100644 --- a/src/Avalonia.Controls/Application.cs +++ b/src/Avalonia.Controls/Application.cs @@ -38,8 +38,8 @@ namespace Avalonia /// private DataTemplates? _dataTemplates; - private readonly Lazy _clipboard = - new Lazy(() => (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))); + private readonly Lazy _clipboard = + new Lazy(() => (IClipboard?)AvaloniaLocator.Current.GetService(typeof(IClipboard))); private readonly Styler _styler = new Styler(); private Styles? _styles; private IResourceDictionary? _resources; @@ -85,7 +85,7 @@ namespace Avalonia /// /// The current instance of the class. /// - public static Application Current + public static Application? Current { get { return AvaloniaLocator.Current.GetService(); } } @@ -125,7 +125,7 @@ namespace Avalonia /// /// Gets the application clipboard. /// - public IClipboard Clipboard => _clipboard.Value; + public IClipboard? Clipboard => _clipboard.Value; /// /// Gets the application's global resource dictionary. diff --git a/src/Avalonia.Controls/Avalonia.Controls.csproj b/src/Avalonia.Controls/Avalonia.Controls.csproj index 7f1f4bc8f3..e2c6a714aa 100644 --- a/src/Avalonia.Controls/Avalonia.Controls.csproj +++ b/src/Avalonia.Controls/Avalonia.Controls.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs index 8b22cdd4ec..8537c9acbc 100644 --- a/src/Avalonia.Controls/Button.cs +++ b/src/Avalonia.Controls/Button.cs @@ -304,15 +304,18 @@ namespace Avalonia.Controls /// protected virtual void OnClick() { - OpenFlyout(); + if (IsEffectivelyEnabled) + { + OpenFlyout(); - var e = new RoutedEventArgs(ClickEvent); - RaiseEvent(e); + var e = new RoutedEventArgs(ClickEvent); + RaiseEvent(e); - if (!e.Handled && Command?.CanExecute(CommandParameter) == true) - { - Command.Execute(CommandParameter); - e.Handled = true; + if (!e.Handled && Command?.CanExecute(CommandParameter) == true) + { + Command.Execute(CommandParameter); + e.Handled = true; + } } } diff --git a/src/Avalonia.Controls/ButtonSpinner.cs b/src/Avalonia.Controls/ButtonSpinner.cs index 5fe2cf3704..f1c1a55a17 100644 --- a/src/Avalonia.Controls/ButtonSpinner.cs +++ b/src/Avalonia.Controls/ButtonSpinner.cs @@ -1,4 +1,4 @@ -using System; +using System; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.Data; @@ -196,13 +196,14 @@ namespace Avalonia.Controls protected override void OnPointerWheelChanged(PointerWheelEventArgs e) { base.OnPointerWheelChanged(e); - if (!e.Handled && AllowSpin) + + if (AllowSpin && IsKeyboardFocusWithin) { if (e.Delta.Y != 0) { var spinnerEventArgs = new SpinEventArgs(SpinEvent, (e.Delta.Y < 0) ? SpinDirection.Decrease : SpinDirection.Increase, true); OnSpin(spinnerEventArgs); - e.Handled = spinnerEventArgs.Handled; + e.Handled = true; } } } diff --git a/src/Avalonia.Controls/Calendar/CalendarDatePicker.cs b/src/Avalonia.Controls/Calendar/CalendarDatePicker.cs index af3fdbd662..a856ee071c 100644 --- a/src/Avalonia.Controls/Calendar/CalendarDatePicker.cs +++ b/src/Avalonia.Controls/Calendar/CalendarDatePicker.cs @@ -1,4 +1,4 @@ -// (c) Copyright Microsoft Corporation. +// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. @@ -425,9 +425,6 @@ namespace Avalonia.Controls { FocusableProperty.OverrideDefaultValue(true); - DisplayDateProperty.Changed.AddClassHandler((x,e) => x.OnDisplayDateChanged(e)); - DisplayDateStartProperty.Changed.AddClassHandler((x,e) => x.OnDisplayDateStartChanged(e)); - DisplayDateEndProperty.Changed.AddClassHandler((x,e) => x.OnDisplayDateEndChanged(e)); IsDropDownOpenProperty.Changed.AddClassHandler((x,e) => x.OnIsDropDownOpenChanged(e)); SelectedDateProperty.Changed.AddClassHandler((x,e) => x.OnSelectedDateChanged(e)); SelectedDateFormatProperty.Changed.AddClassHandler((x,e) => x.OnSelectedDateFormatChanged(e)); @@ -459,18 +456,12 @@ namespace Avalonia.Controls if (_calendar != null) { _calendar.SelectionMode = CalendarSelectionMode.SingleDate; - _calendar.SelectedDate = SelectedDate; - SetCalendarDisplayDate(DisplayDate); - SetCalendarDisplayDateStart(DisplayDateStart); - SetCalendarDisplayDateEnd(DisplayDateEnd); _calendar.DayButtonMouseUp += Calendar_DayButtonMouseUp; _calendar.DisplayDateChanged += Calendar_DisplayDateChanged; _calendar.SelectedDatesChanged += Calendar_SelectedDatesChanged; _calendar.PointerReleased += Calendar_PointerReleased; _calendar.KeyDown += Calendar_KeyDown; - //_calendar.SizeChanged += new SizeChangedEventHandler(Calendar_SizeChanged); - //_calendar.IsTabStop = true; var currentBlackoutDays = BlackoutDates; BlackoutDates = _calendar.BlackoutDates; @@ -587,58 +578,6 @@ namespace Avalonia.Controls SetSelectedDate(); } - private void SetCalendarDisplayDate(DateTime value) - { - if (DateTimeHelper.CompareYearMonth(_calendar.DisplayDate, value) != 0) - { - _calendar.DisplayDate = DisplayDate; - if (DateTime.Compare(_calendar.DisplayDate, DisplayDate) != 0) - { - DisplayDate = _calendar.DisplayDate; - } - } - } - private void OnDisplayDateChanged(AvaloniaPropertyChangedEventArgs e) - { - if (_calendar != null) - { - var value = (DateTime)e.NewValue; - SetCalendarDisplayDate(value); - } - } - private void SetCalendarDisplayDateStart(DateTime? value) - { - _calendar.DisplayDateStart = value; - if (_calendar.DisplayDateStart.HasValue && DisplayDateStart.HasValue && DateTime.Compare(_calendar.DisplayDateStart.Value, DisplayDateStart.Value) != 0) - { - DisplayDateStart = _calendar.DisplayDateStart; - } - } - private void OnDisplayDateStartChanged(AvaloniaPropertyChangedEventArgs e) - { - if (_calendar != null) - { - var value = (DateTime?)e.NewValue; - SetCalendarDisplayDateStart(value); - } - } - private void SetCalendarDisplayDateEnd(DateTime? value) - { - _calendar.DisplayDateEnd = value; - if (_calendar.DisplayDateEnd.HasValue && DisplayDateEnd.HasValue && DateTime.Compare(_calendar.DisplayDateEnd.Value, DisplayDateEnd.Value) != 0) - { - DisplayDateEnd = _calendar.DisplayDateEnd; - } - - } - private void OnDisplayDateEndChanged(AvaloniaPropertyChangedEventArgs e) - { - if (_calendar != null) - { - var value = (DateTime?)e.NewValue; - SetCalendarDisplayDateEnd(value); - } - } private void OnIsDropDownOpenChanged(AvaloniaPropertyChangedEventArgs e) { var oldValue = (bool)e.OldValue; @@ -670,11 +609,6 @@ namespace Avalonia.Controls var addedDate = (DateTime?)e.NewValue; var removedDate = (DateTime?)e.OldValue; - if (_calendar != null && addedDate != _calendar.SelectedDate) - { - _calendar.SelectedDate = addedDate; - } - if (SelectedDate != null) { DateTime day = SelectedDate.Value; diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs index d8fd864e9b..d94bff37df 100644 --- a/src/Avalonia.Controls/ContextMenu.cs +++ b/src/Avalonia.Controls/ContextMenu.cs @@ -417,7 +417,7 @@ namespace Avalonia.Controls { var keymap = AvaloniaLocator.Current.GetService(); - if (keymap.OpenContextMenu.Any(k => k.Matches(e)) + if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true && !CancelClosing()) { Close(); diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index fe731b9d4b..441421181c 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -248,7 +248,11 @@ namespace Avalonia.Controls if (e.Source == this && !e.Handled) { - var keymap = AvaloniaLocator.Current.GetService().OpenContextMenu; + var keymap = AvaloniaLocator.Current.GetService()?.OpenContextMenu; + + if (keymap is null) + return; + var matches = false; for (var index = 0; index < keymap.Count; index++) diff --git a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs index d78ddd4169..a08b82f512 100644 --- a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs +++ b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs @@ -399,7 +399,7 @@ namespace Avalonia.Controls.Primitives { var keymap = AvaloniaLocator.Current.GetService(); - if (keymap.OpenContextMenu.Any(k => k.Matches(e))) + if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true) { e.Handled = HideCore(); } diff --git a/src/Avalonia.Controls/Grid.cs b/src/Avalonia.Controls/Grid.cs index 4e60b52f83..74401c450a 100644 --- a/src/Avalonia.Controls/Grid.cs +++ b/src/Avalonia.Controls/Grid.cs @@ -978,7 +978,7 @@ namespace Avalonia.Controls /// width is not registered in columns. /// Passed through to MeasureCell. /// When "true" cells' desired height is not registered in rows. - /// return true when desired size has changed + /// When the method exits, indicates whether the desired size has changed. private void MeasureCellsGroup( int cellsHead, Size referenceSize, diff --git a/src/Avalonia.Controls/MaskedTextBox.cs b/src/Avalonia.Controls/MaskedTextBox.cs index a72c617f05..f59cef8223 100644 --- a/src/Avalonia.Controls/MaskedTextBox.cs +++ b/src/Avalonia.Controls/MaskedTextBox.cs @@ -207,9 +207,14 @@ namespace Avalonia.Controls bool Match(List gestures) => gestures.Any(g => g.Matches(e)); - if (Match(keymap.Paste)) + if (keymap is not null && Match(keymap.Paste)) { - var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync(); + var clipboard = (IClipboard?)AvaloniaLocator.Current.GetService(typeof(IClipboard)); + + if (clipboard is null) + return; + + var text = await clipboard.GetTextAsync(); if (text == null) return; diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index b661bcfe33..b843992f04 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -715,7 +715,7 @@ namespace Avalonia.Controls /// /// The service type. /// A service of the requested type. - public object GetService(Type serviceType) + public object? GetService(Type serviceType) { if (serviceType == typeof(IAccessKeyHandler)) { diff --git a/src/Avalonia.Controls/Platform/PlatformManager.cs b/src/Avalonia.Controls/Platform/PlatformManager.cs index acd45ad29a..8e9f64b3ad 100644 --- a/src/Avalonia.Controls/Platform/PlatformManager.cs +++ b/src/Avalonia.Controls/Platform/PlatformManager.cs @@ -8,9 +8,6 @@ namespace Avalonia.Controls.Platform { public static partial class PlatformManager { - static IPlatformSettings GetSettings() - => AvaloniaLocator.Current.GetService(); - static bool s_designerMode; public static IDisposable DesignerMode() diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index 07bc789cc1..80f3d345a6 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -545,6 +545,10 @@ namespace Avalonia.Controls.Primitives if (!e.Handled) { var keymap = AvaloniaLocator.Current.GetService(); + + if (keymap is null) + return; + bool Match(List gestures) => gestures.Any(g => g.Matches(e)); if (ItemCount > 0 && diff --git a/src/Avalonia.Controls/SystemDialog.cs b/src/Avalonia.Controls/SystemDialog.cs index d81926ecc7..3487f427d7 100644 --- a/src/Avalonia.Controls/SystemDialog.cs +++ b/src/Avalonia.Controls/SystemDialog.cs @@ -66,8 +66,8 @@ namespace Avalonia.Controls { if(parent == null) throw new ArgumentNullException(nameof(parent)); - return ((await AvaloniaLocator.Current.GetService() - .ShowFileDialogAsync(this, parent)) ?? + var service = AvaloniaLocator.Current.GetRequiredService(); + return (await service.ShowFileDialogAsync(this, parent) ?? Array.Empty()).FirstOrDefault(); } } @@ -94,7 +94,8 @@ namespace Avalonia.Controls { if(parent == null) throw new ArgumentNullException(nameof(parent)); - return AvaloniaLocator.Current.GetService().ShowFileDialogAsync(this, parent); + var service = AvaloniaLocator.Current.GetRequiredService(); + return service.ShowFileDialogAsync(this, parent); } } @@ -122,7 +123,8 @@ namespace Avalonia.Controls { if(parent == null) throw new ArgumentNullException(nameof(parent)); - return AvaloniaLocator.Current.GetService().ShowFolderDialogAsync(this, parent); + var service = AvaloniaLocator.Current.GetRequiredService(); + return service.ShowFolderDialogAsync(this, parent); } } diff --git a/src/Avalonia.Controls/Templates/DataTemplateExtensions.cs b/src/Avalonia.Controls/Templates/DataTemplateExtensions.cs index 2b115aec7e..82a1758c26 100644 --- a/src/Avalonia.Controls/Templates/DataTemplateExtensions.cs +++ b/src/Avalonia.Controls/Templates/DataTemplateExtensions.cs @@ -47,7 +47,7 @@ namespace Avalonia.Controls.Templates currentTemplateHost = currentTemplateHost.LogicalParent; } - IGlobalDataTemplates global = AvaloniaLocator.Current.GetService(); + var global = AvaloniaLocator.Current.GetService(); if (global != null && global.IsDataTemplatesInitialized) { diff --git a/src/Avalonia.Controls/TrayIcon.cs b/src/Avalonia.Controls/TrayIcon.cs index 9fbc2fc8b2..03ffe830ed 100644 --- a/src/Avalonia.Controls/TrayIcon.cs +++ b/src/Avalonia.Controls/TrayIcon.cs @@ -65,7 +65,9 @@ namespace Avalonia.Controls } }); - if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) + var app = Application.Current ?? throw new InvalidOperationException("Application not yet initialized."); + + if (app.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) { lifetime.Exit += Lifetime_Exit; } @@ -186,7 +188,8 @@ namespace Avalonia.Controls private static void Lifetime_Exit(object sender, ControlledApplicationLifetimeExitEventArgs e) { - var trayIcons = GetIcons(Application.Current); + var app = Application.Current ?? throw new InvalidOperationException("Application not yet initialized."); + var trayIcons = GetIcons(app); RemoveIcons(trayIcons); } diff --git a/src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs b/src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs index c26c5e0513..1a190391b7 100644 --- a/src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs +++ b/src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs @@ -107,7 +107,7 @@ namespace Avalonia.Controls.Utils this); } - void IWeakSubscriber.OnEvent(object sender, NotifyCollectionChangedEventArgs e) + void IWeakSubscriber.OnEvent(object? sender, NotifyCollectionChangedEventArgs e) { static void Notify( INotifyCollectionChanged incc, diff --git a/src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj b/src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj index 35bd0f97e1..f8a7cdc690 100644 --- a/src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj +++ b/src/Avalonia.DesignerSupport/Avalonia.DesignerSupport.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 + + + @@ -65,9 +78,10 @@ - + - + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml index 375c9b303c..22f9ccf513 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml @@ -83,7 +83,7 @@ Pointer Over: - + _frozenPopupStates; - private TopLevel? _root; + private AvaloniaObject? _root; public MainWindow() { InitializeComponent(); - _keySubscription = InputManager.Instance.Process + _keySubscription = InputManager.Instance?.Process .OfType() .Where(x => x.Type == RawKeyEventType.KeyDown) .Subscribe(RawKeyDown); @@ -50,23 +50,23 @@ namespace Avalonia.Diagnostics.Views this.Opened += lh; } - public TopLevel? Root + public AvaloniaObject? Root { get => _root; set { if (_root != value) { - if (_root != null) + if (_root is ICloseable oldClosable) { - _root.Closed -= RootClosed; + oldClosable.Closed -= RootClosed; } _root = value; - if (_root != null) + if (_root is ICloseable newClosable) { - _root.Closed += RootClosed; + newClosable.Closed += RootClosed; DataContext = new MainViewModel(_root); } else @@ -82,7 +82,7 @@ namespace Avalonia.Diagnostics.Views protected override void OnClosed(EventArgs e) { base.OnClosed(e); - _keySubscription.Dispose(); + _keySubscription?.Dispose(); foreach (var state in _frozenPopupStates) { @@ -91,9 +91,9 @@ namespace Avalonia.Diagnostics.Views _frozenPopupStates.Clear(); - if (_root != null) + if (_root is ICloseable cloneable) { - _root.Closed -= RootClosed; + cloneable.Closed -= RootClosed; _root = null; } @@ -123,7 +123,7 @@ namespace Avalonia.Diagnostics.Views .FirstOrDefault(); } - private static List GetPopupRoots(IVisual root) + private static List GetPopupRoots(TopLevel root) { var popupRoots = new List(); @@ -160,7 +160,8 @@ namespace Avalonia.Diagnostics.Views return; } - var root = Root; + var root = Root as TopLevel + ?? vm.PointerOverRoot as TopLevel; if (root is null) { return; diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs index 3543b1adea..649b65c521 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs @@ -47,7 +47,12 @@ namespace Avalonia.Diagnostics.Views return; } - var visual = (Visual)node.Visual; + var visual = node.Visual as Visual; + + if (visual is null) + { + return; + } _currentLayer = AdornerLayer.GetAdornerLayer(visual); diff --git a/src/Avalonia.Dialogs/Avalonia.Dialogs.csproj b/src/Avalonia.Dialogs/Avalonia.Dialogs.csproj index 665693a654..475a3655e4 100644 --- a/src/Avalonia.Dialogs/Avalonia.Dialogs.csproj +++ b/src/Avalonia.Dialogs/Avalonia.Dialogs.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj index 81af76dc20..bcb63783a4 100644 --- a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj +++ b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Headless.Vnc/Avalonia.Headless.Vnc.csproj b/src/Avalonia.Headless.Vnc/Avalonia.Headless.Vnc.csproj index 4aac862ae8..273910eb59 100644 --- a/src/Avalonia.Headless.Vnc/Avalonia.Headless.Vnc.csproj +++ b/src/Avalonia.Headless.Vnc/Avalonia.Headless.Vnc.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Headless/Avalonia.Headless.csproj b/src/Avalonia.Headless/Avalonia.Headless.csproj index ac591b68a8..2e33b5790a 100644 --- a/src/Avalonia.Headless/Avalonia.Headless.csproj +++ b/src/Avalonia.Headless/Avalonia.Headless.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index 63cbfb2dbe..48d0ef9da9 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -447,6 +447,10 @@ namespace Avalonia.Headless } + public void DrawEllipse(IBrush brush, IPen pen, Rect rect) + { + } + public void DrawGlyphRun(IBrush foreground, GlyphRun glyphRun) { diff --git a/src/Avalonia.Input/AccessKeyHandler.cs b/src/Avalonia.Input/AccessKeyHandler.cs index 5082265ea6..60175ae588 100644 --- a/src/Avalonia.Input/AccessKeyHandler.cs +++ b/src/Avalonia.Input/AccessKeyHandler.cs @@ -133,7 +133,7 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e) + protected virtual void OnPreviewKeyDown(object? sender, KeyEventArgs e) { if (e.Key == Key.LeftAlt || e.Key == Key.RightAlt) { @@ -143,7 +143,7 @@ namespace Avalonia.Input { // TODO: Use FocusScopes to store the current element and restore it when context menu is closed. // Save currently focused input element. - _restoreFocusElement = FocusManager.Instance.Current; + _restoreFocusElement = FocusManager.Instance?.Current; // When Alt is pressed without a main menu, or with a closed main menu, show // access key markers in the window (i.e. "_File"). @@ -172,7 +172,7 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - protected virtual void OnKeyDown(object sender, KeyEventArgs e) + protected virtual void OnKeyDown(object? sender, KeyEventArgs e) { bool menuIsOpen = MainMenu?.IsOpen == true; @@ -188,7 +188,7 @@ namespace Avalonia.Input // If the menu is open, only match controls in the menu's visual tree. if (menuIsOpen) { - matches = matches.Where(x => MainMenu.IsVisualAncestorOf(x)); + matches = matches.Where(x => x is not null && MainMenu!.IsVisualAncestorOf(x)); } var match = matches.FirstOrDefault(); @@ -207,7 +207,7 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - protected virtual void OnPreviewKeyUp(object sender, KeyEventArgs e) + protected virtual void OnPreviewKeyUp(object? sender, KeyEventArgs e) { switch (e.Key) { @@ -234,7 +234,7 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - protected virtual void OnPreviewPointerPressed(object sender, PointerEventArgs e) + protected virtual void OnPreviewPointerPressed(object? sender, PointerEventArgs e) { if (_showingAccessKeys) { @@ -251,7 +251,7 @@ namespace Avalonia.Input _owner!.ShowAccessKeys = _showingAccessKeys = false; } - private void MainMenuClosed(object sender, EventArgs e) + private void MainMenuClosed(object? sender, EventArgs e) { _owner!.ShowAccessKeys = false; } diff --git a/src/Avalonia.Input/Avalonia.Input.csproj b/src/Avalonia.Input/Avalonia.Input.csproj index cc487e285b..e66d1d7e7c 100644 --- a/src/Avalonia.Input/Avalonia.Input.csproj +++ b/src/Avalonia.Input/Avalonia.Input.csproj @@ -1,7 +1,6 @@  - netstandard2.0 - Enable + net6.0;netstandard2.0 @@ -15,4 +14,5 @@ + diff --git a/src/Avalonia.Input/FocusManager.cs b/src/Avalonia.Input/FocusManager.cs index 2efd33df1d..30301788bc 100644 --- a/src/Avalonia.Input/FocusManager.cs +++ b/src/Avalonia.Input/FocusManager.cs @@ -32,7 +32,7 @@ namespace Avalonia.Input /// /// Gets the instance of the . /// - public static IFocusManager Instance => AvaloniaLocator.Current.GetService(); + public static IFocusManager? Instance => AvaloniaLocator.Current.GetService(); /// /// Gets the currently focused . @@ -215,8 +215,11 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - private static void OnPreviewPointerPressed(object sender, RoutedEventArgs e) + private static void OnPreviewPointerPressed(object? sender, RoutedEventArgs e) { + if (sender is null) + return; + var ev = (PointerPressedEventArgs)e; var visual = (IVisual)sender; diff --git a/src/Avalonia.Input/GestureRecognizers/ScrollGestureRecognizer.cs b/src/Avalonia.Input/GestureRecognizers/ScrollGestureRecognizer.cs index 84a26a0cc3..f8cedb636f 100644 --- a/src/Avalonia.Input/GestureRecognizers/ScrollGestureRecognizer.cs +++ b/src/Avalonia.Input/GestureRecognizers/ScrollGestureRecognizer.cs @@ -71,7 +71,7 @@ namespace Avalonia.Input.GestureRecognizers EndGesture(); _tracking = e.Pointer; _gestureId = ScrollGestureEventArgs.GetNextFreeId();; - _trackedRootPoint = e.GetPosition(null); + _trackedRootPoint = e.GetPosition(_target); } } @@ -85,7 +85,7 @@ namespace Avalonia.Input.GestureRecognizers { if (e.Pointer == _tracking) { - var rootPoint = e.GetPosition(null); + var rootPoint = e.GetPosition(_target); if (!_scrolling) { if (CanHorizontallyScroll && Math.Abs(_trackedRootPoint.X - rootPoint.X) > ScrollStartDistance) diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 639b4ef117..a5ee558f47 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -6,6 +6,7 @@ namespace Avalonia.Input { public static class Gestures { + private static bool s_isDoubleTapped = false; public static readonly RoutedEvent TappedEvent = RoutedEvent.Register( "Tapped", RoutingStrategies.Bubble, @@ -81,20 +82,23 @@ namespace Avalonia.Input var e = (PointerPressedEventArgs)ev; var visual = (IVisual)ev.Source; -#pragma warning disable CS0618 // Type or member is obsolete - var clickCount = e.ClickCount; -#pragma warning restore CS0618 // Type or member is obsolete - if (clickCount <= 1) + if (e.ClickCount <= 1) { + s_isDoubleTapped = false; s_lastPress.SetTarget(ev.Source); } - else if (clickCount == 2 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed) + else if (e.ClickCount % 2 == 0 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed) { if (s_lastPress.TryGetTarget(out var target) && target == e.Source) { + s_isDoubleTapped = true; e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e)); } } + else + { + s_isDoubleTapped = false; + } } } @@ -112,7 +116,9 @@ namespace Avalonia.Input { e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e)); } - else + //s_isDoubleTapped needed here to prevent invoking Tapped event when DoubleTapped is called. + //This behaviour matches UWP behaviour. + else if (s_isDoubleTapped == false) { e.Source.RaiseEvent(new TappedEventArgs(TappedEvent, e)); } diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 26ebf86857..def0a26b27 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -499,7 +499,7 @@ namespace Avalonia.Input if (IsFocused) { - FocusManager.Instance.Focus(null); + FocusManager.Instance?.Focus(null); } } @@ -675,7 +675,7 @@ namespace Avalonia.Input /// . /// /// The parent control. - private void UpdateIsEffectivelyEnabled(InputElement parent) + private void UpdateIsEffectivelyEnabled(InputElement? parent) { IsEffectivelyEnabled = IsEnabledCore && (parent?.IsEffectivelyEnabled ?? true); diff --git a/src/Avalonia.Input/InputManager.cs b/src/Avalonia.Input/InputManager.cs index 129b9cf474..f604ff8e74 100644 --- a/src/Avalonia.Input/InputManager.cs +++ b/src/Avalonia.Input/InputManager.cs @@ -17,7 +17,7 @@ namespace Avalonia.Input /// /// Gets the global instance of the input manager. /// - public static IInputManager Instance => AvaloniaLocator.Current.GetService(); + public static IInputManager? Instance => AvaloniaLocator.Current.GetService(); /// public IObservable PreProcess => _preProcess; diff --git a/src/Avalonia.Input/KeyboardDevice.cs b/src/Avalonia.Input/KeyboardDevice.cs index a159b19026..438e3fcadb 100644 --- a/src/Avalonia.Input/KeyboardDevice.cs +++ b/src/Avalonia.Input/KeyboardDevice.cs @@ -14,11 +14,11 @@ namespace Avalonia.Input public event PropertyChangedEventHandler? PropertyChanged; - public static IKeyboardDevice Instance => AvaloniaLocator.Current.GetService(); + public static IKeyboardDevice? Instance => AvaloniaLocator.Current.GetService(); - public IInputManager InputManager => AvaloniaLocator.Current.GetService(); + public IInputManager? InputManager => AvaloniaLocator.Current.GetService(); - public IFocusManager FocusManager => AvaloniaLocator.Current.GetService(); + public IFocusManager? FocusManager => AvaloniaLocator.Current.GetService(); // This should live in the FocusManager, but with the current outdated architecture // the source of truth about the input focus is in KeyboardDevice diff --git a/src/Avalonia.Input/KeyboardNavigationHandler.cs b/src/Avalonia.Input/KeyboardNavigationHandler.cs index 6493777105..f73203f6b7 100644 --- a/src/Avalonia.Input/KeyboardNavigationHandler.cs +++ b/src/Avalonia.Input/KeyboardNavigationHandler.cs @@ -89,7 +89,7 @@ namespace Avalonia.Input var method = direction == NavigationDirection.Next || direction == NavigationDirection.Previous ? NavigationMethod.Tab : NavigationMethod.Directional; - FocusManager.Instance.Focus(next, method, keyModifiers); + FocusManager.Instance?.Focus(next, method, keyModifiers); } } @@ -98,9 +98,9 @@ namespace Avalonia.Input /// /// The event sender. /// The event args. - protected virtual void OnKeyDown(object sender, KeyEventArgs e) + protected virtual void OnKeyDown(object? sender, KeyEventArgs e) { - var current = FocusManager.Instance.Current; + var current = FocusManager.Instance?.Current; if (current != null && e.Key == Key.Tab) { diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index 401c6cb2ac..a2c43013fd 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -240,7 +240,8 @@ namespace Avalonia.Input if (source != null) { var settings = AvaloniaLocator.Current.GetService(); - var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds; + var doubleClickTime = settings?.DoubleClickTime.TotalMilliseconds ?? 500; + var doubleClickSize = settings?.DoubleClickSize ?? new Size(4, 4); if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime) { @@ -250,7 +251,7 @@ namespace Avalonia.Input ++_clickCount; _lastClickTime = timestamp; _lastClickRect = new Rect(p, new Size()) - .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2)); + .Inflate(new Thickness(doubleClickSize.Width / 2, doubleClickSize.Height / 2)); _lastMouseDownButton = properties.PointerUpdateKind.GetMouseButton(); var e = new PointerPressedEventArgs(source, _pointer, root, p, timestamp, properties, inputModifiers, _clickCount); source.RaiseEvent(e); @@ -298,10 +299,10 @@ namespace Avalonia.Input root = root ?? throw new ArgumentNullException(nameof(root)); var hit = HitTest(root, p); + var source = GetSource(hit); - if (hit != null) + if (source is not null) { - var source = GetSource(hit); var e = new PointerReleasedEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, _lastMouseDownButton); @@ -321,10 +322,10 @@ namespace Avalonia.Input root = root ?? throw new ArgumentNullException(nameof(root)); var hit = HitTest(root, p); + var source = GetSource(hit); - if (hit != null) + if (source is not null) { - var source = GetSource(hit); var e = new PointerWheelEventArgs(source, _pointer, root, p, timestamp, props, inputModifiers, delta); source?.RaiseEvent(e); @@ -334,9 +335,10 @@ namespace Avalonia.Input return false; } - private IInteractive GetSource(IVisual hit) + private IInteractive? GetSource(IVisual? hit) { - hit = hit ?? throw new ArgumentNullException(nameof(hit)); + if (hit is null) + return null; return _pointer.Captured ?? (hit as IInteractive) ?? diff --git a/src/Avalonia.Input/Pointer.cs b/src/Avalonia.Input/Pointer.cs index a477711584..3012f07f6a 100644 --- a/src/Avalonia.Input/Pointer.cs +++ b/src/Avalonia.Input/Pointer.cs @@ -54,12 +54,12 @@ namespace Avalonia.Input Captured.DetachedFromVisualTree += OnCaptureDetached; } - IInputElement GetNextCapture(IVisual parent) + IInputElement? GetNextCapture(IVisual parent) { return parent as IInputElement ?? parent.FindAncestorOfType(); } - private void OnCaptureDetached(object sender, VisualTreeAttachmentEventArgs e) + private void OnCaptureDetached(object? sender, VisualTreeAttachmentEventArgs e) { Capture(GetNextCapture(e.Parent)); } diff --git a/src/Avalonia.Input/PointerEventArgs.cs b/src/Avalonia.Input/PointerEventArgs.cs index ba39f7ca8e..8c86cd4637 100644 --- a/src/Avalonia.Input/PointerEventArgs.cs +++ b/src/Avalonia.Input/PointerEventArgs.cs @@ -114,7 +114,7 @@ namespace Avalonia.Input public class PointerPressedEventArgs : PointerEventArgs { - private readonly int _obsoleteClickCount; + private readonly int _clickCount; public PointerPressedEventArgs( IInteractive source, @@ -123,15 +123,14 @@ namespace Avalonia.Input ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, - int obsoleteClickCount = 1) + int clickCount = 1) : base(InputElement.PointerPressedEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers) { - _obsoleteClickCount = obsoleteClickCount; + _clickCount = clickCount; } - [Obsolete("Use DoubleTapped event or Gestures.DoubleRightTapped attached event")] - public int ClickCount => _obsoleteClickCount; + public int ClickCount => _clickCount; [Obsolete("Use PointerPressedEventArgs.GetCurrentPoint(this).Properties")] public MouseButton MouseButton => Properties.PointerUpdateKind.GetMouseButton(); diff --git a/src/Avalonia.Input/TextInput/InputMethodManager.cs b/src/Avalonia.Input/TextInput/InputMethodManager.cs index dafd397348..64422a7fdf 100644 --- a/src/Avalonia.Input/TextInput/InputMethodManager.cs +++ b/src/Avalonia.Input/TextInput/InputMethodManager.cs @@ -8,7 +8,6 @@ namespace Avalonia.Input.TextInput private ITextInputMethodImpl? _im; private IInputElement? _focusedElement; private ITextInputMethodClient? _client; - private IDisposable? _subscribeDisposable; private readonly TransformTrackingHelper _transformTracker = new TransformTrackingHelper(); public TextInputMethodManager() @@ -64,7 +63,7 @@ namespace Avalonia.Input.TextInput } } - private void OnTextViewVisualChanged(object sender, EventArgs e) + private void OnTextViewVisualChanged(object? sender, EventArgs e) => _transformTracker.SetVisual(_client?.TextViewVisual); private void UpdateCursorRect() @@ -79,7 +78,7 @@ namespace Avalonia.Input.TextInput _im.SetCursorRect(_client.CursorRectangle.TransformToAABB(transform.Value)); } - private void OnCursorRectangleChanged(object sender, EventArgs e) + private void OnCursorRectangleChanged(object? sender, EventArgs e) { if (sender == _client) UpdateCursorRect(); diff --git a/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs b/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs index 4211360a8f..325c72bcb5 100644 --- a/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs +++ b/src/Avalonia.Input/TextInput/TransformTrackingHelper.cs @@ -80,7 +80,7 @@ namespace Avalonia.Input.TextInput } } - private void OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) + private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) { SubscribeToParents(); UpdateMatrix(); @@ -94,13 +94,13 @@ namespace Avalonia.Input.TextInput Dispatcher.UIThread.Post(UpdateMatrix, DispatcherPriority.Render); } - private void PropertyChangedHandler(object sender, AvaloniaPropertyChangedEventArgs e) + private void PropertyChangedHandler(object? sender, AvaloniaPropertyChangedEventArgs e) { if (e.IsEffectiveValueChange && e.Property == Visual.BoundsProperty) EnqueueForUpdate(); } - private void OnDetachedFromVisualTree(object sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) + private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs visualTreeAttachmentEventArgs) { UnsubscribeFromParents(); UpdateMatrix(); diff --git a/src/Avalonia.Input/TouchDevice.cs b/src/Avalonia.Input/TouchDevice.cs index d6ad836f37..af8851a82b 100644 --- a/src/Avalonia.Input/TouchDevice.cs +++ b/src/Avalonia.Input/TouchDevice.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using Avalonia.Input.Raw; -using Avalonia.VisualTree; +using Avalonia.Platform; namespace Avalonia.Input { @@ -16,7 +16,9 @@ namespace Avalonia.Input { private readonly Dictionary _pointers = new Dictionary(); private bool _disposed; - + private int _clickCount; + private Rect _lastClickRect; + private ulong _lastClickTime; KeyModifiers GetKeyModifiers(RawInputModifiers modifiers) => (KeyModifiers)(modifiers & RawInputModifiers.KeyboardMask); @@ -27,10 +29,10 @@ namespace Avalonia.Input rv |= RawInputModifiers.LeftMouseButton; return rv; } - + public void ProcessRawEvent(RawInputEventArgs ev) { - if(_disposed) + if (_disposed) return; var args = (RawTouchEventArgs)ev; if (!_pointers.TryGetValue(args.TouchPointId, out var pointer)) @@ -43,16 +45,40 @@ namespace Avalonia.Input PointerType.Touch, _pointers.Count == 0); pointer.Capture(hit); } - + var target = pointer.Captured ?? args.Root; if (args.Type == RawPointerEventType.TouchBegin) { + if (_pointers.Count > 1) + { + _clickCount = 1; + _lastClickTime = 0; + _lastClickRect = new Rect(); + } + else + { + var settings = AvaloniaLocator.Current.GetService(); + if (settings == null) + { + throw new Exception("IPlatformSettings can not be null."); + } + if (!_lastClickRect.Contains(args.Position) + || ev.Timestamp - _lastClickTime > settings.DoubleClickTime.TotalMilliseconds) + { + _clickCount = 0; + } + ++_clickCount; + _lastClickTime = ev.Timestamp; + _lastClickRect = new Rect(args.Position, new Size()) + .Inflate(new Thickness(16, 16)); + } + target.RaiseEvent(new PointerPressedEventArgs(target, pointer, args.Root, args.Position, ev.Timestamp, new PointerPointProperties(GetModifiers(args.InputModifiers, true), PointerUpdateKind.LeftButtonPressed), - GetKeyModifiers(args.InputModifiers))); + GetKeyModifiers(args.InputModifiers), _clickCount)); } if (args.Type == RawPointerEventType.TouchEnd) @@ -84,12 +110,12 @@ namespace Avalonia.Input GetKeyModifiers(args.InputModifiers))); } - + } public void Dispose() { - if(_disposed) + if (_disposed) return; var values = _pointers.Values.ToList(); _pointers.Clear(); @@ -97,6 +123,6 @@ namespace Avalonia.Input foreach (var p in values) p.Dispose(); } - + } } diff --git a/src/Avalonia.Interactivity/Avalonia.Interactivity.csproj b/src/Avalonia.Interactivity/Avalonia.Interactivity.csproj index 2da23410d6..03a53f7d86 100644 --- a/src/Avalonia.Interactivity/Avalonia.Interactivity.csproj +++ b/src/Avalonia.Interactivity/Avalonia.Interactivity.csproj @@ -1,8 +1,6 @@  - netstandard2.0 - Enable - CS8600;CS8602;CS8603 + net6.0;netstandard2.0 @@ -12,4 +10,5 @@ + \ No newline at end of file diff --git a/src/Avalonia.Interactivity/RoutedEvent.cs b/src/Avalonia.Interactivity/RoutedEvent.cs index 3f38a61048..a9b7dc8c89 100644 --- a/src/Avalonia.Interactivity/RoutedEvent.cs +++ b/src/Avalonia.Interactivity/RoutedEvent.cs @@ -120,7 +120,7 @@ namespace Avalonia.Interactivity bool handledEventsToo = false) where TTarget : class, IInteractive { - void Adapter(object sender, RoutedEventArgs e) + void Adapter(object? sender, RoutedEventArgs e) { if (sender is TTarget target && e is TEventArgs args) { @@ -136,7 +136,7 @@ namespace Avalonia.Interactivity RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, bool handledEventsToo = false) where TTarget : class, IInteractive { - void Adapter(object sender, RoutedEventArgs e) + void Adapter(object? sender, RoutedEventArgs e) { if (sender is TTarget target && e is TEventArgs args) { diff --git a/src/Avalonia.Layout/AttachedLayout.cs b/src/Avalonia.Layout/AttachedLayout.cs index 047c01343f..6c884641f8 100644 --- a/src/Avalonia.Layout/AttachedLayout.cs +++ b/src/Avalonia.Layout/AttachedLayout.cs @@ -12,17 +12,17 @@ namespace Avalonia.Layout /// public abstract class AttachedLayout : AvaloniaObject { - public string LayoutId { get; set; } + public string? LayoutId { get; set; } /// /// Occurs when the measurement state (layout) has been invalidated. /// - public event EventHandler MeasureInvalidated; + public event EventHandler? MeasureInvalidated; /// /// Occurs when the arrange state (layout) has been invalidated. /// - public event EventHandler ArrangeInvalidated; + public event EventHandler? ArrangeInvalidated; /// /// Initializes any per-container state the layout requires when it is attached to an diff --git a/src/Avalonia.Layout/Avalonia.Layout.csproj b/src/Avalonia.Layout/Avalonia.Layout.csproj index 076ec56cd6..f2c4b0540b 100644 --- a/src/Avalonia.Layout/Avalonia.Layout.csproj +++ b/src/Avalonia.Layout/Avalonia.Layout.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 @@ -9,4 +9,5 @@ + diff --git a/src/Avalonia.Layout/ElementManager.cs b/src/Avalonia.Layout/ElementManager.cs index 681d23a61f..9a033ca447 100644 --- a/src/Avalonia.Layout/ElementManager.cs +++ b/src/Avalonia.Layout/ElementManager.cs @@ -13,10 +13,10 @@ namespace Avalonia.Layout { internal class ElementManager { - private readonly List _realizedElements = new List(); + private readonly List _realizedElements = new List(); private readonly List _realizedElementLayoutBounds = new List(); private int _firstRealizedDataIndex; - private VirtualizingLayoutContext _context; + private VirtualizingLayoutContext? _context; private bool IsVirtualizingContext { @@ -58,7 +58,7 @@ namespace Avalonia.Layout // Make sure there is enough space for the bounds. // Note: We could optimize when the count becomes smaller, but keeping // it always up to date is the simplest option for now. - _realizedElementLayoutBounds.Resize(count); + _realizedElementLayoutBounds.Resize(count, default); } } } @@ -66,34 +66,32 @@ namespace Avalonia.Layout public int GetRealizedElementCount() { - return IsVirtualizingContext ? _realizedElements.Count : _context.ItemCount; + return IsVirtualizingContext ? _realizedElements.Count : _context!.ItemCount; } public ILayoutable GetAt(int realizedIndex) { - ILayoutable element; + ILayoutable? element; if (IsVirtualizingContext) { - if (_realizedElements[realizedIndex] == null) + element = _realizedElements[realizedIndex]; + + if (element == null) { // Sentinel. Create the element now since we need it. int dataIndex = GetDataIndexFromRealizedRangeIndex(realizedIndex); Logger.TryGet(LogEventLevel.Verbose, "Repeater")?.Log(this, "Creating element for sentinal with data index {Index}", dataIndex); - element = _context.GetOrCreateElementAt( + element = _context!.GetOrCreateElementAt( dataIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); _realizedElements[realizedIndex] = element; } - else - { - element = _realizedElements[realizedIndex]; - } } else { // realizedIndex and dataIndex are the same (everything is realized) - element = _context.GetOrCreateElementAt( + element = _context!.GetOrCreateElementAt( realizedIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); } @@ -112,7 +110,7 @@ namespace Avalonia.Layout _realizedElementLayoutBounds.Add(default); } - public void Insert(int realizedIndex, int dataIndex, ILayoutable element) + public void Insert(int realizedIndex, int dataIndex, ILayoutable? element) { if (realizedIndex == 0) { @@ -136,7 +134,7 @@ namespace Avalonia.Layout if (elementRef != null) { - _context.RecycleElement(elementRef); + _context!.RecycleElement(elementRef); } } @@ -203,26 +201,26 @@ namespace Avalonia.Layout else { // Non virtualized - everything is realized - return index >= 0 && index < _context.ItemCount; + return index >= 0 && index < _context!.ItemCount; } } - public bool IsIndexValidInData(int currentIndex) => (uint)currentIndex < _context.ItemCount; + public bool IsIndexValidInData(int currentIndex) => (uint)currentIndex < _context!.ItemCount; - public ILayoutable GetRealizedElement(int dataIndex) + public ILayoutable? GetRealizedElement(int dataIndex) { return IsVirtualizingContext ? GetAt(GetRealizedRangeIndexFromDataIndex(dataIndex)) : - _context.GetOrCreateElementAt( + _context!.GetOrCreateElementAt( dataIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); } - public void EnsureElementRealized(bool forward, int dataIndex, string layoutId) + public void EnsureElementRealized(bool forward, int dataIndex, string? layoutId) { if (IsDataIndexRealized(dataIndex) == false) { - var element = _context.GetOrCreateElementAt( + var element = _context!.GetOrCreateElementAt( dataIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); @@ -273,14 +271,14 @@ namespace Avalonia.Layout { case NotifyCollectionChangedAction.Add: { - OnItemsAdded(args.NewStartingIndex, args.NewItems.Count); + OnItemsAdded(args.NewStartingIndex, args.NewItems!.Count); } break; case NotifyCollectionChangedAction.Replace: { - int oldSize = args.OldItems.Count; - int newSize = args.NewItems.Count; + int oldSize = args.OldItems!.Count; + int newSize = args.NewItems!.Count; int oldStartIndex = args.OldStartingIndex; int newStartIndex = args.NewStartingIndex; @@ -301,7 +299,7 @@ namespace Avalonia.Layout if (elementRef != null) { - _context.RecycleElement(elementRef); + _context!.RecycleElement(elementRef); _realizedElements[realizedIndex] = null; } } diff --git a/src/Avalonia.Layout/FlowLayoutAlgorithm.cs b/src/Avalonia.Layout/FlowLayoutAlgorithm.cs index 63343fd1a7..40b392225f 100644 --- a/src/Avalonia.Layout/FlowLayoutAlgorithm.cs +++ b/src/Avalonia.Layout/FlowLayoutAlgorithm.cs @@ -16,8 +16,8 @@ namespace Avalonia.Layout private Size _lastAvailableSize; private double _lastItemSpacing; private bool _collectionChangePending; - private VirtualizingLayoutContext _context; - private IFlowLayoutAlgorithmDelegates _algorithmCallbacks; + private VirtualizingLayoutContext? _context; + private IFlowLayoutAlgorithmDelegates? _algorithmCallbacks; private Rect _lastExtent; private int _firstRealizedDataIndexInsideRealizationWindow = -1; private int _lastRealizedDataIndexInsideRealizationWindow = -1; @@ -46,7 +46,7 @@ namespace Avalonia.Layout } } - private Rect RealizationRect => IsVirtualizingContext ? _context.RealizationRect : new Rect(Size.Infinity); + private Rect RealizationRect => IsVirtualizingContext ? _context!.RealizationRect : new Rect(Size.Infinity); public void InitializeForContext(VirtualizingLayoutContext context, IFlowLayoutAlgorithmDelegates callbacks) { @@ -76,7 +76,7 @@ namespace Avalonia.Layout int maxItemsPerLine, ScrollOrientation orientation, bool disableVirtualization, - string layoutId) + string? layoutId) { _orientation.ScrollOrientation = orientation; @@ -87,7 +87,7 @@ namespace Avalonia.Layout layoutId, realizationRect); - var suggestedAnchorIndex = _context.RecommendedAnchorIndex; + var suggestedAnchorIndex = _context!.RecommendedAnchorIndex; if (_elementManager.IsIndexValidInData(suggestedAnchorIndex)) { var anchorRealized = _elementManager.IsDataIndexRealized(suggestedAnchorIndex); @@ -124,7 +124,7 @@ namespace Avalonia.Layout VirtualizingLayoutContext context, bool isWrapping, LineAlignment lineAlignment, - string layoutId) + string? layoutId) { Logger.TryGet(LogEventLevel.Verbose, "Repeater")?.Log(this, "{LayoutId}: ArrangeLayout", layoutId); ArrangeVirtualizingLayout(finalSize, lineAlignment, isWrapping, layoutId); @@ -149,7 +149,7 @@ namespace Avalonia.Layout Size availableSize, VirtualizingLayoutContext context) { - var measureSize = _algorithmCallbacks.Algorithm_GetMeasureSize(index, availableSize, context); + var measureSize = _algorithmCallbacks!.Algorithm_GetMeasureSize(index, availableSize, context); element.Measure(measureSize); var provisionalArrangeSize = _algorithmCallbacks.Algorithm_GetProvisionalArrangeSize(index, measureSize, element.DesiredSize, context); _algorithmCallbacks.Algorithm_OnElementMeasured(element, index, availableSize, measureSize, element.DesiredSize, provisionalArrangeSize, context); @@ -161,7 +161,7 @@ namespace Avalonia.Layout Size availableSize, bool isWrapping, double minItemSpacing, - string layoutId) + string? layoutId) { int anchorIndex = -1; var anchorPosition= new Point(); @@ -170,7 +170,7 @@ namespace Avalonia.Layout if (!IsVirtualizingContext) { // Non virtualizing host, start generating from the element 0 - anchorIndex = context.ItemCount > 0 ? 0 : -1; + anchorIndex = context!.ItemCount > 0 ? 0 : -1; } else { @@ -183,7 +183,7 @@ namespace Avalonia.Layout _lastItemSpacing != minItemSpacing || _collectionChangePending); - var suggestedAnchorIndex = _context.RecommendedAnchorIndex; + var suggestedAnchorIndex = _context!.RecommendedAnchorIndex; var isAnchorSuggestionValid = suggestedAnchorIndex >= 0 && _elementManager.IsDataIndexRealized(suggestedAnchorIndex); @@ -191,10 +191,10 @@ namespace Avalonia.Layout if (isAnchorSuggestionValid) { Logger.TryGet(LogEventLevel.Verbose, "Repeater")?.Log(this, "{LayoutId}: Using suggested anchor {Anchor}", layoutId, suggestedAnchorIndex); - anchorIndex = _algorithmCallbacks.Algorithm_GetAnchorForTargetElement( + anchorIndex = _algorithmCallbacks!.Algorithm_GetAnchorForTargetElement( suggestedAnchorIndex, availableSize, - context).Index; + context!).Index; if (_elementManager.IsDataIndexRealized(anchorIndex)) { @@ -235,7 +235,7 @@ namespace Avalonia.Layout // The anchor is based on the realization window because a connected ItemsRepeater might intersect the realization window // but not the visible window. In that situation, we still need to produce a valid anchor. - var anchorInfo = _algorithmCallbacks.Algorithm_GetAnchorForRealizationRect(availableSize, context); + var anchorInfo = _algorithmCallbacks!.Algorithm_GetAnchorForRealizationRect(availableSize, context!); anchorIndex = anchorInfo.Index; anchorPosition = _orientation.MinorMajorPoint(0, anchorInfo.Offset); } @@ -259,12 +259,12 @@ namespace Avalonia.Layout Logger.TryGet(LogEventLevel.Verbose, "Repeater")?.Log(this, "{LayoutId} Disconnected Window - throwing away all realized elements", layoutId); _elementManager.ClearRealizedRange(); - var anchor = _context.GetOrCreateElementAt(anchorIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); + var anchor = _context!.GetOrCreateElementAt(anchorIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); _elementManager.Add(anchor, anchorIndex); } var anchorElement = _elementManager.GetRealizedElement(anchorIndex); - var desiredSize = MeasureElement(anchorElement, anchorIndex, availableSize, _context); + var desiredSize = MeasureElement(anchorElement!, anchorIndex, availableSize, _context!); var layoutBounds = new Rect(anchorPosition.X, anchorPosition.Y, desiredSize.Width, desiredSize.Height); _elementManager.SetLayoutBoundsForDataIndex(anchorIndex, layoutBounds); @@ -296,7 +296,7 @@ namespace Avalonia.Layout double lineSpacing, int maxItemsPerLine, bool disableVirtualization, - string layoutId) + string? layoutId) { if (anchorIndex != -1) { @@ -322,7 +322,7 @@ namespace Avalonia.Layout // Ensure layout element. _elementManager.EnsureElementRealized(direction == GenerateDirection.Forward, currentIndex, layoutId); var currentElement = _elementManager.GetRealizedElement(currentIndex); - var desiredSize = MeasureElement(currentElement, currentIndex, availableSize, _context); + var desiredSize = MeasureElement(currentElement!, currentIndex, availableSize, _context!); ++count; // Lay it out. @@ -333,7 +333,7 @@ namespace Avalonia.Layout if (direction == GenerateDirection.Forward) { double remainingSpace = _orientation.Minor(availableSize) - (_orientation.MinorStart(previousElementBounds) + _orientation.MinorSize(previousElementBounds) + minItemSpacing + _orientation.Minor(desiredSize)); - if (countInLine >= maxItemsPerLine || _algorithmCallbacks.Algorithm_ShouldBreakLine(currentIndex, remainingSpace)) + if (countInLine >= maxItemsPerLine || _algorithmCallbacks!.Algorithm_ShouldBreakLine(currentIndex, remainingSpace)) { // No more space in this row. wrap to next row. _orientation.SetMinorStart(ref currentBounds, 0); @@ -371,7 +371,7 @@ namespace Avalonia.Layout { // Backward double remainingSpace = _orientation.MinorStart(previousElementBounds) - (_orientation.Minor(desiredSize) + minItemSpacing); - if (countInLine >= maxItemsPerLine || _algorithmCallbacks.Algorithm_ShouldBreakLine(currentIndex, remainingSpace)) + if (countInLine >= maxItemsPerLine || _algorithmCallbacks!.Algorithm_ShouldBreakLine(currentIndex, remainingSpace)) { // Does not fit, wrap to the previous row var availableSizeMinor = _orientation.Minor(availableSize); @@ -432,13 +432,13 @@ namespace Avalonia.Layout // account for that element in the indices inside the realization window. if (direction == GenerateDirection.Forward) { - int dataCount = _context.ItemCount; + int dataCount = _context!.ItemCount; _lastRealizedDataIndexInsideRealizationWindow = previousIndex == dataCount - 1 ? dataCount - 1 : previousIndex - 1; _lastRealizedDataIndexInsideRealizationWindow = Math.Max(0, _lastRealizedDataIndexInsideRealizationWindow); } else { - int dataCount = _context.ItemCount; + int dataCount = _context!.ItemCount; _firstRealizedDataIndexInsideRealizationWindow = previousIndex == 0 ? 0 : previousIndex + 1; _firstRealizedDataIndexInsideRealizationWindow = Math.Min(dataCount - 1, _firstRealizedDataIndexInsideRealizationWindow); } @@ -454,7 +454,7 @@ namespace Avalonia.Layout { _elementManager.ClearRealizedRange(); // FlowLayout requires that the anchor is the first element in the row. - var internalAnchor = _algorithmCallbacks.Algorithm_GetAnchorForTargetElement(index, availableSize, context); + var internalAnchor = _algorithmCallbacks!.Algorithm_GetAnchorForTargetElement(index, availableSize, context); // No need to set the position of the anchor. // (0,0) is fine for now since the extent can @@ -487,7 +487,7 @@ namespace Avalonia.Layout } else { - var realizationRect = _context.RealizationRect; + var realizationRect = _context!.RealizationRect; var elementBounds = _elementManager.GetLayoutBoundsForDataIndex(index); var elementMajorStart = _orientation.MajorStart(elementBounds); @@ -510,11 +510,11 @@ namespace Avalonia.Layout return shouldContinue; } - private Rect EstimateExtent(Size availableSize, string layoutId) + private Rect EstimateExtent(Size availableSize, string? layoutId) { - ILayoutable firstRealizedElement = null; + ILayoutable? firstRealizedElement = null; Rect firstBounds = new Rect(); - ILayoutable lastRealizedElement = null; + ILayoutable? lastRealizedElement = null; Rect lastBounds = new Rect(); int firstDataIndex = -1; int lastDataIndex = -1; @@ -531,9 +531,9 @@ namespace Avalonia.Layout lastBounds = _elementManager.GetLayoutBoundsForRealizedIndex(last); } - Rect extent = _algorithmCallbacks.Algorithm_GetExtent( + Rect extent = _algorithmCallbacks!.Algorithm_GetExtent( availableSize, - _context, + _context!, firstRealizedElement, firstDataIndex, firstBounds, @@ -563,7 +563,7 @@ namespace Avalonia.Layout if (_orientation.MajorStart(currentBounds) != currentLineOffset) { // Staring a new line - _algorithmCallbacks.Algorithm_OnLineArranged(currentDataIndex - countInLine, countInLine, currentLineSize, _context); + _algorithmCallbacks!.Algorithm_OnLineArranged(currentDataIndex - countInLine, countInLine, currentLineSize, _context!); countInLine = 0; currentLineOffset = _orientation.MajorStart(currentBounds); currentLineSize = 0; @@ -575,7 +575,7 @@ namespace Avalonia.Layout } // Raise for the last line. - _algorithmCallbacks.Algorithm_OnLineArranged(_lastRealizedDataIndexInsideRealizationWindow - countInLine + 1, countInLine, currentLineSize, _context); + _algorithmCallbacks!.Algorithm_OnLineArranged(_lastRealizedDataIndexInsideRealizationWindow - countInLine + 1, countInLine, currentLineSize, _context!); } } } @@ -584,7 +584,7 @@ namespace Avalonia.Layout Size finalSize, LineAlignment lineAlignment, bool isWrapping, - string layoutId) + string? layoutId) { // Walk through the realized elements one line at a time and // align them, Then call element.Arrange with the arranged bounds. @@ -636,7 +636,7 @@ namespace Avalonia.Layout LineAlignment lineAlignment, bool isWrapping, Size finalSize, - string layoutId) + string? layoutId) { for (int rangeIndex = lineStartIndex; rangeIndex < lineStartIndex + countInLine; ++rangeIndex) { @@ -723,11 +723,11 @@ namespace Avalonia.Layout { if (IsVirtualizingContext) { - _context.LayoutOrigin = new Point(_lastExtent.X, _lastExtent.Y); + _context!.LayoutOrigin = new Point(_lastExtent.X, _lastExtent.Y); } } - public ILayoutable GetElementIfRealized(int dataIndex) + public ILayoutable? GetElementIfRealized(int dataIndex) { if (_elementManager.IsDataIndexRealized(dataIndex)) { diff --git a/src/Avalonia.Layout/IFlowLayoutAlgorithmDelegates.cs b/src/Avalonia.Layout/IFlowLayoutAlgorithmDelegates.cs index 907a3adf0f..e3eae0caf7 100644 --- a/src/Avalonia.Layout/IFlowLayoutAlgorithmDelegates.cs +++ b/src/Avalonia.Layout/IFlowLayoutAlgorithmDelegates.cs @@ -21,10 +21,10 @@ namespace Avalonia.Layout Rect Algorithm_GetExtent( Size availableSize, VirtualizingLayoutContext context, - ILayoutable firstRealized, + ILayoutable? firstRealized, int firstRealizedItemIndex, Rect firstRealizedLayoutBounds, - ILayoutable lastRealized, + ILayoutable? lastRealized, int lastRealizedItemIndex, Rect lastRealizedLayoutBounds); void Algorithm_OnElementMeasured( diff --git a/src/Avalonia.Layout/LayoutContext.cs b/src/Avalonia.Layout/LayoutContext.cs index dadce58c0c..90bfc0200c 100644 --- a/src/Avalonia.Layout/LayoutContext.cs +++ b/src/Avalonia.Layout/LayoutContext.cs @@ -14,7 +14,7 @@ namespace Avalonia.Layout /// /// Gets or sets an object that represents the state of a layout. /// - public object LayoutState + public object? LayoutState { get => LayoutStateCore; set => LayoutStateCore = value; @@ -23,6 +23,6 @@ namespace Avalonia.Layout /// /// Implements the behavior of in a derived or custom LayoutContext. /// - protected virtual object LayoutStateCore { get; set; } + protected virtual object? LayoutStateCore { get; set; } } } diff --git a/src/Avalonia.Layout/LayoutContextAdapter.cs b/src/Avalonia.Layout/LayoutContextAdapter.cs index 695866df94..25132c2802 100644 --- a/src/Avalonia.Layout/LayoutContextAdapter.cs +++ b/src/Avalonia.Layout/LayoutContextAdapter.cs @@ -16,7 +16,7 @@ namespace Avalonia.Layout _nonVirtualizingContext = nonVirtualizingContext; } - protected override object LayoutStateCore + protected override object? LayoutStateCore { get => _nonVirtualizingContext.LayoutState; set => _nonVirtualizingContext.LayoutState = value; diff --git a/src/Avalonia.Layout/LayoutHelper.cs b/src/Avalonia.Layout/LayoutHelper.cs index 2fe59b49ca..71a2fa085b 100644 --- a/src/Avalonia.Layout/LayoutHelper.cs +++ b/src/Avalonia.Layout/LayoutHelper.cs @@ -101,7 +101,7 @@ namespace Avalonia.Layout if (result == 0 || double.IsNaN(result) || double.IsInfinity(result)) { - throw new Exception($"Invalid LayoutScaling returned from {visualRoot.GetType()}"); + throw new Exception($"Invalid LayoutScaling returned from {visualRoot!.GetType()}"); } return result; diff --git a/src/Avalonia.Layout/LayoutQueue.cs b/src/Avalonia.Layout/LayoutQueue.cs index 1a9eb6b785..24adeb0793 100644 --- a/src/Avalonia.Layout/LayoutQueue.cs +++ b/src/Avalonia.Layout/LayoutQueue.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace Avalonia.Layout { internal class LayoutQueue : IReadOnlyCollection, IDisposable + where T : notnull { private struct Info { diff --git a/src/Avalonia.Layout/Layoutable.cs b/src/Avalonia.Layout/Layoutable.cs index 7568ea8e09..09e0c4263a 100644 --- a/src/Avalonia.Layout/Layoutable.cs +++ b/src/Avalonia.Layout/Layoutable.cs @@ -794,7 +794,7 @@ namespace Avalonia.Layout /// /// The sender. /// The event args. - private void LayoutManagedLayoutUpdated(object sender, EventArgs e) => _layoutUpdated?.Invoke(this, e); + private void LayoutManagedLayoutUpdated(object? sender, EventArgs e) => _layoutUpdated?.Invoke(this, e); /// /// Tests whether any of a 's properties include negative values, diff --git a/src/Avalonia.Layout/NonVirtualizingLayoutContext.cs b/src/Avalonia.Layout/NonVirtualizingLayoutContext.cs index cef551f32e..91348f5e6d 100644 --- a/src/Avalonia.Layout/NonVirtualizingLayoutContext.cs +++ b/src/Avalonia.Layout/NonVirtualizingLayoutContext.cs @@ -12,7 +12,7 @@ namespace Avalonia.Layout /// public abstract class NonVirtualizingLayoutContext : LayoutContext { - private VirtualizingLayoutContext _contextAdapter; + private VirtualizingLayoutContext? _contextAdapter; /// /// Gets the collection of child controls from the container that provides the context. @@ -26,6 +26,6 @@ namespace Avalonia.Layout protected abstract IReadOnlyList ChildrenCore { get; } internal VirtualizingLayoutContext GetVirtualizingContextAdapter() => - _contextAdapter ?? (_contextAdapter = new LayoutContextAdapter(this)); + _contextAdapter ??= new LayoutContextAdapter(this); } } diff --git a/src/Avalonia.Layout/StackLayout.cs b/src/Avalonia.Layout/StackLayout.cs index 4a93c8344f..32e9c4dc8e 100644 --- a/src/Avalonia.Layout/StackLayout.cs +++ b/src/Avalonia.Layout/StackLayout.cs @@ -78,10 +78,10 @@ namespace Avalonia.Layout internal Rect GetExtent( Size availableSize, VirtualizingLayoutContext context, - ILayoutable firstRealized, + ILayoutable? firstRealized, int firstRealizedItemIndex, Rect firstRealizedLayoutBounds, - ILayoutable lastRealized, + ILayoutable? lastRealized, int lastRealizedItemIndex, Rect lastRealizedLayoutBounds) { @@ -89,7 +89,7 @@ namespace Avalonia.Layout // Constants int itemsCount = context.ItemCount; - var stackState = (StackLayoutState)context.LayoutState; + var stackState = (StackLayoutState)context.LayoutState!; double averageElementSize = GetAverageElementSize(availableSize, context, stackState) + Spacing; _orientation.SetMinorSize(ref extent, stackState.MaxArrangeBounds); @@ -131,7 +131,7 @@ namespace Avalonia.Layout { if (context is VirtualizingLayoutContext virtualContext) { - var stackState = (StackLayoutState)virtualContext.LayoutState; + var stackState = (StackLayoutState)virtualContext.LayoutState!; var provisionalArrangeSizeWinRt = provisionalArrangeSize; stackState.OnElementMeasured( index, @@ -177,7 +177,7 @@ namespace Avalonia.Layout if (targetIndex >= 0 && targetIndex < itemsCount) { index = targetIndex; - var state = (StackLayoutState)context.LayoutState; + var state = (StackLayoutState)context.LayoutState!; double averageElementSize = GetAverageElementSize(availableSize, context, state) + Spacing; offset = index * averageElementSize + _orientation.MajorStart(state.FlowAlgorithm.LastExtent); } @@ -188,10 +188,10 @@ namespace Avalonia.Layout Rect IFlowLayoutAlgorithmDelegates.Algorithm_GetExtent( Size availableSize, VirtualizingLayoutContext context, - ILayoutable firstRealized, + ILayoutable? firstRealized, int firstRealizedItemIndex, Rect firstRealizedLayoutBounds, - ILayoutable lastRealized, + ILayoutable? lastRealized, int lastRealizedItemIndex, Rect lastRealizedLayoutBounds) { @@ -234,7 +234,7 @@ namespace Avalonia.Layout if (itemsCount > 0) { var realizationRect = context.RealizationRect; - var state = (StackLayoutState)context.LayoutState; + var state = (StackLayoutState)context.LayoutState!; var lastExtent = state.FlowAlgorithm.LastExtent; double averageElementSize = GetAverageElementSize(availableSize, context, state) + Spacing; @@ -279,13 +279,13 @@ namespace Avalonia.Layout protected internal override void UninitializeForContextCore(VirtualizingLayoutContext context) { - var stackState = (StackLayoutState)context.LayoutState; + var stackState = (StackLayoutState)context.LayoutState!; stackState.UninitializeForContext(context); } protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize) { - ((StackLayoutState)context.LayoutState).OnMeasureStart(); + ((StackLayoutState)context.LayoutState!).OnMeasureStart(); var desiredSize = GetFlowAlgorithm(context).Measure( availableSize, @@ -358,6 +358,6 @@ namespace Avalonia.Layout private void InvalidateLayout() => InvalidateMeasure(); - private FlowLayoutAlgorithm GetFlowAlgorithm(VirtualizingLayoutContext context) => ((StackLayoutState)context.LayoutState).FlowAlgorithm; + private FlowLayoutAlgorithm GetFlowAlgorithm(VirtualizingLayoutContext context) => ((StackLayoutState)context.LayoutState!).FlowAlgorithm; } } diff --git a/src/Avalonia.Layout/UniformGridLayout.cs b/src/Avalonia.Layout/UniformGridLayout.cs index 6b147590ab..508113834a 100644 --- a/src/Avalonia.Layout/UniformGridLayout.cs +++ b/src/Avalonia.Layout/UniformGridLayout.cs @@ -258,7 +258,7 @@ namespace Avalonia.Layout Size availableSize, VirtualizingLayoutContext context) { - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; return new Size(gridState.EffectiveItemWidth, gridState.EffectiveItemHeight); } @@ -268,7 +268,7 @@ namespace Avalonia.Layout Size desiredSize, VirtualizingLayoutContext context) { - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; return new Size(gridState.EffectiveItemWidth, gridState.EffectiveItemHeight); } @@ -285,7 +285,7 @@ namespace Avalonia.Layout var realizationRect = context.RealizationRect; if (itemsCount > 0 && _orientation.MajorSize(realizationRect) > 0) { - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; var lastExtent = gridState.FlowAlgorithm.LastExtent; var itemsPerLine = Math.Min( // note use of unsigned ints Math.Max(1u, (uint)(_orientation.Minor(availableSize) / GetMinorSizeWithSpacing(context))), @@ -324,7 +324,7 @@ namespace Avalonia.Layout Math.Max(1u, _maximumRowsOrColumns)); int indexOfFirstInLine = (targetIndex / itemsPerLine) * itemsPerLine; index = indexOfFirstInLine; - var state = context.LayoutState as UniformGridLayoutState; + var state = (UniformGridLayoutState)context.LayoutState!; offset = _orientation.MajorStart(GetLayoutRectForDataIndex(availableSize, indexOfFirstInLine, state.FlowAlgorithm.LastExtent, context)); } @@ -338,10 +338,10 @@ namespace Avalonia.Layout Rect IFlowLayoutAlgorithmDelegates.Algorithm_GetExtent( Size availableSize, VirtualizingLayoutContext context, - ILayoutable firstRealized, + ILayoutable? firstRealized, int firstRealizedItemIndex, Rect firstRealizedLayoutBounds, - ILayoutable lastRealized, + ILayoutable? lastRealized, int lastRealizedItemIndex, Rect lastRealizedLayoutBounds) { @@ -421,7 +421,7 @@ namespace Avalonia.Layout protected internal override void UninitializeForContextCore(VirtualizingLayoutContext context) { - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; gridState.UninitializeForContext(context); } @@ -429,7 +429,7 @@ namespace Avalonia.Layout { // Set the width and height on the grid state. If the user already set them then use the preset. // If not, we have to measure the first element and get back a size which we're going to be using for the rest of the items. - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; gridState.EnsureElementSize(availableSize, context, _minItemWidth, _minItemHeight, _itemsStretch, Orientation, MinRowSpacing, MinColumnSpacing, _maximumRowsOrColumns); var desiredSize = GetFlowAlgorithm(context).Measure( @@ -467,7 +467,7 @@ namespace Avalonia.Layout // Always invalidate layout to keep the view accurate. InvalidateLayout(); - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; gridState.ClearElementOnDataSourceChange(context, args); } @@ -517,7 +517,7 @@ namespace Avalonia.Layout private double GetMinorSizeWithSpacing(VirtualizingLayoutContext context) { var minItemSpacing = MinItemSpacing; - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; return _orientation.ScrollOrientation == ScrollOrientation.Vertical? gridState.EffectiveItemWidth + minItemSpacing : gridState.EffectiveItemHeight + minItemSpacing; @@ -526,7 +526,7 @@ namespace Avalonia.Layout private double GetMajorSizeWithSpacing(VirtualizingLayoutContext context) { var lineSpacing = LineSpacing; - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; return _orientation.ScrollOrientation == ScrollOrientation.Vertical ? gridState.EffectiveItemHeight + lineSpacing : gridState.EffectiveItemWidth + lineSpacing; @@ -544,7 +544,7 @@ namespace Avalonia.Layout int rowIndex = (int)(index / itemsPerLine); int indexInRow = index - (rowIndex * itemsPerLine); - var gridState = (UniformGridLayoutState)context.LayoutState; + var gridState = (UniformGridLayoutState)context.LayoutState!; Rect bounds = _orientation.MinorMajorRect( indexInRow * GetMinorSizeWithSpacing(context) + _orientation.MinorStart(lastExtent), rowIndex * GetMajorSizeWithSpacing(context) + _orientation.MajorStart(lastExtent), @@ -556,6 +556,6 @@ namespace Avalonia.Layout private void InvalidateLayout() => InvalidateMeasure(); - private FlowLayoutAlgorithm GetFlowAlgorithm(VirtualizingLayoutContext context) => ((UniformGridLayoutState)context.LayoutState).FlowAlgorithm; + private FlowLayoutAlgorithm GetFlowAlgorithm(VirtualizingLayoutContext context) => ((UniformGridLayoutState)context.LayoutState!).FlowAlgorithm; } } diff --git a/src/Avalonia.Layout/UniformGridLayoutState.cs b/src/Avalonia.Layout/UniformGridLayoutState.cs index 282bbab1a8..d6b5a30bfc 100644 --- a/src/Avalonia.Layout/UniformGridLayoutState.cs +++ b/src/Avalonia.Layout/UniformGridLayoutState.cs @@ -18,7 +18,7 @@ namespace Avalonia.Layout // If it does not, then we need to do context.GetElement(0) at which point we have requested an element and are on point to clear it. // If we are responsible for clearing element 0 we keep m_cachedFirstElement valid. // If we are not (because FlowLayoutAlgorithm is holding it for us) then we just null out this field and use the one from FlowLayoutAlgorithm. - private ILayoutable _cachedFirstElement; + private ILayoutable? _cachedFirstElement; internal FlowLayoutAlgorithm FlowAlgorithm { get; } = new FlowLayoutAlgorithm(); internal double EffectiveItemWidth { get; private set; } diff --git a/src/Avalonia.Layout/Utils/ListUtils.cs b/src/Avalonia.Layout/Utils/ListUtils.cs index eb2480acd3..9ca8bb0525 100644 --- a/src/Avalonia.Layout/Utils/ListUtils.cs +++ b/src/Avalonia.Layout/Utils/ListUtils.cs @@ -23,10 +23,5 @@ namespace Avalonia.Layout.Utils list.AddRange(Enumerable.Repeat(value, size - cur)); } } - - public static void Resize(this List list, int count) - { - Resize(list, count, default); - } } } diff --git a/src/Avalonia.Layout/VirtualLayoutContextAdapter.cs b/src/Avalonia.Layout/VirtualLayoutContextAdapter.cs index 80ccee2114..f068187523 100644 --- a/src/Avalonia.Layout/VirtualLayoutContextAdapter.cs +++ b/src/Avalonia.Layout/VirtualLayoutContextAdapter.cs @@ -6,14 +6,14 @@ namespace Avalonia.Layout public class VirtualLayoutContextAdapter : NonVirtualizingLayoutContext { private readonly VirtualizingLayoutContext _virtualizingContext; - private ChildrenCollection _children; + private ChildrenCollection? _children; public VirtualLayoutContextAdapter(VirtualizingLayoutContext virtualizingContext) { _virtualizingContext = virtualizingContext; } - protected override object LayoutStateCore + protected override object? LayoutStateCore { get => _virtualizingContext.LayoutState; set => _virtualizingContext.LayoutState = value; diff --git a/src/Avalonia.Layout/VirtualizingLayoutContext.cs b/src/Avalonia.Layout/VirtualizingLayoutContext.cs index 079b91a90f..f48c9b0ef2 100644 --- a/src/Avalonia.Layout/VirtualizingLayoutContext.cs +++ b/src/Avalonia.Layout/VirtualizingLayoutContext.cs @@ -43,7 +43,7 @@ namespace Avalonia.Layout /// public abstract class VirtualizingLayoutContext : LayoutContext { - private NonVirtualizingLayoutContext _contextAdapter; + private NonVirtualizingLayoutContext? _contextAdapter; /// /// Gets the number of items in the data. diff --git a/src/Avalonia.Layout/WrapLayout/UvMeasure.cs b/src/Avalonia.Layout/WrapLayout/UvMeasure.cs index e10e6bd0f8..91fa459acb 100644 --- a/src/Avalonia.Layout/WrapLayout/UvMeasure.cs +++ b/src/Avalonia.Layout/WrapLayout/UvMeasure.cs @@ -27,7 +27,7 @@ namespace Avalonia.Layout } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is UvMeasure measure) { diff --git a/src/Avalonia.Layout/WrapLayout/WrapItem.cs b/src/Avalonia.Layout/WrapLayout/WrapItem.cs index 2f0b39a2d1..e823ade6d4 100644 --- a/src/Avalonia.Layout/WrapLayout/WrapItem.cs +++ b/src/Avalonia.Layout/WrapLayout/WrapItem.cs @@ -20,6 +20,6 @@ namespace Avalonia.Layout public UvMeasure? Position { get; internal set; } - public ILayoutable Element { get; internal set; } + public ILayoutable? Element { get; internal set; } } } diff --git a/src/Avalonia.Layout/WrapLayout/WrapLayout.cs b/src/Avalonia.Layout/WrapLayout/WrapLayout.cs index ded2afc3dd..d12a83d1d7 100644 --- a/src/Avalonia.Layout/WrapLayout/WrapLayout.cs +++ b/src/Avalonia.Layout/WrapLayout/WrapLayout.cs @@ -88,7 +88,7 @@ namespace Avalonia.Layout /// protected internal override void OnItemsChangedCore(VirtualizingLayoutContext context, object source, NotifyCollectionChangedEventArgs args) { - var state = (WrapLayoutState)context.LayoutState; + var state = (WrapLayoutState)context.LayoutState!; switch (args.Action) { @@ -126,7 +126,7 @@ namespace Avalonia.Layout var realizationBounds = new UvBounds(Orientation, context.RealizationRect); var position = UvMeasure.Zero; - var state = (WrapLayoutState)context.LayoutState; + var state = (WrapLayoutState)context.LayoutState!; if (state.Orientation != Orientation) { state.SetOrientation(Orientation); @@ -261,7 +261,7 @@ namespace Avalonia.Layout var spacingMeasure = new UvMeasure(Orientation, HorizontalSpacing, VerticalSpacing); var realizationBounds = new UvBounds(Orientation, context.RealizationRect); - var state = (WrapLayoutState)context.LayoutState; + var state = (WrapLayoutState)context.LayoutState!; bool Arrange(WrapItem item, bool isLast = false) { if (item.Measure.HasValue == false) diff --git a/src/Avalonia.Layout/WrapLayout/WrapLayoutState.cs b/src/Avalonia.Layout/WrapLayout/WrapLayoutState.cs index 7955ea983c..720ab96830 100644 --- a/src/Avalonia.Layout/WrapLayout/WrapLayoutState.cs +++ b/src/Avalonia.Layout/WrapLayout/WrapLayoutState.cs @@ -62,8 +62,11 @@ namespace Avalonia.Layout internal void SetOrientation(Orientation orientation) { - foreach (var item in _items.Where(i => i.Measure.HasValue)) + foreach (var item in _items) { + if (!item.Measure.HasValue) + continue; + UvMeasure measure = item.Measure.Value; double v = measure.V; measure.V = measure.U; @@ -120,10 +123,10 @@ namespace Avalonia.Layout } lastPosition = item.Position; - maxV = Math.Max(maxV, item.Measure.Value.V); + maxV = Math.Max(maxV, item.Measure!.Value.V); } - double totalHeight = lastPosition.Value.V + maxV; + double totalHeight = lastPosition!.Value.V + maxV; if (calculateAverage) { return (totalHeight / itemCount) * _context.ItemCount; diff --git a/src/Avalonia.Native/Avalonia.Native.csproj b/src/Avalonia.Native/Avalonia.Native.csproj index 3913484431..c1143b7885 100644 --- a/src/Avalonia.Native/Avalonia.Native.csproj +++ b/src/Avalonia.Native/Avalonia.Native.csproj @@ -4,7 +4,7 @@ $([MSBuild]::IsOSPlatform(OSX)) $(PackAvaloniaNative) true - netstandard2.0 + net6.0;netstandard2.0 true diff --git a/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs b/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs index b9d8fd3711..bda1c91750 100644 --- a/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs +++ b/src/Avalonia.Native/AvaloniaNativeMenuExporter.cs @@ -142,6 +142,13 @@ namespace Avalonia.Native private void DoLayoutReset(bool forceUpdate = false) { + var macOpts = AvaloniaLocator.Current.GetService(); + + if (macOpts != null && macOpts.DisableNativeMenus) + { + return; + } + if (_resetQueued || forceUpdate) { _resetQueued = false; diff --git a/src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs b/src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs index eef765e7ec..10619d675b 100644 --- a/src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs +++ b/src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs @@ -73,5 +73,10 @@ namespace Avalonia /// You can prevent Avalonia from adding those items to the OSX Application Menu with this property. The default value is false. /// public bool DisableDefaultApplicationMenuItems { get; set; } + + /// + /// Gets or sets a value indicating whether the native macOS menu bar will be enabled for the application. + /// + public bool DisableNativeMenus { get; set; } } } diff --git a/src/Avalonia.OpenGL/Avalonia.OpenGL.csproj b/src/Avalonia.OpenGL/Avalonia.OpenGL.csproj index d761e60c07..2b32926008 100644 --- a/src/Avalonia.OpenGL/Avalonia.OpenGL.csproj +++ b/src/Avalonia.OpenGL/Avalonia.OpenGL.csproj @@ -1,7 +1,7 @@ - + - netstandard2.0 + net6.0;netstandard2.0 true diff --git a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj index 2792ae1c91..348f5f3a10 100644 --- a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj +++ b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj @@ -1,10 +1,8 @@  - netstandard2.0 + net6.0;netstandard2.0 Avalonia.ReactiveUI false - enable - nullable @@ -12,4 +10,5 @@ + diff --git a/src/Avalonia.ReactiveUI/RoutedViewHost.cs b/src/Avalonia.ReactiveUI/RoutedViewHost.cs index 63456bc13a..a475cf5eac 100644 --- a/src/Avalonia.ReactiveUI/RoutedViewHost.cs +++ b/src/Avalonia.ReactiveUI/RoutedViewHost.cs @@ -57,7 +57,13 @@ namespace Avalonia.ReactiveUI /// public static readonly StyledProperty RouterProperty = AvaloniaProperty.Register(nameof(Router)); - + + /// + /// for the property. + /// + public static readonly StyledProperty ViewContractProperty = + AvaloniaProperty.Register(nameof(ViewContract)); + /// /// Initializes a new instance of the class. /// @@ -70,15 +76,18 @@ namespace Avalonia.ReactiveUI .Where(router => router == null)! .Cast(); + var viewContract = this.WhenAnyValue(x => x.ViewContract); + this.WhenAnyValue(x => x.Router) .Where(router => router != null) .SelectMany(router => router!.CurrentViewModel) .Merge(routerRemoved) - .Subscribe(NavigateToViewModel) + .CombineLatest(viewContract) + .Subscribe(tuple => NavigateToViewModel(tuple.First, tuple.Second)) .DisposeWith(disposables); }); } - + /// /// Gets or sets the of the view model stack. /// @@ -87,17 +96,27 @@ namespace Avalonia.ReactiveUI get => GetValue(RouterProperty); set => SetValue(RouterProperty, value); } - + + /// + /// Gets or sets the view contract. + /// + public string? ViewContract + { + get => GetValue(ViewContractProperty); + set => SetValue(ViewContractProperty, value); + } + /// /// Gets or sets the ReactiveUI view locator used by this router. /// public IViewLocator? ViewLocator { get; set; } - + /// /// Invoked when ReactiveUI router navigates to a view model. /// /// ViewModel to which the user navigates. - private void NavigateToViewModel(object? viewModel) + /// The contract for view resolution. + private void NavigateToViewModel(object? viewModel, string? contract) { if (Router == null) { @@ -112,17 +131,33 @@ namespace Avalonia.ReactiveUI Content = DefaultContent; return; } - + var viewLocator = ViewLocator ?? global::ReactiveUI.ViewLocator.Current; - var viewInstance = viewLocator.ResolveView(viewModel); + var viewInstance = viewLocator.ResolveView(viewModel, contract); if (viewInstance == null) { - this.Log().Warn($"Couldn't find view for '{viewModel}'. Is it registered? Falling back to default content."); + if (contract == null) + { + this.Log().Warn($"Couldn't find view for '{viewModel}'. Is it registered? Falling back to default content."); + } + else + { + this.Log().Warn($"Couldn't find view with contract '{contract}' for '{viewModel}'. Is it registered? Falling back to default content."); + } + Content = DefaultContent; return; } - - this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel}."); + + if (contract == null) + { + this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel}."); + } + else + { + this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel} and contract '{contract}'."); + } + viewInstance.ViewModel = viewModel; if (viewInstance is IDataContextProvider provider) provider.DataContext = viewModel; diff --git a/src/Avalonia.ReactiveUI/ViewModelViewHost.cs b/src/Avalonia.ReactiveUI/ViewModelViewHost.cs index c88323d674..16dee00ebc 100644 --- a/src/Avalonia.ReactiveUI/ViewModelViewHost.cs +++ b/src/Avalonia.ReactiveUI/ViewModelViewHost.cs @@ -3,7 +3,7 @@ using System.Reactive.Disposables; using ReactiveUI; using Splat; -namespace Avalonia.ReactiveUI +namespace Avalonia.ReactiveUI { /// /// This content control will automatically load the View associated with @@ -18,6 +18,12 @@ namespace Avalonia.ReactiveUI public static readonly AvaloniaProperty ViewModelProperty = AvaloniaProperty.Register(nameof(ViewModel)); + /// + /// for the property. + /// + public static readonly StyledProperty ViewContractProperty = + AvaloniaProperty.Register(nameof(ViewContract)); + /// /// Initializes a new instance of the class. /// @@ -25,8 +31,8 @@ namespace Avalonia.ReactiveUI { this.WhenActivated(disposables => { - this.WhenAnyValue(x => x.ViewModel) - .Subscribe(NavigateToViewModel) + this.WhenAnyValue(x => x.ViewModel, x => x.ViewContract) + .Subscribe(tuple => NavigateToViewModel(tuple.Item1, tuple.Item2)) .DisposeWith(disposables); }); } @@ -39,7 +45,16 @@ namespace Avalonia.ReactiveUI get => GetValue(ViewModelProperty); set => SetValue(ViewModelProperty, value); } - + + /// + /// Gets or sets the view contract. + /// + public string? ViewContract + { + get => GetValue(ViewContractProperty); + set => SetValue(ViewContractProperty, value); + } + /// /// Gets or sets the view locator. /// @@ -49,7 +64,8 @@ namespace Avalonia.ReactiveUI /// Invoked when ReactiveUI router navigates to a view model. /// /// ViewModel to which the user navigates. - private void NavigateToViewModel(object? viewModel) + /// The contract for view resolution. + private void NavigateToViewModel(object? viewModel, string? contract) { if (viewModel == null) { @@ -57,17 +73,33 @@ namespace Avalonia.ReactiveUI Content = DefaultContent; return; } - + var viewLocator = ViewLocator ?? global::ReactiveUI.ViewLocator.Current; - var viewInstance = viewLocator.ResolveView(viewModel); + var viewInstance = viewLocator.ResolveView(viewModel, contract); if (viewInstance == null) { - this.Log().Warn($"Couldn't find view for '{viewModel}'. Is it registered? Falling back to default content."); + if (contract == null) + { + this.Log().Warn($"Couldn't find view for '{viewModel}'. Is it registered? Falling back to default content."); + } + else + { + this.Log().Warn($"Couldn't find view with contract '{contract}' for '{viewModel}'. Is it registered? Falling back to default content."); + } + Content = DefaultContent; return; } - - this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel}."); + + if (contract == null) + { + this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel}."); + } + else + { + this.Log().Info($"Ready to show {viewInstance} with autowired {viewModel} and contract '{contract}'."); + } + viewInstance.ViewModel = viewModel; if (viewInstance is IStyledElement styled) styled.DataContext = viewModel; diff --git a/src/Avalonia.Remote.Protocol/Avalonia.Remote.Protocol.csproj b/src/Avalonia.Remote.Protocol/Avalonia.Remote.Protocol.csproj index 6c241bbc75..5a8301a2e9 100644 --- a/src/Avalonia.Remote.Protocol/Avalonia.Remote.Protocol.csproj +++ b/src/Avalonia.Remote.Protocol/Avalonia.Remote.Protocol.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 AVALONIA_REMOTE_PROTOCOL;$(DefineConstants) true Key.snk diff --git a/src/Avalonia.Styling/Avalonia.Styling.csproj b/src/Avalonia.Styling/Avalonia.Styling.csproj index d9f0cef3da..139ba1bd2e 100644 --- a/src/Avalonia.Styling/Avalonia.Styling.csproj +++ b/src/Avalonia.Styling/Avalonia.Styling.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 Avalonia.Styling Avalonia @@ -9,4 +9,5 @@ + diff --git a/src/Avalonia.Styling/Controls/ChildNameScope.cs b/src/Avalonia.Styling/Controls/ChildNameScope.cs index e6707e71db..58114a57fd 100644 --- a/src/Avalonia.Styling/Controls/ChildNameScope.cs +++ b/src/Avalonia.Styling/Controls/ChildNameScope.cs @@ -15,20 +15,20 @@ namespace Avalonia.Controls public void Register(string name, object element) => _inner.Register(name, element); - public SynchronousCompletionAsyncResult FindAsync(string name) + public SynchronousCompletionAsyncResult FindAsync(string name) { var found = Find(name); if (found != null) - return new SynchronousCompletionAsyncResult(found); + return new SynchronousCompletionAsyncResult(found); // Not found and both current and parent scope are in completed state if(IsCompleted) - return new SynchronousCompletionAsyncResult(null); + return new SynchronousCompletionAsyncResult(null); return DoFindAsync(name); } - public SynchronousCompletionAsyncResult DoFindAsync(string name) + public SynchronousCompletionAsyncResult DoFindAsync(string name) { - var src = new SynchronousCompletionAsyncResultSource(); + var src = new SynchronousCompletionAsyncResultSource(); void ParentSearch() { @@ -56,7 +56,7 @@ namespace Avalonia.Controls return src.AsyncResult; } - public object Find(string name) + public object? Find(string name) { var found = _inner.Find(name); if (found != null) diff --git a/src/Avalonia.Styling/Controls/INameScope.cs b/src/Avalonia.Styling/Controls/INameScope.cs index 2d5295fe45..1ca7db2f37 100644 --- a/src/Avalonia.Styling/Controls/INameScope.cs +++ b/src/Avalonia.Styling/Controls/INameScope.cs @@ -22,14 +22,14 @@ namespace Avalonia.Controls /// /// The name. /// The element, or null if the name was not found. - SynchronousCompletionAsyncResult FindAsync(string name); + SynchronousCompletionAsyncResult FindAsync(string name); /// /// Finds a named element in the name scope, returns immediately, doesn't traverse the name scope stack /// /// The name. /// The element, or null if the name was not found. - object Find(string name); + object? Find(string name); /// /// Marks the name scope as completed, no further registrations will be allowed diff --git a/src/Avalonia.Styling/Controls/NameScope.cs b/src/Avalonia.Styling/Controls/NameScope.cs index 62a04eac8b..77f98f85c4 100644 --- a/src/Avalonia.Styling/Controls/NameScope.cs +++ b/src/Avalonia.Styling/Controls/NameScope.cs @@ -22,8 +22,8 @@ namespace Avalonia.Controls private readonly Dictionary _inner = new Dictionary(); - private readonly Dictionary> _pendingSearches = - new Dictionary>(); + private readonly Dictionary> _pendingSearches = + new Dictionary>(); /// /// Gets the value of the attached on a styled element. @@ -32,7 +32,7 @@ namespace Avalonia.Controls /// The value of the NameScope attached property. public static INameScope GetNameScope(StyledElement styled) { - Contract.Requires(styled != null); + _ = styled ?? throw new ArgumentNullException(nameof(styled)); return styled.GetValue(NameScopeProperty); } @@ -44,7 +44,7 @@ namespace Avalonia.Controls /// The value to set. public static void SetNameScope(StyledElement styled, INameScope value) { - Contract.Requires(styled != null); + _ = styled ?? throw new ArgumentNullException(nameof(styled)); styled.SetValue(NameScopeProperty, value); } @@ -54,12 +54,11 @@ namespace Avalonia.Controls { if (IsCompleted) throw new InvalidOperationException("NameScope is completed, no further registrations are allowed"); - Contract.Requires(name != null); - Contract.Requires(element != null); - object existing; + _ = name ?? throw new ArgumentNullException(nameof(name)); + _ = element ?? throw new ArgumentNullException(nameof(element)); - if (_inner.TryGetValue(name, out existing)) + if (_inner.TryGetValue(name, out var existing)) { if (existing != element) { @@ -77,27 +76,26 @@ namespace Avalonia.Controls } } - public SynchronousCompletionAsyncResult FindAsync(string name) + public SynchronousCompletionAsyncResult FindAsync(string name) { var found = Find(name); if (found != null) - return new SynchronousCompletionAsyncResult(found); + return new SynchronousCompletionAsyncResult(found); if (IsCompleted) - return new SynchronousCompletionAsyncResult((object)null); + return new SynchronousCompletionAsyncResult(null); if (!_pendingSearches.TryGetValue(name, out var tcs)) // We are intentionally running continuations synchronously here - _pendingSearches[name] = tcs = new SynchronousCompletionAsyncResultSource(); + _pendingSearches[name] = tcs = new SynchronousCompletionAsyncResultSource(); return tcs.AsyncResult; } /// - public object Find(string name) + public object? Find(string name) { - Contract.Requires(name != null); + _ = name ?? throw new ArgumentNullException(nameof(name)); - object result; - _inner.TryGetValue(name, out result); + _inner.TryGetValue(name, out var result); return result; } diff --git a/src/Avalonia.Styling/Controls/NameScopeExtensions.cs b/src/Avalonia.Styling/Controls/NameScopeExtensions.cs index 75630711b8..3895b6ceb9 100644 --- a/src/Avalonia.Styling/Controls/NameScopeExtensions.cs +++ b/src/Avalonia.Styling/Controls/NameScopeExtensions.cs @@ -17,11 +17,11 @@ namespace Avalonia.Controls /// The name scope. /// The name. /// The named element or null if not found. - public static T Find(this INameScope nameScope, string name) + public static T? Find(this INameScope nameScope, string name) where T : class { - Contract.Requires(nameScope != null); - Contract.Requires(name != null); + _ = nameScope ?? throw new ArgumentNullException(nameof(nameScope)); + _ = name ?? throw new ArgumentNullException(nameof(name)); var result = nameScope.Find(name); @@ -31,7 +31,7 @@ namespace Avalonia.Controls $"Expected control '{name}' to be '{typeof(T)} but it was '{result.GetType()}'."); } - return (T)result; + return (T?)result; } /// @@ -41,11 +41,11 @@ namespace Avalonia.Controls /// The control to take the name scope from. /// The name. /// The named element or null if not found. - public static T Find(this ILogical anchor, string name) + public static T? Find(this ILogical anchor, string name) where T : class { - Contract.Requires(anchor != null); - Contract.Requires(name != null); + _ = anchor ?? throw new ArgumentNullException(nameof(anchor)); + _ = name ?? throw new ArgumentNullException(nameof(name)); var styledAnchor = anchor as StyledElement; if (styledAnchor == null) return null; @@ -64,8 +64,8 @@ namespace Avalonia.Controls public static T Get(this INameScope nameScope, string name) where T : class { - Contract.Requires(nameScope != null); - Contract.Requires(name != null); + _ = nameScope ?? throw new ArgumentNullException(nameof(nameScope)); + _ = name ?? throw new ArgumentNullException(nameof(name)); var result = nameScope.Find(name); @@ -94,9 +94,9 @@ namespace Avalonia.Controls public static T Get(this ILogical anchor, string name) where T : class { - Contract.Requires(anchor != null); - Contract.Requires(name != null); - + _ = anchor ?? throw new ArgumentNullException(nameof(anchor)); + _ = name ?? throw new ArgumentNullException(nameof(name)); + var nameScope = (anchor as INameScope) ?? NameScope.GetNameScope((StyledElement)anchor); if (nameScope == null) throw new InvalidOperationException( @@ -105,9 +105,9 @@ namespace Avalonia.Controls return nameScope.Get(name); } - public static INameScope FindNameScope(this ILogical control) + public static INameScope? FindNameScope(this ILogical control) { - Contract.Requires(control != null); + _ = control ?? throw new ArgumentNullException(nameof(control)); var scope = control.GetSelfAndLogicalAncestors() .OfType() diff --git a/src/Avalonia.Styling/Controls/NameScopeLocator.cs b/src/Avalonia.Styling/Controls/NameScopeLocator.cs index 51f4c5c4eb..f0ce7f8a5b 100644 --- a/src/Avalonia.Styling/Controls/NameScopeLocator.cs +++ b/src/Avalonia.Styling/Controls/NameScopeLocator.cs @@ -11,9 +11,9 @@ namespace Avalonia.Controls /// /// The scope relative from which the object should be resolved. /// The name of the object to find. - public static IObservable Track(INameScope scope, string name) + public static IObservable Track(INameScope scope, string name) { - return new NeverEndingSynchronousCompletionAsyncResultObservable(scope.FindAsync(name)); + return new NeverEndingSynchronousCompletionAsyncResultObservable(scope.FindAsync(name)); } // This class is implemented in such weird way because for some reason @@ -22,7 +22,7 @@ namespace Avalonia.Controls private class NeverEndingSynchronousCompletionAsyncResultObservable : IObservable { - private T _value; + private T? _value; private SynchronousCompletionAsyncResult? _asyncResult; public NeverEndingSynchronousCompletionAsyncResultObservable(SynchronousCompletionAsyncResult task) @@ -47,7 +47,7 @@ namespace Avalonia.Controls observer.OnNext(_asyncResult.Value.GetResult()); }); else - observer.OnNext(_value); + observer.OnNext(_value!); return Disposable.Empty; } diff --git a/src/Avalonia.Styling/Controls/PseudoClassesExtensions.cs b/src/Avalonia.Styling/Controls/PseudoClassesExtensions.cs index 7b28d1a911..4cddc8c8fb 100644 --- a/src/Avalonia.Styling/Controls/PseudoClassesExtensions.cs +++ b/src/Avalonia.Styling/Controls/PseudoClassesExtensions.cs @@ -12,7 +12,7 @@ namespace Avalonia.Controls /// True to add the pseudoclass or false to remove. public static void Set(this IPseudoClasses classes, string name, bool value) { - Contract.Requires(classes != null); + _ = classes ?? throw new ArgumentNullException(nameof(classes)); if (value) { diff --git a/src/Avalonia.Styling/Controls/ResourceDictionary.cs b/src/Avalonia.Styling/Controls/ResourceDictionary.cs index e797f8cf8b..3af14daa83 100644 --- a/src/Avalonia.Styling/Controls/ResourceDictionary.cs +++ b/src/Avalonia.Styling/Controls/ResourceDictionary.cs @@ -177,7 +177,7 @@ namespace Avalonia.Controls } } - private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty); } diff --git a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs index be1069a4da..513b3f2424 100644 --- a/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs +++ b/src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs @@ -109,7 +109,7 @@ namespace Avalonia.Controls observer.OnNext(Convert(_target.FindResource(_key))); } - private void ResourcesChanged(object sender, ResourcesChangedEventArgs e) + private void ResourcesChanged(object? sender, ResourcesChangedEventArgs e) { PublishNext(Convert(_target.FindResource(_key))); } @@ -159,7 +159,7 @@ namespace Avalonia.Controls } } - private void OwnerChanged(object sender, EventArgs e) + private void OwnerChanged(object? sender, EventArgs e) { if (_owner is object) { @@ -176,7 +176,7 @@ namespace Avalonia.Controls PublishNext(); } - private void ResourcesChanged(object sender, ResourcesChangedEventArgs e) + private void ResourcesChanged(object? sender, ResourcesChangedEventArgs e) { PublishNext(); } diff --git a/src/Avalonia.Styling/INamed.cs b/src/Avalonia.Styling/INamed.cs index 1f8d269b07..df83f3b6ef 100644 --- a/src/Avalonia.Styling/INamed.cs +++ b/src/Avalonia.Styling/INamed.cs @@ -8,6 +8,6 @@ namespace Avalonia /// /// Gets the element name. /// - string Name { get; } + string? Name { get; } } } diff --git a/src/Avalonia.Styling/LogicalTree/ControlLocator.cs b/src/Avalonia.Styling/LogicalTree/ControlLocator.cs index 6d0302ace4..f60ed5aab8 100644 --- a/src/Avalonia.Styling/LogicalTree/ControlLocator.cs +++ b/src/Avalonia.Styling/LogicalTree/ControlLocator.cs @@ -9,19 +9,19 @@ namespace Avalonia.LogicalTree /// public static class ControlLocator { - public static IObservable Track(ILogical relativeTo, int ancestorLevel, Type ancestorType = null) + public static IObservable Track(ILogical relativeTo, int ancestorLevel, Type? ancestorType = null) { return new ControlTracker(relativeTo, ancestorLevel, ancestorType); } - private class ControlTracker : LightweightObservableBase + private class ControlTracker : LightweightObservableBase { private readonly ILogical _relativeTo; private readonly int _ancestorLevel; - private readonly Type _ancestorType; - private ILogical _value; + private readonly Type? _ancestorType; + private ILogical? _value; - public ControlTracker(ILogical relativeTo, int ancestorLevel, Type ancestorType) + public ControlTracker(ILogical relativeTo, int ancestorLevel, Type? ancestorType) { _relativeTo = relativeTo; _ancestorLevel = ancestorLevel; @@ -43,18 +43,18 @@ namespace Avalonia.LogicalTree _value = null; } - protected override void Subscribed(IObserver observer, bool first) + protected override void Subscribed(IObserver observer, bool first) { observer.OnNext(_value); } - private void Attached(object sender, LogicalTreeAttachmentEventArgs e) + private void Attached(object? sender, LogicalTreeAttachmentEventArgs e) { Update(); PublishNext(_value); } - private void Detached(object sender, LogicalTreeAttachmentEventArgs e) + private void Detached(object? sender, LogicalTreeAttachmentEventArgs e) { _value = null; PublishNext(null); diff --git a/src/Avalonia.Styling/LogicalTree/ILogical.cs b/src/Avalonia.Styling/LogicalTree/ILogical.cs index 9c4223618f..caff3d8150 100644 --- a/src/Avalonia.Styling/LogicalTree/ILogical.cs +++ b/src/Avalonia.Styling/LogicalTree/ILogical.cs @@ -12,12 +12,12 @@ namespace Avalonia.LogicalTree /// /// Raised when the control is attached to a rooted logical tree. /// - event EventHandler AttachedToLogicalTree; + event EventHandler? AttachedToLogicalTree; /// /// Raised when the control is detached from a rooted logical tree. /// - event EventHandler DetachedFromLogicalTree; + event EventHandler? DetachedFromLogicalTree; /// /// Gets a value indicating whether the element is attached to a rooted logical tree. @@ -27,7 +27,7 @@ namespace Avalonia.LogicalTree /// /// Gets the logical parent. /// - ILogical LogicalParent { get; } + ILogical? LogicalParent { get; } /// /// Gets the logical children. diff --git a/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs b/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs index 458ab0fce2..74720c0a77 100644 --- a/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs +++ b/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs @@ -15,14 +15,14 @@ namespace Avalonia.LogicalTree /// The logical's ancestors. public static IEnumerable GetLogicalAncestors(this ILogical logical) { - Contract.Requires(logical != null); + _ = logical ?? throw new ArgumentNullException(nameof(logical)); - logical = logical.LogicalParent; + ILogical? l = logical.LogicalParent; - while (logical != null) + while (l != null) { - yield return logical; - logical = logical.LogicalParent; + yield return l; + l = l.LogicalParent; } } @@ -48,14 +48,14 @@ namespace Avalonia.LogicalTree /// The logical. /// If given logical should be included in search. /// First ancestor of given type. - public static T FindLogicalAncestorOfType(this ILogical logical, bool includeSelf = false) where T : class + public static T? FindLogicalAncestorOfType(this ILogical logical, bool includeSelf = false) where T : class { if (logical is null) { return null; } - ILogical parent = includeSelf ? logical : logical.LogicalParent; + var parent = includeSelf ? logical : logical.LogicalParent; while (parent != null) { @@ -120,7 +120,7 @@ namespace Avalonia.LogicalTree /// The logical. /// If given logical should be included in search. /// First descendant of given type. - public static T FindLogicalDescendantOfType(this ILogical logical, bool includeSelf = false) where T : class + public static T? FindLogicalDescendantOfType(this ILogical logical, bool includeSelf = false) where T : class { if (logical is null) { @@ -140,7 +140,7 @@ namespace Avalonia.LogicalTree /// /// The logical. /// The parent, or null if the logical is unparented. - public static ILogical GetLogicalParent(this ILogical logical) + public static ILogical? GetLogicalParent(this ILogical logical) { return logical.LogicalParent; } @@ -153,7 +153,7 @@ namespace Avalonia.LogicalTree /// /// The parent, or null if the logical is unparented or its parent is not of type . /// - public static T GetLogicalParent(this ILogical logical) where T : class + public static T? GetLogicalParent(this ILogical logical) where T : class { return logical.LogicalParent as T; } @@ -165,7 +165,7 @@ namespace Avalonia.LogicalTree /// The logical siblings. public static IEnumerable GetLogicalSiblings(this ILogical logical) { - ILogical parent = logical.LogicalParent; + var parent = logical.LogicalParent; if (parent != null) { @@ -187,7 +187,7 @@ namespace Avalonia.LogicalTree /// public static bool IsLogicalAncestorOf(this ILogical logical, ILogical target) { - ILogical current = target?.LogicalParent; + var current = target?.LogicalParent; while (current != null) { @@ -202,7 +202,7 @@ namespace Avalonia.LogicalTree return false; } - private static T FindDescendantOfTypeCore(ILogical logical) where T : class + private static T? FindDescendantOfTypeCore(ILogical logical) where T : class { var logicalChildren = logical.LogicalChildren; var logicalChildrenCount = logicalChildren.Count; diff --git a/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs b/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs index 891724599c..826fc5b2a4 100644 --- a/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs +++ b/src/Avalonia.Styling/LogicalTree/LogicalTreeAttachmentEventArgs.cs @@ -19,11 +19,8 @@ namespace Avalonia.LogicalTree ILogical source, ILogical parent) { - Contract.Requires(root != null); - Contract.Requires(source != null); - - Root = root; - Source = source; + Root = root ?? throw new ArgumentNullException(nameof(root)); + Source = source ?? throw new ArgumentNullException(nameof(source)); Parent = parent; } diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 2292f5c518..5f498623e1 100644 --- a/src/Avalonia.Styling/StyledElement.cs +++ b/src/Avalonia.Styling/StyledElement.cs @@ -427,7 +427,7 @@ namespace Avalonia if (_logicalRoot != null) { - var e = new LogicalTreeAttachmentEventArgs(_logicalRoot, this, old); + var e = new LogicalTreeAttachmentEventArgs(_logicalRoot, this, old!); OnDetachedFromLogicalTreeCore(e); } @@ -435,7 +435,7 @@ namespace Avalonia if (newRoot is object) { - var e = new LogicalTreeAttachmentEventArgs(newRoot, this, parent); + var e = new LogicalTreeAttachmentEventArgs(newRoot, this, parent!); OnAttachedToLogicalTreeCore(e); } else if (parent is null) @@ -495,21 +495,21 @@ namespace Avalonia DetachStylesFromThisAndDescendents(allStyles); } - protected virtual void LogicalChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + protected virtual void LogicalChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: - SetLogicalParent(e.NewItems); + SetLogicalParent(e.NewItems!); break; case NotifyCollectionChangedAction.Remove: - ClearLogicalParent(e.OldItems); + ClearLogicalParent(e.OldItems!); break; case NotifyCollectionChangedAction.Replace: - ClearLogicalParent(e.OldItems); - SetLogicalParent(e.NewItems); + ClearLogicalParent(e.OldItems!); + SetLogicalParent(e.NewItems!); break; case NotifyCollectionChangedAction.Reset: @@ -729,7 +729,7 @@ namespace Avalonia for (var i = 0; i < count; i++) { - var logical = (ILogical) children[i]; + var logical = (ILogical) children[i]!; if (logical.LogicalParent is null) { @@ -744,7 +744,7 @@ namespace Avalonia for (var i = 0; i < count; i++) { - var logical = (ILogical) children[i]; + var logical = (ILogical) children[i]!; if (logical.LogicalParent == this) { diff --git a/src/Avalonia.Styling/Styling/Activators/NthChildActivator.cs b/src/Avalonia.Styling/Styling/Activators/NthChildActivator.cs index 803809a8ce..6f54cd5904 100644 --- a/src/Avalonia.Styling/Styling/Activators/NthChildActivator.cs +++ b/src/Avalonia.Styling/Styling/Activators/NthChildActivator.cs @@ -37,7 +37,7 @@ namespace Avalonia.Styling.Activators _provider.ChildIndexChanged -= ChildIndexChanged; } - private void ChildIndexChanged(object sender, ChildIndexChangedEventArgs e) + private void ChildIndexChanged(object? sender, ChildIndexChangedEventArgs e) { // Run matching again if: // 1. Selector is reversed, so other item insertion/deletion might affect total count without changing subscribed item index. diff --git a/src/Avalonia.Styling/Styling/Activators/StyleClassActivator.cs b/src/Avalonia.Styling/Styling/Activators/StyleClassActivator.cs index 7906a29cb5..98d3f16a0a 100644 --- a/src/Avalonia.Styling/Styling/Activators/StyleClassActivator.cs +++ b/src/Avalonia.Styling/Styling/Activators/StyleClassActivator.cs @@ -66,7 +66,7 @@ namespace Avalonia.Styling.Activators _classes.CollectionChanged -= ClassesChangedHandler; } - private void ClassesChanged(object sender, NotifyCollectionChangedEventArgs e) + private void ClassesChanged(object? sender, NotifyCollectionChangedEventArgs e) { if (e.Action != NotifyCollectionChangedAction.Move) { diff --git a/src/Avalonia.Styling/Styling/ChildSelector.cs b/src/Avalonia.Styling/Styling/ChildSelector.cs index 85e7aaabde..5c92182b80 100644 --- a/src/Avalonia.Styling/Styling/ChildSelector.cs +++ b/src/Avalonia.Styling/Styling/ChildSelector.cs @@ -6,7 +6,7 @@ namespace Avalonia.Styling internal class ChildSelector : Selector { private readonly Selector _parent; - private string _selectorString; + private string? _selectorString; public ChildSelector(Selector parent) { @@ -25,7 +25,7 @@ namespace Avalonia.Styling public override bool IsCombinator => true; /// - public override Type TargetType => null; + public override Type? TargetType => null; public override string ToString() { @@ -64,6 +64,6 @@ namespace Avalonia.Styling } } - protected override Selector MovePrevious() => null; + protected override Selector? MovePrevious() => null; } } diff --git a/src/Avalonia.Styling/Styling/OrSelector.cs b/src/Avalonia.Styling/Styling/OrSelector.cs index 8251915504..3d6db9b01e 100644 --- a/src/Avalonia.Styling/Styling/OrSelector.cs +++ b/src/Avalonia.Styling/Styling/OrSelector.cs @@ -120,7 +120,7 @@ namespace Avalonia.Styling } else { - while (!result.IsAssignableFrom(selector.TargetType)) + while (result is not null && !result.IsAssignableFrom(selector.TargetType)) { result = result.BaseType; } diff --git a/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs b/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs index a531267eea..1cd1a650ef 100644 --- a/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs +++ b/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs @@ -53,11 +53,16 @@ namespace Avalonia.Styling if (_property.IsAttached) { + builder.Append('('); builder.Append(_property.OwnerType.Name); builder.Append('.'); } builder.Append(_property.Name); + if (_property.IsAttached) + { + builder.Append(')'); + } builder.Append('='); builder.Append(_value ?? string.Empty); builder.Append(']'); @@ -104,7 +109,7 @@ namespace Avalonia.Styling var converter = TypeDescriptor.GetConverter(propertyType); if (converter?.CanConvertFrom(valueType) == true) { - return Equals(propertyValue, converter.ConvertFrom(null, CultureInfo.InvariantCulture, value)); + return Equals(propertyValue, converter.ConvertFrom(null, CultureInfo.InvariantCulture, value!)); } return false; diff --git a/src/Avalonia.Styling/Styling/Selectors.cs b/src/Avalonia.Styling/Styling/Selectors.cs index 64d0a0e96b..7c66469cf1 100644 --- a/src/Avalonia.Styling/Styling/Selectors.cs +++ b/src/Avalonia.Styling/Styling/Selectors.cs @@ -25,10 +25,14 @@ namespace Avalonia.Styling /// The previous selector. /// The name of the style class. /// The selector. - public static Selector Class(this Selector previous, string name) + public static Selector Class(this Selector? previous, string name) { - Contract.Requires(name != null); - Contract.Requires(!string.IsNullOrWhiteSpace(name)); + _ = name ?? throw new ArgumentNullException(nameof(name)); + + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentException("Name may not be empty", nameof(name)); + } var tac = previous as TypeNameAndClassSelector; @@ -48,7 +52,7 @@ namespace Avalonia.Styling /// /// The previous selector. /// The selector. - public static Selector Descendant(this Selector previous) + public static Selector Descendant(this Selector? previous) { return new DescendantSelector(previous); } @@ -59,9 +63,9 @@ namespace Avalonia.Styling /// The previous selector. /// The type. /// The selector. - public static Selector Is(this Selector previous, Type type) + public static Selector Is(this Selector? previous, Type type) { - Contract.Requires(type != null); + _ = type ?? throw new ArgumentNullException(nameof(type)); return TypeNameAndClassSelector.Is(previous, type); } @@ -72,7 +76,7 @@ namespace Avalonia.Styling /// The type. /// The previous selector. /// The selector. - public static Selector Is(this Selector previous) where T : IStyleable + public static Selector Is(this Selector? previous) where T : IStyleable { return previous.Is(typeof(T)); } @@ -83,10 +87,14 @@ namespace Avalonia.Styling /// The previous selector. /// The name. /// The selector. - public static Selector Name(this Selector previous, string name) + public static Selector Name(this Selector? previous, string name) { - Contract.Requires(name != null); - Contract.Requires(!string.IsNullOrWhiteSpace(name)); + _ = name ?? throw new ArgumentNullException(nameof(name)); + + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentException("Name may not be empty", nameof(name)); + } var tac = previous as TypeNameAndClassSelector; @@ -107,7 +115,7 @@ namespace Avalonia.Styling /// The previous selector. /// The selector to be not-ed. /// The selector. - public static Selector Not(this Selector previous, Func argument) + public static Selector Not(this Selector? previous, Func argument) { return new NotSelector(previous, argument(null)); } @@ -118,7 +126,7 @@ namespace Avalonia.Styling /// The previous selector. /// The selector to be not-ed. /// The selector. - public static Selector Not(this Selector previous, Selector argument) + public static Selector Not(this Selector? previous, Selector argument) { return new NotSelector(previous, argument); } @@ -126,7 +134,7 @@ namespace Avalonia.Styling /// /// /// The selector. - public static Selector NthChild(this Selector previous, int step, int offset) + public static Selector NthChild(this Selector? previous, int step, int offset) { return new NthChildSelector(previous, step, offset); } @@ -134,7 +142,7 @@ namespace Avalonia.Styling /// /// /// The selector. - public static Selector NthLastChild(this Selector previous, int step, int offset) + public static Selector NthLastChild(this Selector? previous, int step, int offset) { return new NthLastChildSelector(previous, step, offset); } @@ -145,9 +153,9 @@ namespace Avalonia.Styling /// The previous selector. /// The type. /// The selector. - public static Selector OfType(this Selector previous, Type type) + public static Selector OfType(this Selector? previous, Type type) { - Contract.Requires(type != null); + _ = type ?? throw new ArgumentNullException(nameof(type)); return TypeNameAndClassSelector.OfType(previous, type); } @@ -158,7 +166,7 @@ namespace Avalonia.Styling /// The type. /// The previous selector. /// The selector. - public static Selector OfType(this Selector previous) where T : IStyleable + public static Selector OfType(this Selector? previous) where T : IStyleable { return previous.OfType(typeof(T)); } @@ -191,9 +199,9 @@ namespace Avalonia.Styling /// The property. /// The property value. /// The selector. - public static Selector PropertyEquals(this Selector previous, AvaloniaProperty property, object value) + public static Selector PropertyEquals(this Selector? previous, AvaloniaProperty property, object? value) { - Contract.Requires(property != null); + _ = property ?? throw new ArgumentNullException(nameof(property)); return new PropertyEqualsSelector(previous, property, value); } @@ -205,9 +213,9 @@ namespace Avalonia.Styling /// The property. /// The property value. /// The selector. - public static Selector PropertyEquals(this Selector previous, AvaloniaProperty property, object value) + public static Selector PropertyEquals(this Selector? previous, AvaloniaProperty property, object? value) { - Contract.Requires(property != null); + _ = property ?? throw new ArgumentNullException(nameof(property)); return new PropertyEqualsSelector(previous, property, value); } diff --git a/src/Avalonia.Styling/Styling/Styles.cs b/src/Avalonia.Styling/Styling/Styles.cs index c752bdfeb8..81502f1570 100644 --- a/src/Avalonia.Styling/Styling/Styles.cs +++ b/src/Avalonia.Styling/Styling/Styles.cs @@ -262,7 +262,7 @@ namespace Avalonia.Styling } } - private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { static IReadOnlyList ToReadOnlyList(IList list) { @@ -282,7 +282,7 @@ namespace Avalonia.Styling { for (var i = 0; i < items.Count; ++i) { - var style = (IStyle)items[i]; + var style = (IStyle)items[i]!; if (Owner is object && style is IResourceProvider resourceProvider) { @@ -299,7 +299,7 @@ namespace Avalonia.Styling { for (var i = 0; i < items.Count; ++i) { - var style = (IStyle)items[i]; + var style = (IStyle)items[i]!; if (Owner is object && style is IResourceProvider resourceProvider) { @@ -315,14 +315,14 @@ namespace Avalonia.Styling switch (e.Action) { case NotifyCollectionChangedAction.Add: - Add(e.NewItems); + Add(e.NewItems!); break; case NotifyCollectionChangedAction.Remove: - Remove(e.OldItems); + Remove(e.OldItems!); break; case NotifyCollectionChangedAction.Replace: - Remove(e.OldItems); - Add(e.NewItems); + Remove(e.OldItems!); + Add(e.NewItems!); break; case NotifyCollectionChangedAction.Reset: throw new InvalidOperationException("Reset should not be called on Styles."); diff --git a/src/Avalonia.Styling/Styling/TemplateSelector.cs b/src/Avalonia.Styling/Styling/TemplateSelector.cs index 5ea8defeda..e8051efa6d 100644 --- a/src/Avalonia.Styling/Styling/TemplateSelector.cs +++ b/src/Avalonia.Styling/Styling/TemplateSelector.cs @@ -5,7 +5,7 @@ namespace Avalonia.Styling internal class TemplateSelector : Selector { private readonly Selector _parent; - private string _selectorString; + private string? _selectorString; public TemplateSelector(Selector parent) { @@ -24,7 +24,7 @@ namespace Avalonia.Styling public override bool IsCombinator => true; /// - public override Type TargetType => null; + public override Type? TargetType => null; public override string ToString() { @@ -48,6 +48,6 @@ namespace Avalonia.Styling return _parent.Match(templatedParent, subscribe); } - protected override Selector MovePrevious() => null; + protected override Selector? MovePrevious() => null; } } diff --git a/src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj b/src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj index 06859e0cbb..678f75b43f 100644 --- a/src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj +++ b/src/Avalonia.Themes.Default/Avalonia.Themes.Default.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + net6.0;netstandard2.0 diff --git a/src/Avalonia.Themes.Default/ButtonSpinner.xaml b/src/Avalonia.Themes.Default/ButtonSpinner.xaml index ce2b85d2b5..561ca8bedd 100644 --- a/src/Avalonia.Themes.Default/ButtonSpinner.xaml +++ b/src/Avalonia.Themes.Default/ButtonSpinner.xaml @@ -5,6 +5,7 @@ +