mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
CmdPal: Null pattern matching based on is expression rather than overridable operators (#40972)
What the title says. 😄
Rather than relying on the potentially overloaded `!=` or `==` operators
when checking for null, now we'll use the `is` expression (possibly
combined with the `not` operator) to ensure correct checking. Probably
overkill for many of these classes, but decided to err on the side of
consistency. Would matter more on classes that may be inherited or
extended.
Using `is` and `is not` will provide us a guarantee that no
user-overloaded equality operators (`==`/`!=`) is invoked when a
`expression is null` is evaluated.
In code form, changed all instances of:
```c#
something != null
something == null
```
to:
```c#
something is not null
something is null
```
The one exception was checking null on a `KeyChord`. `KeyChord` is a
struct which is never null so VS will raise an error when trying this
versus just providing a warning when using `keyChord != null`. In
reality, we shouldn't do this check because it can't ever be null. In
the case of a `KeyChord` it **would** be a `KeyChord` equivalent to:
```c#
KeyChord keyChord = new ()
{
Modifiers = 0,
Vkey = 0,
ScanCode = 0
};
```
This commit is contained in:
@@ -2,16 +2,12 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Apps.Commands;
|
||||
using Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
using Microsoft.CmdPal.Ext.Apps.Properties;
|
||||
using Microsoft.CmdPal.Ext.Apps.State;
|
||||
@@ -145,7 +141,7 @@ public sealed partial class AllAppsPage : ListPage
|
||||
*/
|
||||
var existingAppItem = allApps.FirstOrDefault(f => f.AppIdentifier == e.AppIdentifier);
|
||||
|
||||
if (existingAppItem != null)
|
||||
if (existingAppItem is not null)
|
||||
{
|
||||
var appListItem = new AppListItem(existingAppItem, true, e.IsPinned);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
@@ -66,7 +65,7 @@ public sealed partial class AppCache : IDisposable
|
||||
|
||||
private void UpdateUWPIconPath(Theme theme)
|
||||
{
|
||||
if (_packageRepository != null)
|
||||
if (_packageRepository is not null)
|
||||
{
|
||||
foreach (UWPApplication app in _packageRepository)
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ internal sealed partial class AppListItem : ListItem
|
||||
try
|
||||
{
|
||||
var stream = await ThumbnailHelper.GetThumbnail(_app.ExePath, true);
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
heroImage = IconInfo.FromStream(stream);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ internal sealed partial class AppListItem : ListItem
|
||||
try
|
||||
{
|
||||
var stream = await ThumbnailHelper.GetThumbnail(_app.ExePath);
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
icon = new IconInfo(data, data);
|
||||
|
||||
@@ -6,9 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Apps.Utils;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Storage.Packaging.Appx;
|
||||
using Windows.Win32.System.Com;
|
||||
|
||||
@@ -51,14 +49,14 @@ public static class AppxPackageHelper
|
||||
{
|
||||
result.Add((IntPtr)manifestApp);
|
||||
}
|
||||
else if (manifestApp != null)
|
||||
else if (manifestApp is not null)
|
||||
{
|
||||
manifestApp->Release();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (manifestApp != null)
|
||||
if (manifestApp is not null)
|
||||
{
|
||||
manifestApp->Release();
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ public class PackageManagerWrapper : IPackageManager
|
||||
{
|
||||
var user = WindowsIdentity.GetCurrent().User;
|
||||
|
||||
if (user != null)
|
||||
if (user is not null)
|
||||
{
|
||||
var pkgs = _packageManager.FindPackagesForUser(user.Value);
|
||||
|
||||
return pkgs.Select(PackageWrapper.GetWrapperFromPackage).Where(package => package != null);
|
||||
return pkgs.Select(PackageWrapper.GetWrapperFromPackage).Where(package => package is not null);
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IPackage>();
|
||||
|
||||
@@ -11,9 +11,7 @@ using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Apps.Utils;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Storage.Packaging.Appx;
|
||||
using Windows.Win32.System.Com;
|
||||
|
||||
@@ -99,7 +97,7 @@ public partial class UWP
|
||||
private static string[] XmlNamespaces(string path)
|
||||
{
|
||||
var z = XDocument.Load(path);
|
||||
if (z.Root != null)
|
||||
if (z.Root is not null)
|
||||
{
|
||||
var namespaces = z.Root.Attributes().
|
||||
Where(a => a.IsNamespaceDeclaration).
|
||||
|
||||
@@ -308,7 +308,7 @@ public class UWPApplication : IProgram
|
||||
private bool SetScaleIcons(string path, string colorscheme, bool highContrast = false)
|
||||
{
|
||||
var extension = Path.GetExtension(path);
|
||||
if (extension != null)
|
||||
if (extension is not null)
|
||||
{
|
||||
var end = path.Length - extension.Length;
|
||||
var prefix = path.Substring(0, end);
|
||||
@@ -363,7 +363,7 @@ public class UWPApplication : IProgram
|
||||
private bool SetTargetSizeIcon(string path, string colorscheme, bool highContrast = false)
|
||||
{
|
||||
var extension = Path.GetExtension(path);
|
||||
if (extension != null)
|
||||
if (extension is not null)
|
||||
{
|
||||
var end = path.Length - extension.Length;
|
||||
var prefix = path.Substring(0, end);
|
||||
@@ -576,7 +576,7 @@ public class UWPApplication : IProgram
|
||||
|
||||
var group = new DrawingGroup();
|
||||
var converted = ColorConverter.ConvertFromString(currentBackgroundColor);
|
||||
if (converted != null)
|
||||
if (converted is not null)
|
||||
{
|
||||
var color = (Color)converted;
|
||||
var brush = new SolidColorBrush(color);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class Win32Program : IProgram
|
||||
|
||||
public bool QueryEqualsNameForRunCommands(string query)
|
||||
{
|
||||
if (query != null && AppType == ApplicationType.RunCommand)
|
||||
if (query is not null && AppType == ApplicationType.RunCommand)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (!query.Equals(Name, StringComparison.OrdinalIgnoreCase) && !query.Equals(ExecutableName, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -667,7 +667,7 @@ public class Win32Program : IProgram
|
||||
var paths = new List<string>();
|
||||
using (var root = Registry.LocalMachine.OpenSubKey(appPaths))
|
||||
{
|
||||
if (root != null)
|
||||
if (root is not null)
|
||||
{
|
||||
paths.AddRange(GetPathsFromRegistry(root));
|
||||
}
|
||||
@@ -675,7 +675,7 @@ public class Win32Program : IProgram
|
||||
|
||||
using (var root = Registry.CurrentUser.OpenSubKey(appPaths))
|
||||
{
|
||||
if (root != null)
|
||||
if (root is not null)
|
||||
{
|
||||
paths.AddRange(GetPathsFromRegistry(root));
|
||||
}
|
||||
@@ -700,7 +700,7 @@ public class Win32Program : IProgram
|
||||
{
|
||||
using (var key = root.OpenSubKey(subkey))
|
||||
{
|
||||
if (key == null)
|
||||
if (key is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -742,13 +742,13 @@ public class Win32Program : IProgram
|
||||
|
||||
public bool Equals(Win32Program? app1, Win32Program? app2)
|
||||
{
|
||||
if (app1 == null && app2 == null)
|
||||
if (app1 is null && app2 is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return app1 != null
|
||||
&& app2 != null
|
||||
return app1 is not null
|
||||
&& app2 is not null
|
||||
&& (app1.Name?.ToUpperInvariant(), app1.ExecutableName?.ToUpperInvariant(), app1.FullPath?.ToUpperInvariant())
|
||||
.Equals((app2.Name?.ToUpperInvariant(), app2.ExecutableName?.ToUpperInvariant(), app2.FullPath?.ToUpperInvariant()));
|
||||
}
|
||||
@@ -908,7 +908,7 @@ public class Win32Program : IProgram
|
||||
Parallel.ForEach(paths, source =>
|
||||
{
|
||||
var program = GetProgramFromPath(source);
|
||||
if (program != null)
|
||||
if (program is not null)
|
||||
{
|
||||
programsList.Add(program);
|
||||
}
|
||||
@@ -918,7 +918,7 @@ public class Win32Program : IProgram
|
||||
Parallel.ForEach(runCommandPaths, source =>
|
||||
{
|
||||
var program = GetRunCommandProgramFromPath(source);
|
||||
if (program != null)
|
||||
if (program is not null)
|
||||
{
|
||||
runCommandProgramsList.Add(program);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed partial class FileSystemWatcherWrapper : FileSystemWatcher, IFileS
|
||||
get => this.Filters;
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
foreach (var filter in value)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
using Win32Program = Microsoft.CmdPal.Ext.Apps.Programs.Win32Program;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Apps.Storage;
|
||||
@@ -53,7 +52,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
if (!string.IsNullOrEmpty(appPath))
|
||||
{
|
||||
Win32Program? app = Win32Program.GetAppFromPath(appPath);
|
||||
if (app != null)
|
||||
if (app is not null)
|
||||
{
|
||||
Add(app);
|
||||
_isDirty = true;
|
||||
@@ -137,7 +136,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
}
|
||||
|
||||
// To remove the old app which has been renamed and to add the new application.
|
||||
if (oldApp != null)
|
||||
if (oldApp is not null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(oldApp.Name) || string.IsNullOrWhiteSpace(oldApp.ExecutableName) || string.IsNullOrWhiteSpace(oldApp.FullPath))
|
||||
{
|
||||
@@ -149,7 +148,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
}
|
||||
}
|
||||
|
||||
if (newApp != null)
|
||||
if (newApp is not null)
|
||||
{
|
||||
Add(newApp);
|
||||
_isDirty = true;
|
||||
@@ -177,7 +176,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
if (extension.Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
app = GetAppWithSameLnkFilePath(path);
|
||||
if (app == null)
|
||||
if (app is null)
|
||||
{
|
||||
// Cancelled links won't have a resolved path.
|
||||
app = GetAppWithSameNameAndExecutable(Path.GetFileNameWithoutExtension(path), Path.GetFileName(path));
|
||||
@@ -197,7 +196,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
Logger.LogError(ex.Message);
|
||||
}
|
||||
|
||||
if (app != null)
|
||||
if (app is not null)
|
||||
{
|
||||
Remove(app);
|
||||
_isDirty = true;
|
||||
@@ -244,7 +243,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
|
||||
if (!Path.GetExtension(path).Equals(UrlExtension, StringComparison.OrdinalIgnoreCase) && !Path.GetExtension(path).Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Programs.Win32Program? app = Programs.Win32Program.GetAppFromPath(path);
|
||||
if (app != null)
|
||||
if (app is not null)
|
||||
{
|
||||
Add(app);
|
||||
_isDirty = true;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Com;
|
||||
@@ -27,7 +26,7 @@ public static class ComFreeHelper
|
||||
public static unsafe void ComObjectRelease<T>(T* comPtr)
|
||||
where T : unmanaged
|
||||
{
|
||||
if (comPtr != null)
|
||||
if (comPtr is not null)
|
||||
{
|
||||
((IUnknown*)comPtr)->Release();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using ManagedCommon;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Com;
|
||||
@@ -37,7 +35,7 @@ public class ShellLinkHelper : IShellLinkHelper
|
||||
IPersistFile* persistFile = null;
|
||||
Guid iid = typeof(IPersistFile).GUID;
|
||||
((IUnknown*)link)->QueryInterface(&iid, (void**)&persistFile);
|
||||
if (persistFile != null)
|
||||
if (persistFile is not null)
|
||||
{
|
||||
using var persistFileHandle = new SafeComHandle((IntPtr)persistFile);
|
||||
try
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ShellLocalization
|
||||
|
||||
var filename = ComFreeHelper.GetStringAndFree(hr, filenamePtr);
|
||||
|
||||
if (filename == null)
|
||||
if (filename is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public static class ThemeHelper
|
||||
|
||||
// Retrieve the registry value, which is a DWORD (0 or 1)
|
||||
var registryValueObj = Registry.GetValue(registryKey, registryValue, null);
|
||||
if (registryValueObj != null)
|
||||
if (registryValueObj is not null)
|
||||
{
|
||||
// 0 = Dark mode, 1 = Light mode
|
||||
var isLightMode = Convert.ToBoolean((int)registryValueObj, CultureInfo.InvariantCulture);
|
||||
|
||||
@@ -63,7 +63,7 @@ internal sealed partial class AddBookmarkForm : FormContent
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
var formInput = JsonNode.Parse(payload);
|
||||
if (formInput == null)
|
||||
if (formInput is null)
|
||||
{
|
||||
return CommandResult.GoHome();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ internal sealed partial class BookmarkPlaceholderForm : FormContent
|
||||
// parse the submitted JSON and then open the link
|
||||
var formInput = JsonNode.Parse(payload);
|
||||
var formObject = formInput?.AsObject();
|
||||
if (formObject == null)
|
||||
if (formObject is null)
|
||||
{
|
||||
return CommandResult.GoHome();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public partial class BookmarksCommandProvider : CommandProvider
|
||||
|
||||
private void SaveAndUpdateCommands()
|
||||
{
|
||||
if (_bookmarks != null)
|
||||
if (_bookmarks is not null)
|
||||
{
|
||||
var jsonPath = BookmarksCommandProvider.StateJsonPath();
|
||||
Bookmarks.WriteToFile(jsonPath, _bookmarks);
|
||||
@@ -64,12 +64,12 @@ public partial class BookmarksCommandProvider : CommandProvider
|
||||
List<CommandItem> collected = [];
|
||||
collected.Add(new CommandItem(_addNewCommand));
|
||||
|
||||
if (_bookmarks == null)
|
||||
if (_bookmarks is null)
|
||||
{
|
||||
LoadBookmarksFromFile();
|
||||
}
|
||||
|
||||
if (_bookmarks != null)
|
||||
if (_bookmarks is not null)
|
||||
{
|
||||
collected.AddRange(_bookmarks.Data.Select(BookmarkToCommandItem));
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public partial class BookmarksCommandProvider : CommandProvider
|
||||
Logger.LogError(ex.Message);
|
||||
}
|
||||
|
||||
if (_bookmarks == null)
|
||||
if (_bookmarks is null)
|
||||
{
|
||||
_bookmarks = new();
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public partial class BookmarksCommandProvider : CommandProvider
|
||||
name: Resources.bookmarks_delete_name,
|
||||
action: () =>
|
||||
{
|
||||
if (_bookmarks != null)
|
||||
if (_bookmarks is not null)
|
||||
{
|
||||
ExtensionHost.LogMessage($"Deleting bookmark ({bookmark.Name},{bookmark.Bookmark})");
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public partial class UrlCommand : InvokableCommand
|
||||
if (string.IsNullOrEmpty(args))
|
||||
{
|
||||
var uri = GetUri(exe);
|
||||
if (uri != null)
|
||||
if (uri is not null)
|
||||
{
|
||||
_ = Launcher.LaunchUriAsync(uri);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public partial class UrlCommand : InvokableCommand
|
||||
// First, try to get the icon from the thumbnail helper
|
||||
// This works for local files and folders
|
||||
icon = await MaybeGetIconForPath(target);
|
||||
if (icon != null)
|
||||
if (icon is not null)
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public partial class UrlCommand : InvokableCommand
|
||||
{
|
||||
// If the executable exists, try to get the icon from the file
|
||||
icon = await MaybeGetIconForPath(fullExePath);
|
||||
if (icon != null)
|
||||
if (icon is not null)
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public partial class UrlCommand : InvokableCommand
|
||||
try
|
||||
{
|
||||
var uri = GetUri(baseString);
|
||||
if (uri != null)
|
||||
if (uri is not null)
|
||||
{
|
||||
var hostname = uri.Host;
|
||||
var faviconUrl = $"{uri.Scheme}://{hostname}/favicon.ico";
|
||||
@@ -176,7 +176,7 @@ public partial class UrlCommand : InvokableCommand
|
||||
try
|
||||
{
|
||||
var stream = await ThumbnailHelper.GetThumbnail(target);
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
return new IconInfo(data, data);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class NumberTranslator
|
||||
// Currently, we only convert base literals (hexadecimal, binary, octal) to decimal.
|
||||
var converted = ConvertBaseLiteral(token, cultureTo);
|
||||
|
||||
if (converted != null)
|
||||
if (converted is not null)
|
||||
{
|
||||
outputBuilder.Append(converted);
|
||||
continue;
|
||||
|
||||
@@ -16,7 +16,7 @@ public static class ResultHelper
|
||||
public static ListItem CreateResult(decimal? roundedResult, CultureInfo inputCulture, CultureInfo outputCulture, string query, ISettingsInterface settings, TypedEventHandler<object, object> handleSave)
|
||||
{
|
||||
// Return null when the expression is not a valid calculator query.
|
||||
if (roundedResult == null)
|
||||
if (roundedResult is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public static class ResultHelper
|
||||
public static ListItem CreateResult(decimal? roundedResult, CultureInfo inputCulture, CultureInfo outputCulture, string query)
|
||||
{
|
||||
// Return null when the expression is not a valid calculator query.
|
||||
if (roundedResult == null)
|
||||
if (roundedResult is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public sealed partial class CalculatorListPage : DynamicListPage
|
||||
{
|
||||
this._items.Clear();
|
||||
|
||||
if (result != null)
|
||||
if (result is not null)
|
||||
{
|
||||
this._items.Add(result);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed partial class FallbackCalculatorItem : FallbackCommandItem
|
||||
{
|
||||
var result = QueryHelper.Query(query, _settings, true, null);
|
||||
|
||||
if (result == null)
|
||||
if (result is null)
|
||||
{
|
||||
_copyCommand.Text = string.Empty;
|
||||
_copyCommand.Name = string.Empty;
|
||||
|
||||
@@ -139,7 +139,7 @@ internal static class ClipboardHelper
|
||||
switch (clipboardFormat)
|
||||
{
|
||||
case ClipboardFormat.Text:
|
||||
if (clipboardItem.Content == null)
|
||||
if (clipboardItem.Content is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "No valid clipboard content" });
|
||||
return;
|
||||
@@ -152,7 +152,7 @@ internal static class ClipboardHelper
|
||||
break;
|
||||
|
||||
case ClipboardFormat.Image:
|
||||
if (clipboardItem.ImageData == null)
|
||||
if (clipboardItem.ImageData is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "No valid clipboard content" });
|
||||
return;
|
||||
@@ -240,7 +240,7 @@ internal static class ClipboardHelper
|
||||
internal static async Task<SoftwareBitmap?> GetClipboardImageContentAsync(DataPackageView clipboardData)
|
||||
{
|
||||
using var stream = await GetClipboardImageStreamAsync(clipboardData);
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var decoder = await BitmapDecoder.CreateAsync(stream);
|
||||
return await decoder.GetSoftwareBitmapAsync();
|
||||
@@ -255,7 +255,7 @@ internal static class ClipboardHelper
|
||||
{
|
||||
var storageItems = await clipboardData.GetStorageItemsAsync();
|
||||
var file = storageItems.Count == 1 ? storageItems[0] as StorageFile : null;
|
||||
if (file != null)
|
||||
if (file is not null)
|
||||
{
|
||||
return await file.OpenReadAsync();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ClipboardItem
|
||||
}
|
||||
|
||||
[MemberNotNullWhen(true, nameof(ImageData))]
|
||||
private bool IsImage => ImageData != null;
|
||||
private bool IsImage => ImageData is not null;
|
||||
|
||||
[MemberNotNullWhen(true, nameof(Content))]
|
||||
private bool IsText => !string.IsNullOrEmpty(Content);
|
||||
|
||||
@@ -54,7 +54,7 @@ internal sealed partial class ClipboardHistoryListPage : ListPage
|
||||
try
|
||||
{
|
||||
var allowClipboardHistory = Registry.GetValue(registryKey, "AllowClipboardHistory", null);
|
||||
return allowClipboardHistory != null ? (int)allowClipboardHistory == 0 : false;
|
||||
return allowClipboardHistory is not null ? (int)allowClipboardHistory == 0 : false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ internal sealed partial class ClipboardHistoryListPage : ListPage
|
||||
{
|
||||
var imageReceived = await item.Item.Content.GetBitmapAsync();
|
||||
|
||||
if (imageReceived != null)
|
||||
if (imageReceived is not null)
|
||||
{
|
||||
item.ImageData = imageReceived;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ internal sealed partial class ClipboardHistoryListPage : ListPage
|
||||
for (var i = 0; i < clipboardHistory.Count; i++)
|
||||
{
|
||||
var item = clipboardHistory[i];
|
||||
if (item != null)
|
||||
if (item is not null)
|
||||
{
|
||||
listItems.Add(item.ToListItem());
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ internal sealed partial class FallbackOpenFileItem : FallbackCommandItem, System
|
||||
return;
|
||||
}
|
||||
|
||||
if (_suppressCallback != null && _suppressCallback(query))
|
||||
if (_suppressCallback is not null && _suppressCallback(query))
|
||||
{
|
||||
Command = new NoOpCommand();
|
||||
Title = string.Empty;
|
||||
@@ -71,7 +71,7 @@ internal sealed partial class FallbackOpenFileItem : FallbackCommandItem, System
|
||||
try
|
||||
{
|
||||
var stream = ThumbnailHelper.GetThumbnail(item.FullPath).Result;
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
Icon = new IconInfo(data, data);
|
||||
@@ -92,7 +92,7 @@ internal sealed partial class FallbackOpenFileItem : FallbackCommandItem, System
|
||||
_searchEngine.Query(query, _queryCookie);
|
||||
var results = _searchEngine.FetchItems(0, 20, _queryCookie, out var _);
|
||||
|
||||
if (results.Count == 0 || ((results[0] as IndexerListItem) == null))
|
||||
if (results.Count == 0 || ((results[0] as IndexerListItem) is null))
|
||||
{
|
||||
// Exit 2: We searched for the file, and found nothing. Oh well.
|
||||
// Hide ourselves.
|
||||
|
||||
@@ -16,7 +16,7 @@ internal static class DataSourceManager
|
||||
|
||||
public static IDBInitialize GetDataSource()
|
||||
{
|
||||
if (_dataSource == null)
|
||||
if (_dataSource is null)
|
||||
{
|
||||
InitializeDataSource();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
using static Microsoft.CmdPal.Ext.Indexer.Indexer.Utils.NativeHelpers;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
|
||||
|
||||
@@ -54,14 +53,14 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
try
|
||||
{
|
||||
queryTpTimer = new Timer(QueryTimerCallback, this, Timeout.Infinite, Timeout.Infinite);
|
||||
if (queryTpTimer == null)
|
||||
if (queryTpTimer is null)
|
||||
{
|
||||
Logger.LogError("Failed to create query timer");
|
||||
return;
|
||||
}
|
||||
|
||||
queryCompletedEvent = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
if (queryCompletedEvent == null)
|
||||
if (queryCompletedEvent is null)
|
||||
{
|
||||
Logger.LogError("Failed to create query completed event");
|
||||
return;
|
||||
@@ -85,7 +84,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
// Are we currently doing work? If so, let's cancel
|
||||
lock (_lockObject)
|
||||
{
|
||||
if (queryTpTimer != null)
|
||||
if (queryTpTimer is not null)
|
||||
{
|
||||
queryTpTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
queryTpTimer.Dispose();
|
||||
@@ -117,7 +116,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
try
|
||||
{
|
||||
// We need to generate a search query string with the search text the user entered above
|
||||
if (currentRowset != null)
|
||||
if (currentRowset is not null)
|
||||
{
|
||||
// We have a previous rowset, this means the user is typing and we should store this
|
||||
// recapture the where ID from this so the next ExecuteSync call will be faster
|
||||
@@ -146,14 +145,14 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
{
|
||||
getRow.GetRowFromHROW(null, rowHandle, ref Unsafe.AsRef(in IID.IPropertyStore), out var propertyStore);
|
||||
|
||||
if (propertyStore == null)
|
||||
if (propertyStore is null)
|
||||
{
|
||||
Logger.LogError("Failed to get IPropertyStore interface");
|
||||
return false;
|
||||
}
|
||||
|
||||
var searchResult = SearchResult.Create(propertyStore);
|
||||
if (searchResult == null)
|
||||
if (searchResult is null)
|
||||
{
|
||||
Logger.LogError("Failed to create search result");
|
||||
return false;
|
||||
@@ -171,7 +170,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
|
||||
public bool FetchRows(int offset, int limit)
|
||||
{
|
||||
if (currentRowset == null)
|
||||
if (currentRowset is null)
|
||||
{
|
||||
Logger.LogError("No rowset to fetch rows from");
|
||||
return false;
|
||||
@@ -241,7 +240,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
{
|
||||
var queryStr = QueryStringBuilder.GeneratePrimingQuery();
|
||||
var rowset = ExecuteCommand(queryStr);
|
||||
if (rowset != null)
|
||||
if (rowset is not null)
|
||||
{
|
||||
reuseRowset = rowset;
|
||||
reuseWhereID = GetReuseWhereId(reuseRowset);
|
||||
@@ -261,7 +260,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
var guid = typeof(IDBCreateCommand).GUID;
|
||||
session.CreateSession(IntPtr.Zero, ref guid, out var ppDBSession);
|
||||
|
||||
if (ppDBSession == null)
|
||||
if (ppDBSession is null)
|
||||
{
|
||||
Logger.LogError("CreateSession failed");
|
||||
return null;
|
||||
@@ -271,7 +270,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
guid = typeof(ICommandText).GUID;
|
||||
createCommand.CreateCommand(IntPtr.Zero, ref guid, out ICommandText commandText);
|
||||
|
||||
if (commandText == null)
|
||||
if (commandText is null)
|
||||
{
|
||||
Logger.LogError("Failed to get ICommandText interface");
|
||||
return null;
|
||||
@@ -342,13 +341,13 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
{
|
||||
var rowsetInfo = (IRowsetInfo)rowset;
|
||||
|
||||
if (rowsetInfo == null)
|
||||
if (rowsetInfo is null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var prop = GetPropset(rowsetInfo);
|
||||
if (prop == null)
|
||||
if (prop is null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ internal sealed class SearchResult
|
||||
ItemUrl = url;
|
||||
IsFolder = isFolder;
|
||||
|
||||
if (LaunchUri == null || LaunchUri.Length == 0)
|
||||
if (LaunchUri is null || LaunchUri.Length == 0)
|
||||
{
|
||||
// Launch the file with the default app, so use the file path
|
||||
LaunchUri = filePath;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
@@ -28,7 +26,7 @@ internal sealed partial class QueryStringBuilder
|
||||
|
||||
public static string GenerateQuery(string searchText, uint whereId)
|
||||
{
|
||||
if (queryHelper == null)
|
||||
if (queryHelper is null)
|
||||
{
|
||||
ISearchManager searchManager;
|
||||
|
||||
@@ -43,13 +41,13 @@ internal sealed partial class QueryStringBuilder
|
||||
}
|
||||
|
||||
ISearchCatalogManager catalogManager = searchManager.GetCatalog(SystemIndex);
|
||||
if (catalogManager == null)
|
||||
if (catalogManager is null)
|
||||
{
|
||||
throw new ArgumentException($"Failed to get catalog manager for {SystemIndex}");
|
||||
}
|
||||
|
||||
queryHelper = catalogManager.GetQueryHelper();
|
||||
if (queryHelper == null)
|
||||
if (queryHelper is null)
|
||||
{
|
||||
throw new ArgumentException("Failed to get query helper from catalog manager");
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
|
||||
{
|
||||
lock (UpdateMoreCommandsLock)
|
||||
{
|
||||
if (actionRuntime == null)
|
||||
if (actionRuntime is null)
|
||||
{
|
||||
actionRuntime = ActionRuntimeManager.InstanceAsync.GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
if (actionRuntime == null)
|
||||
if (actionRuntime is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
|
||||
{
|
||||
var extension = System.IO.Path.GetExtension(fullPath).ToLower(CultureInfo.InvariantCulture);
|
||||
ActionEntity entity = null;
|
||||
if (extension != null)
|
||||
if (extension is not null)
|
||||
{
|
||||
if (extension == ".jpg" || extension == ".jpeg" || extension == ".png")
|
||||
{
|
||||
@@ -74,7 +74,7 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
|
||||
}
|
||||
}
|
||||
|
||||
if (entity == null)
|
||||
if (entity is null)
|
||||
{
|
||||
entity = actionRuntime.EntityFactory.CreateFileEntity(fullPath);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
|
||||
{
|
||||
lock (UpdateMoreCommandsLock)
|
||||
{
|
||||
if (actionRuntime != null)
|
||||
if (actionRuntime is not null)
|
||||
{
|
||||
actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed;
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ public sealed partial class DirectoryExplorePage : DynamicListPage
|
||||
|
||||
public override void UpdateSearchText(string oldSearch, string newSearch)
|
||||
{
|
||||
if (_directoryContents == null)
|
||||
if (_directoryContents is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(newSearch))
|
||||
{
|
||||
if (_filteredContents != null)
|
||||
if (_filteredContents is not null)
|
||||
{
|
||||
_filteredContents = null;
|
||||
RaiseItemsChanged(-1);
|
||||
@@ -58,7 +58,7 @@ public sealed partial class DirectoryExplorePage : DynamicListPage
|
||||
newSearch,
|
||||
(s, i) => ListHelpers.ScoreListItem(s, i));
|
||||
|
||||
if (_filteredContents != null)
|
||||
if (_filteredContents is not null)
|
||||
{
|
||||
lock (_filteredContents)
|
||||
{
|
||||
@@ -75,12 +75,12 @@ public sealed partial class DirectoryExplorePage : DynamicListPage
|
||||
|
||||
public override IListItem[] GetItems()
|
||||
{
|
||||
if (_filteredContents != null)
|
||||
if (_filteredContents is not null)
|
||||
{
|
||||
return _filteredContents.ToArray();
|
||||
}
|
||||
|
||||
if (_directoryContents != null)
|
||||
if (_directoryContents is not null)
|
||||
{
|
||||
return _directoryContents.ToArray();
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public sealed partial class DirectoryExplorePage : DynamicListPage
|
||||
try
|
||||
{
|
||||
var stream = ThumbnailHelper.GetThumbnail(item.FilePath).Result;
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
icon = new IconInfo(data, data);
|
||||
|
||||
@@ -31,7 +31,7 @@ public sealed partial class DirectoryPage : ListPage
|
||||
|
||||
public override IListItem[] GetItems()
|
||||
{
|
||||
if (_directoryContents != null)
|
||||
if (_directoryContents is not null)
|
||||
{
|
||||
return _directoryContents.ToArray();
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public sealed partial class DirectoryPage : ListPage
|
||||
try
|
||||
{
|
||||
var stream = ThumbnailHelper.GetThumbnail(item.FilePath).Result;
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
icon = new IconInfo(data, data);
|
||||
|
||||
@@ -42,7 +42,7 @@ public sealed partial class SearchEngine : IDisposable
|
||||
{
|
||||
hasMore = false;
|
||||
var results = new List<IListItem>();
|
||||
if (_searchQuery != null)
|
||||
if (_searchQuery is not null)
|
||||
{
|
||||
var cookie = _searchQuery.Cookie;
|
||||
if (cookie == queryCookie)
|
||||
@@ -59,7 +59,7 @@ public sealed partial class SearchEngine : IDisposable
|
||||
try
|
||||
{
|
||||
var stream = ThumbnailHelper.GetThumbnail(result.LaunchUri).Result;
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
icon = new IconInfo(data, data);
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Registry.Classes;
|
||||
using Microsoft.CmdPal.Ext.Registry.Constants;
|
||||
using Microsoft.CmdPal.Ext.Registry.Properties;
|
||||
@@ -118,7 +117,7 @@ internal static class RegistryHelper
|
||||
subKey = result.First().Key;
|
||||
}
|
||||
|
||||
if (result.Count > 1 || subKey == null)
|
||||
if (result.Count > 1 || subKey is null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -183,7 +182,7 @@ internal static class RegistryHelper
|
||||
if (string.Equals(subKey, searchSubKey, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var key = parentKey.OpenSubKey(subKey, RegistryKeyPermissionCheck.ReadSubTree);
|
||||
if (key != null)
|
||||
if (key is not null)
|
||||
{
|
||||
list.Add(new RegistryEntry(key));
|
||||
}
|
||||
@@ -194,7 +193,7 @@ internal static class RegistryHelper
|
||||
try
|
||||
{
|
||||
var key = parentKey.OpenSubKey(subKey, RegistryKeyPermissionCheck.ReadSubTree);
|
||||
if (key != null)
|
||||
if (key is not null)
|
||||
{
|
||||
list.Add(new RegistryEntry(key));
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ internal static class ResultHelper
|
||||
foreach (var valueName in valueNames)
|
||||
{
|
||||
var value = key.GetValue(valueName);
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
valueList.Add(KeyValuePair.Create(valueName, value));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ internal static class ValueHelper
|
||||
{
|
||||
var unformattedValue = key.GetValue(valueName);
|
||||
|
||||
if (unformattedValue == null)
|
||||
if (unformattedValue is null)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot proceed when {nameof(unformattedValue)} is null.");
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ internal sealed partial class ExecuteItem : InvokableCommand
|
||||
|
||||
private void Execute(Func<ProcessStartInfo, Process?> startProcess, ProcessStartInfo info)
|
||||
{
|
||||
if (startProcess == null)
|
||||
if (startProcess is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ShellListPageHelpers
|
||||
return null;
|
||||
}
|
||||
|
||||
if (li != null)
|
||||
if (li is not null)
|
||||
{
|
||||
li.TextToSuggest = searchText;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ internal sealed partial class RunExeItem : ListItem
|
||||
try
|
||||
{
|
||||
var stream = await ThumbnailHelper.GetThumbnail(FullExePath);
|
||||
if (stream != null)
|
||||
if (stream is not null)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
icon = new IconInfo(data, data);
|
||||
|
||||
@@ -245,14 +245,14 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
var histItemsNotInSearch =
|
||||
_historyItems
|
||||
.Where(kv => !kv.Key.Equals(newSearch, StringComparison.OrdinalIgnoreCase));
|
||||
if (_exeItem != null)
|
||||
if (_exeItem is not null)
|
||||
{
|
||||
// If we have an exe item, we want to remove it from the history items
|
||||
histItemsNotInSearch = histItemsNotInSearch
|
||||
.Where(kv => !kv.Value.Title.Equals(_exeItem.Title, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (_uriItem != null)
|
||||
if (_uriItem is not null)
|
||||
{
|
||||
// If we have an uri item, we want to remove it from the history items
|
||||
histItemsNotInSearch = histItemsNotInSearch
|
||||
@@ -307,8 +307,8 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
}
|
||||
|
||||
var filteredTopLevel = ListHelpers.FilterList(_topLevelItems, SearchText);
|
||||
List<ListItem> uriItems = _uriItem != null ? [_uriItem] : [];
|
||||
List<ListItem> exeItems = _exeItem != null ? [_exeItem] : [];
|
||||
List<ListItem> uriItems = _uriItem is not null ? [_uriItem] : [];
|
||||
List<ListItem> exeItems = _exeItem is not null ? [_exeItem] : [];
|
||||
|
||||
return
|
||||
exeItems
|
||||
@@ -459,7 +459,7 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
|
||||
var hist = _historyService.GetRunHistory();
|
||||
var histItems = hist
|
||||
.Select(h => (h, ShellListPageHelpers.ListItemForCommandString(h, AddToHistory)))
|
||||
.Where(tuple => tuple.Item2 != null)
|
||||
.Where(tuple => tuple.Item2 is not null)
|
||||
.Select(tuple => (tuple.h, tuple.Item2!))
|
||||
.ToList();
|
||||
_historyItems.Clear();
|
||||
|
||||
@@ -72,7 +72,7 @@ internal sealed partial class PathListItem : ListItem
|
||||
_icon = new Lazy<IconInfo>(() =>
|
||||
{
|
||||
var iconStream = ThumbnailHelper.GetThumbnail(path).Result;
|
||||
var icon = iconStream != null ? IconInfo.FromStream(iconStream) :
|
||||
var icon = iconStream is not null ? IconInfo.FromStream(iconStream) :
|
||||
_isDirectory ? Icons.FolderIcon : Icons.RunV2Icon;
|
||||
return icon;
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ internal sealed partial class FallbackSystemCommandItem : FallbackCommandItem
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
if (result is null)
|
||||
{
|
||||
Command = null;
|
||||
Title = string.Empty;
|
||||
|
||||
@@ -155,7 +155,7 @@ internal sealed class NetworkConnectionProperties
|
||||
internal static List<NetworkConnectionProperties> GetList()
|
||||
{
|
||||
var interfaces = NetworkInterface.GetAllNetworkInterfaces()
|
||||
.Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.GetPhysicalAddress() != null)
|
||||
.Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.GetPhysicalAddress() is not null)
|
||||
.Select(i => new NetworkConnectionProperties(i))
|
||||
.OrderByDescending(i => i.IPv4) // list IPv4 first
|
||||
.ThenBy(i => i.IPv6Primary) // then IPv6
|
||||
@@ -195,9 +195,9 @@ internal sealed class NetworkConnectionProperties
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Ip6Site}:**\n\n* ", IPv6SiteLocal) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Ip6Unique}:**\n\n* ", IPv6UniqueLocal) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Gateways}:**\n\n* ", Gateways) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Dhcp}:**\n\n* ", DhcpServers == null ? string.Empty : DhcpServers) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Dns}:**\n\n* ", DnsServers == null ? string.Empty : DnsServers) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Wins}:**\n\n* ", WinsServers == null ? string.Empty : WinsServers) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Dhcp}:**\n\n* ", DhcpServers is null ? string.Empty : DhcpServers) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Dns}:**\n\n* ", DnsServers is null ? string.Empty : DnsServers) +
|
||||
CreateIpInfoForDetailsText($"**{Resources.Microsoft_plugin_sys_Wins}:**\n\n* ", WinsServers is null ? string.Empty : WinsServers) +
|
||||
$"\n\n**{Resources.Microsoft_plugin_sys_AdapterName}:** {Adapter}" +
|
||||
$"\n\n**{Resources.Microsoft_plugin_sys_PhysicalAddress}:** {PhysicalAddress}" +
|
||||
$"\n\n**{Resources.Microsoft_plugin_sys_Speed}:** {GetFormattedSpeedValue(Speed)}";
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.CmdPal.Ext.TimeDate.Helpers;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.TimeDate;
|
||||
@@ -66,7 +64,7 @@ internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
if (result is not null)
|
||||
{
|
||||
Title = result.Title;
|
||||
Subtitle = result.Subtitle;
|
||||
@@ -90,7 +88,7 @@ internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
|
||||
|
||||
foreach (var option in _validOptions)
|
||||
{
|
||||
if (option == null)
|
||||
if (option is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ internal static class AvailableResultsList
|
||||
|
||||
var timeExtended = timeLongFormat ?? settings.TimeWithSecond;
|
||||
var dateExtended = dateLongFormat ?? settings.DateWithWeekday;
|
||||
var isSystemDateTime = timestamp == null;
|
||||
var isSystemDateTime = timestamp is null;
|
||||
var dateTimeNow = timestamp ?? DateTime.Now;
|
||||
var dateTimeNowUtc = dateTimeNow.ToUniversalTime();
|
||||
var firstWeekRule = firstWeekOfYear ?? TimeAndDateHelper.GetCalendarWeekRule(settings.FirstWeekOfYear);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class SettingsManager : JsonSettingsManager, ISettingsInterface
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_firstWeekOfYear.Value == null || string.IsNullOrEmpty(_firstWeekOfYear.Value))
|
||||
if (_firstWeekOfYear.Value is null || string.IsNullOrEmpty(_firstWeekOfYear.Value))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class SettingsManager : JsonSettingsManager, ISettingsInterface
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_firstDayOfWeek.Value == null || string.IsNullOrEmpty(_firstDayOfWeek.Value))
|
||||
if (_firstDayOfWeek.Value is null || string.IsNullOrEmpty(_firstDayOfWeek.Value))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using ManagedCommon;
|
||||
@@ -87,7 +86,7 @@ public static class DefaultBrowserInfo
|
||||
var appName = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\Application", "ApplicationName")
|
||||
?? GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}", "FriendlyTypeName");
|
||||
|
||||
if (appName != null)
|
||||
if (appName is not null)
|
||||
{
|
||||
// Handle indirect strings:
|
||||
if (appName.StartsWith('@'))
|
||||
|
||||
@@ -67,7 +67,7 @@ public class SettingsManager : JsonSettingsManager
|
||||
|
||||
public void SaveHistory(HistoryItem historyItem)
|
||||
{
|
||||
if (historyItem == null)
|
||||
if (historyItem is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ internal sealed partial class WebSearchListPage : DynamicListPage
|
||||
Id = "com.microsoft.cmdpal.websearch";
|
||||
_settingsManager = settingsManager;
|
||||
_historyItems = _settingsManager.ShowHistory != Resources.history_none ? _settingsManager.LoadHistory() : null;
|
||||
if (_historyItems != null)
|
||||
if (_historyItems is not null)
|
||||
{
|
||||
_allItems.AddRange(_historyItems);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ internal sealed partial class WebSearchListPage : DynamicListPage
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
IEnumerable<ListItem>? filteredHistoryItems = null;
|
||||
|
||||
if (_historyItems != null)
|
||||
if (_historyItems is not null)
|
||||
{
|
||||
filteredHistoryItems = _settingsManager.ShowHistory != Resources.history_none ? ListHelpers.FilterList(_historyItems, query).OfType<ListItem>() : null;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ internal sealed partial class WebSearchListPage : DynamicListPage
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
if (filteredHistoryItems != null)
|
||||
if (filteredHistoryItems is not null)
|
||||
{
|
||||
results.AddRange(filteredHistoryItems);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
@@ -79,7 +78,7 @@ public partial class InstallPackageCommand : InvokableCommand
|
||||
{
|
||||
// TODO: LOCK in here, so this can only be invoked once until the
|
||||
// install / uninstall is done. Just use like, an atomic
|
||||
if (_installTask != null)
|
||||
if (_installTask is not null)
|
||||
{
|
||||
return CommandResult.KeepOpen();
|
||||
}
|
||||
@@ -143,7 +142,7 @@ public partial class InstallPackageCommand : InvokableCommand
|
||||
{
|
||||
await Task.Delay(2500).ConfigureAwait(false);
|
||||
|
||||
if (_installTask == null)
|
||||
if (_installTask is null)
|
||||
{
|
||||
WinGetExtensionHost.Instance.HideStatus(_installBanner);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public partial class InstallPackageListItem : ListItem
|
||||
|
||||
var version = _package.DefaultInstallVersion ?? _package.InstalledVersion;
|
||||
var versionTagText = "Unknown";
|
||||
if (version != null)
|
||||
if (version is not null)
|
||||
{
|
||||
versionTagText = version.Version == "Unknown" && version.PackageCatalog.Info.Id == "StoreEdgeFD" ? "msstore" : version.Version;
|
||||
}
|
||||
@@ -60,11 +60,11 @@ public partial class InstallPackageListItem : ListItem
|
||||
Logger.LogWarning($"{ex.ErrorCode}");
|
||||
}
|
||||
|
||||
if (metadata != null)
|
||||
if (metadata is not null)
|
||||
{
|
||||
if (metadata.Tags.Where(t => t.Equals(WinGetExtensionPage.ExtensionsTag, StringComparison.OrdinalIgnoreCase)).Any())
|
||||
{
|
||||
if (_installCommand != null)
|
||||
if (_installCommand is not null)
|
||||
{
|
||||
_installCommand.SkipDependencies = true;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public partial class InstallPackageListItem : ListItem
|
||||
return;
|
||||
}
|
||||
|
||||
var isInstalled = _package.InstalledVersion != null;
|
||||
var isInstalled = _package.InstalledVersion is not null;
|
||||
|
||||
var installedState = isInstalled ?
|
||||
(_package.IsUpdateAvailable ?
|
||||
@@ -193,11 +193,11 @@ public partial class InstallPackageListItem : ListItem
|
||||
Icon = Icons.DeleteIcon,
|
||||
};
|
||||
|
||||
if (WinGetStatics.AppSearchCallback != null)
|
||||
if (WinGetStatics.AppSearchCallback is not null)
|
||||
{
|
||||
var callback = WinGetStatics.AppSearchCallback;
|
||||
var installedApp = callback(_package.DefaultInstallVersion == null ? _package.Name : _package.DefaultInstallVersion.DisplayName);
|
||||
if (installedApp != null)
|
||||
var installedApp = callback(_package.DefaultInstallVersion is null ? _package.Name : _package.DefaultInstallVersion.DisplayName);
|
||||
if (installedApp is not null)
|
||||
{
|
||||
this.Command = installedApp.Command;
|
||||
contextMenu = [.. installedApp.MoreCommands];
|
||||
|
||||
@@ -53,7 +53,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
|
||||
{
|
||||
// emptySearchForTag ===
|
||||
// we don't have results yet, we haven't typed anything, and we're searching for a tag
|
||||
var emptySearchForTag = _results == null &&
|
||||
var emptySearchForTag = _results is null &&
|
||||
string.IsNullOrEmpty(SearchText) &&
|
||||
HasTag;
|
||||
|
||||
@@ -64,7 +64,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
|
||||
return items;
|
||||
}
|
||||
|
||||
if (_results != null && _results.Any())
|
||||
if (_results is not null && _results.Any())
|
||||
{
|
||||
ListItem[] results = _results.Select(PackageToListItem).ToArray();
|
||||
IsLoading = false;
|
||||
@@ -100,7 +100,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
|
||||
private void DoUpdateSearchText(string newSearch)
|
||||
{
|
||||
// Cancel any ongoing search
|
||||
if (_cancellationTokenSource != null)
|
||||
if (_cancellationTokenSource is not null)
|
||||
{
|
||||
Logger.LogDebug("Cancelling old search", memberName: nameof(DoUpdateSearchText));
|
||||
_cancellationTokenSource.Cancel();
|
||||
@@ -221,7 +221,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
|
||||
// WinGetStatics static ctor when we were created.
|
||||
PackageCatalog catalog = await catalogTask.Value;
|
||||
|
||||
if (catalog == null)
|
||||
if (catalog is null)
|
||||
{
|
||||
// This error should have already been displayed by WinGetStatics
|
||||
return [];
|
||||
|
||||
@@ -18,10 +18,10 @@ internal sealed partial class SwitchToWindowCommand : InvokableCommand
|
||||
{
|
||||
Name = Resources.switch_to_command_title;
|
||||
_window = window;
|
||||
if (_window != null)
|
||||
if (_window is not null)
|
||||
{
|
||||
var p = Process.GetProcessById((int)_window.Process.ProcessID);
|
||||
if (p != null)
|
||||
if (p is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ internal static class ResultHelper
|
||||
/// <returns>List of results</returns>
|
||||
internal static List<WindowWalkerListItem> GetResultList(List<SearchResult> searchControllerResults, bool isKeywordSearch)
|
||||
{
|
||||
if (searchControllerResults == null || searchControllerResults.Count == 0)
|
||||
if (searchControllerResults is null || searchControllerResults.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class VirtualDesktopHelper
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Virtual Desktop Manager is initialized successfully
|
||||
/// </summary>
|
||||
public bool VirtualDesktopManagerInitialized => _virtualDesktopManager != null;
|
||||
public bool VirtualDesktopManagerInitialized => _virtualDesktopManager is not null;
|
||||
|
||||
/// <summary>
|
||||
/// Method to update the list of Virtual Desktops from Registry
|
||||
@@ -98,10 +98,10 @@ public class VirtualDesktopHelper
|
||||
|
||||
// List of all desktops
|
||||
using RegistryKey? virtualDesktopKey = Registry.CurrentUser.OpenSubKey(registryExplorerVirtualDesktops, false);
|
||||
if (virtualDesktopKey != null)
|
||||
if (virtualDesktopKey is not null)
|
||||
{
|
||||
var allDeskValue = (byte[]?)virtualDesktopKey.GetValue("VirtualDesktopIDs", null) ?? Array.Empty<byte>();
|
||||
if (allDeskValue != null)
|
||||
if (allDeskValue is not null)
|
||||
{
|
||||
// We clear only, if we can read from registry. Otherwise, we keep the existing values.
|
||||
_availableDesktops.Clear();
|
||||
@@ -124,10 +124,10 @@ public class VirtualDesktopHelper
|
||||
// Guid for current desktop
|
||||
var virtualDesktopsKeyName = _isWindowsEleven ? registryExplorerVirtualDesktops : registrySessionVirtualDesktops;
|
||||
using RegistryKey? virtualDesktopsKey = Registry.CurrentUser.OpenSubKey(virtualDesktopsKeyName, false);
|
||||
if (virtualDesktopsKey != null)
|
||||
if (virtualDesktopsKey is not null)
|
||||
{
|
||||
var currentVirtualDesktopValue = virtualDesktopsKey.GetValue("CurrentVirtualDesktop", null);
|
||||
if (currentVirtualDesktopValue != null)
|
||||
if (currentVirtualDesktopValue is not null)
|
||||
{
|
||||
_currentDesktop = new Guid((byte[])currentVirtualDesktopValue);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public class VirtualDesktopHelper
|
||||
using RegistryKey? deskSubKey = Registry.CurrentUser.OpenSubKey(registryPath, false);
|
||||
var desktopName = deskSubKey?.GetValue("Name");
|
||||
|
||||
return (desktopName != null) ? (string)desktopName : defaultName;
|
||||
return (desktopName is not null) ? (string)desktopName : defaultName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -313,7 +313,7 @@ public class VirtualDesktopHelper
|
||||
/// <returns>HResult of the called method as integer.</returns>
|
||||
public int GetWindowDesktopId(IntPtr hWindow, out Guid desktopId)
|
||||
{
|
||||
if (_virtualDesktopManager == null)
|
||||
if (_virtualDesktopManager is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "VirtualDesktopHelper.GetWindowDesktopId() failed: The instance of <IVirtualDesktopHelper> isn't available." });
|
||||
desktopId = Guid.Empty;
|
||||
@@ -330,7 +330,7 @@ public class VirtualDesktopHelper
|
||||
/// <returns>An instance of <see cref="VDesktop"/> for the desktop where the window is assigned to, or an empty instance of <see cref="VDesktop"/> on failure.</returns>
|
||||
public VDesktop GetWindowDesktop(IntPtr hWindow)
|
||||
{
|
||||
if (_virtualDesktopManager == null)
|
||||
if (_virtualDesktopManager is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "VirtualDesktopHelper.GetWindowDesktop() failed: The instance of <IVirtualDesktopHelper> isn't available." });
|
||||
return CreateVDesktopInstance(Guid.Empty);
|
||||
@@ -348,7 +348,7 @@ public class VirtualDesktopHelper
|
||||
/// <returns>Type of <see cref="VirtualDesktopAssignmentType"/>.</returns>
|
||||
public VirtualDesktopAssignmentType GetWindowDesktopAssignmentType(IntPtr hWindow, Guid? desktop = null)
|
||||
{
|
||||
if (_virtualDesktopManager == null)
|
||||
if (_virtualDesktopManager is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "VirtualDesktopHelper.GetWindowDesktopAssignmentType() failed: The instance of <IVirtualDesktopHelper> isn't available." });
|
||||
return VirtualDesktopAssignmentType.Unknown;
|
||||
@@ -415,7 +415,7 @@ public class VirtualDesktopHelper
|
||||
/// <returns><see langword="True"/> on success and <see langword="false"/> on failure.</returns>
|
||||
public bool MoveWindowToDesktop(IntPtr hWindow, ref Guid desktopId)
|
||||
{
|
||||
if (_virtualDesktopManager == null)
|
||||
if (_virtualDesktopManager is null)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "VirtualDesktopHelper.MoveWindowToDesktop() failed: The instance of <IVirtualDesktopHelper> isn't available." });
|
||||
return false;
|
||||
|
||||
@@ -47,7 +47,7 @@ public static class ServiceHelper
|
||||
var result = serviceList.Select(s =>
|
||||
{
|
||||
var serviceResult = ServiceResult.CreateServiceController(s);
|
||||
if (serviceResult == null)
|
||||
if (serviceResult is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public static class ServiceHelper
|
||||
// ToolTipData = new ToolTipData(serviceResult.DisplayName, serviceResult.ServiceName),
|
||||
// IcoPath = icoPath,
|
||||
};
|
||||
}).Where(s => s != null);
|
||||
}).Where(s => s is not null);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ internal static class UnsupportedSettingsHelper
|
||||
: currentBuildNumber;
|
||||
|
||||
var filteredSettingsList = windowsSettings.Settings.Where(found
|
||||
=> (found.DeprecatedInBuild == null || currentWindowsBuild < found.DeprecatedInBuild)
|
||||
&& (found.IntroducedInBuild == null || currentWindowsBuild >= found.IntroducedInBuild));
|
||||
=> (found.DeprecatedInBuild is null || currentWindowsBuild < found.DeprecatedInBuild)
|
||||
&& (found.IntroducedInBuild is null || currentWindowsBuild >= found.IntroducedInBuild));
|
||||
|
||||
filteredSettingsList = filteredSettingsList.OrderBy(found => found.Name);
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ internal sealed partial class SampleContentForm : FormContent
|
||||
public override CommandResult SubmitForm(string payload)
|
||||
{
|
||||
var formInput = JsonNode.Parse(payload)?.AsObject();
|
||||
if (formInput == null)
|
||||
if (formInput is null)
|
||||
{
|
||||
return CommandResult.GoHome();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public partial class SampleUpdatingItemsPage : ListPage
|
||||
|
||||
public override IListItem[] GetItems()
|
||||
{
|
||||
if (timer == null)
|
||||
if (timer is null)
|
||||
{
|
||||
timer = new Timer(500);
|
||||
timer.Elapsed += (object source, ElapsedEventArgs e) =>
|
||||
|
||||
Reference in New Issue
Block a user