Skip to content

Commit d10270a

Browse files
authored
Code Quality: Use collection expressions and make sure FileTags is not null (#15143)
1 parent afcd8b4 commit d10270a

File tree

114 files changed

+300
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+300
-292
lines changed

src/Files.App.Server/Database/FileTagsDatabase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ public void UpdateTag(ulong oldFrn, ulong? frn, string? newFilePath)
162162
}
163163
}
164164

165-
public string[]? GetTags(string? filePath, ulong? frn)
165+
public string[] GetTags(string? filePath, ulong? frn)
166166
{
167-
return FindTag(filePath, frn)?.Tags;
167+
return FindTag(filePath, frn)?.Tags ?? [];
168168
}
169169

170170
public IEnumerable<TaggedFile> GetAll()

src/Files.App.Storage/FtpStorage/FtpManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Files.App.Storage.FtpStorage
88
{
99
public static class FtpManager
1010
{
11-
public static readonly Dictionary<string, NetworkCredential> Credentials = new();
11+
public static readonly Dictionary<string, NetworkCredential> Credentials = [];
1212

1313
public static readonly NetworkCredential Anonymous = new("anonymous", "anonymous");
1414
}

src/Files.App/Actions/FileSystem/OpenFileLocationAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ExecuteAsync()
4949
context.ShellPage?.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
5050
{
5151
NavPathParam = folderPath,
52-
SelectItems = new[] { Path.GetFileName(item.TargetPath.TrimPath()) },
52+
SelectItems = [Path.GetFileName(item.TargetPath.TrimPath())],
5353
AssociatedTabInstance = context.ShellPage
5454
});
5555
}

src/Files.App/Actions/FileSystem/OpenItemAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public async Task ExecuteAsync()
132132
context.ShellPage.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
133133
{
134134
NavPathParam = folderPath,
135-
SelectItems = new[] { item.ItemNameRaw },
135+
SelectItems = [item.ItemNameRaw],
136136
AssociatedTabInstance = context.ShellPage
137137
});
138138
}

src/Files.App/Actions/Open/OpenTerminalAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ protected string[] GetPaths()
8585
}
8686
else if (context.Folder is not null)
8787
{
88-
return new string[1] { context.Folder.ItemPath };
88+
return [context.Folder.ItemPath];
8989
}
9090

91-
return Array.Empty<string>();
91+
return [];
9292
}
9393

9494
private bool GetIsExecutable()

src/Files.App/Actions/Sidebar/PinFolderToSidebarAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task ExecuteAsync()
4747

