Introduce FirstOrDefault extensions method for Array.Find and List.Find.

This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
This commit is contained in:
RoosterDragon
2023-11-17 09:49:27 +00:00
committed by Gustas
parent acca837142
commit e6914f707a
54 changed files with 83 additions and 89 deletions

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
@@ -176,7 +175,7 @@ namespace OpenRA.Mods.Common.Activities
{
if (ammoPools != null)
{
var pool = Array.Find(ammoPools, x => x.Info.Name == minelayer.Info.AmmoPoolName);
var pool = ammoPools.FirstOrDefault(x => x.Info.Name == minelayer.Info.AmmoPoolName);
if (pool == null)
return false;
@@ -194,7 +193,7 @@ namespace OpenRA.Mods.Common.Activities
{
if (ammoPools != null)
{
var pool = Array.Find(ammoPools, x => x.Info.Name == minelayer.Info.AmmoPoolName);
var pool = ammoPools.FirstOrDefault(x => x.Info.Name == minelayer.Info.AmmoPoolName);
if (pool == null)
return false;

View File

@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(move.MoveWithinRange(host, closeEnough, targetLineColor: moveInfo.GetTargetLineColor()));
var delta = (self.CenterPosition - host.CenterPosition).LengthSquared;
Array.Find(transportCallers, t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell);
transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell);
return false;
}
@@ -256,7 +256,7 @@ namespace OpenRA.Mods.Common.Activities
void RepairTick(Actor self)
{
var repairsUnits = Array.Find(allRepairsUnits, r => !r.IsTraitDisabled && !r.IsTraitPaused);
var repairsUnits = allRepairsUnits.FirstOrDefault(r => !r.IsTraitDisabled && !r.IsTraitPaused);
if (repairsUnits == null)
{
if (!allRepairsUnits.Any(r => r.IsTraitPaused))

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.FileFormats
public void ExtractFile(string filename, Stream output, Action<int> onProgress = null)
{
var file = Array.Find(files, f => f.FileName == filename);
var file = files.FirstOrDefault(f => f.FileName == filename);
if (file == null)
throw new FileNotFoundException(filename);

View File

@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Lint
continue;
var childType = childNode.Key.Split('@')[0];
var field = Array.Find(translationNodes, t => t.Name == childType);
var field = translationNodes.FirstOrDefault(t => t.Name == childType);
if (field.Name == null)
continue;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using Eluant;
using OpenRA.Scripting;
@@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Returns the player with the specified internal name, or nil if a match is not found.")]
public Player GetPlayer(string name)
{
return Array.Find(Context.World.Players, p => p.InternalName == name);
return Context.World.Players.FirstOrDefault(p => p.InternalName == name);
}
[Desc("Returns a table of players filtered by the specified function.")]

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using Eluant;
using OpenRA.Mods.Common.Traits;
@@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Returns the count of the actor's specified ammopool.")]
public int AmmoCount(string poolName = "primary")
{
var pool = Array.Find(ammoPools, a => a.Info.Name == poolName);
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
if (pool == null)
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");
@@ -44,7 +43,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Returns the maximum count of ammo the actor can load.")]
public int MaximumAmmoCount(string poolName = "primary")
{
var pool = Array.Find(ammoPools, a => a.Info.Name == poolName);
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
if (pool == null)
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");
@@ -55,7 +54,7 @@ namespace OpenRA.Mods.Common.Scripting
"(Use a negative amount to remove ammo.)")]
public void Reload(string poolName = "primary", int amount = 1)
{
var pool = Array.Find(ammoPools, a => a.Info.Name == poolName);
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
if (pool == null)
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using Eluant;
using OpenRA.Mods.Common.Traits;
@@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting
"If duration > 0 the condition will be automatically revoked after the defined number of ticks.")]
public int GrantCondition(string condition, int duration = 0)
{
var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this));
var external = externalConditions.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(this));
if (external == null)
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using Eluant;
using OpenRA.Mods.Common.Traits;
@@ -33,7 +32,7 @@ namespace OpenRA.Mods.Common.Scripting
"If duration > 0 the condition will be automatically revoked after the defined number of ticks.")]
public int GrantCondition(string condition, int duration = 0)
{
var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this));
var external = externalConditions.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(this));
if (external == null)
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Scripting
{
get
{
var c = Player.World.LobbyInfo.Clients.Find(i => i.Index == Player.ClientIndex);
var c = Player.World.LobbyInfo.Clients.FirstOrDefault(i => i.Index == Player.ClientIndex);
return c?.Team ?? 0;
}
}
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Scripting
{
get
{
var c = Player.World.LobbyInfo.Clients.Find(i => i.Index == Player.ClientIndex);
var c = Player.World.LobbyInfo.Clients.FirstOrDefault(i => i.Index == Player.ClientIndex);
return c?.Handicap ?? 0;
}
}

