Clear empty keys as you go

This commit is contained in:
Matt Nadareski
2020-10-31 21:20:16 -07:00
parent 6f789d2454
commit e3b32fd974
2 changed files with 31 additions and 0 deletions

View File

@@ -166,6 +166,9 @@ namespace BurnOutSharp
}
}
// Clear out any empty keys
Utilities.ClearEmptyKeys(protections);
return protections;
}
@@ -569,6 +572,9 @@ namespace BurnOutSharp
#endregion
}
// Clear out any empty keys
Utilities.ClearEmptyKeys(protections);
return protections;
}
}

View File

@@ -67,6 +67,31 @@ namespace BurnOutSharp
}
}
/// <summary>
/// Remove empty or null keys from a results dictionary
/// </summary>
/// <param name="original">Dictionary to clean</param>
public static void ClearEmptyKeys(Dictionary<string, List<string>> original)
{
// If the dictionary is missing, we can't do anything
if (original == null)
return;
// Get a list of all of the keys
var keys = original.Keys.ToList();
// Iterate and reset keys
for (int i = 0; i < keys.Count; i++)
{
// Get the current key
string key = keys[i];
// If the key is empty, remove it
if (original[key] == null || !original[key].Any())
original.Remove(key);
}
}
/// <summary>
/// Prepend a parent path from dictionary keys, if possible
/// </summary>