From e3b32fd974d52600765ff99a237d51b31ffaedd2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 31 Oct 2020 21:20:16 -0700 Subject: [PATCH] Clear empty keys as you go --- BurnOutSharp/Scanner.cs | 6 ++++++ BurnOutSharp/Utilities.cs | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index fd672456..40b456d4 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -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; } } diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs index 49418237..9132bfef 100644 --- a/BurnOutSharp/Utilities.cs +++ b/BurnOutSharp/Utilities.cs @@ -67,6 +67,31 @@ namespace BurnOutSharp } } + /// + /// Remove empty or null keys from a results dictionary + /// + /// Dictionary to clean + public static void ClearEmptyKeys(Dictionary> 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); + } + } + /// /// Prepend a parent path from dictionary keys, if possible ///