View File

@@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Server
{
// Client 0 will always be the Host
// In some cases client 0 doesn't exist, so we untick all players
var host = server.LobbyInfo.Clients.Find(c => c.Index == 0);
var host = server.LobbyInfo.Clients.FirstOrDefault(c => c.Index == 0);
if (host != null)
host.State = Session.ClientState.NotReady;
else
@@ -442,7 +442,7 @@ namespace OpenRA.Mods.Common.Server
}
else
{
var occupantConn = server.Conns.Find(c => c.PlayerIndex == occupant.Index);
var occupantConn = server.Conns.FirstOrDefault(c => c.PlayerIndex == occupant.Index);
if (occupantConn != null)
{
server.SendOrderTo(conn, "ServerError", SlotClosed);
@@ -1143,7 +1143,7 @@ namespace OpenRA.Mods.Common.Server
if (spawnPoint == 0)
return true;
var existingClient = server.LobbyInfo.Clients.Find(cc => cc.SpawnPoint == spawnPoint);
var existingClient = server.LobbyInfo.Clients.FirstOrDefault(cc => cc.SpawnPoint == spawnPoint);
if (client != existingClient && !client.IsAdmin)
{
server.SendLocalizedMessageTo(conn, AdminClearSpawn);

View File

@@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Server
var slot = server.LobbyInfo.FirstEmptyBotSlot();
var bot = server.Map.PlayerActorInfo.TraitInfos<IBotInfo>().Select(t => t.Type).FirstOrDefault();
var botController = server.LobbyInfo.Clients.Find(c => c.IsAdmin);
var botController = server.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
if (slot != null && bot != null)
server.InterpretCommand($"slot_bot {slot} {botController.Index} {bot}", conn);
}

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -163,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits
if (world.Map.Contains(cell))
{
var explored = subject.Actor.Owner.Shroud.IsExplored(cell);
var cannotMove = Array.Find(subjects, a => !a.Trait.Info.MoveIntoShroud).Trait;
var cannotMove = subjects.FirstOrDefault(a => !a.Trait.Info.MoveIntoShroud).Trait;
var blocked = !explored && cannotMove != null;
if (isAssaultMove)

View File

@@ -305,7 +305,7 @@ namespace OpenRA.Mods.Common.Traits
// HACK: Use of this function requires that there is one squad of this type.
Squad GetSquadOfType(SquadType type)
{
return Squads.Find(s => s.Type == type);
return Squads.FirstOrDefault(s => s.Type == type);
}
Squad RegisterNewSquad(IBot bot, SquadType type, (Actor Actor, WVec Offset) target = default)

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -143,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -95,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -121,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -129,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
@@ -123,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var currentTransform = self.CurrentActivity as Transform;
var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused);
var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);
if (transform == null && currentTransform == null)
return;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
{
if (external == null || !external.CanGrantCondition(self))
{
external = externals.Find(t => t.CanGrantCondition(self));
external = externals.FirstOrDefault(t => t.CanGrantCondition(self));
if (external == null)
break;
}

View File

@@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Traits
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
{
var minelayer = minelayers.Find(m => m.IsInWorld && !m.IsDead);
var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead);
if (minelayer == null)
yield break;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
if (allProductionPaused)
return;
var item = Queue.Find(i => !i.Paused);
var item = Queue.FirstOrDefault(i => !i.Paused);
if (item == null)
return;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
@@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
// TODO: This won't make sense for MP saves
var localPlayer = worldRenderer.World.LocalPlayer;
if ((localPlayer != null && localPlayer.PlayerActor != self) ||
(localPlayer == null && self.Owner != Array.Find(self.World.Players, p => p.IsBot)))
(localPlayer == null && self.Owner != self.World.Players.FirstOrDefault(p => p.IsBot)))
return null;
var nodes = new List<MiniYamlNode>()

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
{
CancelUnbuildableItems();
var item = Queue.Find(i => !i.Paused);
var item = Queue.FirstOrDefault(i => !i.Paused);
if (item == null)
return;

View File

@@ -175,7 +175,7 @@ namespace OpenRA.Mods.Common.Traits
.Where(p => p.AcceptsPlug(plugInfo.Type))
.ToList();
var pluggable = pluggables.Find(p => a.Location + p.Info.Offset == targetLocation)
var pluggable = pluggables.FirstOrDefault(p => a.Location + p.Info.Offset == targetLocation)
?? pluggables.FirstOrDefault();
if (pluggable == null)

View File

@@ -515,7 +515,7 @@ namespace OpenRA.Mods.Common.Traits
protected virtual void PauseProduction(string itemName, bool paused)
{
Queue.Find(a => a.Item == itemName)?.Pause(paused);
Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused);
}
protected virtual void CancelProduction(string itemName, uint numberToCancel)

View File

@@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits
Arrow GetArrow(double degree)
{
var arrow = Array.Find(directionArrows, d => d.EndAngle >= degree);
var arrow = directionArrows.FirstOrDefault(d => d.EndAngle >= degree);
return arrow ?? directionArrows[0];
}

View File

@@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits
if (!Ready)
return;
var power = Instances.Find(i => !i.IsTraitPaused);
var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);
if (power == null)
return;

