Use negated pattern.

This commit is contained in:
2022-11-14 01:20:28 +00:00
parent 6a4dea75ea
commit c4a95c40ca
14 changed files with 50 additions and 41 deletions

View File

@@ -169,7 +169,7 @@ public static class ImageInfo
imageFormat.Info.Heads > 0 &&
imageFormat.Info.SectorsPerTrack > 0 &&
imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
(!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
imageFormat is not ITapeImage { IsTape: true })
AaruConsole.WriteLine("[bold]Media geometry:[/] [italic]{0} cylinders, {1} heads, {2} sectors per track[/]",
imageFormat.Info.Cylinders, imageFormat.Info.Heads, imageFormat.Info.SectorsPerTrack);

View File

@@ -151,7 +151,7 @@ public static class Partitions
}
// Be sure that device partitions are not excluded if not mapped by any scheme...
if(!(tapeImage is null))
if(tapeImage is not null)
{
var startLocations = childPartitions.Select(detectedPartition => detectedPartition.Start).ToList();
@@ -165,7 +165,7 @@ public static class Partitions
}));
}
if(!(partitionableImage is null))
if(partitionableImage is not null)
{
var startLocations = childPartitions.Select(detectedPartition => detectedPartition.Start).ToList();

View File

@@ -707,7 +707,7 @@ public static class Statistics
{
Bus = device.Bus,
Manufacturer = device.Manufacturer,
ManufacturerSpecified = !(device.Manufacturer is null),
ManufacturerSpecified = device.Manufacturer is not null,
Model = device.Model,
Revision = device.Revision
});

View File

@@ -65,7 +65,7 @@ public sealed class App : Application
void OnSplashFinished(object sender, EventArgs e)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop))
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
return;
// Ensure not exit
@@ -85,10 +85,13 @@ public sealed class App : Application
void OnAboutClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
MainWindow: MainWindow
{
DataContext: MainWindowViewModel mainWindowViewModel
}
})
return;
mainWindowViewModel.ExecuteAboutCommand();
@@ -96,10 +99,13 @@ public sealed class App : Application
void OnQuitClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
MainWindow: MainWindow
{
DataContext: MainWindowViewModel mainWindowViewModel
}
})
return;
mainWindowViewModel.ExecuteExitCommand();
@@ -107,10 +113,13 @@ public sealed class App : Application
void OnPreferencesClicked(object sender, EventArgs args)
{
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
{
MainWindow: MainWindow { DataContext: MainWindowViewModel mainWindowViewModel }
}))
MainWindow: MainWindow
{
DataContext: MainWindowViewModel mainWindowViewModel
}
})
return;
mainWindowViewModel.ExecuteSettingsCommand();

View File

