From 2b824899ff271c0681f7d03f527ec5b549a2f98a Mon Sep 17 00:00:00 2001 From: blowfish Date: Thu, 7 Sep 2017 21:36:58 -0700 Subject: [PATCH] Inline out variable declarations Yay C#7 --- ModuleManager/MMPatchLoader.cs | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ModuleManager/MMPatchLoader.cs b/ModuleManager/MMPatchLoader.cs index c3e8b574..80e08a4c 100644 --- a/ModuleManager/MMPatchLoader.cs +++ b/ModuleManager/MMPatchLoader.cs @@ -184,8 +184,7 @@ private void PrePatchInit() modlist += "Non-DLL mods added (:FOR[xxx]):\n"; foreach (UrlDir.UrlConfig cfgmod in GameDatabase.Instance.root.AllConfigs) { - string name; - if (ParseCommand(cfgmod.type, out name) != Command.Insert) + if (ParseCommand(cfgmod.type, out string name) != Command.Insert) { progress.PatchAdded(); if (name.Contains(":FOR[")) @@ -969,8 +968,7 @@ public IEnumerator ApplyPatch(string Stage) try { string name = RemoveWS(mod.type); - string tmp; - Command cmd = ParseCommand(name, out tmp); + Command cmd = ParseCommand(name, out string tmp); if (cmd != Command.Insert) { @@ -1125,8 +1123,8 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon #if LOGSPAM vals += "\n " + modVal.name + "= " + modVal.value; #endif - string valName; - Command cmd = ParseCommand(modVal.name, out valName); + + Command cmd = ParseCommand(modVal.name, out string valName); if (cmd == Command.Special) { @@ -1149,8 +1147,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon if (assignMatch.Groups[2].Success) { - double os, s; - if (double.TryParse(modVal.value, out s) && double.TryParse(val.value, out os)) + if (double.TryParse(modVal.value, out double s) && double.TryParse(val.value, out double os)) { switch (assignMatch.Groups[2].Value[0]) { @@ -1295,9 +1292,19 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon if (varValue != null) { - ConfigNode.Value origVal; - string value = FindAndReplaceValue(mod, ref valName, varValue, newNode, op, index, - out origVal, context, match.Groups[3].Success, position, isPosStar, seperator); + string value = FindAndReplaceValue( + mod, + ref valName, + varValue, newNode, + op, + index, + out ConfigNode.Value origVal, + context, + match.Groups[3].Success, + position, + isPosStar, + seperator + ); if (value != null) { @@ -1417,16 +1424,14 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon } string subName = subMod.name; - string tmp; - Command command = ParseCommand(subName, out tmp); + Command command = ParseCommand(subName, out string tmp); if (command == Command.Insert) { ConfigNode newSubMod = new ConfigNode(subMod.name); newSubMod = ModifyNode(nodeStack.Push(newSubMod), subMod, context); subName = newSubMod.name; - int index; - if (subName.Contains(",") && int.TryParse(subName.Split(',')[1], out index)) + if (subName.Contains(",") && int.TryParse(subName.Split(',')[1], out int index)) { // In this case insert the node at position index (with the same node names) newSubMod.name = subName.Split(',')[0]; @@ -1461,8 +1466,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon ConfigNode newSubMod = new ConfigNode(toPaste.name); newSubMod = ModifyNode(nodeStack.Push(newSubMod), toPaste, context); - int index; - if (subName.LastIndexOf(",") > 0 && int.TryParse(subName.Substring(subName.LastIndexOf(",") + 1), out index)) + if (subName.LastIndexOf(",") > 0 && int.TryParse(subName.Substring(subName.LastIndexOf(",") + 1), out int index)) { // In this case insert the node at position index InsertNode(newNode, newSubMod, index); @@ -1917,8 +1921,7 @@ private static ConfigNode.Value RecurseVariableSearch(string path, NodeStack nod if (match.Groups[3].Success) { ConfigNode.Value newVal = new ConfigNode.Value(cVal.name, cVal.value); - int splitIdx = 0; - int.TryParse(match.Groups[3].Value, out splitIdx); + int.TryParse(match.Groups[3].Value, out int splitIdx); char sep = ','; if (match.Groups[4].Success) @@ -1998,7 +2001,6 @@ private static string ProcessVariableSearch(string value, NodeStack nodeStack, P oValue = strArray[posIndex]; if (op != ' ') { - double s, os; if (op == '^') { try @@ -2024,7 +2026,7 @@ private static string ProcessVariableSearch(string value, NodeStack nodeStack, P return null; } } - else if (double.TryParse(value, out s) && double.TryParse(oValue, out os)) + else if (double.TryParse(value, out double s) && double.TryParse(oValue, out double os)) { switch (op) { @@ -2316,8 +2318,7 @@ public static bool WildcardMatchValues(ConfigNode node, string type, string valu if (!compare && WildcardMatch(values[i], value)) return true; - double val2; - if (compare && Double.TryParse(values[i], out val2) + if (compare && Double.TryParse(values[i], out double val2) && ((value[0] == '<' && val2 < val) || (value[0] == '>' && val2 > val))) { return true;