View File

@@ -332,7 +332,7 @@ namespace OpenRA.Mods.Common.Traits
public EditorActorPreview this[string id]
{
get { return previews.Find(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); }
get { return previews.FirstOrDefault(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); }
}
}
}

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
refineryNode.RemoveNode(dockOffsetNode);
}
var buildingNode = actorNode.Value.Nodes.Find(n => buildings.Any(b => n.KeyMatches(b, includeRemovals: false)));
var buildingNode = actorNode.Value.Nodes.FirstOrDefault(n => buildings.Any(b => n.KeyMatches(b, includeRemovals: false)));
if (buildingNode != null)
{
var dimensions = buildingNode.ChildrenMatching("Dimensions", includeRemovals: false).FirstOrDefault()?.NodeValue<CVec>() ?? new CVec(1, 1);

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.UpdateRules.Rules;
@@ -99,7 +98,7 @@ namespace OpenRA.Mods.Common.UpdateRules
if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule)))
return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) };
return Array.Find(Paths, p => p.source == source)?.Rules(chain);
return Paths.FirstOrDefault(p => p.source == source)?.Rules(chain);
}
public static IEnumerable<string> KnownPaths { get { return Paths.Select(p => p.source); } }

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
var fs = map ?? modData.DefaultFileSystem;
var topLevelNodes = MiniYaml.Load(fs, manifestNodes, mapProperty);
return topLevelNodes.Find(n => n.Key == key);
return topLevelNodes.FirstOrDefault(n => n.Key == key);
}
}
}

View File

@@ -247,8 +247,7 @@ namespace OpenRA.Mods.Common.Widgets
var position = GetTextPosition(text, font, rb);
// PERF: Avoid LINQ by using Children.Find(...) != null instead of Children.Any(...)
var hover = Ui.MouseOverWidget == this || Children.Find(c => c == Ui.MouseOverWidget) != null;
var hover = Ui.MouseOverWidget == this || Children.FirstOrDefault(c => c == Ui.MouseOverWidget) != null;
DrawBackground(rb, disabled, Depressed, hover, highlighted);
if (Contrast)
font.DrawTextWithContrast(text, position + stateOffset,

View File

@@ -146,8 +146,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (map.Package != null)
{
selectedDirectory = writableDirectories.Find(k => k.Folder.Contains(map.Package.Name));
selectedDirectory ??= writableDirectories.Find(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name)));
selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name));
selectedDirectory ??= writableDirectories.FirstOrDefault(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name)));
}
// Prioritize MapClassification.User directories over system directories

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SelectTab(bool reverse)
{
palette.CurrentQueue = Array.Find(queues, q => q.Enabled);
palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled);
// When a tab is selected, scroll to the top because the current row position may be invalid for the new tab
palette.ScrollToTop();

View File

