/// <summary> /// Checks whether the configuration file contains unused keys and removes them. /// </summary> void CleanupConfig() { List <string[]> paths = new List <string[]>(); // iterate over the current configuration file to find all existing paths IEnumerator enumerator = Config.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)enumerator.Current; if (pair.Value.GetType().IsGenericType&& pair.Value.GetType().GetGenericTypeDefinition() == typeof(Dictionary <,>) && ((IDictionary)pair.Value).Count != 0) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (DictionaryEntry entry in (IDictionary)pair.Value) { dictionary.Add((string)entry.Key, entry.Value); } foreach (KeyValuePair <string, object> pair2 in dictionary) { if (pair2.Value.GetType().IsGenericType&& pair2.Value.GetType().GetGenericTypeDefinition() == typeof(Dictionary <,>) && ((IDictionary)pair.Value).Count != 0) { Dictionary <string, object> dictionary2 = new Dictionary <string, object>(); foreach (DictionaryEntry entry in (IDictionary)pair2.Value) { dictionary2.Add((string)entry.Key, entry.Value); } foreach (KeyValuePair <string, object> pair3 in dictionary2) { if (char.IsDigit(pair3.Key[0]) && pair3.Key[1].Equals('.') && char.IsDigit(pair3.Key[2]) && pair3.Key[3].Equals('.') && char.IsDigit(pair3.Key[4])) { paths.Add(new string[3] { pair.Key, pair2.Key, pair3.Key }); } else { paths.Add(new string[2] { pair.Key, pair2.Key }); break; } } } else { paths.Add(new string[2] { pair.Key, pair2.Key }); } } } else { paths.Add(new string[1] { pair.Key }); } } } finally { ((IDisposable)enumerator).Dispose(); } // iterate over the found paths and determine whether they are part of the default configuration foreach (string[] path in paths) { int index = -1; foreach (ConfigValue value in DefaultConfig.values.Values) { if (path.Length != value.path.Length) { continue; } for (int j = 0; j < path.Length; j++) { if (path[j].Equals(value.path[j])) { index = j > index ? j : index; } else { break; } } } // if a path is not part of the default configuration remove it if (index < path.Length - 1) { if (index == -1) { Config.Remove(path[index + 1]); } else { string[] strArray = new string[index + 1]; for (int j = 0; j < strArray.Length; j++) { strArray[j] = path[j]; } ((Dictionary <string, object>)Config.Get(strArray)).Remove(path[index + 1]); } } } }