4848
private bool GetIsExecutable()
4949
{
50-
string[] pinnedFolders = App.QuickAccessManager.Model.PinnedFolders.ToArray();
50+
string[] pinnedFolders = [.. App.QuickAccessManager.Model.PinnedFolders];
5151

5252
return context.HasSelection
5353
? context.SelectedItems.All(IsPinnable)

src/Files.App/Actions/Sidebar/UnpinFolderToSidebarAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task ExecuteAsync()
4444

4545
private bool GetIsExecutable()
4646
{
47-
string[] pinnedFolders = App.QuickAccessManager.Model.PinnedFolders.ToArray();
47+
string[] pinnedFolders = [.. App.QuickAccessManager.Model.PinnedFolders];
4848

4949
return context.HasSelection
5050
? context.SelectedItems.All(IsPinned)

src/Files.App/Data/Commands/HotKey/HotKeyCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Files.App.Data.Commands
1111
[DebuggerDisplay("{Code}")]
1212
public readonly struct HotKeyCollection : IEnumerable<HotKey>, IEquatable<HotKeyCollection>
1313
{
14-
private static readonly char[] parseSeparators = new char[] { ',', ';', ' ', '\t' };
14+
private static readonly char[] parseSeparators = [',', ';', ' ', '\t'];
1515

1616
private readonly ImmutableArray<HotKey> hotKeys;
1717

@@ -25,7 +25,7 @@ namespace Files.App.Data.Commands
2525
public string Code => string.Join(',', hotKeys.Select(hotKey => hotKey.Code));
2626
public string Label => string.Join(", ", hotKeys.Where(hotKey => hotKey.IsVisible).Select(hotKey => hotKey.Label));
2727

28-
public HotKeyCollection() => hotKeys = ImmutableArray<HotKey>.Empty;
28+
public HotKeyCollection() => hotKeys = [];
2929
public HotKeyCollection(params HotKey[] hotKeys) => this.hotKeys = Clean(hotKeys);
3030
public HotKeyCollection(IEnumerable<HotKey> hotKeys) => this.hotKeys = Clean(hotKeys);
3131

src/Files.App/Data/Factories/AppThemeResourcesFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Files.App.Data.Factories
55
{
66
public static class AppThemeResourceFactory
77
{
8-
public static ObservableCollection<AppThemeResourceItem> AppThemeResources { get; } = new ObservableCollection<AppThemeResourceItem>()
9-
{
8+
public static ObservableCollection<AppThemeResourceItem> AppThemeResources { get; } =
9+
[
1010
new AppThemeResourceItem
1111
{
1212
BackgroundColor = "#00000000", /* Transparent */
@@ -107,6 +107,6 @@ public static class AppThemeResourceFactory
107107
BackgroundColor = "#327E735F", /* #7E735F */
108108
Name = "Camouflage".GetLocalizedResource()
109109
}
110-
};
110+
];
111111
}
112112
}

src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
106106
ShowInSearchPage = true,
107107
ShowInFtpPage = true,
108108
ShowInZipPage = true,
109-
Items = new List<ContextMenuFlyoutItemViewModel>
110-
{
109+
Items =
110+
[
111111
new ContextMenuFlyoutItemViewModelBuilder(Commands.LayoutDetails)
112112
{
113113
IsToggle = true
@@ -132,7 +132,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
132132
{
133133
IsToggle = true
134134
}.Build(),
135-
},
135+
],
136136
},
137137
new ContextMenuFlyoutItemViewModel()
138138
{
@@ -146,8 +146,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
146146
ShowInSearchPage = true,
147147
ShowInFtpPage = true,
148148
ShowInZipPage = true,
149-
Items = new List<ContextMenuFlyoutItemViewModel>
150-
{
149+
Items =
150+
[
151151
new ContextMenuFlyoutItemViewModelBuilder(Commands.SortByName)
152152
{
153153
IsToggle = true
@@ -204,7 +204,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
204204
{
205205
IsToggle = true
206206
}.Build(),
207-
},
207+
],
208208
},
209209
new ContextMenuFlyoutItemViewModel()
210210
{
@@ -215,8 +215,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
215215
ShowInSearchPage = true,
216216
ShowInFtpPage = true,
217217
ShowInZipPage = true,
218-
Items = new List<ContextMenuFlyoutItemViewModel>
219-
{
218+
Items =
219+
[
220220
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByNone)
221221
{
222222
IsToggle = true
@@ -232,8 +232,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
232232
ShowInSearchPage = true,
233233
ShowInFtpPage = true,
234234
ShowInZipPage = true,
235-
Items = new List<ContextMenuFlyoutItemViewModel>
236-
{
235+
Items =
236+
[
237237
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByDateModifiedYear)
238238
{
239239
IsToggle = true
@@ -246,7 +246,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
246246
{
247247
IsToggle = true
248248
}.Build(),
249-
},
249+
],
250250
},
251251
new ContextMenuFlyoutItemViewModel()
252252
{
@@ -255,8 +255,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
255255
ShowInSearchPage = true,
256256
ShowInFtpPage = true,
257257
ShowInZipPage = true,
258-
Items = new List<ContextMenuFlyoutItemViewModel>
259-
{
258+
Items =
259+
[
260260
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByDateCreatedYear)
261261
{
262262
IsToggle = true
@@ -269,7 +269,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
269269
{
270270
IsToggle = true
271271
}.Build(),
272-
},
272+
],
273273
},
274274
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByType)
275275
{
@@ -296,8 +296,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
296296
Text = "DateDeleted".GetLocalizedResource(),
297297
ShowInRecycleBin = true,
298298
IsHidden = !currentInstanceViewModel.IsPageTypeRecycleBin,
299-
Items = new List<ContextMenuFlyoutItemViewModel>
300-
{
299+
Items =
300+
[
301301
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByDateDeletedYear)
302302
{
303303
IsToggle = true
@@ -310,7 +310,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
310310
{
311311
IsToggle = true
312312
}.Build(),
313-
},
313+
],
314314
},
315315
new ContextMenuFlyoutItemViewModelBuilder(Commands.GroupByFolderPath)
316316
{
@@ -334,7 +334,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
334334
IsToggle = true,
335335
IsVisible = true
336336
}.Build(),
337-
},
337+
],
338338
},
339339
new ContextMenuFlyoutItemViewModelBuilder(Commands.RefreshItems)
340340
{
@@ -387,13 +387,13 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
387387
Tag = "OpenWithOverflow",
388388
IsHidden = true,
389389
CollapseLabel = true,
390-
Items = new List<ContextMenuFlyoutItemViewModel>() {
390+
Items = [
391391
new()
392392
{
393393
Text = "Placeholder",
394394
ShowInSearchPage = true,
395395
}
396-
},
396+
],
397397
ShowInSearchPage = true,
398398
ShowItem = itemsSelected && showOpenItemWith
399399
},
@@ -406,12 +406,12 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
406406
Text = "BaseLayoutItemContextFlyoutSetAs/Text".GetLocalizedResource(),
407407
ShowItem = itemsSelected && (selectedItemsPropertiesViewModel?.IsSelectedItemImage ?? false),
408408
ShowInSearchPage = true,
409-
Items = new List<ContextMenuFlyoutItemViewModel>
410-
{
409+
Items =
410+
[
411411
new ContextMenuFlyoutItemViewModelBuilder(Commands.SetAsWallpaperBackground).Build(),
412412
new ContextMenuFlyoutItemViewModelBuilder(Commands.SetAsLockscreenBackground).Build(),
413413
new ContextMenuFlyoutItemViewModelBuilder(Commands.SetAsSlideshowBackground).Build(),
414-
}
414+
]
415415
},
416416
new ContextMenuFlyoutItemViewModelBuilder(Commands.RotateLeft)
417417
{
@@ -511,12 +511,12 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
511511
{
512512
OpacityIconStyle = "ColorIconZip",
513513
},
514-
Items = new List<ContextMenuFlyoutItemViewModel>
515-
{
514+
Items =
515+
[
516516
new ContextMenuFlyoutItemViewModelBuilder(Commands.CompressIntoArchive).Build(),
517517
new ContextMenuFlyoutItemViewModelBuilder(Commands.CompressIntoZip).Build(),
518518
new ContextMenuFlyoutItemViewModelBuilder(Commands.CompressIntoSevenZip).Build(),
519-
},
519+
],
520520
ShowItem = UserSettingsService.GeneralSettingsService.ShowCompressionOptions && itemsSelected && CompressHelper.CanCompress(selectedItems)
521521
},
522522
new ContextMenuFlyoutItemViewModel
@@ -527,13 +527,13 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
527527
{
528528
OpacityIconStyle = "ColorIconZip",
529529
},
530-
Items = new List<ContextMenuFlyoutItemViewModel>
531-
{
530+
Items =
531+
[
532532
new ContextMenuFlyoutItemViewModelBuilder(Commands.DecompressArchive).Build(),
533533
new ContextMenuFlyoutItemViewModelBuilder(Commands.DecompressArchiveHereSmart).Build(),
534534
new ContextMenuFlyoutItemViewModelBuilder(Commands.DecompressArchiveHere).Build(),
535535
new ContextMenuFlyoutItemViewModelBuilder(Commands.DecompressArchiveToChildFolder).Build(),
536-
},
536+
],
537537
ShowItem = UserSettingsService.GeneralSettingsService.ShowCompressionOptions && CompressHelper.CanDecompress(selectedItems)
538538
},
539539
new ContextMenuFlyoutItemViewModel()
@@ -550,13 +550,13 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
550550
Tag = "SendToOverflow",
551551
IsHidden = true,
552552
CollapseLabel = true,
553-
Items = new List<ContextMenuFlyoutItemViewModel>() {
553+
Items = [
554554
new()
555555
{
556556
Text = "Placeholder",
557557
ShowInSearchPage = true,
558558
}
559-
},
559+
],
560560
ShowInSearchPage = true,
561561
ShowItem = itemsSelected && UserSettingsService.GeneralSettingsService.ShowSendToMenu
562562
},
@@ -592,7 +592,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
592592
{
593593
Text = "Loading".GetLocalizedResource(),
594594
Glyph = "\xE712",
595-
Items = new List<ContextMenuFlyoutItemViewModel>(),
595+
Items = [],
596596
ID = "ItemOverflow",
597597
Tag = "ItemOverflow",
598598
ShowInFtpPage = true,
@@ -671,7 +671,7 @@ public static void SwapPlaceholderWithShellOption(CommandBarFlyout contextMenu,
671671

672672
if (replacingItem is not null)
673673
{
674-
var (_, bitLockerCommands) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel(new List<ContextMenuFlyoutItemViewModel>() { replacingItem });
674+
var (_, bitLockerCommands) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel([replacingItem]);
675675
contextMenu.SecondaryCommands.Insert(
676676
position,
677677
bitLockerCommands.FirstOrDefault()

src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class PropertiesNavigationViewItemFactory
1212
{
1313
public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize(object item)
1414
{
15-
ObservableCollection<NavigationViewItemButtonStyleItem> PropertiesNavigationViewItems = new();
15+
ObservableCollection<NavigationViewItemButtonStyleItem> PropertiesNavigationViewItems = [];
1616

1717
var generalItem = new NavigationViewItemButtonStyleItem()
1818
{

src/Files.App/Data/Factories/SecurityAdvancedAccessControlItemFactory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static ObservableCollection<AccessMaskItem> Initialize(AccessControlEntry
2323

2424
if (isAdvanced)
2525
{
26-
accessControls = new()
27-
{
26+
accessControls =
27+
[
2828
new(current)
2929
{
3030
AccessMask = AccessMaskFlags.FullControl,
@@ -133,7 +133,7 @@ public static ObservableCollection<AccessMaskItem> Initialize(AccessControlEntry
133133
AccessMaskName = "SecurityTakeOwnershipLabel/Text".GetLocalizedResource(),
134134
IsEditable = !isInherited
135135
}
136-
};
136+
];
137137

138138
if (isFolder)
139139
{
@@ -155,8 +155,8 @@ public static ObservableCollection<AccessMaskItem> Initialize(AccessControlEntry
155155
}
156156
else
157157
{
158-
accessControls = new()
159-
{
158+
accessControls =
159+
[
160160
new(current)
161161
{
162162
AccessMask = AccessMaskFlags.FullControl,
@@ -197,7 +197,7 @@ public static ObservableCollection<AccessMaskItem> Initialize(AccessControlEntry
197197
{
198198
AccessMaskName = "SecuritySpecialLabel/Text".GetLocalizedResource()
199199
}
200-
};
200+
];
201201

202202
if (!isFolder)
203203
{

0 commit comments

Comments
 (0)