Abstractions.Settings.DynamicSettings.SetDefault C# (CSharp) Method

SetDefault() public method

Sets the default value for a setting. Checks to see if the setting is already defined in the registry. If so, the method does nothing. Otherwise the setting is initialized to value.
public SetDefault ( string name, object value ) : void
name string The name of the setting
value object The default value for the setting
return void
        public void SetDefault(string name, object value)
        {
            try
            {
                GetSetting(name);
            }
            catch (KeyNotFoundException)
            {
                SetSetting(name, value);
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(m_rootKey, true))
                {
                    if (m_rootKey.EndsWith(@"\global", StringComparison.CurrentCultureIgnoreCase))
                    {
                        System.Security.AccessControl.RegistrySecurity acc = key.GetAccessControl(System.Security.AccessControl.AccessControlSections.All);
                        System.Security.AccessControl.RegistryAccessRule authenticated = new System.Security.AccessControl.RegistryAccessRule(
                            new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.AuthenticatedUserSid, null),
                            System.Security.AccessControl.RegistryRights.ReadKey,
                            System.Security.AccessControl.InheritanceFlags.None,
                            System.Security.AccessControl.PropagationFlags.None,
                            System.Security.AccessControl.AccessControlType.Allow);
                        acc.AddAccessRule(authenticated);
                        key.SetAccessControl(acc);
                    }
                }
            }
        }