pGina.Shared.Settings.pGinaDynamicSettings.CleanSubSettings C# (CSharp) Method

CleanSubSettings() public static method

Remove all sub-keys that are NOT in the provided list.
public static CleanSubSettings ( System.Guid pluginGuid, List toKeep ) : void
pluginGuid System.Guid The plugin's Guid.
toKeep List The list of sub-keys to keep, all others are deleted.
return void
        public static void CleanSubSettings(Guid pluginGuid, List<string> toKeep)
        {
            string subKey = string.Format(@"{0}\Plugins\{1}", pGinaRoot, pluginGuid.ToString());
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(subKey, true))
            {
                if (key != null)
                {
                    string[] names = key.GetSubKeyNames();
                    foreach (string n in names)
                    {
                        if (! toKeep.Contains(n))
                        {
                            key.DeleteSubKey(n, false);
                        }
                    }
                }
            }
        }