@@ -246,7 +246,7 @@ public sealed class BlockMap : ItemsControl
case NotifyCollectionChangedAction.Add:
case NotifyCollectionChangedAction.Replace:
{
if(!(e.NewItems is {} items))
if(e.NewItems is not {} items)
throw new ArgumentException("Invalid list of items");
using IDrawingContextImpl ctxi = _bitmap.CreateDrawingContext(null);
@@ -254,7 +254,7 @@ public sealed class BlockMap : ItemsControl
foreach(object item in items)
{
if(!(item is ValueTuple<ulong, double> block))
if(item is not ValueTuple<ulong, double> block)
throw new ArgumentException("Invalid item in list", nameof(Items));
DrawCluster(block.Item1, block.Item2, false, ctx);
@@ -267,8 +267,8 @@ public sealed class BlockMap : ItemsControl
case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Move:
{
if(!(e.NewItems is {} newItems) ||
!(e.OldItems is {} oldItems))
if(e.NewItems is not {} newItems ||
e.OldItems is not {} oldItems)
throw new ArgumentException("Invalid list of items");
using IDrawingContextImpl ctxi = _bitmap.CreateDrawingContext(null);
@@ -276,7 +276,7 @@ public sealed class BlockMap : ItemsControl
foreach(object item in oldItems)
{
if(!(item is ValueTuple<ulong, double> block))
if(item is not ValueTuple<ulong, double> block)
throw new ArgumentException("Invalid item in list", nameof(Items));
DrawCluster(block.Item1, block.Item2, false, ctx);
@@ -284,7 +284,7 @@ public sealed class BlockMap : ItemsControl
foreach(object item in newItems)
{
if(!(item is ValueTuple<ulong, double> block))
if(item is not ValueTuple<ulong, double> block)
throw new ArgumentException("Invalid item in list", nameof(Items));
DrawCluster(block.Item1, block.Item2, false, ctx);
@@ -314,7 +314,7 @@ public sealed class BlockMap : ItemsControl
foreach(object item in Items)
{
if(!(item is ValueTuple<ulong, double> block))
if(item is not ValueTuple<ulong, double> block)
throw new ArgumentException("Invalid item in list", nameof(Items));
DrawCluster(block.Item1, block.Item2, false, ctx);
@@ -384,7 +384,7 @@ public sealed class BlockMap : ItemsControl
protected override void ItemsChanged([NotNull] AvaloniaPropertyChangedEventArgs e)
{
if(e.NewValue != null &&
!(e.NewValue is IList<(ulong, double)>))
e.NewValue is not IList<(ulong, double)>)
throw new
ArgumentException("Items must be a IList<(ulong, double)> with ulong being the block and double being the time spent reading it, or NaN for an error.");

View File

@@ -184,7 +184,7 @@ public sealed class ImageInfoViewModel : ViewModelBase
imageFormat.Info.Heads > 0 &&
imageFormat.Info.SectorsPerTrack > 0 &&
imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
(!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
(imageFormat is not ITapeImage tapeImage || !tapeImage.IsTape))
MediaGeometryText =
$"Media geometry: {imageFormat.Info.Cylinders} cylinders, {imageFormat.Info.Heads} heads, {imageFormat.Info.SectorsPerTrack} sectors per track";

View File

@@ -857,7 +857,7 @@ public sealed class ScsiInfoViewModel : ViewModelBase
async Task ExecuteSaveEvpdPageCommand()
{
if(!(SelectedEvpdPage is ScsiPageModel pageModel))
if(SelectedEvpdPage is not ScsiPageModel pageModel)
return;
var dlgSaveBinary = new SaveFileDialog();

View File

@@ -573,7 +573,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
{
var warning = false;
if(!(plugin is IWritableImage outputFormat))
if(plugin is not IWritableImage outputFormat)
{
await MessageBoxManager.GetMessageBoxStandardWindow("Error", "Error trying to find selected plugin",
icon: Icon.Error).ShowDialog(_view);

View File

@@ -389,7 +389,7 @@ public sealed class ImageVerifyViewModel : ViewModelBase
if(VerifyImageChecked)
{
if(!(_inputFormat is IVerifiableImage verifiableImage))
if(_inputFormat is not IVerifiableImage verifiableImage)
await Dispatcher.UIThread.InvokeAsync(() =>
{
ImageResultVisible = true;
@@ -519,7 +519,7 @@ public sealed class ImageVerifyViewModel : ViewModelBase
endCheck = DateTime.UtcNow;
}
else if(!(verifiableSectorsImage is null))
else if(verifiableSectorsImage is not null)
{
ulong remainingSectors = _inputFormat.Info.Sectors;
ulong currentSector = 0;

View File

@@ -342,7 +342,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteCalculateEntropyCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
var imageEntropyWindow = new ImageEntropy();
@@ -355,7 +355,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteVerifyImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
var imageVerifyWindow = new ImageVerify();
@@ -368,7 +368,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteChecksumImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
var imageChecksumWindow = new ImageChecksum();
@@ -381,7 +381,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteConvertImageCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
var imageConvertWindow = new ImageConvert();
@@ -396,7 +396,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteCreateSidecarCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
var imageSidecarWindow = new ImageSidecar();
@@ -411,7 +411,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteViewImageSectorsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
new ViewSector
@@ -422,7 +422,7 @@ public sealed class MainWindowViewModel : ViewModelBase
void ExecuteDecodeImageMediaTagsCommand()
{
if(!(TreeViewSelectedItem is ImageModel imageModel))
if(TreeViewSelectedItem is not ImageModel imageModel)
return;
new DecodeMediaTags

View File

@@ -759,7 +759,7 @@ public sealed class MediaDumpViewModel : ViewModelBase
Encoding encoding = null;
if(!(SelectedEncoding is null))
if(SelectedEncoding is not null)
try
{
encoding = Claunia.Encoding.Encoding.GetEncoding(SelectedEncoding.Name);

View File

@@ -131,7 +131,7 @@ public sealed partial class BlindWrite5
_mode2A[1] -= 2;
var decoded2A = ModePage_2A.Decode(_mode2A);
if(!(decoded2A is null))
if(decoded2A is not null)
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "mode page 2A: {0}",
Modes.PrettifyModePage_2A(decoded2A));
else

View File

@@ -86,7 +86,7 @@ sealed class ListNamespacesCommand : Command
PluginBase plugins = GetPluginBase.Instance;
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in
plugins.ReadOnlyFilesystems.Where(kvp => !(kvp.Value.Namespaces is null)))
plugins.ReadOnlyFilesystems.Where(kvp => kvp.Value.Namespaces is not null))
{
Table table = new()
{