public IOption Add(string name, object def, OptionEventHandler action)
        {
            IOption opt = GetByName(name);

            if (opt == null)
            {
                try
                {
                    RegistryKey folderKey = FolderKey(path);
                    object      regValue  = folderKey.GetValue(name);

                    if (regValue != null)
                    {
                        RegistryValueKind kind = folderKey.GetValueKind(name);
                        switch (kind)
                        {
                        case RegistryValueKind.DWord:
                            opt = new IntOption(path, name, (int)def);
                            opt.ValueChanged += action;
                            opt.Value         = regValue;
                            break;

                        case RegistryValueKind.String:
                        default:
                            if (def is int)
                            {
                                opt = new IntOption(path, name, (int)def);
                            }
                            else
                            {
                                opt = new Option(path, name, (string)def);
                            }
                            opt.ValueChanged += action;
                            opt.Value         = regValue;
                            break;
                        }
                    }
                    else
                    {
                        if (def is int)
                        {
                            opt = new IntOption(path, name, (int)def);
                        }
                        else
                        {
                            opt = new Option(path, name, (string)def);
                        }
                        opt.ValueChanged += action;
                        opt.Value         = def;
                        opt.Save();
                    }
                    options.Add(opt);
                }
                catch
                {
                }
            }

            return(opt);
        }
Example #2
0
 public string LoadStringOption(string name, string def, OptionEventHandler action)
 {
     return(options.Add(name, def, action).Value.ToString());
 }
Example #3
0
 /// <summary>
 /// Загрузка нового параметра из реестра
 /// В случае отсутствия создается новый
 /// </summary>
 /// <typeparam name="T">тип параметра. Int или String</typeparam>
 /// <param name="name">Название параметра</param>
 /// <param name="def">Значеение, в случае отсутвия параметра в реестре</param>
 /// <param name="action">событие изменения параметра в программе</param>
 /// <returns></returns>
 public IOption LoadOption <T>(string name, T def, OptionEventHandler action)
 {
     return(options.Add(name, def, action));
 }