/// <summary> /// Open the SubKey with the given Name /// </summary> /// <param name="name">Name of the Key</param> /// <param name="create">create it if it does not exist</param> /// <returns>the opened/created subKey (null if created is false and the key does not exist)</returns> /// <exception cref="Exception">Thrown if the passed Element is not a Key but a value</exception> XmlRegistryKey OpenSubKey(string[] path, bool create) { XmlRegistryKey key = this; string curkey = ""; for (int i = 0; i < path.Length; i++) { key = key.OpenLocalSubKey(path[i], create); curkey += "\\" + path[i]; if (key == null) { return(null); //throw new Exception("The Key "+curkey+" was not found!"); } } return(key); }
/// <summary> /// Remove a SubKey /// </summary> /// <param name="path"></param> /// <param name="throwOnException"></param> void DeleteSubKey(string[] path, bool throwOnException) { if (path.Length < 1) { return; } XmlRegistryKey key = this; string curkey = ""; for (int i = 0; i < path.Length - 1; i++) { key = key.OpenLocalSubKey(path[i], false); curkey += "\\" + path[i]; if (key == null) { if (throwOnException) { throw new Exception("The Key " + curkey + " was not found!"); } else { return; } } } string name = path[path.Length - 1]; if (!key.tree.Contains(name) && throwOnException) { throw new Exception("The Key " + curkey + " was not found!"); } if (key.tree.Contains(name)) { key.tree.Remove(name); } }