Saving and Loading data in the registry (new version)


using System;
using Microsoft.Win32;

namespace Framework
    public static class RegistryAccess
        //Loading a value:
        public static string LoadSettingFromRegistry(string _registryKey, string settingKey)
            var MyKey = Registry.CurrentUser.OpenSubKey(_registryKey);
            if (MyKey == null)
                return null;
            var ValFromReg = (string) MyKey.GetValue(settingKey);
            return (ValFromReg != null) ? ValFromReg : null;

        //Saving a value:
        public static void SaveSettingToRegistry<T>(string _registryKey, string settingKey, T value)
            var MyKey = Registry.CurrentUser.CreateSubKey(_registryKey);
            var was = MyKey.GetValue(settingKey);
            MyKey.SetValue(settingKey, value);
            var isnow = MyKey.GetValue(settingKey);
            if (isnow.ToString() != value.ToString())
                throw new Exception("not changed");



What's your thoughts on this?


Protected by WP Anti Spam