From f82e925944f2251e5ddfdc6da7cedd03ae6a8ec7 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 11 Oct 2023 12:37:31 -0400 Subject: [PATCH] Version-gate some newer syntax --- CHANGELIST.md | 1 + MPF.UI.Core/ElementConverter.cs | 4 ++++ MPF.UI.Core/UserControls/LogOutput.xaml.cs | 6 +++++- MPF.UI.Core/Windows/OptionsWindow.xaml.cs | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 3bddef76..76c8478e 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -15,6 +15,7 @@ - Enable nullability in MPF.Test - Handle some suggested changes - Var-ify many instances +- Version-gate some newer syntax ### 2.7.0 (2023-10-11) diff --git a/MPF.UI.Core/ElementConverter.cs b/MPF.UI.Core/ElementConverter.cs index 7ec74f92..d0b95107 100644 --- a/MPF.UI.Core/ElementConverter.cs +++ b/MPF.UI.Core/ElementConverter.cs @@ -37,7 +37,11 @@ namespace MPF.UI.Core #endif { // If it's an IElement but ends up null +#if NET48 if (!(value is IElement element)) +#else + if (value is not IElement element) +#endif return null; switch (element) diff --git a/MPF.UI.Core/UserControls/LogOutput.xaml.cs b/MPF.UI.Core/UserControls/LogOutput.xaml.cs index 85186586..414589bd 100644 --- a/MPF.UI.Core/UserControls/LogOutput.xaml.cs +++ b/MPF.UI.Core/UserControls/LogOutput.xaml.cs @@ -168,13 +168,17 @@ namespace MPF.UI.Core.UserControls { Dispatcher.Invoke(() => { +#if NET48 if (lastLine == null) lastLine = new Run(); +#else + lastLine ??= new Run(); +#endif lastLine.Text = logLine.Text; lastLine.Foreground = logLine.GetForegroundColor(); }); } - #endregion +#endregion #region Helpers diff --git a/MPF.UI.Core/Windows/OptionsWindow.xaml.cs b/MPF.UI.Core/Windows/OptionsWindow.xaml.cs index 68307f32..1005f5ca 100644 --- a/MPF.UI.Core/Windows/OptionsWindow.xaml.cs +++ b/MPF.UI.Core/Windows/OptionsWindow.xaml.cs @@ -57,7 +57,11 @@ namespace MPF.UI.Core.Windows return; // Strips button prefix to obtain the setting name +#if NET48 string pathSettingName = button.Name.Substring(0, button.Name.IndexOf("Button")); +#else + string pathSettingName = button.Name[..button.Name.IndexOf("Button")]; +#endif // TODO: hack for now, then we'll see bool shouldBrowseForPath = pathSettingName == "DefaultOutputPath"; @@ -124,7 +128,11 @@ namespace MPF.UI.Core.Windows /// /// Create an open folder dialog box /// +#if NET48 private static FolderBrowserDialog CreateFolderBrowserDialog() => new FolderBrowserDialog(); +#else + private static FolderBrowserDialog CreateFolderBrowserDialog() => new(); +#endif /// /// Create an open file dialog box