Version-gate some newer syntax

This commit is contained in:
Matt Nadareski
2023-10-11 12:37:31 -04:00
parent c19f9ea173
commit f82e925944
4 changed files with 18 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)

View File

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

View File

@@ -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
/// <summary>
/// Create an open folder dialog box
/// </summary>
#if NET48
private static FolderBrowserDialog CreateFolderBrowserDialog() => new FolderBrowserDialog();
#else
private static FolderBrowserDialog CreateFolderBrowserDialog() => new();
#endif
/// <summary>
/// Create an open file dialog box