Skip to content

Commit

Permalink
Inline out variable declarations
Browse files Browse the repository at this point in the history
Yay C#7
  • Loading branch information
blowfishpro committed Sep 8, 2017
1 parent ca12c39 commit 2b82489
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions ModuleManager/MMPatchLoader.cs
Expand Up @@ -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["))
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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])
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1998,7 +2001,6 @@ private static string ProcessVariableSearch(string value, NodeStack nodeStack, P
oValue = strArray[posIndex];
if (op != ' ')
{
double s, os;
if (op == '^')
{
try
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2b82489

Please sign in to comment.