Fix CA1854
This commit is contained in:
committed by
Pavel Penev
parent
c2568ebd1f
commit
c8efc5fdd7
@@ -200,18 +200,18 @@ namespace OpenRA
|
||||
|
||||
static string[] YamlList(Dictionary<string, MiniYaml> yaml, string key)
|
||||
{
|
||||
if (!yaml.ContainsKey(key))
|
||||
if (!yaml.TryGetValue(key, out var value))
|
||||
return Array.Empty<string>();
|
||||
|
||||
return yaml[key].Nodes.Select(n => n.Key).ToArray();
|
||||
return value.Nodes.Select(n => n.Key).ToArray();
|
||||
}
|
||||
|
||||
static IReadOnlyDictionary<string, string> YamlDictionary(Dictionary<string, MiniYaml> yaml, string key)
|
||||
{
|
||||
if (!yaml.ContainsKey(key))
|
||||
if (!yaml.TryGetValue(key, out var value))
|
||||
return new Dictionary<string, string>();
|
||||
|
||||
return yaml[key].ToDictionary(my => my.Value);
|
||||
return value.ToDictionary(my => my.Value);
|
||||
}
|
||||
|
||||
public bool Contains<T>() where T : IGlobalModData
|
||||
|
||||
@@ -348,8 +348,8 @@ namespace OpenRA
|
||||
|
||||
while (this[uid].Status != MapStatus.Available)
|
||||
{
|
||||
if (mapUpdates.ContainsKey(uid))
|
||||
uid = mapUpdates[uid];
|
||||
if (mapUpdates.TryGetValue(uid, out var newUid))
|
||||
uid = newUid;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -152,8 +152,8 @@ namespace OpenRA
|
||||
for (var i = 0; i < p.Length; i++)
|
||||
{
|
||||
var key = p[i].Name;
|
||||
if (!args.ContainsKey(key)) throw new InvalidOperationException($"ObjectCreator: key `{key}' not found");
|
||||
a[i] = args[key];
|
||||
if (!args.TryGetValue(key, out var arg)) throw new InvalidOperationException($"ObjectCreator: key `{key}' not found");
|
||||
a[i] = arg;
|
||||
}
|
||||
|
||||
return ctor.Invoke(a);
|
||||
|
||||
@@ -380,17 +380,17 @@ namespace OpenRA
|
||||
|
||||
if (voicedActor != null)
|
||||
{
|
||||
if (!rules.VoicePools.Value.ContainsKey(definition))
|
||||
if (!rules.VoicePools.Value.TryGetValue(definition, out var p))
|
||||
throw new InvalidOperationException($"Can't find {definition} in voice pool.");
|
||||
|
||||
pool = rules.VoicePools.Value[definition];
|
||||
pool = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!rules.NotificationsPools.Value.ContainsKey(definition))
|
||||
if (!rules.NotificationsPools.Value.TryGetValue(definition, out var p))
|
||||
throw new InvalidOperationException($"Can't find {definition} in notification pool.");
|
||||
|
||||
pool = rules.NotificationsPools.Value[definition];
|
||||
pool = p;
|
||||
}
|
||||
|
||||
var clip = pool.GetNext();
|
||||
|
||||
@@ -257,10 +257,10 @@ namespace OpenRA.UtilityCommands
|
||||
var validChildTypes = new List<(MiniYamlNodeBuilder Node, string Type, string Value)>();
|
||||
foreach (var childNode in node.Value.Nodes)
|
||||
{
|
||||
if (translatables.ContainsKey(nodeType))
|
||||
if (translatables.TryGetValue(nodeType, out var fieldName))
|
||||
{
|
||||
var childType = childNode.Key.Split('@')[0];
|
||||
if (translatables[nodeType].Contains(childType)
|
||||
if (fieldName.Contains(childType)
|
||||
&& !string.IsNullOrEmpty(childNode.Value.Value)
|
||||
&& !IsAlreadyTranslated(childNode.Value.Value)
|
||||
&& childNode.Value.Value.Any(char.IsLetterOrDigit))
|
||||
|
||||
@@ -96,11 +96,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public bool HasModelSequence(string model, string sequence)
|
||||
{
|
||||
if (!models.ContainsKey(model))
|
||||
if (!models.TryGetValue(model, out var sequences))
|
||||
throw new InvalidOperationException(
|
||||
$"Model `{model}` does not have any sequences defined.");
|
||||
|
||||
return models[model].ContainsKey(sequence);
|
||||
return sequences.ContainsKey(sequence);
|
||||
}
|
||||
|
||||
public IVertexBuffer<ModelVertex> VertexBuffer => loader.VertexBuffer;
|
||||
|
||||
@@ -262,9 +262,9 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
|
||||
var name = entries[1].ToLowerInvariant();
|
||||
|
||||
if (DeployableActors.ContainsKey(name))
|
||||
if (DeployableActors.TryGetValue(name, out var n))
|
||||
{
|
||||
name = DeployableActors[name];
|
||||
name = n;
|
||||
isDeployed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
|
||||
var res = (Type: (byte)0, Index: (byte)0);
|
||||
var type = kv.Value.ToLowerInvariant();
|
||||
if (OverlayResourceMapping.ContainsKey(type))
|
||||
res = OverlayResourceMapping[type];
|
||||
if (OverlayResourceMapping.TryGetValue(type, out var r))
|
||||
res = r;
|
||||
|
||||
Map.Resources[cell] = new ResourceTile(res.Type, res.Index);
|
||||
if (OverlayActors.Contains(type))
|
||||
|
||||
@@ -285,10 +285,10 @@ namespace OpenRA.Mods.Common.Lint
|
||||
var isAttribute = !string.IsNullOrEmpty(attribute);
|
||||
var keyWithAtrr = isAttribute ? $"{key}.{attribute}" : key;
|
||||
|
||||
if (!referencedVariablesPerKey.ContainsKey(keyWithAtrr))
|
||||
if (!referencedVariablesPerKey.TryGetValue(keyWithAtrr, out var referencedVariables))
|
||||
return;
|
||||
|
||||
foreach (var referencedVariable in referencedVariablesPerKey[keyWithAtrr])
|
||||
foreach (var referencedVariable in referencedVariables)
|
||||
if (!variableReferences.Contains(referencedVariable))
|
||||
emitError(isAttribute ?
|
||||
$"Missing variable `{referencedVariable}` for attribute `{attribute}` of key `{key}` in {file}." :
|
||||
@@ -302,7 +302,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
|
||||
variableReferences.Add(varName);
|
||||
|
||||
if (!referencedVariablesPerKey.ContainsKey(keyWithAtrr) || !referencedVariablesPerKey[keyWithAtrr].Contains(varName))
|
||||
if (!referencedVariablesPerKey.TryGetValue(keyWithAtrr, out var referencedVariables) || !referencedVariables.Contains(varName))
|
||||
emitWarning(isAttribute ?
|
||||
$"Unused variable `{varName}` for attribute `{attribute}` of key `{key}` in {file}." :
|
||||
$"Unused variable `{varName}` for key `{key}` in {file}.");
|
||||
|
||||
@@ -292,10 +292,10 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var queue = GetBuildableInfo(actorType).Queue.First();
|
||||
|
||||
if (!queues.ContainsKey(queue))
|
||||
if (!queues.TryGetValue(queue, out var cpq))
|
||||
return true;
|
||||
|
||||
return productionHandlers.ContainsKey(queue) || queues[queue].AllQueued().Any();
|
||||
return productionHandlers.ContainsKey(queue) || cpq.AllQueued().Any();
|
||||
}
|
||||
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
|
||||
@@ -361,14 +361,12 @@ namespace OpenRA.Mods.Common.Server
|
||||
{
|
||||
lock (server.LobbyInfo)
|
||||
{
|
||||
if (!server.LobbyInfo.Slots.ContainsKey(s))
|
||||
if (!server.LobbyInfo.Slots.TryGetValue(s, out var slot))
|
||||
{
|
||||
Log.Write("server", $"Invalid slot: {s}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var slot = server.LobbyInfo.Slots[s];
|
||||
|
||||
if (slot.Closed || server.LobbyInfo.ClientInSlot(s) != null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -220,10 +220,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!actors.Contains(actor.Name))
|
||||
return false;
|
||||
|
||||
if (!baseBuilder.Info.BuildingLimits.ContainsKey(actor.Name))
|
||||
if (!baseBuilder.Info.BuildingLimits.TryGetValue(actor.Name, out var limit))
|
||||
return true;
|
||||
|
||||
return playerBuildings.Count(a => a.Info.Name == actor.Name) < baseBuilder.Info.BuildingLimits[actor.Name];
|
||||
return playerBuildings.Count(a => a.Info.Name == actor.Name) < limit;
|
||||
});
|
||||
|
||||
if (orderBy != null)
|
||||
|
||||
@@ -308,11 +308,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
clientActor, lookup.Keys, clientActor.Location, BlockedByActor.None,
|
||||
location =>
|
||||
{
|
||||
if (!lookup.ContainsKey(location))
|
||||
if (!lookup.TryGetValue(location, out var dock))
|
||||
return 0;
|
||||
|
||||
var dock = lookup[location];
|
||||
|
||||
// Prefer docks with less occupancy (multiplier is to offset distance cost):
|
||||
// TODO: add custom wieghts. E.g. owner vs allied.
|
||||
return dock.Trait.ReservationCount * client.OccupancyCostModifier;
|
||||
|
||||
@@ -51,10 +51,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var pos = map.CellContaining(self.CenterPosition);
|
||||
var terrainType = map.GetTerrainInfo(pos).Type;
|
||||
|
||||
if (!Info.TerrainModifier.ContainsKey(terrainType))
|
||||
if (!Info.TerrainModifier.TryGetValue(terrainType, out var modifiedDamage))
|
||||
return FullDamage;
|
||||
|
||||
return Info.TerrainModifier[terrainType];
|
||||
return modifiedDamage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
|
||||
{
|
||||
var key = MakeKey(prerequisites);
|
||||
if (!upgradables.ContainsKey(key))
|
||||
if (!upgradables.TryGetValue(key, out var list))
|
||||
{
|
||||
upgradables.Add(key, new List<(Actor, GrantConditionOnPrerequisite)>());
|
||||
upgradables.Add(key, list = new List<(Actor, GrantConditionOnPrerequisite)>());
|
||||
techTree.Add(key, prerequisites, 0, this);
|
||||
}
|
||||
|
||||
upgradables[key].Add((actor, u));
|
||||
list.Add((actor, u));
|
||||
|
||||
// Notify the current state
|
||||
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));
|
||||
|
||||
@@ -59,9 +59,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var key = MakeKey(t);
|
||||
|
||||
if (!Powers.ContainsKey(key))
|
||||
if (!Powers.TryGetValue(key, out var spi))
|
||||
{
|
||||
Powers.Add(key, t.CreateInstance(key, this));
|
||||
Powers.Add(key, spi = t.CreateInstance(key, this));
|
||||
|
||||
if (t.Info.Prerequisites.Length > 0)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
Powers[key].Instances.Add(t);
|
||||
spi.Instances.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,10 +80,10 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
var dockNode = new MiniYamlNodeBuilder("DockHost", "");
|
||||
|
||||
var lowActorName = actorNode.Key.ToLowerInvariant();
|
||||
if (!refineryNodes.ContainsKey(lowActorName) || !refineryNodes[lowActorName].Any(n => n.Key == "Type"))
|
||||
if (!refineryNodes.TryGetValue(lowActorName, out var nodes) || !nodes.Any(n => n.Key == "Type"))
|
||||
dockNode.AddNode("Type", "Unload");
|
||||
else
|
||||
dockNode.AddNode(refineryNodes[lowActorName].First(n => n.Key == "Type"));
|
||||
dockNode.AddNode(nodes.First(n => n.Key == "Type"));
|
||||
|
||||
foreach (var value in moveRefineyValues)
|
||||
{
|
||||
|
||||
@@ -622,10 +622,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
foreach (var content in mountedPackage.Contents)
|
||||
{
|
||||
if (!files.ContainsKey(content))
|
||||
if (!files.TryGetValue(content, out var list))
|
||||
files.Add(content, new List<IReadOnlyPackage> { mountedPackage });
|
||||
else
|
||||
files[content].Add(mountedPackage);
|
||||
list.Add(mountedPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +107,11 @@ namespace OpenRA
|
||||
try
|
||||
{
|
||||
var command = args[0];
|
||||
if (!actions.ContainsKey(command))
|
||||
if (!actions.TryGetValue(command, out var kvp))
|
||||
throw new NoSuchCommandException(command);
|
||||
|
||||
var action = actions[command].Key;
|
||||
var validateActionArgs = actions[command].Value;
|
||||
var action = kvp.Key;
|
||||
var validateActionArgs = kvp.Value;
|
||||
|
||||
if (validateActionArgs.Invoke(args))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user