diff --git a/NAPS2.App.Tests/Appium/LanguageSelectionTests.cs b/NAPS2.App.Tests/Appium/LanguageSelectionTests.cs index a95c84c9f..88b0f67b0 100644 --- a/NAPS2.App.Tests/Appium/LanguageSelectionTests.cs +++ b/NAPS2.App.Tests/Appium/LanguageSelectionTests.cs @@ -11,7 +11,7 @@ namespace NAPS2.App.Tests.Appium; [Collection("appium")] public class LanguageSelectionTests : AppiumTests { - private static readonly HashSet ExpectedMissingLanguages = new() { "bn", "hi", "id", "th", "ur" }; + private static readonly HashSet ExpectedMissingLanguages = ["bn", "hi", "id", "th", "ur"]; [VerifyTheory(AllowDebug = true, WindowsAppium = true)] [ClassData(typeof(AppiumTestData))] diff --git a/NAPS2.Images.Gtk/GtkImage.cs b/NAPS2.Images.Gtk/GtkImage.cs index 93149b25e..83e111c65 100644 --- a/NAPS2.Images.Gtk/GtkImage.cs +++ b/NAPS2.Images.Gtk/GtkImage.cs @@ -78,7 +78,7 @@ public class GtkImage : IMemoryImage } if (imageFormat == ImageFileFormat.Tiff) { - ((GtkImageContext) ImageContext).TiffIo.SaveTiff(new List { this }, path); + ((GtkImageContext) ImageContext).TiffIo.SaveTiff([this], path); return; } ImageContext.CheckSupportsFormat(imageFormat); @@ -97,7 +97,7 @@ public class GtkImage : IMemoryImage } if (imageFormat == ImageFileFormat.Tiff) { - ((GtkImageContext) ImageContext).TiffIo.SaveTiff(new List { this }, stream); + ((GtkImageContext) ImageContext).TiffIo.SaveTiff([this], stream); return; } ImageContext.CheckSupportsFormat(imageFormat); diff --git a/NAPS2.Internals/Serialization/XmlSerializer.cs b/NAPS2.Internals/Serialization/XmlSerializer.cs index a3f97c503..7dfb67007 100644 --- a/NAPS2.Internals/Serialization/XmlSerializer.cs +++ b/NAPS2.Internals/Serialization/XmlSerializer.cs @@ -18,13 +18,13 @@ public abstract class XmlSerializer protected static readonly Dictionary> CustomTypesCache = new(); - protected static readonly List ArrayLikeTypes = new() - { + protected static readonly List ArrayLikeTypes = + [ typeof(List<>), typeof(HashSet<>), typeof(ImmutableList<>), - typeof(ImmutableHashSet<>), - }; + typeof(ImmutableHashSet<>) + ]; protected static readonly Dictionary TypeInfoCache = new() { @@ -79,7 +79,7 @@ public abstract class XmlSerializer { lock (TypeInfoCache) { - CustomTypesCache.GetOrSet(type, new List()).Add(customTypes); + CustomTypesCache.GetOrSet(type, []).Add(customTypes); } } diff --git a/NAPS2.Internals/Threading/AsyncSink.cs b/NAPS2.Internals/Threading/AsyncSink.cs index 6f0e6bfb2..fa2e0b198 100644 --- a/NAPS2.Internals/Threading/AsyncSink.cs +++ b/NAPS2.Internals/Threading/AsyncSink.cs @@ -5,10 +5,7 @@ public class AsyncSink where T : class { private static TaskCompletionSource CreateTcs() => new(TaskCreationOptions.RunContinuationsAsynchronously); - private readonly List> _items = new() - { - CreateTcs() - }; + private readonly List> _items = [CreateTcs()]; private bool _completed; public async IAsyncEnumerable AsAsyncEnumerable() diff --git a/NAPS2.Internals/Threading/SmoothProgress.cs b/NAPS2.Internals/Threading/SmoothProgress.cs index cc6dc17cf..7b994a1f5 100644 --- a/NAPS2.Internals/Threading/SmoothProgress.cs +++ b/NAPS2.Internals/Threading/SmoothProgress.cs @@ -39,9 +39,9 @@ public class SmoothProgress : IDisposable _stopwatch = Stopwatch.StartNew(); - _previousInputPos = new LinkedList(); + _previousInputPos = []; _previousInputPos.AddLast(0); - _previousInputTimes = new LinkedList(); + _previousInputTimes = []; _previousInputTimes.AddLast(0); } } diff --git a/NAPS2.Internals/Util/CollectionExtensions.cs b/NAPS2.Internals/Util/CollectionExtensions.cs index 4e08bd05f..243e40bda 100644 --- a/NAPS2.Internals/Util/CollectionExtensions.cs +++ b/NAPS2.Internals/Util/CollectionExtensions.cs @@ -13,7 +13,7 @@ public static class CollectionExtensions /// public static HashSet ToHashSet(this IEnumerable enumerable) { - return new HashSet(enumerable); + return [..enumerable]; } #endif @@ -134,7 +134,7 @@ public static class CollectionExtensions { if (!dict.ContainsKey(key)) { - dict[key] = new HashSet(); + dict[key] = []; } dict[key].Add(value); } @@ -152,7 +152,7 @@ public static class CollectionExtensions { if (!dict.ContainsKey(key)) { - dict[key] = new HashSet(); + dict[key] = []; } foreach (var value in values) { diff --git a/NAPS2.Internals/Util/DisposableSet.cs b/NAPS2.Internals/Util/DisposableSet.cs index 714a93aaa..95d0a6938 100644 --- a/NAPS2.Internals/Util/DisposableSet.cs +++ b/NAPS2.Internals/Util/DisposableSet.cs @@ -2,7 +2,7 @@ namespace NAPS2.Util; public class DisposableSet : IDisposable where T : IDisposable { - private readonly HashSet _set = new(); + private readonly HashSet _set = []; public void Add(T obj) { diff --git a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs index 3c135e56b..bb2c48f2b 100644 --- a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs +++ b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs @@ -24,7 +24,7 @@ public class GtkListView : IListView where T : notnull private bool _refreshing; private readonly ScrolledWindow _scrolledWindow; private readonly FlowBox _flowBox; - private List _entries = new(); + private List _entries = []; public GtkListView(ListViewBehavior behavior) { diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/ListViewDataSource.cs b/NAPS2.Lib.Mac/EtoForms/Mac/ListViewDataSource.cs index a0b92ebea..441a46341 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/ListViewDataSource.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/ListViewDataSource.cs @@ -18,7 +18,7 @@ public class ListViewDataSource : NSCollectionViewDataSource where T : notnul _itemActivated = itemActivated; } - public List Items { get; } = new(); + public List Items { get; } = []; public override nint GetNumberofItems(NSCollectionView collectionView, nint section) { diff --git a/NAPS2.Lib.Mac/EtoForms/Ui/MacDesktopForm.cs b/NAPS2.Lib.Mac/EtoForms/Ui/MacDesktopForm.cs index dde1d14bf..db7fe0960 100644 --- a/NAPS2.Lib.Mac/EtoForms/Ui/MacDesktopForm.cs +++ b/NAPS2.Lib.Mac/EtoForms/Ui/MacDesktopForm.cs @@ -186,8 +186,8 @@ public class MacDesktopForm : DesktopForm private List CreateMacToolbarItems() { - return new List - { + return + [ MacToolbarItems.Create("scan", Commands.Scan), MacToolbarItems.Create("profiles", Commands.Profiles), MacToolbarItems.CreateSpace(), @@ -214,7 +214,7 @@ public class MacDesktopForm : DesktopForm #pragma warning restore CA1422 #pragma warning restore CA1416 } - }; + ]; } protected override LayoutElement GetZoomButtons() => C.Spacer(); diff --git a/NAPS2.Lib.Mac/EtoForms/Ui/MacPreviewForm.cs b/NAPS2.Lib.Mac/EtoForms/Ui/MacPreviewForm.cs index 8d798c688..6ae9323d2 100644 --- a/NAPS2.Lib.Mac/EtoForms/Ui/MacPreviewForm.cs +++ b/NAPS2.Lib.Mac/EtoForms/Ui/MacPreviewForm.cs @@ -50,8 +50,8 @@ public class MacPreviewForm : PreviewForm private List CreateMacToolbarItems() { - return new List - { + return + [ MacToolbarItems.Create("prev", GoToPrevCommand, nav: true), MacToolbarItems.Create("next", GoToNextCommand, nav: true), MacToolbarItems.CreateMenu("rotate", Commands.RotateMenu, new MenuProvider() @@ -81,7 +81,7 @@ public class MacPreviewForm : PreviewForm #pragma warning restore CA1422 #pragma warning restore CA1416 } - }; + ]; } private void ZoomUpdated(NSSlider sender) diff --git a/NAPS2.Lib.Tests/Dependencies/DownloadControllerTests.cs b/NAPS2.Lib.Tests/Dependencies/DownloadControllerTests.cs index ce68c3ee5..91912b71e 100644 --- a/NAPS2.Lib.Tests/Dependencies/DownloadControllerTests.cs +++ b/NAPS2.Lib.Tests/Dependencies/DownloadControllerTests.cs @@ -54,7 +54,7 @@ public class DownloadControllerTests : ContextualTests [Fact] public async void NoUrl() { - DownloadInfo info = new("", new List(), 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip); + DownloadInfo info = new("", [], 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip); var mockHandler = Substitute.For>(); @@ -75,7 +75,7 @@ public class DownloadControllerTests : ContextualTests _controller.DownloadError += mockHandler; - _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List() { new DownloadMirror(DummyValidUrl) }, 0, "THIS IS NOT AN SHA1 AND WILL FAIL", DownloadFormat.Gzip)); + _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", [new DownloadMirror(DummyValidUrl)], 0, "THIS IS NOT AN SHA1 AND WILL FAIL", DownloadFormat.Gzip)); _controller.QueueFile(_mockComponent); Assert.False(await _controller.StartDownloadsAsync()); @@ -90,7 +90,8 @@ public class DownloadControllerTests : ContextualTests [Fact] public async void InvalidMirrorsChecksum() { - _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List() { new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip)); + _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", + [new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip)); _httpHandler.Expect(DummyInvalidUrl).Respond("application/zip", _animalsZipStream); _httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream); @@ -110,7 +111,7 @@ public class DownloadControllerTests : ContextualTests [Fact] public async void Valid() { - _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List() { new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip)); + _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", [new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip)); _httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream); @@ -129,7 +130,8 @@ public class DownloadControllerTests : ContextualTests [Fact] public async void ValidUsingMirrorUrl() { - _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List() { new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip)); + _mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", + [new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip)); _httpHandler.Expect(DummyInvalidUrl); _httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream); diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsImageList.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsImageList.cs index fc06ea4c5..c1a79d6d1 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsImageList.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsImageList.cs @@ -31,7 +31,7 @@ public abstract class WinFormsImageList where T : notnull public class Custom : WinFormsImageList { - private readonly List _images = new(); + private readonly List _images = []; public Custom(WinFormsListView listView, ListViewBehavior behavior) : base(listView, behavior) { diff --git a/NAPS2.Lib.WinForms/ImportExport/PrintDocumentPrinter.cs b/NAPS2.Lib.WinForms/ImportExport/PrintDocumentPrinter.cs index 5b62280b6..d68a5d390 100644 --- a/NAPS2.Lib.WinForms/ImportExport/PrintDocumentPrinter.cs +++ b/NAPS2.Lib.WinForms/ImportExport/PrintDocumentPrinter.cs @@ -53,7 +53,7 @@ public class PrintDocumentPrinter : IScannedImagePrinter imagesToPrint = images.Skip(start).Take(length).ToList(); break; default: - imagesToPrint = new List(); + imagesToPrint = []; break; } if (imagesToPrint.Count == 0) diff --git a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs index 81f93f736..e84c4613a 100644 --- a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs +++ b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs @@ -88,7 +88,7 @@ internal static class TwainApi _settings = settings; _tw = tw; _form = form; - Bitmaps = new List(); + Bitmaps = []; form.Activated += FTwainGui_Activated; } diff --git a/NAPS2.Lib/Automation/AutomatedScanning.cs b/NAPS2.Lib/Automation/AutomatedScanning.cs index f9f7c389f..df5e60b97 100644 --- a/NAPS2.Lib/Automation/AutomatedScanning.cs +++ b/NAPS2.Lib/Automation/AutomatedScanning.cs @@ -96,7 +96,7 @@ public class AutomatedScanning return; } - _scanList = new List>(); + _scanList = []; if (_options.ImportPath != null) { @@ -571,7 +571,7 @@ public class AutomatedScanning _config.Run.Set(c => c.PdfSettings.Compat, compat); int scanIndex = 0; - _actualOutputPaths = new List(); + _actualOutputPaths = []; foreach (var fileContents in _scanList) { var op = _operationFactory.Create(); @@ -625,7 +625,7 @@ public class AutomatedScanning } OutputVerbose(ConsoleResources.StartingScan, i, _options.Number); _pagesScanned = 0; - _scanList.Add(new List()); + _scanList.Add([]); var scanParams = new ScanParams { NoUI = !_options.Progress, diff --git a/NAPS2.Lib/Config/StubProfileManager.cs b/NAPS2.Lib/Config/StubProfileManager.cs index a5cebb02a..5cf56300d 100644 --- a/NAPS2.Lib/Config/StubProfileManager.cs +++ b/NAPS2.Lib/Config/StubProfileManager.cs @@ -5,7 +5,7 @@ namespace NAPS2.Config; public class StubProfileManager : IProfileManager { - private readonly List _profiles = new List(); + private readonly List _profiles = []; public ImmutableList Profiles => ImmutableList.CreateRange(_profiles); diff --git a/NAPS2.Lib/EtoForms/EtoOperationProgress.cs b/NAPS2.Lib/EtoForms/EtoOperationProgress.cs index 2a853c3a1..e5563010c 100644 --- a/NAPS2.Lib/EtoForms/EtoOperationProgress.cs +++ b/NAPS2.Lib/EtoForms/EtoOperationProgress.cs @@ -10,7 +10,7 @@ public class EtoOperationProgress : OperationProgress private readonly INotify _notify; private readonly Naps2Config _config; - private readonly HashSet _activeOperations = new(); + private readonly HashSet _activeOperations = []; public EtoOperationProgress(IFormFactory formFactory, INotify notify, Naps2Config config) { diff --git a/NAPS2.Lib/EtoForms/Layout/LayoutLine.cs b/NAPS2.Lib/EtoForms/Layout/LayoutLine.cs index bff8ab181..044d77d22 100644 --- a/NAPS2.Lib/EtoForms/Layout/LayoutLine.cs +++ b/NAPS2.Lib/EtoForms/Layout/LayoutLine.cs @@ -145,8 +145,8 @@ public abstract class LayoutLine : LayoutContainer } // If we aren't aligned or we don't have a parent to do that pre-calculation, then we just determine our cell // sizes and scaling directly without any special alignment constraints. - cellLengths = new List(); - cellScaling = new List(); + cellLengths = []; + cellScaling = []; var lengthChildContext = childContext with { IsCellLengthQuery = true }; foreach (var child in Children) { diff --git a/NAPS2.Lib/EtoForms/MenuProvider.cs b/NAPS2.Lib/EtoForms/MenuProvider.cs index ea55a8c11..7fcc5df75 100644 --- a/NAPS2.Lib/EtoForms/MenuProvider.cs +++ b/NAPS2.Lib/EtoForms/MenuProvider.cs @@ -4,7 +4,7 @@ namespace NAPS2.EtoForms; public class MenuProvider { - private readonly List _items = new(); + private readonly List _items = []; public MenuProvider Dynamic(ListProvider commandListProvider) { diff --git a/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs b/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs index c1767e47f..b5f9fe15b 100644 --- a/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs +++ b/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs @@ -7,7 +7,7 @@ public class NotificationManager ColorScheme = colorScheme; } - public List Notifications { get; } = new(); + public List Notifications { get; } = []; public ColorScheme ColorScheme { get; } diff --git a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs index 33e37321f..8036f54f5 100644 --- a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs @@ -153,8 +153,8 @@ public abstract class DesktopForm : EtoFormBase { // TODO: Remove icon from delete command somehow // TODO: Is this memory leaking (because of event handlers) when commands are converted to menuitems? - _contextMenu.Items.AddRange(new List - { + _contextMenu.Items.AddRange( + [ Commands.ViewImage, new SeparatorMenuItem(), Commands.SelectAll, @@ -162,15 +162,15 @@ public abstract class DesktopForm : EtoFormBase Commands.Paste, new SeparatorMenuItem(), Commands.Delete - }); + ]); } else { - _contextMenu.Items.AddRange(new List - { + _contextMenu.Items.AddRange( + [ Commands.SelectAll, Commands.Paste - }); + ]); } } diff --git a/NAPS2.Lib/EtoForms/Ui/OcrDownloadForm.cs b/NAPS2.Lib/EtoForms/Ui/OcrDownloadForm.cs index 768b6e29c..c9f1cbee9 100644 --- a/NAPS2.Lib/EtoForms/Ui/OcrDownloadForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/OcrDownloadForm.cs @@ -77,7 +77,7 @@ public class OcrDownloadForm : EtoDialogBase private HashSet SelectedLanguageComponents { - get { return new HashSet(_languageList.Selection.Select(lang => $"ocr-{lang.Code}")); } + get { return [.._languageList.Selection.Select(lang => $"ocr-{lang.Code}")]; } } private void Download() diff --git a/NAPS2.Lib/EtoForms/Ui/PdfSettingsForm.cs b/NAPS2.Lib/EtoForms/Ui/PdfSettingsForm.cs index bd22eec84..3c05ec300 100644 --- a/NAPS2.Lib/EtoForms/Ui/PdfSettingsForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/PdfSettingsForm.cs @@ -21,8 +21,8 @@ public class PdfSettingsForm : EtoDialogBase private readonly CheckBox _rememberSettings = new() { Text = UiStrings.RememberTheseSettings }; private readonly Button _restoreDefaults = new() { Text = UiStrings.RestoreDefaults }; - private readonly List _permissions = new() - { + private readonly List _permissions = + [ new CheckBox { Text = UiStrings.AllowPrinting }, new CheckBox { Text = UiStrings.AllowFullQualityPrinting }, new CheckBox { Text = UiStrings.AllowDocumentModification }, @@ -31,7 +31,7 @@ public class PdfSettingsForm : EtoDialogBase new CheckBox { Text = UiStrings.AllowContentCopyingForAccessibility }, new CheckBox { Text = UiStrings.AllowAnnotations }, new CheckBox { Text = UiStrings.AllowFormFilling } - }; + ]; private readonly DropDown _compat = C.EnumDropDown(compat => compat switch { diff --git a/NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs b/NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs index 370615b3d..4a2dff546 100644 --- a/NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs @@ -11,7 +11,7 @@ public class SelectDeviceForm : EtoDialogBase private readonly ErrorOutput _errorOutput; private readonly ListBox _devices = new(); private readonly Button _selectDevice; - private readonly List _lazyDeviceList = new(); + private readonly List _lazyDeviceList = []; // TODO: The spinner doesn't seem to animate on WinForms private readonly Spinner _spinner = new() { Enabled = true }; diff --git a/NAPS2.Lib/Images/ImageListDiffer.cs b/NAPS2.Lib/Images/ImageListDiffer.cs index 6dd561783..f4dbaa322 100644 --- a/NAPS2.Lib/Images/ImageListDiffer.cs +++ b/NAPS2.Lib/Images/ImageListDiffer.cs @@ -12,7 +12,7 @@ using TrimOperation = ListViewDiffs.TrimOperation; public class ImageListDiffer { private readonly UiImageList _imageList; - private List _currentState = new(); + private List _currentState = []; public ImageListDiffer(UiImageList imageList) { diff --git a/NAPS2.Lib/Images/UiImageList.cs b/NAPS2.Lib/Images/UiImageList.cs index 5d7bd3530..24838756b 100644 --- a/NAPS2.Lib/Images/UiImageList.cs +++ b/NAPS2.Lib/Images/UiImageList.cs @@ -8,7 +8,7 @@ public class UiImageList private ListSelection _selection; private StateToken _savedState = new(ImmutableList.Empty); - public UiImageList() : this(new List()) + public UiImageList() : this([]) { } diff --git a/NAPS2.Lib/Images/UndoStack.cs b/NAPS2.Lib/Images/UndoStack.cs index d8a01219c..4199fbf0a 100644 --- a/NAPS2.Lib/Images/UndoStack.cs +++ b/NAPS2.Lib/Images/UndoStack.cs @@ -12,7 +12,7 @@ public class UndoStack : IDisposable public UndoStack(int maxLength) { _maxLength = maxLength; - _stack = new LinkedList(); + _stack = []; _stack.AddFirst(Memento.Empty); _current = _stack.First!; } diff --git a/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs b/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs index 301336b40..eeba0d843 100644 --- a/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs +++ b/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs @@ -47,7 +47,7 @@ internal static class SaveSeparatorHelper if (images.Count > 0) { yield return images; - images = new List(); + images = []; } } else diff --git a/NAPS2.Lib/Ocr/OcrOperationManager.cs b/NAPS2.Lib/Ocr/OcrOperationManager.cs index 7c536d953..565efa823 100644 --- a/NAPS2.Lib/Ocr/OcrOperationManager.cs +++ b/NAPS2.Lib/Ocr/OcrOperationManager.cs @@ -48,7 +48,7 @@ public class OcrOperationManager } op = _currentOp; op.Status.MaxProgress += 1; - _ongoingTasks.GetOrSet((OcrController) sender!, () => new HashSet()).Add(e.ResultTask); + _ongoingTasks.GetOrSet((OcrController) sender!, () => []).Add(e.ResultTask); } op.InvokeStatusChanged(); if (newOp) diff --git a/NAPS2.Lib/Ocr/TesseractLanguageManager.cs b/NAPS2.Lib/Ocr/TesseractLanguageManager.cs index b9f56d002..647cdb29c 100644 --- a/NAPS2.Lib/Ocr/TesseractLanguageManager.cs +++ b/NAPS2.Lib/Ocr/TesseractLanguageManager.cs @@ -4,11 +4,11 @@ namespace NAPS2.Ocr; public class TesseractLanguageManager { - private static readonly List Mirrors = new() - { + private static readonly List Mirrors = + [ new(@"https://github.com/cyanfish/naps2-components/releases/download/tesseract-4.0.0b4/{0}"), new(@"https://sourceforge.net/projects/naps2/files/components/tesseract-4.0.0b4/{0}/download") - }; + ]; private readonly TesseractLanguageData _languageData = TesseractLanguageData.Latest; diff --git a/NAPS2.Lib/Recovery/RecoveryIndex.cs b/NAPS2.Lib/Recovery/RecoveryIndex.cs index a097c037d..a3e65db1c 100644 --- a/NAPS2.Lib/Recovery/RecoveryIndex.cs +++ b/NAPS2.Lib/Recovery/RecoveryIndex.cs @@ -8,7 +8,7 @@ public class RecoveryIndex public RecoveryIndex() { - Images = new List(); + Images = []; } public int Version { get; set; } diff --git a/NAPS2.Lib/Scan/Batch/BatchScanPerformer.cs b/NAPS2.Lib/Scan/Batch/BatchScanPerformer.cs index 523cd0507..5d95afb32 100644 --- a/NAPS2.Lib/Scan/Batch/BatchScanPerformer.cs +++ b/NAPS2.Lib/Scan/Batch/BatchScanPerformer.cs @@ -93,7 +93,7 @@ public class BatchScanPerformer : IBatchScanPerformer OcrCancelToken = _cancelToken, ThumbnailSize = thumbnailController.RenderSize }; - _scans = new List>(); + _scans = []; } public async Task Do() diff --git a/NAPS2.Sdk.Tests/Asserts/ImageAsserts.cs b/NAPS2.Sdk.Tests/Asserts/ImageAsserts.cs index bb7f7d670..64a2a619f 100644 --- a/NAPS2.Sdk.Tests/Asserts/ImageAsserts.cs +++ b/NAPS2.Sdk.Tests/Asserts/ImageAsserts.cs @@ -144,7 +144,7 @@ public static class ImageAsserts public class PixelColorData : IEnumerable<((int x, int y), (int r, int g, int b))> { - private readonly List<((int x, int y), (int r, int g, int b))> _colors = new(); + private readonly List<((int x, int y), (int r, int g, int b))> _colors = []; public void Add((int x, int y) pos, (int r, int g, int b) color) { diff --git a/NAPS2.Sdk.Tests/Images/BlankDetectorTests.cs b/NAPS2.Sdk.Tests/Images/BlankDetectorTests.cs index bd01f18d1..a9459659c 100644 --- a/NAPS2.Sdk.Tests/Images/BlankDetectorTests.cs +++ b/NAPS2.Sdk.Tests/Images/BlankDetectorTests.cs @@ -48,11 +48,11 @@ public class BlankDetectorTests : ContextualTests return image.CopyWithPixelFormat(pixelFormat); } - public static IEnumerable TestCases = new List - { + public static IEnumerable TestCases = + [ new object[] { ImagePixelFormat.ARGB32 }, new object[] { ImagePixelFormat.RGB24 }, new object[] { ImagePixelFormat.Gray8 }, new object[] { ImagePixelFormat.BW1 } - }; + ]; } \ No newline at end of file diff --git a/NAPS2.Sdk.Tests/Images/LoadSaveTests.cs b/NAPS2.Sdk.Tests/Images/LoadSaveTests.cs index 498ff2f65..bba027ca5 100644 --- a/NAPS2.Sdk.Tests/Images/LoadSaveTests.cs +++ b/NAPS2.Sdk.Tests/Images/LoadSaveTests.cs @@ -278,8 +278,8 @@ public class LoadSaveTests : ContextualTests (byte[]) ImageResources.ResourceManager.GetObject(resource, CultureInfo.InvariantCulture); // TODO: Ignore resolution by default in the existing tests, but have separate tests/test cases for resolution - public static IEnumerable TestCases = new List - { + public static IEnumerable TestCases = + [ new object[] { ImageFileFormat.Png, ".png", "dog_alpha", @@ -387,5 +387,5 @@ public class LoadSaveTests : ContextualTests new[] { ImagePixelFormat.RGB24, ImagePixelFormat.RGB24, ImagePixelFormat.RGB24 }, false }, #endif - }; + ]; } \ No newline at end of file diff --git a/NAPS2.Sdk.Tests/Images/TransformTests.cs b/NAPS2.Sdk.Tests/Images/TransformTests.cs index bb125a8de..42a0c283a 100644 --- a/NAPS2.Sdk.Tests/Images/TransformTests.cs +++ b/NAPS2.Sdk.Tests/Images/TransformTests.cs @@ -462,8 +462,8 @@ public class TransformTests : ContextualTests Assert.True(IsDisposed(original)); } - public static IEnumerable CommutativeGrayTransforms = new List - { + public static IEnumerable CommutativeGrayTransforms = + [ // Note that hue and saturation aren't commutative with grayscale as the the grayscale transform weighs each // color channel differently new object[] { new BrightnessTransform(300) }, @@ -472,5 +472,5 @@ public class TransformTests : ContextualTests new object[] { new RotationTransform(46) }, new object[] { new ThumbnailTransform() }, new object[] { new CropTransform(10, 10, 10, 10) } - }; + ]; } \ No newline at end of file diff --git a/NAPS2.Sdk.Tests/Mocks/StubScanBridge.cs b/NAPS2.Sdk.Tests/Mocks/StubScanBridge.cs index 2be1114b5..687612186 100644 --- a/NAPS2.Sdk.Tests/Mocks/StubScanBridge.cs +++ b/NAPS2.Sdk.Tests/Mocks/StubScanBridge.cs @@ -6,9 +6,9 @@ namespace NAPS2.Sdk.Tests.Mocks; internal class StubScanBridge : IScanBridge { - public List MockDevices { get; set; } = new(); + public List MockDevices { get; set; } = []; - public List MockOutput { get; set; } = new(); + public List MockOutput { get; set; } = []; public Exception Error { get; set; } diff --git a/NAPS2.Sdk.Tests/Scan/ScanErrorHandling.cs b/NAPS2.Sdk.Tests/Scan/ScanErrorHandling.cs index 8ac8547ab..4f9c568c6 100644 --- a/NAPS2.Sdk.Tests/Scan/ScanErrorHandling.cs +++ b/NAPS2.Sdk.Tests/Scan/ScanErrorHandling.cs @@ -81,7 +81,7 @@ public class ScanErrorHandling : ContextualTests public async void Scan_LocalPostProcess() { var localPostProcessor = Substitute.For(); - var bridge = new StubScanBridge { MockOutput = new List { CreateScannedImage() } }; + var bridge = new StubScanBridge { MockOutput = [CreateScannedImage()] }; var bridgeFactory = Substitute.For(); var controller = new ScanController(ScanningContext, localPostProcessor, new ScanOptionsValidator(), diff --git a/NAPS2.Sdk.Tests/Scan/TwainImageProcessorTests.cs b/NAPS2.Sdk.Tests/Scan/TwainImageProcessorTests.cs index 724a7dd30..e04b7a157 100644 --- a/NAPS2.Sdk.Tests/Scan/TwainImageProcessorTests.cs +++ b/NAPS2.Sdk.Tests/Scan/TwainImageProcessorTests.cs @@ -30,7 +30,7 @@ public class TwainImageProcessorTests : ContextualTests _scanEvents = Substitute.For(); _callback = Substitute.For>(); - _images = new List(); + _images = []; _callback.When(x => x(Arg.Any())) .Do(x => _images.Add((IMemoryImage) x[0])); diff --git a/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs b/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs index 93df497dd..078a57b53 100644 --- a/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs +++ b/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs @@ -88,11 +88,11 @@ public class WorkerChannelTests : ContextualTests { var remoteScanController = new MockRemoteScanController { - Images = new List - { + Images = + [ CreateScannedImage(), CreateScannedImage() - } + ] }; using var channel = Start(remoteScanController); @@ -113,11 +113,11 @@ public class WorkerChannelTests : ContextualTests { var remoteScanController = new MockRemoteScanController { - Images = new List - { + Images = + [ CreateScannedImage(), CreateScannedImage() - }, + ], Exception = new DeviceException("Test error") }; using var channel = Start(remoteScanController); @@ -161,7 +161,7 @@ public class WorkerChannelTests : ContextualTests private class MockRemoteScanController : IRemoteScanController { - public List Images { get; set; } = new(); + public List Images { get; set; } = []; public Exception Exception { get; set; } diff --git a/NAPS2.Sdk/ImportExport/Email/EmailMessage.cs b/NAPS2.Sdk/ImportExport/Email/EmailMessage.cs index d680f4806..fc6602c42 100644 --- a/NAPS2.Sdk/ImportExport/Email/EmailMessage.cs +++ b/NAPS2.Sdk/ImportExport/Email/EmailMessage.cs @@ -2,19 +2,13 @@ public class EmailMessage { - public EmailMessage() - { - Recipients = new List(); - Attachments = new List(); - } - public string? Subject { get; set; } public string? BodyText { get; set; } - public List Recipients { get; set; } + public List Recipients { get; set; } = []; - public List Attachments { get; set; } + public List Attachments { get; set; } = []; /// /// Gets or sets a value indicating whether the email should be sent automatically without prompting the user to make changes first. diff --git a/NAPS2.Sdk/Ocr/OcrRequestQueue.cs b/NAPS2.Sdk/Ocr/OcrRequestQueue.cs index 40e777989..37dbdee0c 100644 --- a/NAPS2.Sdk/Ocr/OcrRequestQueue.cs +++ b/NAPS2.Sdk/Ocr/OcrRequestQueue.cs @@ -13,7 +13,7 @@ internal class OcrRequestQueue { private readonly Dictionary _requestCache = new(); private Semaphore _queueWaitHandle = new(0, int.MaxValue); - private List _workerTasks = new(); + private List _workerTasks = []; private CancellationTokenSource _workerCts = new(); /// @@ -94,7 +94,7 @@ internal class OcrRequestQueue if (_workerTasks.Count > 0 && !hasPending) { _workerCts.Cancel(); - _workerTasks = new List(); + _workerTasks = []; _workerCts = new CancellationTokenSource(); _queueWaitHandle = new Semaphore(0, int.MaxValue); } diff --git a/NAPS2.Sdk/Pdf/PdfExporter.cs b/NAPS2.Sdk/Pdf/PdfExporter.cs index 0dcee6137..4b874668b 100644 --- a/NAPS2.Sdk/Pdf/PdfExporter.cs +++ b/NAPS2.Sdk/Pdf/PdfExporter.cs @@ -457,7 +457,7 @@ public class PdfExporter : IPdfExporter private static string ReverseText(string text) { TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(text); - List elements = new List(); + var elements = new List(); while (enumerator.MoveNext()) { elements.Add(enumerator.GetTextElement()); diff --git a/NAPS2.Sdk/Remoting/Server/ScanJob.cs b/NAPS2.Sdk/Remoting/Server/ScanJob.cs index 5cff21b10..dd1b9c06c 100644 --- a/NAPS2.Sdk/Remoting/Server/ScanJob.cs +++ b/NAPS2.Sdk/Remoting/Server/ScanJob.cs @@ -99,7 +99,7 @@ internal class ScanJob : IEsclScanJob if (ContentType == "application/pdf") { var pdfExporter = new PdfExporter(_scanningContext); - await pdfExporter.Export(stream, new List { _enumerable.Current }); + await pdfExporter.Export(stream, [_enumerable.Current]); } } diff --git a/NAPS2.Sdk/Scan/BarcodeDetector.cs b/NAPS2.Sdk/Scan/BarcodeDetector.cs index d86ab2382..8ee54e0c9 100644 --- a/NAPS2.Sdk/Scan/BarcodeDetector.cs +++ b/NAPS2.Sdk/Scan/BarcodeDetector.cs @@ -23,7 +23,7 @@ internal static class BarcodeDetector var zxingOptions = options.ZXingOptions ?? new DecodingOptions { TryHarder = true, - PossibleFormats = options.PatchTOnly ? new List { PATCH_T_FORMAT } : null + PossibleFormats = options.PatchTOnly ? [PATCH_T_FORMAT] : null }; var reader = new BarcodeReader(x => new MemoryImageLuminanceSource(x)) { diff --git a/NAPS2.Tools/Localization/TranslatableString.cs b/NAPS2.Tools/Localization/TranslatableString.cs index 5e974bbf2..0d8a88153 100644 --- a/NAPS2.Tools/Localization/TranslatableString.cs +++ b/NAPS2.Tools/Localization/TranslatableString.cs @@ -12,5 +12,5 @@ public class TranslatableString public string? Translation { get; } - public List Context { get; } = new List(); + public List Context { get; } = []; } \ No newline at end of file diff --git a/NAPS2.Tools/Program.cs b/NAPS2.Tools/Program.cs index c8de9d98f..1977c5bb9 100644 --- a/NAPS2.Tools/Program.cs +++ b/NAPS2.Tools/Program.cs @@ -59,7 +59,7 @@ public static class Program public class CommandList { - private readonly List _optionTypes = new(); + private readonly List _optionTypes = []; private readonly Dictionary _optionTypeToCommandType = new(); public CommandList Add() where TOption : OptionsBase where TCommand : ICommand diff --git a/NAPS2.Tools/Project/Packaging/PackageInfo.cs b/NAPS2.Tools/Project/Packaging/PackageInfo.cs index 3bbc2fdf7..1d33c5917 100644 --- a/NAPS2.Tools/Project/Packaging/PackageInfo.cs +++ b/NAPS2.Tools/Project/Packaging/PackageInfo.cs @@ -4,8 +4,8 @@ namespace NAPS2.Tools.Project.Packaging; public class PackageInfo { - private readonly List _files = new(); - private readonly HashSet _destPaths = new(); + private readonly List _files = []; + private readonly HashSet _destPaths = []; public PackageInfo(Platform platform, string versionName, string versionNumber, string? packageName) { @@ -30,7 +30,7 @@ public class PackageInfo public IEnumerable Files => _files; - public HashSet Languages { get; } = new(); + public HashSet Languages { get; } = []; public void AddFile(FileInfo file, string destFolder, string? destFileName = null) {