mirror of
https://github.com/cyanfish/naps2.git
synced 2024-07-14 18:40:39 +03:00
C# 12: Use collection initializers
This commit is contained in:
parent
6976d5c165
commit
b92362af02
@ -11,7 +11,7 @@ namespace NAPS2.App.Tests.Appium;
|
||||
[Collection("appium")]
|
||||
public class LanguageSelectionTests : AppiumTests
|
||||
{
|
||||
private static readonly HashSet<string> ExpectedMissingLanguages = new() { "bn", "hi", "id", "th", "ur" };
|
||||
private static readonly HashSet<string> ExpectedMissingLanguages = ["bn", "hi", "id", "th", "ur"];
|
||||
|
||||
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
|
||||
[ClassData(typeof(AppiumTestData))]
|
||||
|
@ -78,7 +78,7 @@ public class GtkImage : IMemoryImage
|
||||
}
|
||||
if (imageFormat == ImageFileFormat.Tiff)
|
||||
{
|
||||
((GtkImageContext) ImageContext).TiffIo.SaveTiff(new List<IMemoryImage> { 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<IMemoryImage> { this }, stream);
|
||||
((GtkImageContext) ImageContext).TiffIo.SaveTiff([this], stream);
|
||||
return;
|
||||
}
|
||||
ImageContext.CheckSupportsFormat(imageFormat);
|
||||
|
@ -18,13 +18,13 @@ public abstract class XmlSerializer
|
||||
|
||||
protected static readonly Dictionary<Type, List<CustomXmlTypes>> CustomTypesCache = new();
|
||||
|
||||
protected static readonly List<Type> ArrayLikeTypes = new()
|
||||
{
|
||||
protected static readonly List<Type> ArrayLikeTypes =
|
||||
[
|
||||
typeof(List<>),
|
||||
typeof(HashSet<>),
|
||||
typeof(ImmutableList<>),
|
||||
typeof(ImmutableHashSet<>),
|
||||
};
|
||||
typeof(ImmutableHashSet<>)
|
||||
];
|
||||
|
||||
protected static readonly Dictionary<Type, XmlTypeInfo> TypeInfoCache = new()
|
||||
{
|
||||
@ -79,7 +79,7 @@ public abstract class XmlSerializer
|
||||
{
|
||||
lock (TypeInfoCache)
|
||||
{
|
||||
CustomTypesCache.GetOrSet(type, new List<CustomXmlTypes>()).Add(customTypes);
|
||||
CustomTypesCache.GetOrSet(type, []).Add(customTypes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,7 @@ public class AsyncSink<T> where T : class
|
||||
{
|
||||
private static TaskCompletionSource<T?> CreateTcs() => new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
private readonly List<TaskCompletionSource<T?>> _items = new()
|
||||
{
|
||||
CreateTcs()
|
||||
};
|
||||
private readonly List<TaskCompletionSource<T?>> _items = [CreateTcs()];
|
||||
private bool _completed;
|
||||
|
||||
public async IAsyncEnumerable<T> AsAsyncEnumerable()
|
||||
|
@ -39,9 +39,9 @@ public class SmoothProgress : IDisposable
|
||||
|
||||
_stopwatch = Stopwatch.StartNew();
|
||||
|
||||
_previousInputPos = new LinkedList<double>();
|
||||
_previousInputPos = [];
|
||||
_previousInputPos.AddLast(0);
|
||||
_previousInputTimes = new LinkedList<long>();
|
||||
_previousInputTimes = [];
|
||||
_previousInputTimes.AddLast(0);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public static class CollectionExtensions
|
||||
/// <returns></returns>
|
||||
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> enumerable)
|
||||
{
|
||||
return new HashSet<T>(enumerable);
|
||||
return [..enumerable];
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -134,7 +134,7 @@ public static class CollectionExtensions
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict[key] = new HashSet<TValue>();
|
||||
dict[key] = [];
|
||||
}
|
||||
dict[key].Add(value);
|
||||
}
|
||||
@ -152,7 +152,7 @@ public static class CollectionExtensions
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict[key] = new HashSet<TValue>();
|
||||
dict[key] = [];
|
||||
}
|
||||
foreach (var value in values)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@ namespace NAPS2.Util;
|
||||
|
||||
public class DisposableSet<T> : IDisposable where T : IDisposable
|
||||
{
|
||||
private readonly HashSet<T> _set = new();
|
||||
private readonly HashSet<T> _set = [];
|
||||
|
||||
public void Add(T obj)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ public class GtkListView<T> : IListView<T> where T : notnull
|
||||
private bool _refreshing;
|
||||
private readonly ScrolledWindow _scrolledWindow;
|
||||
private readonly FlowBox _flowBox;
|
||||
private List<Entry> _entries = new();
|
||||
private List<Entry> _entries = [];
|
||||
|
||||
public GtkListView(ListViewBehavior<T> behavior)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public class ListViewDataSource<T> : NSCollectionViewDataSource where T : notnul
|
||||
_itemActivated = itemActivated;
|
||||
}
|
||||
|
||||
public List<T> Items { get; } = new();
|
||||
public List<T> Items { get; } = [];
|
||||
|
||||
public override nint GetNumberofItems(NSCollectionView collectionView, nint section)
|
||||
{
|
||||
|
@ -186,8 +186,8 @@ public class MacDesktopForm : DesktopForm
|
||||
|
||||
private List<NSToolbarItem?> CreateMacToolbarItems()
|
||||
{
|
||||
return new List<NSToolbarItem?>
|
||||
{
|
||||
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();
|
||||
|
@ -50,8 +50,8 @@ public class MacPreviewForm : PreviewForm
|
||||
|
||||
private List<NSToolbarItem?> CreateMacToolbarItems()
|
||||
{
|
||||
return new List<NSToolbarItem?>
|
||||
{
|
||||
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)
|
||||
|
@ -54,7 +54,7 @@ public class DownloadControllerTests : ContextualTests
|
||||
[Fact]
|
||||
public async void NoUrl()
|
||||
{
|
||||
DownloadInfo info = new("", new List<DownloadMirror>(), 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip);
|
||||
DownloadInfo info = new("", [], 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip);
|
||||
|
||||
var mockHandler = Substitute.For<Action<string>>();
|
||||
|
||||
@ -75,7 +75,7 @@ public class DownloadControllerTests : ContextualTests
|
||||
|
||||
_controller.DownloadError += mockHandler;
|
||||
|
||||
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List<DownloadMirror>() { 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<DownloadMirror>() { 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<DownloadMirror>() { 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<DownloadMirror>() { 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);
|
||||
|
@ -31,7 +31,7 @@ public abstract class WinFormsImageList<T> where T : notnull
|
||||
|
||||
public class Custom : WinFormsImageList<T>
|
||||
{
|
||||
private readonly List<Image> _images = new();
|
||||
private readonly List<Image> _images = [];
|
||||
|
||||
public Custom(WinFormsListView<T> listView, ListViewBehavior<T> behavior) : base(listView, behavior)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ public class PrintDocumentPrinter : IScannedImagePrinter
|
||||
imagesToPrint = images.Skip(start).Take(length).ToList();
|
||||
break;
|
||||
default:
|
||||
imagesToPrint = new List<ProcessedImage>();
|
||||
imagesToPrint = [];
|
||||
break;
|
||||
}
|
||||
if (imagesToPrint.Count == 0)
|
||||
|
@ -88,7 +88,7 @@ internal static class TwainApi
|
||||
_settings = settings;
|
||||
_tw = tw;
|
||||
_form = form;
|
||||
Bitmaps = new List<IMemoryImage>();
|
||||
Bitmaps = [];
|
||||
form.Activated += FTwainGui_Activated;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class AutomatedScanning
|
||||
return;
|
||||
}
|
||||
|
||||
_scanList = new List<List<ProcessedImage>>();
|
||||
_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<string>();
|
||||
_actualOutputPaths = [];
|
||||
foreach (var fileContents in _scanList)
|
||||
{
|
||||
var op = _operationFactory.Create<SavePdfOperation>();
|
||||
@ -625,7 +625,7 @@ public class AutomatedScanning
|
||||
}
|
||||
OutputVerbose(ConsoleResources.StartingScan, i, _options.Number);
|
||||
_pagesScanned = 0;
|
||||
_scanList.Add(new List<ProcessedImage>());
|
||||
_scanList.Add([]);
|
||||
var scanParams = new ScanParams
|
||||
{
|
||||
NoUI = !_options.Progress,
|
||||
|
@ -5,7 +5,7 @@ namespace NAPS2.Config;
|
||||
|
||||
public class StubProfileManager : IProfileManager
|
||||
{
|
||||
private readonly List<ScanProfile> _profiles = new List<ScanProfile>();
|
||||
private readonly List<ScanProfile> _profiles = [];
|
||||
|
||||
public ImmutableList<ScanProfile> Profiles => ImmutableList.CreateRange(_profiles);
|
||||
|
||||
|
@ -10,7 +10,7 @@ public class EtoOperationProgress : OperationProgress
|
||||
private readonly INotify _notify;
|
||||
private readonly Naps2Config _config;
|
||||
|
||||
private readonly HashSet<IOperation> _activeOperations = new();
|
||||
private readonly HashSet<IOperation> _activeOperations = [];
|
||||
|
||||
public EtoOperationProgress(IFormFactory formFactory, INotify notify, Naps2Config config)
|
||||
{
|
||||
|
@ -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<float>();
|
||||
cellScaling = new List<bool>();
|
||||
cellLengths = [];
|
||||
cellScaling = [];
|
||||
var lengthChildContext = childContext with { IsCellLengthQuery = true };
|
||||
foreach (var child in Children)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ namespace NAPS2.EtoForms;
|
||||
|
||||
public class MenuProvider
|
||||
{
|
||||
private readonly List<Item> _items = new();
|
||||
private readonly List<Item> _items = [];
|
||||
|
||||
public MenuProvider Dynamic(ListProvider<Command> commandListProvider)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ public class NotificationManager
|
||||
ColorScheme = colorScheme;
|
||||
}
|
||||
|
||||
public List<NotificationModel> Notifications { get; } = new();
|
||||
public List<NotificationModel> Notifications { get; } = [];
|
||||
|
||||
public ColorScheme ColorScheme { get; }
|
||||
|
||||
|
@ -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<MenuItem>
|
||||
{
|
||||
_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<MenuItem>
|
||||
{
|
||||
_contextMenu.Items.AddRange(
|
||||
[
|
||||
Commands.SelectAll,
|
||||
Commands.Paste
|
||||
});
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class OcrDownloadForm : EtoDialogBase
|
||||
|
||||
private HashSet<string> SelectedLanguageComponents
|
||||
{
|
||||
get { return new HashSet<string>(_languageList.Selection.Select(lang => $"ocr-{lang.Code}")); }
|
||||
get { return [.._languageList.Selection.Select(lang => $"ocr-{lang.Code}")]; }
|
||||
}
|
||||
|
||||
private void Download()
|
||||
|
@ -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<CheckBox> _permissions = new()
|
||||
{
|
||||
private readonly List<CheckBox> _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<PdfCompat>(compat => compat switch
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ public class SelectDeviceForm : EtoDialogBase
|
||||
private readonly ErrorOutput _errorOutput;
|
||||
private readonly ListBox _devices = new();
|
||||
private readonly Button _selectDevice;
|
||||
private readonly List<ScanDevice> _lazyDeviceList = new();
|
||||
private readonly List<ScanDevice> _lazyDeviceList = [];
|
||||
// TODO: The spinner doesn't seem to animate on WinForms
|
||||
private readonly Spinner _spinner = new() { Enabled = true };
|
||||
|
||||
|
@ -12,7 +12,7 @@ using TrimOperation = ListViewDiffs<UiImage>.TrimOperation;
|
||||
public class ImageListDiffer
|
||||
{
|
||||
private readonly UiImageList _imageList;
|
||||
private List<ImageRenderState> _currentState = new();
|
||||
private List<ImageRenderState> _currentState = [];
|
||||
|
||||
public ImageListDiffer(UiImageList imageList)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ public class UiImageList
|
||||
private ListSelection<UiImage> _selection;
|
||||
private StateToken _savedState = new(ImmutableList<ProcessedImage.WeakReference>.Empty);
|
||||
|
||||
public UiImageList() : this(new List<UiImage>())
|
||||
public UiImageList() : this([])
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ public class UndoStack : IDisposable
|
||||
public UndoStack(int maxLength)
|
||||
{
|
||||
_maxLength = maxLength;
|
||||
_stack = new LinkedList<Memento>();
|
||||
_stack = [];
|
||||
_stack.AddFirst(Memento.Empty);
|
||||
_current = _stack.First!;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ internal static class SaveSeparatorHelper
|
||||
if (images.Count > 0)
|
||||
{
|
||||
yield return images;
|
||||
images = new List<ProcessedImage>();
|
||||
images = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -48,7 +48,7 @@ public class OcrOperationManager
|
||||
}
|
||||
op = _currentOp;
|
||||
op.Status.MaxProgress += 1;
|
||||
_ongoingTasks.GetOrSet((OcrController) sender!, () => new HashSet<Task>()).Add(e.ResultTask);
|
||||
_ongoingTasks.GetOrSet((OcrController) sender!, () => []).Add(e.ResultTask);
|
||||
}
|
||||
op.InvokeStatusChanged();
|
||||
if (newOp)
|
||||
|
@ -4,11 +4,11 @@ namespace NAPS2.Ocr;
|
||||
|
||||
public class TesseractLanguageManager
|
||||
{
|
||||
private static readonly List<DownloadMirror> Mirrors = new()
|
||||
{
|
||||
private static readonly List<DownloadMirror> 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;
|
||||
|
||||
|
@ -8,7 +8,7 @@ public class RecoveryIndex
|
||||
|
||||
public RecoveryIndex()
|
||||
{
|
||||
Images = new List<RecoveryIndexImage>();
|
||||
Images = [];
|
||||
}
|
||||
|
||||
public int Version { get; set; }
|
||||
|
@ -93,7 +93,7 @@ public class BatchScanPerformer : IBatchScanPerformer
|
||||
OcrCancelToken = _cancelToken,
|
||||
ThumbnailSize = thumbnailController.RenderSize
|
||||
};
|
||||
_scans = new List<List<ProcessedImage>>();
|
||||
_scans = [];
|
||||
}
|
||||
|
||||
public async Task Do()
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -48,11 +48,11 @@ public class BlankDetectorTests : ContextualTests
|
||||
return image.CopyWithPixelFormat(pixelFormat);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TestCases = new List<object[]>
|
||||
{
|
||||
public static IEnumerable<object[]> TestCases =
|
||||
[
|
||||
new object[] { ImagePixelFormat.ARGB32 },
|
||||
new object[] { ImagePixelFormat.RGB24 },
|
||||
new object[] { ImagePixelFormat.Gray8 },
|
||||
new object[] { ImagePixelFormat.BW1 }
|
||||
};
|
||||
];
|
||||
}
|
@ -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<object[]> TestCases = new List<object[]>
|
||||
{
|
||||
public static IEnumerable<object[]> 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
|
||||
};
|
||||
];
|
||||
}
|
@ -462,8 +462,8 @@ public class TransformTests : ContextualTests
|
||||
Assert.True(IsDisposed(original));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CommutativeGrayTransforms = new List<object[]>
|
||||
{
|
||||
public static IEnumerable<object[]> 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) }
|
||||
};
|
||||
];
|
||||
}
|
@ -6,9 +6,9 @@ namespace NAPS2.Sdk.Tests.Mocks;
|
||||
|
||||
internal class StubScanBridge : IScanBridge
|
||||
{
|
||||
public List<ScanDevice> MockDevices { get; set; } = new();
|
||||
public List<ScanDevice> MockDevices { get; set; } = [];
|
||||
|
||||
public List<ProcessedImage> MockOutput { get; set; } = new();
|
||||
public List<ProcessedImage> MockOutput { get; set; } = [];
|
||||
|
||||
public Exception Error { get; set; }
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class ScanErrorHandling : ContextualTests
|
||||
public async void Scan_LocalPostProcess()
|
||||
{
|
||||
var localPostProcessor = Substitute.For<ILocalPostProcessor>();
|
||||
var bridge = new StubScanBridge { MockOutput = new List<ProcessedImage> { CreateScannedImage() } };
|
||||
var bridge = new StubScanBridge { MockOutput = [CreateScannedImage()] };
|
||||
var bridgeFactory = Substitute.For<IScanBridgeFactory>();
|
||||
var controller =
|
||||
new ScanController(ScanningContext, localPostProcessor, new ScanOptionsValidator(),
|
||||
|
@ -30,7 +30,7 @@ public class TwainImageProcessorTests : ContextualTests
|
||||
_scanEvents = Substitute.For<IScanEvents>();
|
||||
_callback = Substitute.For<Action<IMemoryImage>>();
|
||||
|
||||
_images = new List<IMemoryImage>();
|
||||
_images = [];
|
||||
_callback.When(x => x(Arg.Any<IMemoryImage>()))
|
||||
.Do(x => _images.Add((IMemoryImage) x[0]));
|
||||
|
||||
|
@ -88,11 +88,11 @@ public class WorkerChannelTests : ContextualTests
|
||||
{
|
||||
var remoteScanController = new MockRemoteScanController
|
||||
{
|
||||
Images = new List<ProcessedImage>
|
||||
{
|
||||
Images =
|
||||
[
|
||||
CreateScannedImage(),
|
||||
CreateScannedImage()
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
using var channel = Start(remoteScanController);
|
||||
@ -113,11 +113,11 @@ public class WorkerChannelTests : ContextualTests
|
||||
{
|
||||
var remoteScanController = new MockRemoteScanController
|
||||
{
|
||||
Images = new List<ProcessedImage>
|
||||
{
|
||||
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<ProcessedImage> Images { get; set; } = new();
|
||||
public List<ProcessedImage> Images { get; set; } = [];
|
||||
|
||||
public Exception Exception { get; set; }
|
||||
|
||||
|
@ -2,19 +2,13 @@
|
||||
|
||||
public class EmailMessage
|
||||
{
|
||||
public EmailMessage()
|
||||
{
|
||||
Recipients = new List<EmailRecipient>();
|
||||
Attachments = new List<EmailAttachment>();
|
||||
}
|
||||
|
||||
public string? Subject { get; set; }
|
||||
|
||||
public string? BodyText { get; set; }
|
||||
|
||||
public List<EmailRecipient> Recipients { get; set; }
|
||||
public List<EmailRecipient> Recipients { get; set; } = [];
|
||||
|
||||
public List<EmailAttachment> Attachments { get; set; }
|
||||
public List<EmailAttachment> Attachments { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the email should be sent automatically without prompting the user to make changes first.
|
||||
|
@ -13,7 +13,7 @@ internal class OcrRequestQueue
|
||||
{
|
||||
private readonly Dictionary<OcrRequestParams, OcrRequest> _requestCache = new();
|
||||
private Semaphore _queueWaitHandle = new(0, int.MaxValue);
|
||||
private List<Task> _workerTasks = new();
|
||||
private List<Task> _workerTasks = [];
|
||||
private CancellationTokenSource _workerCts = new();
|
||||
|
||||
/// <summary>
|
||||
@ -94,7 +94,7 @@ internal class OcrRequestQueue
|
||||
if (_workerTasks.Count > 0 && !hasPending)
|
||||
{
|
||||
_workerCts.Cancel();
|
||||
_workerTasks = new List<Task>();
|
||||
_workerTasks = [];
|
||||
_workerCts = new CancellationTokenSource();
|
||||
_queueWaitHandle = new Semaphore(0, int.MaxValue);
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ public class PdfExporter : IPdfExporter
|
||||
private static string ReverseText(string text)
|
||||
{
|
||||
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(text);
|
||||
List<string> elements = new List<string>();
|
||||
var elements = new List<string>();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
elements.Add(enumerator.GetTextElement());
|
||||
|
@ -99,7 +99,7 @@ internal class ScanJob : IEsclScanJob
|
||||
if (ContentType == "application/pdf")
|
||||
{
|
||||
var pdfExporter = new PdfExporter(_scanningContext);
|
||||
await pdfExporter.Export(stream, new List<ProcessedImage> { _enumerable.Current });
|
||||
await pdfExporter.Export(stream, [_enumerable.Current]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ internal static class BarcodeDetector
|
||||
var zxingOptions = options.ZXingOptions ?? new DecodingOptions
|
||||
{
|
||||
TryHarder = true,
|
||||
PossibleFormats = options.PatchTOnly ? new List<BarcodeFormat> { PATCH_T_FORMAT } : null
|
||||
PossibleFormats = options.PatchTOnly ? [PATCH_T_FORMAT] : null
|
||||
};
|
||||
var reader = new BarcodeReader<IMemoryImage>(x => new MemoryImageLuminanceSource(x))
|
||||
{
|
||||
|
@ -12,5 +12,5 @@ public class TranslatableString
|
||||
|
||||
public string? Translation { get; }
|
||||
|
||||
public List<string> Context { get; } = new List<string>();
|
||||
public List<string> Context { get; } = [];
|
||||
}
|
@ -59,7 +59,7 @@ public static class Program
|
||||
|
||||
public class CommandList
|
||||
{
|
||||
private readonly List<Type> _optionTypes = new();
|
||||
private readonly List<Type> _optionTypes = [];
|
||||
private readonly Dictionary<Type, Type> _optionTypeToCommandType = new();
|
||||
|
||||
public CommandList Add<TOption, TCommand>() where TOption : OptionsBase where TCommand : ICommand<TOption>
|
||||
|
@ -4,8 +4,8 @@ namespace NAPS2.Tools.Project.Packaging;
|
||||
|
||||
public class PackageInfo
|
||||
{
|
||||
private readonly List<PackageFile> _files = new();
|
||||
private readonly HashSet<string> _destPaths = new();
|
||||
private readonly List<PackageFile> _files = [];
|
||||
private readonly HashSet<string> _destPaths = [];
|
||||
|
||||
public PackageInfo(Platform platform, string versionName, string versionNumber, string? packageName)
|
||||
{
|
||||
@ -30,7 +30,7 @@ public class PackageInfo
|
||||
|
||||
public IEnumerable<PackageFile> Files => _files;
|
||||
|
||||
public HashSet<string> Languages { get; } = new();
|
||||
public HashSet<string> Languages { get; } = [];
|
||||
|
||||
public void AddFile(FileInfo file, string destFolder, string? destFileName = null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user