Repository: files-community/Files
File: src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs (C#)

Code before:

					openWithItem.OpacityIcon = new OpacityIconModel()
					{
						OpacityIconStyle = "ColorIconOpenWith",
					};
					var (_, openWithItems) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel([openWithItem]);
					var placeholder = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => Equals((x as AppBarButton)?.Tag, "OpenWithPlaceholder")) as AppBarButton;
					if (placeholder is not null)
						placeholder.Visibility = Visibility.Collapsed;
					itemContextMenuFlyout.SecondaryCommands.Insert(0, openWithItems.FirstOrDefault());
				}

				// Add items to sendto dropdown
				if (sendToItem?.LoadSubMenuAction is not null)
				{
					await sendToItem.LoadSubMenuAction();

					var (_, sendToItems) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel([sendToItem]);
					var placeholder = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => Equals((x as AppBarButton)?.Tag, "SendToPlaceholder")) as AppBarButton;
					if (placeholder is not null)
						placeholder.Visibility = Visibility.Collapsed;
					itemContextMenuFlyout.SecondaryCommands.Insert(1, sendToItems.FirstOrDefault());
				}


				var itemsWithSubMenu = shellMenuItems.Where(x => x.LoadSubMenuAction is not null).ToList();
				var subMenuTasks = itemsWithSubMenu.Select(async item =>
				{
					await item.LoadSubMenuAction();
					if (!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
					{
						AddItemsToMainMenu(itemContextMenuFlyout.SecondaryCommands, item);
					}
					else
					{
						var overflowItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") as AppBarButton;

						if (overflowItem != null)
						{
							AddItemsToOverflowMenu(overflowItem, item);
						}
					}
				});

				await Task.WhenAll(subMenuTasks);
			}
			catch { }
		}

		public static void AddItemsToMainMenu(IEnumerable<ICommandBarElement> mainMenu, ContextMenuFlyoutItemViewModel viewModel)
		{

Review comment (suggestion):
```suggestion
				// Add items to shell submenu
				var itemsWithSubMenu = shellMenuItems.Where(x => x.LoadSubMenuAction is not null);
```

Code after:

					openWithItem.OpacityIcon = new OpacityIconModel()
					{
						OpacityIconStyle = "ColorIconOpenWith",
					};
					var (_, openWithItems) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel([openWithItem]);
					var placeholder = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => Equals((x as AppBarButton)?.Tag, "OpenWithPlaceholder")) as AppBarButton;
					if (placeholder is not null)
						placeholder.Visibility = Visibility.Collapsed;
					itemContextMenuFlyout.SecondaryCommands.Insert(0, openWithItems.FirstOrDefault());
				}

				// Add items to sendto dropdown
				if (sendToItem?.LoadSubMenuAction is not null)
				{
					await sendToItem.LoadSubMenuAction();

					var (_, sendToItems) = ContextFlyoutModelToElementHelper.GetAppBarItemsFromModel([sendToItem]);
					var placeholder = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => Equals((x as AppBarButton)?.Tag, "SendToPlaceholder")) as AppBarButton;
					if (placeholder is not null)
						placeholder.Visibility = Visibility.Collapsed;
					itemContextMenuFlyout.SecondaryCommands.Insert(1, sendToItems.FirstOrDefault());
				}

				// Add items to shell submenu
				var itemsWithSubMenu = shellMenuItems.Where(x => x.LoadSubMenuAction is not null);
				var subMenuTasks = itemsWithSubMenu.Select(async item =>
				{
					await item.LoadSubMenuAction();
					if (!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
					{
						AddItemsToMainMenu(itemContextMenuFlyout.SecondaryCommands, item);
					}
					else if (itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton 
						         && appBarButton.Tag as string == "ItemOverflow") is AppBarButton overflowItem)
					{
						AddItemsToOverflowMenu(overflowItem, item);
					}
				});

				await Task.WhenAll(subMenuTasks);
			}
			catch { }
		}

		public static void AddItemsToMainMenu(IEnumerable<ICommandBarElement> mainMenu, ContextMenuFlyoutItemViewModel viewModel)
		{
			var appBarButton = mainMenu.FirstOrDefault(x => (x as AppBarButton)?.Tag == viewModel.Tag) as AppBarButton;

			if (appBarButton is not null)
			{