From ed3ca78667fa3cecf6f1f53de069e86076a214d2 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 30 Oct 2023 16:18:16 +0100 Subject: [PATCH] Use TryGetValue instead of ContainsKey followed by indexing --- .../Lint/CheckTranslationReference.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index 91ee2b4cf0..ed252e878b 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -203,33 +203,33 @@ namespace OpenRA.Mods.Common.Lint var nodeType = node.Key.Split('@')[0]; foreach (var childNode in node.Value.Nodes) { - if (translatables.ContainsKey(nodeType)) + if (!translatables.TryGetValue(nodeType, out var translationNodes)) + continue; + + var childType = childNode.Key.Split('@')[0]; + var field = Array.Find(translationNodes, t => t.Name == childType); + if (field.Name == null) + continue; + + var key = childNode.Value.Value; + if (key == null) { - var childType = childNode.Key.Split('@')[0]; - var field = Array.Find(translatables[nodeType], t => t.Name == childType); - if (field.Name == null) - continue; + if (!field.Attribute.Optional) + emitError($"Widget `{node.Key}` in field `{childType}` has an empty translation reference."); - var key = childNode.Value.Value; - if (key == null) - { - if (!field.Attribute.Optional) - emitError($"Widget `{node.Key}` in field `{childType}` has an empty translation reference."); - - continue; - } - - if (referencedKeys.Contains(key)) - continue; - - if (!key.Any(char.IsLetter)) - continue; - - if (!translation.HasMessage(key)) - emitWarning($"`{key}` defined by `{node.Key}` is not present in `{language}` translation."); - - referencedKeys.Add(key); + continue; } + + if (referencedKeys.Contains(key)) + continue; + + if (!key.Any(char.IsLetter)) + continue; + + if (!translation.HasMessage(key)) + emitWarning($"`{key}` defined by `{node.Key}` is not present in `{language}` translation."); + + referencedKeys.Add(key); } foreach (var childNode in node.Value.Nodes)