@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
var localClient = orderManager.LocalClient;
var localPlayer = localClient == null ? null : Array.Find(world.Players, player => player.ClientIndex == localClient.Index);
var localPlayer = localClient == null ? null : world.Players.FirstOrDefault(player => player.ClientIndex == localClient.Index);
bool LocalPlayerCanKick() => localClient != null
&& (Game.IsHost || ((!orderManager.LocalClient.IsObserver) && localPlayer.WinState == WinState.Undefined));
bool CanClientBeKicked(Session.Client client, Func<bool> isVoteKick) =>

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
modFileSystem.UnmountAll();
var download = downloadYaml.Find(n => n.Key == content.QuickDownload);
var download = downloadYaml.FirstOrDefault(n => n.Key == content.QuickDownload);
if (download == null)
throw new InvalidOperationException($"Mod QuickDownload `{content.QuickDownload}` definition not found.");

View File

@@ -274,7 +274,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var botTypes = map.PlayerActorInfo.TraitInfos<IBotInfo>().Select(t => t.Type);
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
var botController = orderManager.LobbyInfo.Clients.Find(c => c.IsAdmin);
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots))
{
var botOptions = new List<DropDownOption>()

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
foreach (var b in map.PlayerActorInfo.TraitInfos<IBotInfo>())
{
var botController = orderManager.LobbyInfo.Clients.Find(c => c.IsAdmin);
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
bots.Add(new SlotDropDownOption(b.Name,
$"slot_bot {slot.PlayerReference} {botController.Index} {b.Type}",
() => client != null && client.Bot == b.Type));
@@ -266,7 +266,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static void ClearPlayerSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, MapPreview preview, MouseInput mi)
{
var selectedSpawn = DetermineSelectedSpawnPoint(mapPreview, preview, mi);
if (Game.IsHost || orderManager.LobbyInfo.Clients.Find(cc => cc.SpawnPoint == selectedSpawn) == orderManager.LocalClient)
if (Game.IsHost || orderManager.LobbyInfo.Clients.FirstOrDefault(cc => cc.SpawnPoint == selectedSpawn) == orderManager.LocalClient)
orderManager.IssueOrder(Order.Command($"clear_spawn {selectedSpawn}"));
}

View File

@@ -356,7 +356,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
gameModeDropdown.GetText = () =>
{
var item = categories.Find(m => m.Category == category);
var item = categories.FirstOrDefault(m => m.Category == category);
if (item == default((string, int)))
item.Category = TranslationProvider.GetString(NoMatches);

View File

@@ -696,7 +696,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SelectFirstVisibleReplay()
{
SelectReplay(replays.Find(r => replayState[r].Visible));
SelectReplay(replays.FirstOrDefault(r => replayState[r].Visible));
}
void SelectReplay(ReplayMetadata replay)

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
videoVolumeSlider.OnChange += x => Game.Sound.VideoVolume = x;
var devices = Game.Sound.AvailableDevices();
soundDevice = Array.Find(devices, d => d.Device == ss.Device) ?? devices[0];
soundDevice = devices.FirstOrDefault(d => d.Device == ss.Device) ?? devices[0];
var audioDeviceDropdown = panel.Get<DropDownButtonWidget>("AUDIO_DEVICE");
audioDeviceDropdown.OnMouseDown = _ => ShowAudioDeviceDropdown(audioDeviceDropdown, devices, scrollPanel);

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets
{
resourceType = value;
if (resourceType != null)
resourceRenderer = Array.Find(resourceRenderers, r => r.ResourceTypes.Contains(resourceType));
resourceRenderer = resourceRenderers.FirstOrDefault(r => r.ResourceTypes.Contains(resourceType));
else
resourceRenderer = null;
}

View File

@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Widgets
public void ScrollToItem(string itemKey, bool smooth = false)
{
var item = Children.Find(c => c is ScrollItemWidget si && si.ItemKey == itemKey);
var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.ItemKey == itemKey);
if (item != null)
ScrollToItem(item, smooth);
@@ -291,7 +291,7 @@ namespace OpenRA.Mods.Common.Widgets
public void ScrollToSelectedItem()
{
var item = Children.Find(c => c is ScrollItemWidget si && si.IsSelected());
var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.IsSelected());
if (item != null)
ScrollToItem(item);
@@ -468,7 +468,7 @@ namespace OpenRA.Mods.Common.Widgets
if (collection != col)
return;
var widget = Children.Find(w => widgetItemEquals(w, item));
var widget = Children.FirstOrDefault(w => widgetItemEquals(w, item));
if (widget != null)
RemoveChild(widget);
});